events

package
v0.0.0-...-8b20b1e Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package events implements an event system to reward student progression across the whole app.

See https://docs.google.com/spreadsheets/d/1nY7zKsZ6JjW51QDSbt7OgaVSqzL-UoBHu6Qp6C3P7XQ

Index

Constants

View Source
const NbEvents = 11

Variables

This section is empty.

Functions

func InsertEvent

func InsertEvent(db DB, item Event) error

func InsertManyEvents

func InsertManyEvents(tx *sql.Tx, items ...Event) error

Insert the links Event in the database. It is a no-op if 'items' is empty.

Types

type Advance

type Advance []dayEvents // sorted by day

Advance is the stored list of events, for one student. Generally speaking, its features are dynamic : see the various access methods

func NewAdvance

func NewAdvance(events Events) Advance

func (Advance) Stats

func (adv Advance) Stats(maxRankThreshold int) StudentAdvance

Stats aggregate the events and compute the associated rank.

The rank is computed using [maxRankThreshold], the amount of points required to access the last rank, and a fixed progression scale :

| Rank		| 0 | 1 | 2 	|	3 	| 4		| 5		| 6
| Ratio (%)	| 0 | 5 | 15 	|	30 	| 50	| 73	| 100

type DB

type DB interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Prepare(query string) (*sql.Stmt, error)
}

DB groups transaction like objects, and is implemented by *sql.DB and *sql.Tx

type Date

type Date time.Time

func (*Date) Scan

func (s *Date) Scan(src interface{}) error

func (Date) Value

func (s Date) Value() (driver.Value, error)

type Event

type Event struct {
	IdStudent teacher.IdStudent `gomacro-sql-on-delete:"CASCADE"`
	Event     EventK
	Date      Date
}

func ScanEvent

func ScanEvent(row *sql.Row) (Event, error)

func (Event) Delete

func (item Event) Delete(tx DB) error

Delete the link Event from the database. Only the foreign keys IdStudent fields are used in 'item'.

type EventK

type EventK int16
const (
	E_IsyTriv_Create       EventK = iota // Créer une partie d'IsyTriv
	E_IsyTriv_Streak3                    // Réussir trois questions IsyTriv d'affilée
	E_IsyTriv_Win                        // Remporter une partie IsyTriv
	E_Homework_TaskDone                  // Terminer un exercice
	E_Homework_TravailDone               // Terminer une feuille d'exercices
	E_All_QuestionRight                  // Répondre correctement à une question
	E_All_QuestionWrong                  // Répondre incorrectement à une question
	E_Misc_SetPlaylist                   // Modifier sa playlist

	// these events are computed from the others and
	// not store in the DB, but are displayed like regular events
	E_ConnectStreak3  // Se connecter 3 jours de suite
	E_ConnectStreak7  // Se connecter 7 jours de suite
	E_ConnectStreak30 // Se connecter 30 jours de suite
)

type EventNotification

type EventNotification struct {
	Events []EventK // the events (often with length 1)
	Points int      // the number of points earned
}

func RegisterEvents

func RegisterEvents(db *sql.DB, idStudent teacher.IdStudent, events ...EventK) (EventNotification, error)

RegisterEvents stores the given events for the given student at the present time.

It returns the number of points earned by the student.

func (*EventNotification) HideIfNoPoints

func (en *EventNotification) HideIfNoPoints()

type Events

type Events []Event

func DeleteEventsByIdStudents

func DeleteEventsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (Events, error)

func ScanEvents

func ScanEvents(rs *sql.Rows) (Events, error)

func SelectAllEvents

func SelectAllEvents(db DB) (Events, error)

SelectAll returns all the items in the events table.

func SelectEventsByIdStudents

func SelectEventsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (Events, error)

func (Events) ByIdStudent

func (items Events) ByIdStudent() map[teacher.IdStudent]Events

ByIdStudent returns a map with 'IdStudent' as keys.

func (Events) IdStudents

func (items Events) IdStudents() []teacher.IdStudent

IdStudents returns the list of ids of IdStudent contained in this link table. They are not garanteed to be distinct.

type StudentAdvance

type StudentAdvance struct {
	Occurences  [NbEvents]int
	TotalPoints int
	Flames      int

	Rank                              int
	PointsCurrentRank, PointsNextRank int
}

Jump to

Keyboard shortcuts

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