Documentation ¶
Index ¶
- func AutoMigrate(db *gorm.DB) error
- func ValidEmail(email string) bool
- type Answers
- type Question
- type QuestionList
- func (ql QuestionList) InDifficultyRange(min, max int) QuestionList
- func (ql QuestionList) Limit(limit int) QuestionList
- func (ql QuestionList) OrderedByDifficulty() QuestionList
- func (ql QuestionList) Score() float64
- func (ql QuestionList) Suffled() QuestionList
- func (ql QuestionList) Valid() QuestionList
- type QuestionPool
- type QuestionType
- type Quiz
- type QuizOptions
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoMigrate ¶
func ValidEmail ¶
Types ¶
type Answers ¶
type Answers []string
https://raaaaaaaay86.medium.com/how-to-store-plain-string-slice-by-using-gorm-f855602013e6
func (*Answers) Scan ¶
Scan scan value into Jsonb, implements sql.Scanner interface https://raaaaaaaay86.medium.com/how-to-store-plain-string-slice-by-using-gorm-f855602013e6 https://gorm.io/docs/data_types.html
func (Answers) Value ¶
Value return json value, implement driver.Valuer interface https://raaaaaaaay86.medium.com/how-to-store-plain-string-slice-by-using-gorm-f855602013e6 https://gorm.io/docs/data_types.html
type Question ¶
type Question struct { gorm.Model Index int // used for sorting in the final quiz SessionEmail string Session Session `gorm:"foreignKey:SessionEmail"` Text string `yaml:"text,omitempty"` Difficulty int `yaml:"difficulty,omitempty"` Type QuestionType `yaml:"type,omitempty"` RightAnswer int `yaml:"rightAnswer,omitempty"` UserAnswer int `yaml:"userAnswer,omitempty"` Answers Answers `yaml:"answers,omitempty" gorm:"type:VARCHAR(255)"` AllowedSeconds int `yaml:"allowedSeconds,omitempty"` StartedAt time.Time }
type QuestionList ¶
type QuestionList []Question
func (QuestionList) InDifficultyRange ¶
func (ql QuestionList) InDifficultyRange(min, max int) QuestionList
func (QuestionList) Limit ¶
func (ql QuestionList) Limit(limit int) QuestionList
Limit return exactly `limit` number of questions. If the total questions are more than the requests, it will remove the additional ones, with preference to the questions with difficulty that is already represented. For example If there are 5 total questions like this: - 2 with difficulty 1 - 1 with difficulty 2 - 2 with difficutly 3 when limit is "3" the method will return one questions from each difficulty (instead for example: 2 with difficulty 1 and 1 with difficulty 2). In other words, it tries to have questions from all difficulties if possible. Desired questions are picked starting from lower to higher levels but when a difficulty level runs out of questions, one from a higher level is picked instead.
func (QuestionList) OrderedByDifficulty ¶
func (ql QuestionList) OrderedByDifficulty() QuestionList
func (QuestionList) Score ¶
func (ql QuestionList) Score() float64
func (QuestionList) Suffled ¶
func (ql QuestionList) Suffled() QuestionList
func (QuestionList) Valid ¶
func (ql QuestionList) Valid() QuestionList
type QuestionPool ¶
type QuestionPool struct {
Questions QuestionList `yaml:"questions,omitempty"`
}
func NewQuestionPool ¶
func NewQuestionPool(template string) (QuestionPool, error)
func NewQuestionPoolFromFile ¶
func NewQuestionPoolFromFile(filePath string) (QuestionPool, error)
type QuestionType ¶
type QuestionType string
https://raaaaaaaay86.medium.com/how-to-store-plain-string-slice-by-using-gorm-f855602013e6
type Quiz ¶
type Quiz struct {
Questions QuestionList `yaml:"questions,omitempty"`
}
Quiz is the collection of questions from a QuestionPool based on QuizOptions. It's an intermidiate model used to prepare the Questions that will be stored in the database.
func NewQuizWithOpts ¶
func NewQuizWithOpts(opts QuizOptions) (Quiz, error)
type QuizOptions ¶
type QuizOptions struct { TotalQuestions int MinDifficulty int MaxDifficulty int QuestionTimeoutSec int AvailableQuestions QuestionList }
type Session ¶
type Session struct { gorm.Model Email string Questions []Question `gorm:"foreignKey:SessionEmail;references:Email"` }
func (Session) CurrentQuestion ¶
CurrentQuestion returns the first non-expired question If the session has an expired question, this method returns an error (there is no "CurrentQuestion" since the whole Session is expired)
func (Session) HasExpiredQuestions ¶
HasExpiredQuestions returns `true` if there is at least one expired Question