diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index 2a25ec0..9dc86c9 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -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 diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index 2d0034b..ba0eb2b 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -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 { diff --git a/repository/statistics/statistics.go b/repository/statistics/statistics.go index 6495254..ba2a1bb 100644 --- a/repository/statistics/statistics.go +++ b/repository/statistics/statistics.go @@ -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