admin: Retrieve stats on exercices
This commit is contained in:
parent
63b4cdc622
commit
b409fa6806
10 changed files with 241 additions and 19 deletions
|
|
@ -136,6 +136,31 @@ func (m *MCQ) RecoverId() (Flag, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// NbTries returns the MCQ resolution statistics.
|
||||
func (m *MCQ) NbTries() (tries int64, err error) {
|
||||
err = DBQueryRow("SELECT COUNT(*) AS tries FROM exercice_tries_mcq WHERE id_mcq = ?", m.Id).Scan(&tries)
|
||||
return
|
||||
}
|
||||
|
||||
func (m *MCQ) TeamsOnIt() ([]int64, error) {
|
||||
if rows, err := DBQuery("SELECT DISTINCT M.id_team FROM exercice_tries_mcq F INNER JOIN exercice_tries T ON T.id_try = F.id_try INNER JOIN teams M ON M.id_team = T.id_team WHERE id_mcq = ?", m.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
teams := []int64{}
|
||||
for rows.Next() {
|
||||
var idteam int64
|
||||
if err := rows.Scan(&idteam); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teams = append(teams, idteam)
|
||||
}
|
||||
|
||||
return teams, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Create registers a MCQ into the database and recursively add its entries.
|
||||
func (m *MCQ) Create(e *Exercice) (Flag, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, ordre, title) VALUES (?, ?, ?)", e.Id, m.Order, m.Title); err != nil {
|
||||
|
|
@ -319,6 +344,24 @@ func (m *MCQ) IsOptionnal() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// Check if the given vals contains at least a response for the given MCQ.
|
||||
func (m *MCQ) HasOneEntry(v interface{}) bool {
|
||||
var vals map[int]bool
|
||||
if va, ok := v.(map[int]bool); !ok {
|
||||
return false
|
||||
} else {
|
||||
vals = va
|
||||
}
|
||||
|
||||
for _, n := range m.Entries {
|
||||
if _, ok := vals[n.Id]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the given vals are the expected ones to validate this flag.
|
||||
func (m *MCQ) Check(v interface{}) int {
|
||||
var vals map[int]bool
|
||||
|
|
|
|||
Reference in a new issue