tasks

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: 9 Imported by: 0

Documentation

Overview

Package tasks exposes the data structure required to assign exercices during activities, and to track the progression of the students.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IdMonoquestionArrayToPQ

func IdMonoquestionArrayToPQ(ids []IdMonoquestion) pq.Int64Array

func IdRandomMonoquestionArrayToPQ

func IdRandomMonoquestionArrayToPQ(ids []IdRandomMonoquestion) pq.Int64Array

func IdTaskArrayToPQ

func IdTaskArrayToPQ(ids []IdTask) pq.Int64Array

func InsertManyProgressions

func InsertManyProgressions(tx *sql.Tx, items ...Progression) error

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

func InsertManyRandomMonoquestionVariants

func InsertManyRandomMonoquestionVariants(tx *sql.Tx, items ...RandomMonoquestionVariant) error

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

func InsertProgression

func InsertProgression(db DB, item Progression) error

func InsertRandomMonoquestionVariant

func InsertRandomMonoquestionVariant(db DB, item RandomMonoquestionVariant) error

func ResizeProgressions

func ResizeProgressions(db DB, id IdTask, nbQuestions int) error

ResizeProgressions makes sure the given task has progression items in range [0; nbQuestions[ This function should be called when updating a task content.

Types

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 IdMonoquestion

type IdMonoquestion int64

func DeleteMonoquestionsByIDs

func DeleteMonoquestionsByIDs(tx DB, ids ...IdMonoquestion) ([]IdMonoquestion, error)

Deletes the Monoquestion in the database and returns the ids.

func DeleteMonoquestionsByIdQuestions

func DeleteMonoquestionsByIdQuestions(tx DB, idQuestions_ ...editor.IdQuestion) ([]IdMonoquestion, error)

func ScanIdMonoquestionArray

func ScanIdMonoquestionArray(rs *sql.Rows) ([]IdMonoquestion, error)

ScanIdMonoquestionArray scans the result of a query returning a list of ID's.

func (IdMonoquestion) AsOptional

func (id IdMonoquestion) AsOptional() OptionalIdMonoquestion

type IdMonoquestionSet

type IdMonoquestionSet map[IdMonoquestion]bool

func NewIdMonoquestionSetFrom

func NewIdMonoquestionSetFrom(ids []IdMonoquestion) IdMonoquestionSet

func (IdMonoquestionSet) Add

func (IdMonoquestionSet) Has

func (IdMonoquestionSet) Keys

func (s IdMonoquestionSet) Keys() []IdMonoquestion

type IdProgression

type IdProgression int64

type IdRandomMonoquestion

type IdRandomMonoquestion int64

func DeleteRandomMonoquestionsByIDs

func DeleteRandomMonoquestionsByIDs(tx DB, ids ...IdRandomMonoquestion) ([]IdRandomMonoquestion, error)

Deletes the RandomMonoquestion in the database and returns the ids.

func DeleteRandomMonoquestionsByIdQuestiongroups

func DeleteRandomMonoquestionsByIdQuestiongroups(tx DB, idQuestiongroups_ ...editor.IdQuestiongroup) ([]IdRandomMonoquestion, error)

func ScanIdRandomMonoquestionArray

func ScanIdRandomMonoquestionArray(rs *sql.Rows) ([]IdRandomMonoquestion, error)

ScanIdRandomMonoquestionArray scans the result of a query returning a list of ID's.

func (IdRandomMonoquestion) AsOptional

type IdRandomMonoquestionSet

type IdRandomMonoquestionSet map[IdRandomMonoquestion]bool

func NewIdRandomMonoquestionSetFrom

func NewIdRandomMonoquestionSetFrom(ids []IdRandomMonoquestion) IdRandomMonoquestionSet

func (IdRandomMonoquestionSet) Add

func (IdRandomMonoquestionSet) Has

func (IdRandomMonoquestionSet) Keys

type IdTask

type IdTask int64

func DeleteTasksByIDs

func DeleteTasksByIDs(tx DB, ids ...IdTask) ([]IdTask, error)

Deletes the Task in the database and returns the ids.

func DeleteTasksByIdExercices

func DeleteTasksByIdExercices(tx DB, idExercices_ ...editor.IdExercice) ([]IdTask, error)

func DeleteTasksByIdMonoquestions

func DeleteTasksByIdMonoquestions(tx DB, idMonoquestions_ ...IdMonoquestion) ([]IdTask, error)

func DeleteTasksByIdRandomMonoquestions

func DeleteTasksByIdRandomMonoquestions(tx DB, idRandomMonoquestions_ ...IdRandomMonoquestion) ([]IdTask, error)

func ScanIdTaskArray

func ScanIdTaskArray(rs *sql.Rows) ([]IdTask, error)

ScanIdTaskArray scans the result of a query returning a list of ID's.

type IdTaskSet

type IdTaskSet map[IdTask]bool

func NewIdTaskSetFrom

func NewIdTaskSetFrom(ids []IdTask) IdTaskSet

func (IdTaskSet) Add

func (s IdTaskSet) Add(id IdTask)

func (IdTaskSet) Has

func (s IdTaskSet) Has(id IdTask) bool

func (IdTaskSet) Keys

func (s IdTaskSet) Keys() []IdTask

type Monoquestion

type Monoquestion struct {
	Id         IdMonoquestion
	IdQuestion editor.IdQuestion
	NbRepeat   int
	Bareme     int // for one question
}

Monoquestion is a shortcut for an exercice composed of only one question. It is used to avoid creating cumbersome exercice wrappers around questions. gomacro:SQL ADD CHECK(NbRepeat > 0)

func DeleteMonoquestionById

func DeleteMonoquestionById(tx DB, id IdMonoquestion) (Monoquestion, error)

Deletes the Monoquestion and returns the item

func ScanMonoquestion

func ScanMonoquestion(row *sql.Row) (Monoquestion, error)

func SelectMonoquestion

func SelectMonoquestion(tx DB, id IdMonoquestion) (Monoquestion, error)

SelectMonoquestion returns the entry matching 'id'.

func (Monoquestion) Insert

func (item Monoquestion) Insert(tx DB) (out Monoquestion, err error)

Insert one Monoquestion in the database and returns the item with id filled.

func (Monoquestion) Update

func (item Monoquestion) Update(tx DB) (out Monoquestion, err error)

Update Monoquestion in the database and returns the new version.

type Monoquestions

type Monoquestions map[IdMonoquestion]Monoquestion

func ScanMonoquestions

func ScanMonoquestions(rs *sql.Rows) (Monoquestions, error)

func SelectAllMonoquestions

func SelectAllMonoquestions(db DB) (Monoquestions, error)

SelectAll returns all the items in the monoquestions table.

func SelectMonoquestions

func SelectMonoquestions(tx DB, ids ...IdMonoquestion) (Monoquestions, error)

SelectMonoquestions returns the entry matching the given 'ids'.

func SelectMonoquestionsByIdQuestions

func SelectMonoquestionsByIdQuestions(tx DB, idQuestions_ ...editor.IdQuestion) (Monoquestions, error)

func (Monoquestions) ByIdQuestion

func (items Monoquestions) ByIdQuestion() map[editor.IdQuestion]Monoquestions

ByIdQuestion returns a map with 'IdQuestion' as keys.

func (Monoquestions) IDs

func (m Monoquestions) IDs() []IdMonoquestion

func (Monoquestions) IdQuestions

func (items Monoquestions) IdQuestions() []editor.IdQuestion

IdQuestions returns the list of ids of IdQuestion contained in this table. They are not garanteed to be distinct.

type OptionalIdMonoquestion

type OptionalIdMonoquestion struct {
	Valid bool
	ID    IdMonoquestion
}

func (*OptionalIdMonoquestion) Scan

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

func (OptionalIdMonoquestion) Value

type OptionalIdQuestion

type OptionalIdQuestion struct {
	Valid bool
	ID    editor.IdQuestion
}

type OptionalIdRandomMonoquestion

type OptionalIdRandomMonoquestion struct {
	Valid bool
	ID    IdRandomMonoquestion
}

func (*OptionalIdRandomMonoquestion) Scan

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

func (OptionalIdRandomMonoquestion) Value

type Progression

type Progression struct {
	IdStudent teacher.IdStudent `gomacro-sql-on-delete:"CASCADE"`
	IdTask    IdTask            `gomacro-sql-on-delete:"CASCADE"`

	// Index in the question list
	// For exercice, it is the question number
	// For monoquestion, it is the "repetion" number
	Index int16 `json:"index"`

	History QuestionHistory `json:"history"`
}

Progression is a link table storing the student progressions on tasks. gomacro:SQL ADD UNIQUE(IdStudent, IdTask, Index) gomacro:SQL _SELECT KEY (IdStudent, IdTask)

func ScanProgression

func ScanProgression(row *sql.Row) (Progression, error)

func SelectProgressionByIdStudentAndIdTaskAndIndex

func SelectProgressionByIdStudentAndIdTaskAndIndex(tx DB, idStudent teacher.IdStudent, idTask IdTask, index int16) (item Progression, found bool, err error)

SelectProgressionByIdStudentAndIdTaskAndIndex return zero or one item, thanks to a UNIQUE SQL constraint.

func (Progression) Delete

func (item Progression) Delete(tx DB) error

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

type Progressions

type Progressions []Progression

func DeleteProgressionsByIdStudentAndIdTask

func DeleteProgressionsByIdStudentAndIdTask(tx DB, idStudent teacher.IdStudent, idTask IdTask) (item Progressions, err error)

DeleteProgressionsByIdStudentAndIdTask deletes the item matching the given fields, returning the deleted items.

func DeleteProgressionsByIdStudents

func DeleteProgressionsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (Progressions, error)

func DeleteProgressionsByIdTasks

func DeleteProgressionsByIdTasks(tx DB, idTasks_ ...IdTask) (Progressions, error)

func ScanProgressions

func ScanProgressions(rs *sql.Rows) (Progressions, error)

func SelectAllProgressions

func SelectAllProgressions(db DB) (Progressions, error)

SelectAll returns all the items in the progressions table.

func SelectProgressionsByIdStudentAndIdTask

func SelectProgressionsByIdStudentAndIdTask(tx DB, idStudent teacher.IdStudent, idTask IdTask) (item Progressions, err error)

SelectProgressionsByIdStudentAndIdTask selects the items matching the given fields.

func SelectProgressionsByIdStudents

func SelectProgressionsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (Progressions, error)

func SelectProgressionsByIdTasks

func SelectProgressionsByIdTasks(tx DB, idTasks_ ...IdTask) (Progressions, error)

func (Progressions) ByIdStudent

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

ByIdStudent returns a map with 'IdStudent' as keys.

func (Progressions) ByIdTask

func (items Progressions) ByIdTask() map[IdTask]Progressions

ByIdTask returns a map with 'IdTask' as keys.

func (Progressions) EnsureOrder

func (l Progressions) EnsureOrder()

EnsureOrder must be call on the questions of one exercice, to make sure the order in the slice is consistent with the one indicated by `Index`

func (Progressions) IdStudents

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

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

func (Progressions) IdTasks

func (items Progressions) IdTasks() []IdTask

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

type QuestionHistory

type QuestionHistory []bool

QuestionHistory stores the successes for one question, in chronological order. For instance, [true, false, true] means : first try: correct, second: wrong answer,third: correct

func (*QuestionHistory) Scan

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

func (QuestionHistory) Stats

func (qh QuestionHistory) Stats() (success, failure int)

Stats returns the number of tries

func (QuestionHistory) Success

func (qh QuestionHistory) Success() bool

Success return true if at least one try is sucessful

func (QuestionHistory) Value

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

type RandomMonoquestion

type RandomMonoquestion struct {
	Id              IdRandomMonoquestion
	IdQuestiongroup editor.IdQuestiongroup
	NbRepeat        int
	Bareme          int                    // for one question
	Difficulty      editor.DifficultyQuery // optional, empty for all questions
}

RandomMonoquestion allows the teacher to specify a whole [Questiongroup], with questions chosen randomly for each student, according to an (optional) difficulty tag. gomacro:SQL ADD CHECK(NbRepeat > 0)

func DeleteRandomMonoquestionById

func DeleteRandomMonoquestionById(tx DB, id IdRandomMonoquestion) (RandomMonoquestion, error)

Deletes the RandomMonoquestion and returns the item

func ScanRandomMonoquestion

func ScanRandomMonoquestion(row *sql.Row) (RandomMonoquestion, error)

func SelectRandomMonoquestion

func SelectRandomMonoquestion(tx DB, id IdRandomMonoquestion) (RandomMonoquestion, error)

SelectRandomMonoquestion returns the entry matching 'id'.

func (RandomMonoquestion) Insert

func (item RandomMonoquestion) Insert(tx DB) (out RandomMonoquestion, err error)

Insert one RandomMonoquestion in the database and returns the item with id filled.

func (RandomMonoquestion) Update

func (item RandomMonoquestion) Update(tx DB) (out RandomMonoquestion, err error)

Update RandomMonoquestion in the database and returns the new version.

type RandomMonoquestionVariant

type RandomMonoquestionVariant struct {
	IdStudent            teacher.IdStudent    `gomacro-sql-on-delete:"CASCADE"`
	IdRandomMonoquestion IdRandomMonoquestion `gomacro-sql-on-delete:"CASCADE"`
	Index                int16                `json:"index"`
	IdQuestion           editor.IdQuestion
}

RandomMonoquestionVariant is a link table storing which variants is attributed to a given student gomacro:SQL ADD UNIQUE(IdStudent, IdRandomMonoquestion, Index) gomacro:SQL _SELECT KEY (IdStudent, IdRandomMonoquestion)

func ScanRandomMonoquestionVariant

func ScanRandomMonoquestionVariant(row *sql.Row) (RandomMonoquestionVariant, error)

func SelectRandomMonoquestionVariantByIdStudentAndIdRandomMonoquestionAndIndex

func SelectRandomMonoquestionVariantByIdStudentAndIdRandomMonoquestionAndIndex(tx DB, idStudent teacher.IdStudent, idRandomMonoquestion IdRandomMonoquestion, index int16) (item RandomMonoquestionVariant, found bool, err error)

SelectRandomMonoquestionVariantByIdStudentAndIdRandomMonoquestionAndIndex return zero or one item, thanks to a UNIQUE SQL constraint.

func (RandomMonoquestionVariant) Delete

func (item RandomMonoquestionVariant) Delete(tx DB) error

Delete the link RandomMonoquestionVariant from the database. Only the foreign keys IdStudent, IdRandomMonoquestion, IdQuestion fields are used in 'item'.

type RandomMonoquestionVariants

type RandomMonoquestionVariants []RandomMonoquestionVariant

func DeleteRandomMonoquestionVariantsByIdQuestions

func DeleteRandomMonoquestionVariantsByIdQuestions(tx DB, idQuestions_ ...editor.IdQuestion) (RandomMonoquestionVariants, error)

func DeleteRandomMonoquestionVariantsByIdRandomMonoquestions

func DeleteRandomMonoquestionVariantsByIdRandomMonoquestions(tx DB, idRandomMonoquestions_ ...IdRandomMonoquestion) (RandomMonoquestionVariants, error)

func DeleteRandomMonoquestionVariantsByIdStudentAndIdRandomMonoquestion

func DeleteRandomMonoquestionVariantsByIdStudentAndIdRandomMonoquestion(tx DB, idStudent teacher.IdStudent, idRandomMonoquestion IdRandomMonoquestion) (item RandomMonoquestionVariants, err error)

DeleteRandomMonoquestionVariantsByIdStudentAndIdRandomMonoquestion deletes the item matching the given fields, returning the deleted items.

func DeleteRandomMonoquestionVariantsByIdStudents

func DeleteRandomMonoquestionVariantsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (RandomMonoquestionVariants, error)

func ScanRandomMonoquestionVariants

func ScanRandomMonoquestionVariants(rs *sql.Rows) (RandomMonoquestionVariants, error)

func SelectAllRandomMonoquestionVariants

func SelectAllRandomMonoquestionVariants(db DB) (RandomMonoquestionVariants, error)

SelectAll returns all the items in the random_monoquestion_variants table.

func SelectRandomMonoquestionVariantsByIdQuestions

func SelectRandomMonoquestionVariantsByIdQuestions(tx DB, idQuestions_ ...editor.IdQuestion) (RandomMonoquestionVariants, error)

func SelectRandomMonoquestionVariantsByIdRandomMonoquestions

func SelectRandomMonoquestionVariantsByIdRandomMonoquestions(tx DB, idRandomMonoquestions_ ...IdRandomMonoquestion) (RandomMonoquestionVariants, error)

func SelectRandomMonoquestionVariantsByIdStudentAndIdRandomMonoquestion

func SelectRandomMonoquestionVariantsByIdStudentAndIdRandomMonoquestion(tx DB, idStudent teacher.IdStudent, idRandomMonoquestion IdRandomMonoquestion) (item RandomMonoquestionVariants, err error)

SelectRandomMonoquestionVariantsByIdStudentAndIdRandomMonoquestion selects the items matching the given fields.

func SelectRandomMonoquestionVariantsByIdStudents

func SelectRandomMonoquestionVariantsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (RandomMonoquestionVariants, error)

func (RandomMonoquestionVariants) ByIdQuestion

ByIdQuestion returns a map with 'IdQuestion' as keys.

func (RandomMonoquestionVariants) ByIdRandomMonoquestion

ByIdRandomMonoquestion returns a map with 'IdRandomMonoquestion' as keys.

func (RandomMonoquestionVariants) ByIdStudent

ByIdStudent returns a map with 'IdStudent' as keys.

func (RandomMonoquestionVariants) EnsureOrder

func (l RandomMonoquestionVariants) EnsureOrder()

EnsureOrder must be call on the questions of one exercice, to make sure the order in the slice is consistent with the one indicated by `Index`

func (RandomMonoquestionVariants) IdQuestions

func (items RandomMonoquestionVariants) IdQuestions() []editor.IdQuestion

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

func (RandomMonoquestionVariants) IdRandomMonoquestions

func (items RandomMonoquestionVariants) IdRandomMonoquestions() []IdRandomMonoquestion

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

func (RandomMonoquestionVariants) IdStudents

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

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

type RandomMonoquestions

type RandomMonoquestions map[IdRandomMonoquestion]RandomMonoquestion

func ScanRandomMonoquestions

func ScanRandomMonoquestions(rs *sql.Rows) (RandomMonoquestions, error)

func SelectAllRandomMonoquestions

func SelectAllRandomMonoquestions(db DB) (RandomMonoquestions, error)

SelectAll returns all the items in the random_monoquestions table.

func SelectRandomMonoquestions

func SelectRandomMonoquestions(tx DB, ids ...IdRandomMonoquestion) (RandomMonoquestions, error)

SelectRandomMonoquestions returns the entry matching the given 'ids'.

func SelectRandomMonoquestionsByIdQuestiongroups

func SelectRandomMonoquestionsByIdQuestiongroups(tx DB, idQuestiongroups_ ...editor.IdQuestiongroup) (RandomMonoquestions, error)

func (RandomMonoquestions) ByIdQuestiongroup

func (items RandomMonoquestions) ByIdQuestiongroup() map[editor.IdQuestiongroup]RandomMonoquestions

ByIdQuestiongroup returns a map with 'IdQuestiongroup' as keys.

func (RandomMonoquestions) IDs

func (RandomMonoquestions) IdQuestiongroups

func (items RandomMonoquestions) IdQuestiongroups() []editor.IdQuestiongroup

IdQuestiongroups returns the list of ids of IdQuestiongroup contained in this table. They are not garanteed to be distinct.

type Task

type Task struct {
	Id                   IdTask
	IdExercice           editor.OptionalIdExercice    `gomacro-sql-foreign:"Exercice"`
	IdMonoquestion       OptionalIdMonoquestion       `gomacro-sql-foreign:"Monoquestion"`
	IdRandomMonoquestion OptionalIdRandomMonoquestion `gomacro-sql-foreign:"RandomMonoquestion"`
}

Task is a pointer to an assignement to one exercice, either an `Exercice`, a `Monoquestion` or a `RandomMonoquestion` gomacro:SQL ADD UNIQUE(Id, IdExercice) gomacro:SQL ADD CHECK((IdExercice IS NOT NULL)::int + (IdMonoquestion IS NOT NULL)::int + (IdRandomMonoquestion IS NOT NULL)::int = 1)

func DeleteTaskById

func DeleteTaskById(tx DB, id IdTask) (Task, error)

Deletes the Task and returns the item

func ScanTask

func ScanTask(row *sql.Row) (Task, error)

func SelectTask

func SelectTask(tx DB, id IdTask) (Task, error)

SelectTask returns the entry matching 'id'.

func SelectTaskByIdAndIdExercice

func SelectTaskByIdAndIdExercice(tx DB, id IdTask, idExercice editor.OptionalIdExercice) (item Task, found bool, err error)

SelectTaskByIdAndIdExercice return zero or one item, thanks to a UNIQUE SQL constraint.

func (Task) Insert

func (item Task) Insert(tx DB) (out Task, err error)

Insert one Task in the database and returns the item with id filled.

func (Task) Update

func (item Task) Update(tx DB) (out Task, err error)

Update Task in the database and returns the new version.

type Tasks

type Tasks map[IdTask]Task

func ScanTasks

func ScanTasks(rs *sql.Rows) (Tasks, error)

func SelectAllTasks

func SelectAllTasks(db DB) (Tasks, error)

SelectAll returns all the items in the tasks table.

func SelectTasks

func SelectTasks(tx DB, ids ...IdTask) (Tasks, error)

SelectTasks returns the entry matching the given 'ids'.

func SelectTasksByIdExercices

func SelectTasksByIdExercices(tx DB, idExercices_ ...editor.IdExercice) (Tasks, error)

func SelectTasksByIdMonoquestions

func SelectTasksByIdMonoquestions(tx DB, idMonoquestions_ ...IdMonoquestion) (Tasks, error)

func SelectTasksByIdRandomMonoquestions

func SelectTasksByIdRandomMonoquestions(tx DB, idRandomMonoquestions_ ...IdRandomMonoquestion) (Tasks, error)

func (Tasks) IDs

func (m Tasks) IDs() []IdTask

Jump to

Keyboard shortcuts

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