Include works in allGrades
This commit is contained in:
parent
93b5857fa6
commit
a9bb758e99
2
db.go
2
db.go
@ -273,7 +273,7 @@ CREATE TABLE IF NOT EXISTS survey_shared(
|
||||
return err
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE VIEW IF NOT EXISTS student_scores AS SELECT T.id_user, T.id_survey, Q.id_question, MAX(R.score) AS score FROM (SELECT DISTINCT R.id_user, S.id_survey FROM survey_responses R INNER JOIN survey_quests Q ON R.id_question = Q.id_question INNER JOIN surveys S ON Q.id_survey = S.id_survey) T LEFT OUTER JOIN survey_quests Q ON T.id_survey = Q.id_survey LEFT OUTER JOIN survey_responses R ON R.id_user = T.id_user AND Q.id_question = R.id_question GROUP BY id_user, id_survey, id_question;
|
||||
CREATE VIEW IF NOT EXISTS student_scores AS SELECT "survey" AS kind, T.id_user, T.id_survey AS id, Q.id_question, MAX(R.score) AS score FROM (SELECT DISTINCT R.id_user, S.id_survey FROM survey_responses R INNER JOIN survey_quests Q ON R.id_question = Q.id_question INNER JOIN surveys S ON Q.id_survey = S.id_survey) T LEFT OUTER JOIN survey_quests Q ON T.id_survey = Q.id_survey LEFT OUTER JOIN survey_responses R ON R.id_user = T.id_user AND Q.id_question = R.id_question GROUP BY id_user, kind, id, id_question UNION SELECT "work" AS kind, G.id_user, G.id_work AS id, 0 AS id_question, G.grade AS score FROM works W RIGHT OUTER JOIN user_work_grades G ON G.id_work = W.id_work GROUP BY id_user, kind, id, id_question;
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
20
grades.go
20
grades.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@ -81,28 +82,29 @@ func gradeHandler(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetAllGrades() (scores map[int64]map[int64]*float64, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_user, id_survey, SUM(score)/COUNT(*) FROM student_scores GROUP BY id_user, id_survey"); errr != nil {
|
||||
func GetAllGrades() (scores map[int64]map[string]*float64, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_user, kind, id, SUM(score)/COUNT(*) FROM student_scores GROUP BY id_user, kind, id"); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
scores = map[int64]map[int64]*float64{}
|
||||
scores = map[int64]map[string]*float64{}
|
||||
|
||||
for rows.Next() {
|
||||
var id_user int64
|
||||
var id_survey int64
|
||||
var kind string
|
||||
var id int64
|
||||
var score *float64
|
||||
|
||||
if err = rows.Scan(&id_user, &id_survey, &score); err != nil {
|
||||
if err = rows.Scan(&id_user, &kind, &id, &score); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if scores[id_user] == nil {
|
||||
scores[id_user] = map[int64]*float64{}
|
||||
scores[id_user] = map[string]*float64{}
|
||||
}
|
||||
|
||||
scores[id_user][id_survey] = score
|
||||
scores[id_user][fmt.Sprintf("%c.%d", kind[0], id)] = score
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return
|
||||
@ -113,7 +115,7 @@ func GetAllGrades() (scores map[int64]map[int64]*float64, err error) {
|
||||
}
|
||||
|
||||
func (s Survey) GetGrades() (scores map[int64]*float64, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_question, SUM(score)/COUNT(*) FROM student_scores WHERE id_survey=? GROUP BY id_question", s.Id); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT id_question, SUM(score)/COUNT(*) FROM student_scores WHERE kind = 'survey' AND id=? GROUP BY id_question", s.Id); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
@ -138,7 +140,7 @@ func (s Survey) GetGrades() (scores map[int64]*float64, err error) {
|
||||
}
|
||||
|
||||
func (s Survey) GetUserGrades(u *User) (scores map[int64]*float64, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_question, MAX(score) FROM student_scores WHERE id_survey=? AND id_user = ? GROUP BY id_question", s.Id, u.Id); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT id_question, MAX(score) FROM student_scores WHERE kind = 'survey' AND id=? AND id_user = ? GROUP BY id_question", s.Id, u.Id); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
@ -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()
|
||||
|
@ -20,7 +20,7 @@
|
||||
<small class="text-muted">Notes</small>
|
||||
</h2>
|
||||
|
||||
{#await getSurveys()}
|
||||
{#await getSurveys(true)}
|
||||
<div class="d-flex justify-content-center">
|
||||
<div class="spinner-border me-2" role="status"></div>
|
||||
Chargement des questionnaires corrigés…
|
||||
@ -38,9 +38,15 @@
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Login</th>
|
||||
{#each surveys as survey (survey.id)}
|
||||
{#if survey.corrected && (promo === null || survey.promo == promo)}
|
||||
<th><a href="surveys/{survey.id}" style="text-decoration: none">{survey.title}</a></th>
|
||||
{#each surveys as survey}
|
||||
{#if survey.corrected && (!promo || survey.promo == promo)}
|
||||
<th>
|
||||
{#if survey.kind == "survey"}
|
||||
<a href="surveys/{survey.id}" style="text-decoration: none">{survey.title}</a>
|
||||
{:else}
|
||||
<a href="works/{survey.id}" style="text-decoration: none">{survey.title}</a>
|
||||
{/if}
|
||||
</th>
|
||||
{/if}
|
||||
{/each}
|
||||
</tr>
|
||||
@ -57,13 +63,15 @@
|
||||
</tr>
|
||||
{:then users}
|
||||
{#each users as user (user.id)}
|
||||
{#if promo === null || user.promo === promo}
|
||||
{#if !promo || user.promo == promo}
|
||||
<tr>
|
||||
<td><a href="users/{user.id}" style="text-decoration: none">{user.id}</a></td>
|
||||
<td><a href="users/{user.login}" style="text-decoration: none">{user.login}</a></td>
|
||||
{#each surveys as survey (survey.id)}
|
||||
{#if survey.corrected && (promo === null || survey.promo == promo)}
|
||||
<td>{grades[user.id] && grades[user.id][survey.id]?grades[user.id][survey.id]:""}</td>
|
||||
{#each surveys as survey}
|
||||
{#if survey.corrected && (!promo || survey.promo == promo)}
|
||||
<td>
|
||||
{grades[user.id] && grades[user.id][survey.kind + "." + survey.id]?grades[user.id][survey.kind + "." + survey.id]:""}
|
||||
</td>
|
||||
{/if}
|
||||
{/each}
|
||||
</tr>
|
||||
|
@ -1,5 +1,5 @@
|
||||
export async function load({ params }) {
|
||||
return {
|
||||
promo: params.promo,
|
||||
promo: parseInt(params.promo),
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user