attribute

package
v0.0.0-...-a9c8cbe Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModelName -
	ModelName string = "attribute"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GetParamFunc

type GetParamFunc func(formula string) (params []string, err error)

GetParamFunc - Function that returns formula parameters from an attribute record

type Model

type Model struct {
	Env       env.Env
	Logger    zerolog.Logger
	RepoStore *repostore.RepoStore
}

Model -

func NewModel

func NewModel(e env.Env, l zerolog.Logger, ms *repostore.RepoStore) (m *Model, err error)

NewModel -

func (*Model) CreateAttributeRec

func (m *Model) CreateAttributeRec(rec *record.AppAttributeRecord) (err error)

CreateAttributeRec -

func (*Model) DeleteAttributeRec

func (m *Model) DeleteAttributeRec(appAttributeID string) (err error)

DeleteAttributeRec -

func (*Model) GetAttributeRec

func (m *Model) GetAttributeRec(ID string) (rec *record.AppAttributeRecord, err error)

GetAttributeRec -

func (*Model) GetAttributeRecs

func (m *Model) GetAttributeRecs(params map[string]interface{}) (recs []*record.AppAttributeRecord, err error)

GetAttributeRecs -

func (*Model) GetAttributeValues

func (m *Model) GetAttributeValues(rec *record.AppAttributeRecord, params map[string]int) (
	calculatedValue, minValue, maxValue int,
	err error)

GetAttributeValues - returns the calculated, min and max values of an attribute based on its formula, params is expected to contain calculated values for existing attributes that the formula depends on. Be sure to OrderEntityAttributes before attempting to cycle calculating their values.

func (*Model) GetEntityAttributeValue

func (m *Model) GetEntityAttributeValue(rec *record.AppEntityAttributeRecord, params map[string]int) (
	calculatedValue, minValue, maxValue int,
	err error)

GetEntityAttributeValue - See GetAttributeValue

func (*Model) GetEntityAttributeValues

func (m *Model) GetEntityAttributeValues(recs []*record.AppEntityAttributeRecord) (map[string]int, error)

GetEntityAttributeValues - Sorts, calculates and returns resulting values

func (*Model) GetFormulaParams

func (m *Model) GetFormulaParams(rec *record.AppAttributeRecord) (params []string, err error)

GetFormulaParams - returns array of parameter names from the formula that are required to calculate an attribute value.

func (*Model) GetMaxValueFormulaParams

func (m *Model) GetMaxValueFormulaParams(rec *record.AppAttributeRecord) (params []string, err error)

GetMaxValueFormulaParams -

func (*Model) GetMinValueFormulaParams

func (m *Model) GetMinValueFormulaParams(rec *record.AppAttributeRecord) (params []string, err error)

GetMinValueFormulaParams -

func (*Model) Init

func (m *Model) Init() error

Init -

func (*Model) OrderAttributeRecs

func (m *Model) OrderAttributeRecs(attrs []*record.AppAttributeRecord) error

OrderAttributeRecs - orders attributes based on formula parameter dependencies, to be used for ordering attributes prior to calculating attribute values.

func (*Model) OrderEntityAttributeRecs

func (m *Model) OrderEntityAttributeRecs(attrs []*record.AppEntityAttributeRecord) error

OrderEntityAttributeRecs - see OrderAttributes

func (*Model) UpdateAttributeRec

func (m *Model) UpdateAttributeRec(rec *record.AppAttributeRecord) (err error)

UpdateAttributeRec -

func (*Model) ValidateAttributeRecs

func (m *Model) ValidateAttributeRecs(attrs []*record.AppAttributeRecord) error

ValidateAttributeRecs - checks attributes to ensure there are no cyclic dependencies in formula params, that is, attribute X cannot depend on attribute Y that also depends on attribute X. Also checks that all attribute formula are correct. This function assumes attribute records are ordered before being passed in.

func (*Model) ValidateAttributes

func (m *Model) ValidateAttributes(appID string) error

ValidateAttributes -

func (*Model) ValidateEntityAttributeRecs

func (m *Model) ValidateEntityAttributeRecs(attrs []*record.AppEntityAttributeRecord) error

ValidateEntityAttributeRecs - checks attributes to ensure there are no cyclic dependencies in formula params, that is, attribute X cannot depend on attribute Y that also depends on attribute X. Also checks that all attribute formula are correct. This function assumes attribute records are ordered before being passed in.

type SortableAttribute

type SortableAttribute struct {
	AttributeRec       *record.AppAttributeRecord
	EntityAttributeRec *record.AppEntityAttributeRecord
}

SortableAttribute -

type Sorter

type Sorter struct {
	Logger       zerolog.Logger
	SwapA        int
	SwapB        int
	GetParamFunc GetParamFunc
	Attributes   []*SortableAttribute
}

Sorter -

func NewSorter

func NewSorter(l zerolog.Logger, f GetParamFunc) (*Sorter, error)

NewSorter - Returns a new sorter

func (*Sorter) Len

func (s *Sorter) Len() int

func (*Sorter) Less

func (s *Sorter) Less(i, j int) bool

func (*Sorter) Sort

func (s *Sorter) Sort(sortAttributes []*SortableAttribute) error

Sort -

func (*Sorter) Swap

func (s *Sorter) Swap(i, j int)

Jump to

Keyboard shortcuts

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