Add some statistical info to contest view

This commit is contained in:
Andrea Fazzi 2021-01-02 12:12:38 +01:00
parent be1cc96af3
commit 62b26cc7b2
3 changed files with 23 additions and 4 deletions

View file

@ -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
}

View file

@ -1 +1,2 @@
*.csv
*.xlsx

View file

@ -21,7 +21,12 @@
<dd class="col-sm-9">{{.Data.NumQuestions}}</dd>
<dt class="col-sm-3">Numero di risposte per domanda</dt>
<dd class="col-sm-9">{{.Data.NumAnswersPerQuestion}}</dd>
<dt class="col-sm-3">Numero di partecipanti iscritti</dt>
<dd class="col-sm-9">{{len .Data.Participants}}</dd>
<dt class="col-sm-3">Numero di prove visualizzate</dt>
<dd class="col-sm-9">{{len .Data.StartedResponses}}</dd>
<dt class="col-sm-3">Numero di prove salvate</dt>
<dd class="col-sm-9">{{len .Data.SavedResponses}}</dd>
</dl>
<div class="row">