Merge branch 'master' of ssh://git.andreafazzi.eu:10022/andrea/oef

This commit is contained in:
Andrea Fazzi 2021-01-10 17:49:29 +01:00
commit a723587860
4 changed files with 14 additions and 8 deletions

View file

@ -1 +1 @@
0.9.9-38-gd884404-master
0.9.9-39-gc97792e-master

View file

@ -110,13 +110,13 @@ func (c *Contest) Read(db *Database, args map[string]string, w http.ResponseWrit
}
for _, r := range contest.Rank {
if err := calcScore(db, r); err != nil {
if err := calcScoreAndDuration(db, r); err != nil {
return nil, err
}
}
sort.SliceStable(contest.Rank, func(i, j int) bool {
return contest.Rank[i].Score < contest.Rank[j].Score
return (contest.Rank[i].Score >= contest.Rank[j].Score) && (contest.Rank[i].Duration < contest.Rank[j].Duration)
})
return &contest, nil

View file

@ -40,6 +40,7 @@ type Response struct {
Score int `gorm:"-"`
ScoreString string `gorm:"-"`
Duration time.Duration `gorm:"-"`
Questions []*Question
SingleResponses []*SingleResponse `gorm:"-"`
@ -104,7 +105,7 @@ func (model *Response) BeforeSave(tx *gorm.DB) error {
return nil
}
func calcScore(db *Database, response *Response) error {
func calcScoreAndDuration(db *Database, response *Response) error {
response.Score = 0
if response.AnswersIDs != "" {
srIDs := strings.Split(response.AnswersIDs, " ")
@ -130,7 +131,12 @@ func calcScore(db *Database, response *Response) error {
}
response.ScoreString = fmt.Sprintf("%s punti %v", strconv.Itoa(response.Score), response.EndTime.Sub(response.StartTime))
if response.StartTime.IsZero() {
response.ScoreString = "non ancora visualizzata"
} else {
response.Duration = response.UpdatedAt.Sub(response.StartTime)
response.ScoreString = fmt.Sprintf("%s punti %v", strconv.Itoa(response.Score), response.Duration)
}
return nil
}

View file

@ -40,7 +40,7 @@
<dt class="col-sm-3">Durata della gara</dt>
<dd class="col-sm-9">
{{if not .Data.Contest.IsAlwaysActive}}
{{.Data.Contest.Duration}} min (la prova dovrà comunque essere consegnata <strong>al massimo</strong> entro le ore {{.Data.Contest.EndTime|convertTime}})
{{.Data.Contest.Duration}} min {{if .Data.StartTime|zeroTime}}(la prova dovrà comunque essere consegnata al massimo entro le ore {{.Data.Contest.EndTime|convertTime}}){{end}}
{{else}}
La gara ha una durata illimitata.
{{end}}