models

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEvent added in v0.4.0

type BaseEvent struct {
	ID          ulid.ULID
	Timestamp   time.Time
	Type        EventType
	RoomID      string
	Description string
}

BaseEvent struct with embedded fields

func (*BaseEvent) GetDescription added in v0.4.0

func (e *BaseEvent) GetDescription() string

func (*BaseEvent) GetID added in v0.4.0

func (e *BaseEvent) GetID() string

func (*BaseEvent) GetRoomID added in v0.4.0

func (e *BaseEvent) GetRoomID() string

func (*BaseEvent) GetTimestamp added in v0.4.0

func (e *BaseEvent) GetTimestamp() time.Time

func (*BaseEvent) GetType added in v0.4.0

func (e *BaseEvent) GetType() EventType

type Event added in v0.4.0

type Event interface {
	GetID() string
	GetTimestamp() time.Time
	GetType() EventType
	GetDescription() string
	GetRoomID() string
}

Event interface definition

func ConvertProtoEvent added in v0.5.0

func ConvertProtoEvent(protoEvent *guessesv1.Event) (Event, error)

ConvertProtoEvent converts the room event type from the ConnectRPC format back to the internal event format.

Returns ErrEventTypeInvalid if the event is malformed.

Returns ErrUlidInvalid if the event id can't be parsed as an ULID.

func NewEvent added in v0.4.0

func NewEvent(baseEvent BaseEvent) (Event, error)

NewEvent creates a specific Event based on the BaseEvent Type

func NewGenericEvent added in v0.4.0

func NewGenericEvent(eventType EventType, roomId string, description string) Event

Factory function for creating a new GenericEvent

func NewGenericEventWithTimestamp added in v0.4.0

func NewGenericEventWithTimestamp(timestamp time.Time, eventType EventType, roomId string, description string) Event

Factory function for creating a new GenericEvent. This function is useful for synchronizing the event with other functions.

func NewGuessEvent added in v0.4.0

func NewGuessEvent(eventType EventType, roomId, userId, questionId string, correct bool, description string) Event

func NewLeaderboardUpdatedEvent added in v0.4.0

func NewLeaderboardUpdatedEvent(eventType EventType, roomId string, leaderboard *Leaderboard, description string) Event

type EventType added in v0.4.0

type EventType int
const (
	/* events */
	GuessSubmitted EventType = iota
	LeaderboardUpdated
)

func (EventType) String added in v0.5.8

func (e EventType) String() string

type GenericEvent added in v0.4.0

type GenericEvent struct {
	BaseEvent
}

type Guess

type Guess struct {
	RoomID     string `validate:"required,len=4" redis:"roomid"`
	UserID     string `validate:"required,uuid" redis:"userid"`
	QuestionID string `validate:"required,gte=0" redis:"questionid"`
	Correct    bool   `redis:"correct"`
}

func NewGuess

func NewGuess(roomID, userID, questionID string, correct bool) (*Guess, error)

func (*Guess) Validate

func (u *Guess) Validate() error

type GuessEvent added in v0.4.0

type GuessEvent struct {
	BaseEvent
	UserId     string
	QuestionId string
	Correct    bool
}

type Leaderboard

type Leaderboard struct {
	RankList []RankElement
}

type LeaderboardUpdatedEvent added in v0.4.0

type LeaderboardUpdatedEvent struct {
	BaseEvent
	Leaderboard *Leaderboard
}

func (*LeaderboardUpdatedEvent) GetLeaderboard added in v0.4.2

func (e *LeaderboardUpdatedEvent) GetLeaderboard() *Leaderboard

type RankElement

type RankElement struct {
	UserID string
	Score  float64
}

type Score

type Score struct {
	CorrectAnswers     uint32 `redis:"correct"`
	WrongAnswers       uint32 `redis:"wrong"`
	ComboMultiplierIdx uint32 `redis:"combo"`
	TotalQuestions     uint32 `redis:"total"`
	Pontuation         float64
}

func NewScore

func NewScore(totalQuestions uint32) *Score

func (*Score) IncreasePontuation

func (s *Score) IncreasePontuation(timeTaken time.Duration, multiplier float64)

IncreasePontuation calculates the pontuation based on the time taken to answer the question and the combo multiplier value, following the formula: f(t) = BasePontuation * e^(DecayRate * t) * multiplier

func (*Score) UpdateStatistics

func (s *Score) UpdateStatistics(isCorrect bool, timeTaken time.Duration)

Jump to

Keyboard shortcuts

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