meals

package
v0.0.0-...-0dfd57a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Service meals tracks calories and imports them from fddb.

Index

Constants

View Source
const (
	Milligram Weight = 1.0 / 1000
	Gram      Weight = 1000 * Milligram
	Kilogram         = 1000 * Gram

	Joule     Energy = 1.0 / 1000
	Kilojoule        = 1000 * Joule
	Kcal             = 4184 * Joule

	Millilitre Volume = 1.0
	Litre      Volume = 1000 * Millilitre
)

Variables

View Source
var Module = &services.Module{
	Name:        "meals",
	Version:     "1.0",
	NewInstance: NewService,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	FDDB struct {
		ApiKey   string
		Username string
		Password string
	}
}

type Dependencies

type Dependencies struct {
	DB     *gorm.DB
	Config services.Config
	Client sarif.Client
}

type Energy

type Energy float64

func (*Energy) Scan

func (w *Energy) Scan(src interface{}) error

func (Energy) String

func (v Energy) String() string

func (Energy) StringKcal

func (v Energy) StringKcal() string

func (*Energy) UnmarshalJSON

func (w *Energy) UnmarshalJSON(item []byte) error

type Product

type Product struct {
	Id    int64  `json:"-"`
	RefId int64  `json:"ref_id,omitempty"`
	Name  string `json:"name,omitempty"`
	Code  string `json:"code,omitempty"`

	ServingWeight Weight `json:"serving_weight,omitempty"`
	ServingVolume Volume `json:"serving_volume,omitempty"`
	Stats

	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

func (Product) Servings

func (p Product) Servings(n float64) Stats

func (Product) TableName

func (p Product) TableName() string

type Service

type Service struct {
	DB *gorm.DB
	sarif.Client
	// contains filtered or unexported fields
}

func NewService

func NewService(deps *Dependencies) *Service

func (*Service) Enable

func (s *Service) Enable() error

func (*Service) FddbLoop

func (s *Service) FddbLoop()

func (*Service) FetchFddb

func (s *Service) FetchFddb(day time.Time) error

type Serving

type Serving struct {
	Id           int64     `json:"-"`
	RefId        int64     `json:"ref_id,omitempty"`
	Name         string    `json:"name"`
	AmountWeight Weight    `json:"amount_weight"`
	AmountVolume Volume    `json:"amount_volume"`
	Time         time.Time `json:"time" sql:"index"`

	ProductId int64    `json:"-"`
	Product   *Product `json:"product,omitempty"`

	Size            float64 `json:"size,omitempty" sql:"-"`
	CalculatedStats *Stats  `json:"stats,omitempty"`
}

func (*Serving) Stats

func (s *Serving) Stats() Stats

func (Serving) TableName

func (s Serving) TableName() string

type ServingFilter

type ServingFilter struct {
	After  time.Time `json:"after"`
	Before time.Time `json:"before"`
}

type ServingStats

type ServingStats struct {
	Servings []*Serving `json:"servings,omitempty"`
	Stats
}

func (ServingStats) String

func (s ServingStats) String() string

type Stats

type Stats struct {
	Weight Weight `json:"weight,omitempty"`
	Volume Volume `json:"volume,omitempty"`
	Energy Energy `json:"energy,omitempty"`

	Fat           Weight `json:"fat,omitempty"`
	Carbohydrates Weight `json:"carbohydrates,omitempty"`
	Sugar         Weight `json:"sugar,omitempty"`
	Protein       Weight `json:"protein,omitempty"`
	Salt          Weight `json:"salt,omitempty"`
	Water         Volume `json:"water,omitempty"`
}

func (*Stats) Add

func (s *Stats) Add(o Stats)

func (*Stats) Multiply

func (s *Stats) Multiply(size float64)

func (*Stats) Normalize

func (s *Stats) Normalize()

func (*Stats) ScaleToVolume

func (s *Stats) ScaleToVolume(v Volume)

func (*Stats) ScaleToWeight

func (s *Stats) ScaleToWeight(w Weight)

type Volume

type Volume float64

func (*Volume) Scan

func (w *Volume) Scan(src interface{}) error

func (Volume) String

func (v Volume) String() string

func (*Volume) UnmarshalJSON

func (w *Volume) UnmarshalJSON(item []byte) error

type Weight

type Weight float64

func (*Weight) Scan

func (w *Weight) Scan(src interface{}) error

func (Weight) String

func (v Weight) String() string

func (*Weight) UnmarshalJSON

func (w *Weight) UnmarshalJSON(item []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL