themes.json: add stat of tries count

This commit is contained in:
nemunaire 2016-01-25 03:05:32 +01:00
commit 9b293b7d32
2 changed files with 20 additions and 0 deletions

View file

@ -20,6 +20,7 @@ type exportedExercice struct {
Title string `json:"title"` Title string `json:"title"`
Gain int64 `json:"gain"` Gain int64 `json:"gain"`
Solved int64 `json:"solved"` Solved int64 `json:"solved"`
Tried int64 `json:"tried"`
} }
type exportedTheme struct { type exportedTheme struct {
@ -43,6 +44,7 @@ func exportThemes() (interface{}, error) {
exercice.Title, exercice.Title,
exercice.Gain, exercice.Gain,
exercice.SolvedCount(), exercice.SolvedCount(),
exercice.TriedTeamCount(),
} }
} }
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{ ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{

View file

@ -158,6 +158,24 @@ func (e Exercice) SolvedCount() int64 {
} }
} }
func (e Exercice) TriedTeamCount() int64 {
var nb int64
if err := DBQueryRow("SELECT COUNT(DISTINCT id_team) FROM exercice_tries WHERE id_exercice = ?", e.Id).Scan(&nb); err != nil {
return 0
} else {
return nb
}
}
func (e Exercice) TriedCount() int64 {
var nb int64
if err := DBQueryRow("SELECT COUNT(id_team) FROM exercice_tries WHERE id_exercice = ?", e.Id).Scan(&nb); err != nil {
return 0
} else {
return nb
}
}
func (e Exercice) CheckResponse(resps map[string]string, t Team) (bool, error) { func (e Exercice) CheckResponse(resps map[string]string, t Team) (bool, error) {
s, _, _ := t.HasSolved(e) s, _, _ := t.HasSolved(e)
if s { if s {