Save MCQ diff

This commit is contained in:
nemunaire 2017-12-17 02:48:02 +01:00
parent b079f7891c
commit 830dacd6f5
5 changed files with 28 additions and 2 deletions

View File

@ -57,7 +57,7 @@
<span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Faire son rapport
</div>
<ul class="list-group" ng-if="(my.exercices[current_exercice].tries || my.exercices[current_exercice].submitted || sberr)">
<li class="list-group-item text-warning" ng-if="my.exercices[current_exercice].tries"><ng-pluralize count="my.exercices[current_exercice].tries" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}.</li>
<li class="list-group-item text-warning" ng-if="my.exercices[current_exercice].tries"><ng-pluralize count="my.exercices[current_exercice].tries" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. <span ng-if="my.exercices[current_exercice].solve_dist"><ng-pluralize count="my.exercices[current_exercice].solve_dist" when="{'one': '{} réponse erronée', 'other': '{} réponses erronées'}"></ng-pluralize>.</span></li>
<li class="list-group-item" ng-class="messageClass" ng-if="my.exercices[current_exercice].submitted || sberr"><strong ng-if="!sberr">Votre solution a bien été envoyée !</strong><strong ng-if="sberr">{{ sberr }}</strong> {{ message }}</li>
</ul>
<div class="card-body" ng-if="!my.exercices[current_exercice].submitted || sberr">

View File

@ -205,6 +205,7 @@ CREATE TABLE IF NOT EXISTS exercice_tries(
id_exercice INTEGER NOT NULL,
id_team INTEGER NOT NULL,
time TIMESTAMP NOT NULL,
nbdiff INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice),
FOREIGN KEY(id_team) REFERENCES teams(id_team)
);

View File

@ -168,6 +168,14 @@ func (e Exercice) NewTry(t Team) error {
}
}
func (e Exercice) UpdateTry(t Team, nbdiff int) error {
if _, err := DBExec("UPDATE exercice_tries SET nbdiff = ?, time = ? WHERE id_exercice = ? AND id_team = ? ORDER BY time DESC LIMIT 1", nbdiff, time.Now(), e.Id, t.Id); err != nil {
return err
} else {
return nil
}
}
func (e Exercice) Solved(t Team) error {
if _, err := DBExec("INSERT INTO exercice_solved (id_exercice, id_team, time, coefficient) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), e.Coefficient); err != nil {
return err

View File

@ -146,6 +146,15 @@ func (t Team) CountTries(e Exercice) (int64, time.Time) {
}
}
func (t Team) LastTryDist(e Exercice) int64 {
var nb *int64
if DBQueryRow("SELECT nbdiff FROM exercice_tries WHERE id_team = ? AND id_exercice = ? ORDER BY time DESC LIMIT 1", t.Id, e.Id).Scan(&nb); nb == nil {
return 0
} else {
return *nb
}
}
func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
var nb *int64
var tm *time.Time

View File

@ -36,6 +36,7 @@ type myTeamExercice struct {
Keys []string `json:"keys,omitempty"`
SolvedMat []bool `json:"solved_matrix,omitempty"`
MCQs []myTeamMCQ `json:"mcqs,omitempty"`
SolveDist int64 `json:"solve_dist,omitempty"`
SolvedTime time.Time `json:"solved_time,omitempty"`
SolvedRank int64 `json:"solved_rank,omitempty"`
Tries int64 `json:"tries,omitempty"`
@ -91,6 +92,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
exercice.Tries, _ = t.CountTries(e)
} else {
exercice.Tries, exercice.SolvedTime = t.CountTries(e)
if exercice.Tries > 0 {
exercice.SolveDist = t.LastTryDist(e)
}
}
if gain, err := e.EstimateGain(*t, solved); err == nil {
@ -140,7 +144,11 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
for _, e := range mcq.Entries {
choices[e.Id] = e.Label
}
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, mcq.Kind, choices, t.HasPartiallyRespond(mcq)})
if t == nil {
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, mcq.Kind, choices, nil})
} else {
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, mcq.Kind, choices, t.HasPartiallyRespond(mcq)})
}
}
}