statistic

package
v0.0.0-...-a0fcb3e Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AggregationModeSum = "SUM"
	AggregationModeSub = "SUB"
	AggregationModeMax = "MAX"
	AggregationModeMin = "MIN"
)

Variables

View Source
var (
	ErrStatisticValidation    = errors.New("invalid statistic")
	ErrInvalidStatisticID     = errors.New("invalid id")
	ErrInvalidName            = errors.New("invalid name")
	ErrMissingGameID          = errors.New("missing game id")
	ErrInvalidAggregationMode = errors.New("invalid aggregation mode")
	ErrStatisticNotFound      = errors.New("statistic not found")
)
View Source
var (
	ErrPlayerStatisticNotFound = errors.New("player statistic not found")
)

Functions

This section is empty.

Types

type CreateFunc

type CreateFunc func(ctx context.Context, data NewStatisticData) (Statistic, error)

Create a statistic

func BuildCreateStatisticFunc

func BuildCreateStatisticFunc(storageCreateStatisticFunc StorageCreateStatisticFunc) CreateFunc

type GetByIDAndGameIDFunc

type GetByIDAndGameIDFunc func(ctx context.Context, id, gameID string) (Statistic, error)

Get statistic by is and game id

func BuildGetStatisticByIDAndGameID

func BuildGetStatisticByIDAndGameID(storageGetStatisticByIDAndGameID StorageGetStatisticByIDAndGameID) GetByIDAndGameIDFunc

type GetPlayerProgressionFunc

type GetPlayerProgressionFunc func(ctx context.Context, statisticID, playerID string) (PlayerProgression, error)

Get player progression by statistic id and player id

func BuildGetPlayerProgression

func BuildGetPlayerProgression(storageGetPlayerProgressionFunc StorageGetPlayerProgressionFunc) GetPlayerProgressionFunc

type NewStatisticData

type NewStatisticData struct {
	GameID          string    // ID of the game responsible for the statistic
	Name            string    // Statistic name
	Description     string    // Statistic details
	AggregationMode string    // Data aggregation mode
	InitialValue    *float64  // Initial statistic value for players
	Goal            *float64  // Goal value. nil means no goal
	Landmarks       []float64 // Statistic landmarks
}

type NotifierPlayerProgressionUpdates

type NotifierPlayerProgressionUpdates func(ctx context.Context, statistic Statistic, progression PlayerProgression, updates PlayerProgressionUpdates) error

Notify player progression updates

type PlayerProgression

type PlayerProgression struct {
	StartedAt       time.Time                   // Time the player started the progression for the given statistic
	UpdatedAt       time.Time                   // Last time the player updated it's statistic progress
	PlayerID        string                      // Player's ID
	StatisticID     string                      // Statistic ID
	CurrentValue    *float64                    // Current progression value
	GoalValue       *float64                    // Statistic's goal
	GoalCompleted   *bool                       // Has the player reached the goal?
	GoalCompletedAt time.Time                   // Time the player reached the goal
	Landmarks       []PlayerProgressionLandmark // Landmarks player progression
}

type PlayerProgressionLandmark

type PlayerProgressionLandmark struct {
	Value       float64   // Landmark value
	Completed   bool      // Has the player reached the landmark?
	CompletedAt time.Time // Time the player reached the landmark
}

type PlayerProgressionUpdates

type PlayerProgressionUpdates struct {
	GoalJustCompleted      bool                               // Player just reached the goal?
	GoalCompletedAt        time.Time                          // Time the player reached the goal
	LandmarksJustCompleted []PlayerProgressionUpdatesLandmark // Landmarks that the player has just reached
}

type PlayerProgressionUpdatesLandmark

type PlayerProgressionUpdatesLandmark struct {
	Value       float64   // Landmark value
	CompletedAt time.Time // Time the player reached the landmark
}

type SoftDeleteByIDAndGameIDFunc

type SoftDeleteByIDAndGameIDFunc func(ctx context.Context, id, gameID string) error

Soft delete a statistic by id and game id

func BuildSoftDeleteStatistic

func BuildSoftDeleteStatistic(storageSoftDeleteStatistic StorageSoftDeleteStatistic) SoftDeleteByIDAndGameIDFunc

type Statistic

type Statistic struct {
	CreatedAt       time.Time // Time that the statistic was created
	UpdatedAt       time.Time // Last time that the statistic was updated
	DeletedAt       time.Time // Time that the statistic was deleted
	ID              string    // Statistic ID
	GameID          string    // ID of the game responsible for the statistic
	Name            string    // Statistic name
	Description     string    // Statistic details
	AggregationMode string    // Data aggregation mode
	InitialValue    *float64  // Initial statistic value for players
	Goal            *float64  // Goal value. nil means no goal
	Landmarks       []float64 // Statistic landmarks
}

type StorageCreateStatisticFunc

type StorageCreateStatisticFunc func(ctx context.Context, data NewStatisticData) (Statistic, error)

Create a statistic

type StorageGetPlayerProgressionFunc

type StorageGetPlayerProgressionFunc func(ctx context.Context, statisticID, playerID string) (PlayerProgression, error)

Get player progression by statistic id and player id

type StorageGetStatisticByIDAndGameID

type StorageGetStatisticByIDAndGameID func(ctx context.Context, id, gameID string) (Statistic, error)

Get statistic by is and game id

type StorageSoftDeleteStatistic

type StorageSoftDeleteStatistic func(ctx context.Context, id, gameID string) error

Soft delete a statistic by id and game id

type StorageUpdatePlayerProgressionFunc

type StorageUpdatePlayerProgressionFunc func(ctx context.Context, statistic Statistic, playerID string, value float64) (PlayerProgression, PlayerProgressionUpdates, error)

Updates the player statistic progression using the provided value

type UpsertPlayerProgressionFunc

type UpsertPlayerProgressionFunc func(ctx context.Context, statistic Statistic, playerID string, value float64) error

Update player statistic progression using the provided value

func BuildUpsertPlayerProgressionFunc

func BuildUpsertPlayerProgressionFunc(
	notifierPlayerProgressionUpdates NotifierPlayerProgressionUpdates,
	storageUpdatePlayerProgressionFunc StorageUpdatePlayerProgressionFunc,
) UpsertPlayerProgressionFunc

Jump to

Keyboard shortcuts

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