Documentation ¶
Index ¶
- type BaseEvent
- type Event
- func ConvertProtoEvent(protoEvent *guessesv1.Event) (Event, error)
- func NewEvent(baseEvent BaseEvent) (Event, error)
- func NewGenericEvent(eventType EventType, roomId string, description string) Event
- func NewGenericEventWithTimestamp(timestamp time.Time, eventType EventType, roomId string, description string) Event
- func NewGuessEvent(eventType EventType, roomId, userId, questionId string, correct bool, ...) Event
- func NewLeaderboardUpdatedEvent(eventType EventType, roomId string, leaderboard *Leaderboard, ...) Event
- type EventType
- type GenericEvent
- type Guess
- type GuessEvent
- type Leaderboard
- type LeaderboardUpdatedEvent
- type RankElement
- type Score
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 (*BaseEvent) GetTimestamp ¶ added in v0.4.0
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
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 NewGenericEvent ¶ added in v0.4.0
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 NewLeaderboardUpdatedEvent ¶ added in v0.4.0
func NewLeaderboardUpdatedEvent(eventType EventType, roomId string, leaderboard *Leaderboard, description string) Event
type GenericEvent ¶ added in v0.4.0
type GenericEvent struct {
BaseEvent
}
type Guess ¶
type GuessEvent ¶ added in v0.4.0
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 Score ¶
type Score struct { CorrectAnswers uint32 `redis:"correct"` WrongAnswers uint32 `redis:"wrong"` ComboMultiplierIdx uint32 `redis:"combo"` TotalQuestions uint32 `redis:"total"` Pontuation float64 }
func (*Score) IncreasePontuation ¶
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