tracula

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 14 Imported by: 0

README

tracula

A simple package to collect and organise game population data.
Ideally used for creating batch processes in game tracking apps.

Installation

go get github.com/J-leg/tracula

Usage

Simple implementation of a periodic batch process on Google Cloud Platform (as a GCloud function) here

Documentation

Index

Constants

View Source
const (
	MONTHS           = 12
	FUNCTIONDURATION = 8

	DAILY    = 0
	MONTHLY  = 1
	RECOVERY = 2
	REFRESH  = 3
	TRACKER  = 4

	ROUTINELIMIT        = 50 // Max number of go-routines running concurrently
	REFRESHROUTINELIMIT = 50

	NOACTIVITYLIMIT = 3
)

Constants

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

DB Constants

View Source
const (
	HOURSPERDAY    = 24
	RETENTIONLIMIT = 90
)

Variables

This section is empty.

Functions

func Execute

func Execute(cfg *Config)

Execute : Core execution for daily updates Update all apps

func ExecuteMonthly

func ExecuteMonthly(cfg *Config)

ExecuteMonthly : Monthly process

func ExecuteRecovery

func ExecuteRecovery(cfg *Config)

ExecuteRecovery : Best effort to retry all exception instances

func ExecuteRefresh added in v1.0.5

func ExecuteRefresh(cfg *Config)

ExecuteRefresh updates the app library

func ExecuteTracker added in v1.0.5

func ExecuteTracker(cfg *Config)

ExecuteTracker runs a job to aggregate any apps that are worth tracking

Types

type App

type App struct {
	ID           primitive.ObjectID `bson:"_id,omitempty"`
	Metrics      []Metric           `bson:"metrics"`
	DailyMetrics []DailyMetric      `bson:"daily_metrics"`
	StaticData   StaticAppData      `bson:"static_data"`
}

type AppRef added in v1.0.5

type AppRef struct {
	ID         primitive.ObjectID `bson:"_id,omitempty"`
	RefID      primitive.ObjectID `bson:"ref_id"`
	StaticData StaticAppData      `bson:"static_data"`
}

type Collections

type Collections struct {
	Stats      *mongo.Collection
	Exceptions *mongo.Collection
	TrackPool  *mongo.Collection
}

Collections struct containing MongoDB collections to be used

type Config

type Config struct {
	Ctx          context.Context
	Col          *Collections
	Trace        *loggers
	LoggerClient *logging.Client
	LocalEnabled bool
}

Config for execution

func InitConfig

func InitConfig(ctx context.Context, cols *Collections) *Config

InitConfig - initialise config struct and return pointer to it

func (Config) FlushExceptions

func (cfg Config) FlushExceptions()

FlushExceptions : Clear exception queue

func (Config) GetExceptions

func (cfg Config) GetExceptions() ([]AppRef, error)

GetExceptions - Return list of App

func (Config) PushApp added in v1.0.5

func (cfg Config) PushApp(element *App) error

func (Config) PushDaily

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

PushDaily : Insert daily metric

func (Config) PushException

func (cfg Config) PushException(app *AppRef, date *time.Time) error

PushException : Insert exception instance

func (Config) PushMonthly

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

PushMonthly : Insert new month instance

func (Config) UpdateApp

func (cfg Config) UpdateApp(app *App) error

UpdateApp : Update app

func (Config) UpdateDailyList

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

UpdateDailyList : Update daily metric list for app

type DailyMetric

type DailyMetric struct {
	Date        time.Time `bson:"date"`
	PlayerCount int       `bson:"player_count"`
}

DailyMetric - Metric obj

type Db

type Db interface {
	GetExceptions() ([]AppRef, error)

	PushApp(element *App) error
	PushDaily(id primitive.ObjectID, element *DailyMetric) error
	PushMonthly(id primitive.ObjectID, element *Metric) error
	PushException(app *AppRef, currentDateTime *time.Time) error

	UpdateApp(app *App) error
	UpdateDailyList(id primitive.ObjectID, newMetricList *[]DailyMetric) error

	FlushExceptions()
	// contains filtered or unexported methods
}

Db interface

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

type StaticAppData added in v1.0.5

type StaticAppData struct {
	Name   string `bson:"name"`
	AppID  int    `bson:"app_id"`
	Domain string `bson:"domain"`
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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