fix score csv trouble
This commit is contained in:
parent
2fbd1b5569
commit
e72f0a3c32
@ -4,11 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
|
||||||
"gitea.pena/SQuiz/common/model"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||||
|
"gitea.pena/SQuiz/common/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
@ -120,11 +121,11 @@ func (r *ResultRepository) GetQuizResultsCSV(ctx context.Context, quizID uint64,
|
|||||||
mainQuery := `WITH ordered_content AS (
|
mainQuery := `WITH ordered_content AS (
|
||||||
SELECT a.id, a.question_id, a.quiz_id, a.fingerprint, a.session, a.result, a.created_at, a.new, a.deleted,a.version,
|
SELECT a.id, a.question_id, a.quiz_id, a.fingerprint, a.session, a.result, a.created_at, a.new, a.deleted,a.version,
|
||||||
COALESCE(NULLIF(a.content, ''),MAX(NULLIF(a.content, '')) OVER (
|
COALESCE(NULLIF(a.content, ''),MAX(NULLIF(a.content, '')) OVER (
|
||||||
PARTITION BY a.session, a.question_id ORDER BY a.created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) AS last_not_empty
|
PARTITION BY a.session, a.question_id, a.result ORDER BY a.created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) AS last_not_empty
|
||||||
FROM answer a
|
FROM answer a
|
||||||
WHERE a.quiz_id = $1 AND a.deleted = FALSE
|
WHERE a.quiz_id = $1 AND a.deleted = FALSE
|
||||||
)
|
)
|
||||||
SELECT DISTINCT ON (a.question_id, a.session)
|
SELECT DISTINCT ON (a.question_id, a.result, a.session)
|
||||||
a.id, COALESCE(a.last_not_empty,''), a.question_id, a.quiz_id, a.fingerprint,
|
a.id, COALESCE(a.last_not_empty,''), a.question_id, a.quiz_id, a.fingerprint,
|
||||||
a.session, a.result, a.created_at, a.new, a.deleted, a.version
|
a.session, a.result, a.created_at, a.new, a.deleted, a.version
|
||||||
FROM ordered_content a WHERE EXISTS (
|
FROM ordered_content a WHERE EXISTS (
|
||||||
@ -148,7 +149,7 @@ FROM ordered_content a WHERE EXISTS (
|
|||||||
WHERE a2.session = a.session AND a2.result = TRUE AND a2.quiz_id = a.quiz_id
|
WHERE a2.session = a.session AND a2.result = TRUE AND a2.quiz_id = a.quiz_id
|
||||||
)`
|
)`
|
||||||
|
|
||||||
mainQuery += ` ORDER BY a.session, a.question_id ASC, a.created_at DESC, a.result DESC`
|
mainQuery += ` ORDER BY a.session, a.result, a.question_id ASC, a.created_at DESC, a.result DESC`
|
||||||
|
|
||||||
rows, err := r.pool.QueryContext(ctx, mainQuery, queryParams...)
|
rows, err := r.pool.QueryContext(ctx, mainQuery, queryParams...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user