From 5a7e8e433b944e524303c51e554beece89b367d4 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Tue, 5 Jan 2021 11:59:29 +0100 Subject: [PATCH 1/3] [auto] bumped version to 0.9.9-37-g339d087-master --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index c00c1474..9164e693 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.9-36-g7faac49-master +0.9.9-37-g339d087-master From c97792e7621ed3e81b70e51c3d0af255b028ae2a Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Tue, 5 Jan 2021 12:28:40 +0100 Subject: [PATCH 2/3] Improve ranking --- orm/contest.go | 4 ++-- orm/response.go | 14 ++++++++++---- templates/responses_show.html.tpl | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/orm/contest.go b/orm/contest.go index 8687f120..48fa9d76 100644 --- a/orm/contest.go +++ b/orm/contest.go @@ -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 diff --git a/orm/response.go b/orm/response.go index 26ecd671..18c437eb 100644 --- a/orm/response.go +++ b/orm/response.go @@ -38,8 +38,9 @@ type Response struct { EndTime time.Time TimeLeft time.Duration - Score int `gorm:"-"` - ScoreString string `gorm:"-"` + 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 } diff --git a/templates/responses_show.html.tpl b/templates/responses_show.html.tpl index 9d37aff2..be7eac78 100644 --- a/templates/responses_show.html.tpl +++ b/templates/responses_show.html.tpl @@ -40,7 +40,7 @@
Durata della gara
{{if not .Data.Contest.IsAlwaysActive}} - {{.Data.Contest.Duration}} min (la prova dovrà comunque essere consegnata al massimo 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}} From 04d3cbcd0ed2e3b62167e35d1cdf498a2c1f3c64 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Tue, 5 Jan 2021 12:28:40 +0100 Subject: [PATCH 3/3] [auto] bumped version to 0.9.9-39-gc97792e-master --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 9164e693..e4810e8e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.9-37-g339d087-master +0.9.9-39-gc97792e-master