db

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBTIMEOUT   = 10
	DATEPATTERN = "2006-01-02 15:04:05"
	STATSCOL    = "population_stats"
	EXCCOL      = "exceptions"
)

DB Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	ID           primitive.ObjectID  `bson:"_id,omitempty"`
	Name         string              `bson:"name"`
	AppID        int                 `bson:"app_id"`
	Metrics      []Metric            `bson:"metrics"`
	DailyMetrics []stats.DailyMetric `bson:"daily_metrics"`
	Domain       string              `bson:"domain"`
}

App - Entry in the DB is of this format

type AppShadow

type AppShadow struct {
	Date time.Time `bson:"date"`
	Ref  dbAppRef  `bson:"reference"`
}

AppShadow : app data (no historical data)

type Db

type Db interface {
	GetAppList() ([]AppShadow, error)
	GetMonthlyList(id primitive.ObjectID) (*[]Metric, error)
	GetDailyList(id primitive.ObjectID) (*[]stats.DailyMetric, error)
	GetExceptions() (*[]AppShadow, error)

	PushDaily(id primitive.ObjectID, element *stats.DailyMetric) error
	PushMonthly(id primitive.ObjectID, element *Metric) error
	PushException(app *AppShadow) error

	UpdateMonthlyList(id primitive.ObjectID, newMetricList *[]Metric) error
	UpdateDailyList(id primitive.ObjectID, newMetricList *[]stats.DailyMetric) error

	FlushExceptions()
}

Db interface

type Dbcfg

type Dbcfg env.Config

Dbcfg : composition: Dbcfg implements interface (allows implementation of the below methods)

func (Dbcfg) FlushExceptions

func (cfg Dbcfg) FlushExceptions()

FlushExceptions : Clear exception queue

func (Dbcfg) GetAppList

func (cfg Dbcfg) GetAppList() ([]AppShadow, error)

GetAppList : Get List of Apps as AppMeta

func (Dbcfg) GetDailyList

func (cfg Dbcfg) GetDailyList(id primitive.ObjectID) (*[]stats.DailyMetric, error)

GetDailyList : Fetch all daily metrics

func (Dbcfg) GetExceptions

func (cfg Dbcfg) GetExceptions() (*[]AppShadow, error)

GetExceptions - Return list of AppShadows

func (Dbcfg) GetMonthlyList

func (cfg Dbcfg) GetMonthlyList(id primitive.ObjectID) (*[]Metric, error)

GetMonthlyList : retrieve previous month's metrics

func (Dbcfg) PushDaily

func (cfg Dbcfg) PushDaily(id primitive.ObjectID, element *stats.DailyMetric) error

PushDaily : Insert daily metric

func (Dbcfg) PushException

func (cfg Dbcfg) PushException(app *AppShadow) error

PushException : Insert exception instance

func (Dbcfg) PushMonthly

func (cfg Dbcfg) PushMonthly(id primitive.ObjectID, element *Metric) error

PushMonthly : Insert new month instance

func (Dbcfg) UpdateDailyList

func (cfg Dbcfg) UpdateDailyList(id primitive.ObjectID, newMetricList *[]stats.DailyMetric) error

UpdateDailyList : Update daily metric list for app

func (Dbcfg) UpdateMonthlyList

func (cfg Dbcfg) UpdateMonthlyList(id primitive.ObjectID, newMetricList *[]Metric) error

UpdateMonthlyList : update list

type Metric

type Metric struct {
	Date        time.Time `bson:"date"`
	AvgPlayers  int       `bson:"avgplayers"`
	Gain        string    `bson:"gain"`
	GainPercent string    `bson:"gainpercent"`
	Peak        int       `bson:"peak"`
}

Metric element

Jump to

Keyboard shortcuts

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