osusu

package
v0.0.0-...-bb33ca5 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB is the gorm database for the app.

Functions

func ComputeNormScores

func ComputeNormScores(recipes []*Recipe)

ComputeNormScores computes the normalized base and text encoding scores for each recipe. The base and text encoding score indices already need to be computed. The normalized scores are the z-scores centered at 50 and bounded at roughly 0 and 100.

func MulScore

func MulScore[T num.Number](s *Score, scalar T)

func OpenDB

func OpenDB() error

OpenDB opens and sets up the database.

Types

type Categories

type Categories int64 //enums:bitflag
const (
	Breakfast Categories = iota
	Brunch
	Lunch
	Dinner
	Dessert
	Snack
	Appetizer
	Side
	Drink
	Ingredient
)
const CategoriesN Categories = 10

CategoriesN is the highest valid value for type Categories, plus one.

func CategoriesValues

func CategoriesValues() []Categories

CategoriesValues returns all possible values for the type Categories.

func (Categories) BitIndexString

func (i Categories) BitIndexString() string

BitIndexString returns the string representation of this Categories value if it is a bit index value (typically an enum constant), and not an actual bit flag value.

func (Categories) Desc

func (i Categories) Desc() string

Desc returns the description of the Categories value.

func (Categories) HasFlag

func (i Categories) HasFlag(f enums.BitFlag) bool

HasFlag returns whether these bit flags have the given bit flag set.

func (Categories) Int64

func (i Categories) Int64() int64

Int64 returns the Categories value as an int64.

func (Categories) IsValid

func (i Categories) IsValid() bool

IsValid returns whether the value is a valid option for type Categories.

func (Categories) MarshalText

func (i Categories) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Categories) Scan

func (i *Categories) Scan(value any) error

Value implements the [sql.Scanner] interface.

func (*Categories) SetFlag

func (i *Categories) SetFlag(on bool, f ...enums.BitFlag)

SetFlag sets the value of the given flags in these flags to the given value.

func (*Categories) SetInt64

func (i *Categories) SetInt64(in int64)

SetInt64 sets the Categories value from an int64.

func (*Categories) SetString

func (i *Categories) SetString(s string) error

SetString sets the Categories value from its string representation, and returns an error if the string is invalid.

func (*Categories) SetStringOr

func (i *Categories) SetStringOr(s string) error

SetStringOr sets the Categories value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.

func (Categories) String

func (i Categories) String() string

String returns the string representation of this Categories value.

func (*Categories) UnmarshalText

func (i *Categories) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Categories) Value

func (i Categories) Value() (driver.Value, error)

Scan implements the driver.Valuer interface.

func (Categories) Values

func (i Categories) Values() []enums.Enum

Values returns all possible values for the type Categories.

type Cuisines

type Cuisines int64 //enums:bitflag
const (
	African Cuisines = iota
	American
	Asian
	British
	Chinese
	European
	French
	Greek
	Indian
	Italian
	Japanese
	Jewish
	Korean
	LatinAmerican // Latin American
	Mexican
	MiddleEastern // Middle Eastern
	Thai
)
const CuisinesN Cuisines = 17

CuisinesN is the highest valid value for type Cuisines, plus one.

func CuisinesValues

func CuisinesValues() []Cuisines

CuisinesValues returns all possible values for the type Cuisines.

func (Cuisines) BitIndexString

func (i Cuisines) BitIndexString() string

BitIndexString returns the string representation of this Cuisines value if it is a bit index value (typically an enum constant), and not an actual bit flag value.

func (Cuisines) Desc

func (i Cuisines) Desc() string

Desc returns the description of the Cuisines value.

func (Cuisines) HasFlag

func (i Cuisines) HasFlag(f enums.BitFlag) bool

HasFlag returns whether these bit flags have the given bit flag set.

func (Cuisines) Int64

func (i Cuisines) Int64() int64

Int64 returns the Cuisines value as an int64.

func (Cuisines) IsValid

func (i Cuisines) IsValid() bool

IsValid returns whether the value is a valid option for type Cuisines.

func (Cuisines) MarshalText

func (i Cuisines) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Cuisines) Scan

func (i *Cuisines) Scan(value any) error

Value implements the [sql.Scanner] interface.

func (*Cuisines) SetFlag

func (i *Cuisines) SetFlag(on bool, f ...enums.BitFlag)

SetFlag sets the value of the given flags in these flags to the given value.

func (*Cuisines) SetInt64

func (i *Cuisines) SetInt64(in int64)

SetInt64 sets the Cuisines value from an int64.

func (*Cuisines) SetString

func (i *Cuisines) SetString(s string) error

SetString sets the Cuisines value from its string representation, and returns an error if the string is invalid.

func (*Cuisines) SetStringOr

func (i *Cuisines) SetStringOr(s string) error

SetStringOr sets the Cuisines value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.

func (Cuisines) String

func (i Cuisines) String() string

String returns the string representation of this Cuisines value.

func (*Cuisines) UnmarshalText

func (i *Cuisines) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Cuisines) Value

func (i Cuisines) Value() (driver.Value, error)

Scan implements the driver.Valuer interface.

func (Cuisines) Values

func (i Cuisines) Values() []enums.Enum

Values returns all possible values for the type Cuisines.

type Entry

type Entry struct {
	gorm.Model  `view:"-"`
	MealID      uint `view:"-"`
	Meal        Meal `view:"-"`
	UserID      uint `view:"-"`
	User        User `view:"-"`
	Time        time.Time
	Category    Categories
	Source      Sources
	Taste       int `view:"slider" min:"0" def:"50" max:"100"`
	Cost        int `view:"slider" min:"0" def:"50" max:"100"`
	Effort      int `view:"slider" min:"0" def:"50" max:"100"`
	Healthiness int `view:"slider" min:"0" def:"50" max:"100"`
}

func (*Entry) Score

func (e *Entry) Score() *Score

type Group

type Group struct {
	gorm.Model `view:"-"`
	Name       string
	Code       string `view:"-"`
	OwnerID    uint   `view:"-"`
	Owner      User   `view:"-"`
	Members    []User
}

type Meal

type Meal struct {
	gorm.Model  `view:"-"`
	GroupID     uint  `view:"-"`
	Group       Group `view:"-"`
	Name        string
	Description string
	Image       string
	Source      Sources
	Category    Categories
	Cuisine     Cuisines
}

func (*Meal) Score

func (m *Meal) Score(entries []Entry) *Score

func (*Meal) Text

func (m *Meal) Text() string

Text returns all of the text associated with the meal as one string. It is intended to be used as text encoding model data, so it should not be presented to end-users.

type Nutrition

type Nutrition struct {
	Calories       int // unit: Calories (kcal)
	Carbohydrate   int // g
	Cholesterol    int // mg
	Fiber          int // g
	Protein        int // g
	Fat            int // g
	SaturatedFat   int // g
	UnsaturatedFat int // g
	Sodium         int // mg
	Sugar          int // g
}

Nutrition represents the nutritional information of a recipe

type Options

type Options struct {
	Categories            Categories
	Sources               Sources
	Cuisines              Cuisines
	TasteImportance       int `view:"slider" min:"0" def:"50" max:"100"`
	RecencyImportance     int `view:"slider" min:"0" def:"50" max:"100"`
	CostImportance        int `view:"slider" min:"0" def:"50" max:"100"`
	EffortImportance      int `view:"slider" min:"0" def:"50" max:"100"`
	HealthinessImportance int `view:"slider" min:"0" def:"50" max:"100"`
}

func DefaultOptions

func DefaultOptions() *Options

type Recipe

type Recipe struct {
	Name              string
	URL               string
	Description       string
	Image             string
	Author            string
	DatePublished     time.Time
	DateModified      time.Time
	Category          []string   `view:"-"`
	CategoryFlag      Categories `json:"-" label:"Category"`
	Cuisine           []string   `view:"-"`
	CuisineFlag       Cuisines   `json:"-" label:"Cuisine"`
	Ingredients       []string
	TotalTime         string        `view:"-"`
	PrepTime          string        `view:"-"`
	CookTime          string        `view:"-"`
	TotalTimeDuration time.Duration `json:"-" label:"Total time" viewif:"TotalTime!=\"\""`
	PrepTimeDuration  time.Duration `json:"-" label:"Prep time" viewif:"PrepTime!=\"\""`
	CookTimeDuration  time.Duration `json:"-" label:"Cook time" viewif:"CookTime!=\"\""`
	Yield             int
	RatingValue       float64 `view:"slider" min:"0" max:"5"`
	RatingCount       int
	RatingScore       int `view:"-" json:"-"`
	RatingWeight      int `view:"-" json:"-"`
	Nutrition         Nutrition
	Source            string `json:"-"`
	// index score values for base information about a recipe (using info like calories, time, ingredients, etc)
	BaseScoreIndex Score `json:"-"`
	// percentile values of BaseScoreIndex
	BaseScore Score
	// keyed by meal ID
	TextEncodingScores map[uint]float32 `json:"-"`
	// index score values for text encoding based scores
	EncodingScoreIndex Score `json:"-"`
	// percentile values of EncodingScoreIndex
	EncodingScore Score `json:"-"`
	Score         Score `json:"-"`
}

A Recipe is an external recipe that can be used for new meal recommendations

func (*Recipe) ComputeBaseScoreIndex

func (r *Recipe) ComputeBaseScoreIndex()

ComputeBaseScoreIndex computes and sets the base score index for the given recipe

func (*Recipe) Init

func (r *Recipe) Init() error

Init initializes computed values in the recipe after it has been loaded.

func (*Recipe) Text

func (r *Recipe) Text() string

Text returns all of the text associated with the recipe as one string. It is intended to be used as text encoding model data, so it should not be presented to end-users.

type Score

type Score struct {
	Taste       int
	Recency     int
	Cost        int
	Effort      int
	Healthiness int
	Total       int
}

func AverageScore

func AverageScore(scores []*Score) *Score

func (*Score) ComputeTotal

func (s *Score) ComputeTotal(opts *Options)

type Sources

type Sources int64 //enums:bitflag
const (
	Cooking Sources = iota
	DineIn
	Takeout
	Delivery
)
const SourcesN Sources = 4

SourcesN is the highest valid value for type Sources, plus one.

func SourcesValues

func SourcesValues() []Sources

SourcesValues returns all possible values for the type Sources.

func (Sources) BitIndexString

func (i Sources) BitIndexString() string

BitIndexString returns the string representation of this Sources value if it is a bit index value (typically an enum constant), and not an actual bit flag value.

func (Sources) Desc

func (i Sources) Desc() string

Desc returns the description of the Sources value.

func (Sources) HasFlag

func (i Sources) HasFlag(f enums.BitFlag) bool

HasFlag returns whether these bit flags have the given bit flag set.

func (Sources) Int64

func (i Sources) Int64() int64

Int64 returns the Sources value as an int64.

func (Sources) IsValid

func (i Sources) IsValid() bool

IsValid returns whether the value is a valid option for type Sources.

func (Sources) MarshalText

func (i Sources) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Sources) Scan

func (i *Sources) Scan(value any) error

Value implements the [sql.Scanner] interface.

func (*Sources) SetFlag

func (i *Sources) SetFlag(on bool, f ...enums.BitFlag)

SetFlag sets the value of the given flags in these flags to the given value.

func (*Sources) SetInt64

func (i *Sources) SetInt64(in int64)

SetInt64 sets the Sources value from an int64.

func (*Sources) SetString

func (i *Sources) SetString(s string) error

SetString sets the Sources value from its string representation, and returns an error if the string is invalid.

func (*Sources) SetStringOr

func (i *Sources) SetStringOr(s string) error

SetStringOr sets the Sources value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.

func (Sources) String

func (i Sources) String() string

String returns the string representation of this Sources value.

func (*Sources) UnmarshalText

func (i *Sources) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Sources) Value

func (i Sources) Value() (driver.Value, error)

Scan implements the driver.Valuer interface.

func (Sources) Values

func (i Sources) Values() []enums.Enum

Values returns all possible values for the type Sources.

type User

type User struct {
	gorm.Model `view:"-"`
	GroupID    uint
	Email      string
	Name       string
	Locale     string
	Picture    string
}

Jump to

Keyboard shortcuts

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