services

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LevelInfos = []*LevelInfo{
	{Level: 1, MinWeeks: 0, Points: 0},
	{Level: 2, MinWeeks: 4, Points: 1000},
	{Level: 3, MinWeeks: 21, Points: 2000},
	{Level: 4, MinWeeks: 36, Points: 3000},
}

Functions

func ContainsString

func ContainsString(v []string, x string) bool

func GetWeekNum

func GetWeekNum(t time.Time) int

GeetWeekNum calculates the number of the week in which the given time lies for DIMO point issuance, which at the time of writing starts at 2022-01-31 05:00 UTC. Indexing is zero-based.

func GetWeekNumForCron

func GetWeekNumForCron(t time.Time) int

GeetWeekNumForCron calculates the week number for the current run of the cron job. We expect the job to run every Monday at 05:00 UTC, but due to skew we just round the time.

func NumToWeekEnd

func NumToWeekEnd(n int) time.Time

func NumToWeekStart

func NumToWeekStart(n int) time.Time

Types

type ActivityResp

type ActivityResp struct {
	Hits struct {
		Hits []struct {
			Source struct {
				Data struct {
					Timestamp time.Time `json:"timestamp"`
				} `json:"data"`
			} `json:"_source"`
		} `json:"hits"`
	} `json:"hits"`
}

type ConnectionMethod

type ConnectionMethod struct {
	DevicesAPIVendor string
	DBConstant       string
	Points           int
}

type DeviceData

type DeviceData struct {
	ID           string
	Integrations []string
}

type DeviceDataClient

type DeviceDataClient interface {
	GetLastActivity(userDeviceID string) (lastActivity time.Time, seen bool, err error)
	DescribeActiveDevices(start, end time.Time) ([]*DeviceData, error)
	GetIntegrations(userDeviceID string, start, end time.Time) (ints []string, err error)
}

func NewDeviceDataClient

func NewDeviceDataClient(settings *config.Settings) DeviceDataClient

type DeviceIntegrationsResp

type DeviceIntegrationsResp struct {
	Aggregations struct {
		Integrations struct {
			Buckets []struct {
				Key string `json:"key"`
			} `json:"buckets"`
		} `json:"integrations"`
	} `json:"aggregations"`
}

type DeviceListResp

type DeviceListResp struct {
	Aggregations struct {
		ActiveDevices struct {
			AfterKey struct {
				Subject *string `json:"subject"`
			} `json:"after_key"`
			Buckets []struct {
				Key struct {
					Subject string `json:"subject"`
				} `json:"key"`
				Integrations struct {
					Buckets []struct {
						Key string `json:"key"`
					} `json:"buckets"`
				} `json:"integrations"`
			} `json:"buckets"`
		} `json:"active_devices"`
	} `json:"aggregations"`
}

type LevelInfo

type LevelInfo struct {
	Level    int
	MinWeeks int
	Points   int
}

func GetLevel

func GetLevel(connStreak int) *LevelInfo

type RewardsTask

type RewardsTask struct {
	Settings    *config.Settings
	Logger      *zerolog.Logger
	DataService DeviceDataClient
	DB          func() *database.DBReaderWriter
}

func (*RewardsTask) Calculate

func (t *RewardsTask) Calculate(issuanceWeek int) error

type StreakInput

type StreakInput struct {
	ConnectedThisWeek           bool
	ExistingConnectionStreak    int
	ExistingDisconnectionStreak int
}

type StreakOutput

type StreakOutput struct {
	DisconnectionStreak int
	ConnectionStreak    int
	Points              int
}

func ComputeStreak

func ComputeStreak(i StreakInput) StreakOutput

Jump to

Keyboard shortcuts

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