dailyturn

package
v0.0.0-...-de2618e Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeTooShort is when the time between two ASNs is not long enough to compute the daily turn
	ErrTimeTooShort = errors.New("time between asn is too short, daily turn will not be computed")
	// ErrNoInventory is when an ASN comes in but there is no existing inventory for that product
	ErrNoInventory = errors.New("no inventory found for product, daily turn will not be computed")
)

Functions

func CreateHistoryMap

func CreateHistoryMap(dbs *sql.DB, tags []tag.Tag) map[string]History

CreateHistoryMap builds a map[string] based of array of product ids for search efficiency

func ProcessIncomingASNList

func ProcessIncomingASNList(dbs *sql.DB, asnList []tag.AdvanceShippingNotice)

ProcessIncomingASNList takes a list of advance shipping notices and ingests it into the database for calculating the dailyturn. NOTE: this should be called AFTER ingesting the new tags into the database. The reason for this is we don't want to double count EPCs already in the database by simply adding quantity to the inventory count, so we let the inventory count fill up via the processing already in place.

func Upsert

func Upsert(dbs *sql.DB, history History) error

Types

type History

type History struct {
	ProductID string   `json:"product_id" bson:"product_id"`
	DailyTurn float64  `json:"daily_turn" bson:"daily_turn"`
	Records   []Record `json:"records" bson:"records"`
	Timestamp int64    `json:"last_timestamp" bson:"last_timestamp"`
}

History is the model of the history of daily turn computations for a product

func FindHistoryByProductId

func FindHistoryByProductId(dbs *sql.DB, productId string) (History, error)

FindHistoryByProductId searches DB for tag based on the productId value Returns the History if found or empty History if it does not exist

func (*History) ComputeAverageDailyTurn

func (history *History) ComputeAverageDailyTurn()

func (*History) Scan

func (history *History) Scan(value interface{}) error

Scan implements sql.Scanner interfaces

func (History) Value

func (history History) Value() (driver.Value, error)

Value implements driver.Valuer interfaces

type PresentOrDepartedResults

type PresentOrDepartedResults struct {
	ProductId    string `db:"_id"`
	DepartedTags int    `db:"departedTags"`
	PresentTags  int    `db:"presentTags"`
}

func FindPresentOrDepartedTagsSinceTimestamp

func FindPresentOrDepartedTagsSinceTimestamp(db *sql.DB, productId string, sinceTimestamp int64) (PresentOrDepartedResults, error)

type Record

type Record struct {
	Present           int     `json:"present" bson:"present"`
	Departed          int     `json:"departed" bson:"departed"`
	DailyTurn         float64 `json:"daily_turn" bson:"daily_turn"`
	PreviousTimestamp int64   `json:"previous_timestamp" bson:"previous_timestamp"`
	Timestamp         int64   `json:"timestamp" bson:"timestamp"`
}

Record is the model for each daily turn data point

func (*Record) ComputeDailyTurn

func (record *Record) ComputeDailyTurn() error

Jump to

Keyboard shortcuts

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