Include works in allGrades

This commit is contained in:
nemunaire 2023-03-08 04:40:03 +01:00
commit a9bb758e99
5 changed files with 31 additions and 21 deletions

View file

@ -342,7 +342,7 @@ func (s Survey) GetScore(u *User) (score *float64, err error) {
if ok {
score = v
} else {
err = DBQueryRow("SELECT SUM(score)/COUNT(*) FROM student_scores WHERE id_survey=? AND id_user=?", s.Id, u.Id).Scan(&score)
err = DBQueryRow("SELECT SUM(score)/COUNT(*) FROM student_scores WHERE kind = 'survey' AND id=? AND id_user=?", s.Id, u.Id).Scan(&score)
if score != nil {
*score = *score / 5.0
}
@ -355,7 +355,7 @@ func (s Survey) GetScore(u *User) (score *float64, err error) {
}
func (s Survey) GetScores() (scores map[int64]*float64, err error) {
if rows, errr := DBQuery("SELECT id_user, SUM(score)/COUNT(*) FROM student_scores WHERE id_survey=? GROUP BY id_user", s.Id); errr != nil {
if rows, errr := DBQuery("SELECT id_user, SUM(score)/COUNT(*) FROM student_scores WHERE kind = 'survey' AND id_survey=? GROUP BY id_user", s.Id); errr != nil {
return nil, errr
} else {
defer rows.Close()