db

package
v0.0.0-...-3445bf9 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 24 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupDatabase

func BackupDatabase(dbPath, backupPath string) error

func BackupDatabaseWithContext

func BackupDatabaseWithContext(ctx context.Context, dbPath, backupPath string) (err error)

func GetContract

func GetContract(id string, expiryYear int, expiryMonth int) (*api.ContractProperties, error)

expiryYear and expiryMonth are optional. When expiryYear is 0, the latest iteration is retrieved. If no matching contract is found in the database, the return value is (nil, nil), i.e., error is not set in that case.

func GetContractCount

func GetContractCount() (int, error)

func GetCoopContracts

func GetCoopContracts() ([]*api.ContractProperties, error)

func GetCoopMemberActivityStats

func GetCoopMemberActivityStats(c *coop.CoopStatus, refreshTime time.Time) (
	activities map[string]*coop.CoopMemberActivity,
	err error,
)

func GetPeekedGroupedByContract

func GetPeekedGroupedByContract(since time.Time) (contractIds []string, groups map[string][]*Peeked, err error)

GetPeekedGroupedByContract retrieves the list of peeked coops since the specified time, grouped by contract ID. Returned groups are ordered reverse chronologically (order is preserved in contractIds).

func GetSoloAndCoopStatusesFromRefresh

func GetSoloAndCoopStatusesFromRefresh(byThisTime time.Time, dedupe bool) (
	timestamp time.Time,
	solos []*solo.SoloContract,
	coops []*coop.CoopStatus,
	err error,
)

GetSoloAndCoopStatusesFromRefresh returns contract statuses from the last refresh by the specified cutoff time. If no such refresh can be found in the database, all return values will be set to the corresponding zero values (including nil err).

If dedupe is true, filter out coops where the user has apparently joined a tracked coop already (coop status can be more up-to-date than contract farm backup).

func GzipFile

func GzipFile(path string) error

func GzipFileRemoveOriginal

func GzipFileRemoveOriginal(path string) error

func InitDB

func InitDB(conf config.DatabaseConfig) error

func InsertContract

func InsertContract(now time.Time, c *api.ContractProperties, checkExistence bool) (exists bool, err error)

InsertContract upserts the contract into the database. If checkExistence is true, perform an additional query beforehand to determine whether the contract already exists in the database, and if so, set exists to true in the return values. If checkExistence is false, then exists in the return values is meaningless.

func InsertCoopStatus

func InsertCoopStatus(timestamp time.Time, refreshId int64, c *api.CoopStatus) error

refreshId is optional, and will be inserted as NULL if zero.

func InsertEvent

func InsertEvent(seen time.Time, e *api.Event) error

func InsertPeeked

func InsertPeeked(p *Peeked) error

func InsertRefresh

func InsertRefresh(timestamp time.Time) (refreshId int64, err error)

func InsertSoloStatus

func InsertSoloStatus(timestamp time.Time, refreshId int64, c *solo.SoloContract) error

refreshId is optional, and will be inserted as NULL if zero.

func WrapCoopStatusWithDB

func WrapCoopStatusWithDB(c *api.CoopStatus) (*coop.CoopStatus, error)

Contract is set to nil if no matching contract is found or if there is a database error.

Types

type Contract

type Contract struct {
	*api.ContractProperties
	RowId int64
}

func GetContracts

func GetContracts() ([]Contract, error)

type ContractSignature

type ContractSignature struct {
	Id          string
	ExpiryYear  int
	ExpiryMonth int
}

ContractSignature is used to determine contract uniqueness.

func GetContractSignature

func GetContractSignature(c *api.ContractProperties) ContractSignature

type Event

type Event struct {
	Id            string
	EventType     string
	Multiplier    float64
	Message       string
	FirstSeenTime time.Time
	LastSeenTime  time.Time
	ExpiryTime    time.Time
}

func GetEvents

func GetEvents() (events []*Event, err error)

func (*Event) Duration

func (e *Event) Duration() time.Duration

func (*Event) HasTimeLeft

func (e *Event) HasTimeLeft() bool

func (*Event) TimeLeft

func (e *Event) TimeLeft() time.Duration

func (*Event) UnhypedMessage

func (e *Event) UnhypedMessage() string

type Peeked

type Peeked struct {
	ContractId                 string
	Code                       string
	LastPeekedTime             time.Time
	HasCompleted               bool
	Openings                   int32
	EggsLaid                   float64
	EggsPerHour                float64
	RequiredEggsPerHour        float64
	TimeLeft                   time.Duration
	MaxEarningBonusPercentage  float64
	MeanEarningBonusPercentage float64
}

func GetPeeked

func GetPeeked(contractId string, since time.Time) ([]*Peeked, error)

GetPeeked retrieves the list of peeked coops since the specified time. contractId is optional; when nonempty, only return peeked coops for that particular contract. Returned coops are ordered reverse chronologically.

func NewPeeked

func NewPeeked(c *coop.CoopStatus, peekedAt time.Time) *Peeked

func (*Peeked) HasNoTimeLeft

func (p *Peeked) HasNoTimeLeft() bool

func (*Peeked) IsOnTrackToFinish

func (p *Peeked) IsOnTrackToFinish() bool

Jump to

Keyboard shortcuts

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