From 62b26cc7b25c84fdb6cdf62adae8293e7803ca68 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Sat, 2 Jan 2021 12:12:38 +0100 Subject: [PATCH] Add some statistical info to contest view --- orm/contest.go | 19 ++++++++++++++++--- scripts/export_participants/.gitignore | 1 + templates/contests_show.html.tpl | 7 ++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/orm/contest.go b/orm/contest.go index 8d948d45..b7786a1f 100644 --- a/orm/contest.go +++ b/orm/contest.go @@ -33,8 +33,11 @@ type Contest struct { ResetStartTime bool - Questions []*Question - Participants []*Participant `gorm:"many2many:subscriptions"` + Questions []*Question + Participants []*Participant `gorm:"many2many:subscriptions"` + Responses []*Response + StartedResponses []*Response + SavedResponses []*Response prevStartTime time.Time } @@ -87,7 +90,17 @@ func (c *Contest) Read(db *Database, args map[string]string, w http.ResponseWrit id := args["id"] - if err := db._db.Preload("Participants").Preload("Questions").First(&contest, id).Error; err != nil { + if err := db._db. + Preload("Participants"). + Preload("Responses"). + Preload("StartedResponses", func(tx *gorm.DB) *gorm.DB { + return db.DB().Debug().Where("start_time <> ?", time.Time{}) + }). + Preload("SavedResponses", func(tx *gorm.DB) *gorm.DB { + return db.DB().Debug().Where("end_time <> ?", time.Time{}) + }). + Preload("Questions"). + First(&contest, id).Error; err != nil { return nil, err } diff --git a/scripts/export_participants/.gitignore b/scripts/export_participants/.gitignore index afed0735..3ebacd69 100644 --- a/scripts/export_participants/.gitignore +++ b/scripts/export_participants/.gitignore @@ -1 +1,2 @@ *.csv +*.xlsx \ No newline at end of file diff --git a/templates/contests_show.html.tpl b/templates/contests_show.html.tpl index 6e43edf9..9ecc4a71 100644 --- a/templates/contests_show.html.tpl +++ b/templates/contests_show.html.tpl @@ -21,7 +21,12 @@
{{.Data.NumQuestions}}
Numero di risposte per domanda
{{.Data.NumAnswersPerQuestion}}
- +
Numero di partecipanti iscritti
+
{{len .Data.Participants}}
+
Numero di prove visualizzate
+
{{len .Data.StartedResponses}}
+
Numero di prove salvate
+
{{len .Data.SavedResponses}}