lil fix question title

This commit is contained in:
skeris 2024-04-08 21:28:39 +03:00
parent 126d5822d5
commit 4495237cb3
3 changed files with 11 additions and 3 deletions

@ -566,6 +566,7 @@ WITH Funnel AS (
Questions AS (
SELECT
q.title AS question_title,
q.page AS question_page,
lc.last_answer_content AS answer_content,
CAST(
COUNT(CASE WHEN a.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
@ -592,6 +593,7 @@ SELECT
Results.question_title AS results_title,
Results.percentage AS results_percentage,
Questions.question_title AS questions_title,
COALESCE(Questions.question_page, 0) AS questions_page,
Questions.answer_content AS answer_content,
Questions.percentage AS questions_percentage
FROM

@ -1749,6 +1749,7 @@ WITH Funnel AS (
Questions AS (
SELECT
q.title AS question_title,
q.page AS question_page,
lc.last_answer_content AS answer_content,
CAST(
COUNT(CASE WHEN a.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
@ -1775,6 +1776,7 @@ SELECT
Results.question_title AS results_title,
Results.percentage AS results_percentage,
Questions.question_title AS questions_title,
COALESCE(Questions.question_page, 0) AS questions_page,
Questions.answer_content AS answer_content,
Questions.percentage AS questions_percentage
FROM
@ -1799,6 +1801,7 @@ type QuestionsStatisticsRow struct {
ResultsTitle string `db:"results_title" json:"results_title"`
ResultsPercentage float64 `db:"results_percentage" json:"results_percentage"`
QuestionsTitle string `db:"questions_title" json:"questions_title"`
QuestionsPage int16 `db:"questions_page" json:"questions_page"`
AnswerContent sql.NullString `db:"answer_content" json:"answer_content"`
QuestionsPercentage float64 `db:"questions_percentage" json:"questions_percentage"`
}
@ -1820,6 +1823,7 @@ func (q *Queries) QuestionsStatistics(ctx context.Context, arg QuestionsStatisti
&i.ResultsTitle,
&i.ResultsPercentage,
&i.QuestionsTitle,
&i.QuestionsPage,
&i.AnswerContent,
&i.QuestionsPercentage,
); err != nil {

@ -1,6 +1,7 @@
package statistics
import (
"fmt"
"context"
"database/sql"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
@ -142,10 +143,11 @@ func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req D
resp.Results[row.ResultsTitle] = row.ResultsPercentage
if resp.Questions[row.QuestionsTitle] == nil {
resp.Questions[row.QuestionsTitle] = make(map[string]float64)
questionTitle := fmt.Sprintf("%s (%d)", row.QuestionsTitle, row.QuestionsPage)
if resp.Questions[questionTitle] == nil {
resp.Questions[questionTitle] = make(map[string]float64)
}
resp.Questions[row.QuestionsTitle][row.AnswerContent.String] = row.QuestionsPercentage
resp.Questions[questionTitle][row.AnswerContent.String] = row.QuestionsPercentage
}
return resp, nil