From 20d0e1d127cce53d0d35b6090a7c89f4527e67b6 Mon Sep 17 00:00:00 2001 From: Pavel Date: Sun, 17 Mar 2024 19:52:29 +0300 Subject: [PATCH] update repo method --- dal/db_query/queries.sql | 10 ++-------- repository/statistics/statistics.go | 2 -- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index 87c3ea4..35e6ff8 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -517,10 +517,7 @@ WITH Funnel AS ( SELECT q.title AS question_title, ta.total_answers, - CASE - WHEN ta.total_answers = 0 THEN 0 - ELSE CAST(COUNT(*)::FLOAT / NULLIF(ta.total_answers, 0) AS INTEGER) - END AS percentage + CAST(COUNT(*) * 100.0 / NULLIF(ta.total_answers, 0) AS INTEGER) AS percentage FROM answer a JOIN @@ -542,10 +539,7 @@ WITH Funnel AS ( q.id, q.title AS question_title, a.content AS answer_content, - CASE - WHEN q.total_answers = 0 THEN 0 - ELSE CAST(COUNT(*)::FLOAT / NULLIF(q.total_answers, 0) AS INTEGER) - END AS percentage + CAST(COUNT(*) * 100.0 / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage FROM answer a JOIN ( diff --git a/repository/statistics/statistics.go b/repository/statistics/statistics.go index 6701a4f..a0d33ea 100644 --- a/repository/statistics/statistics.go +++ b/repository/statistics/statistics.go @@ -3,7 +3,6 @@ package statistics import ( "context" "database/sql" - "fmt" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen" "time" ) @@ -136,7 +135,6 @@ func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req D resp.Funnel[2] = float64(row.CountTResult) / float64(row.CountStartTrue) } - fmt.Println(resp.Funnel) resp.Results[row.ResultsTitle] = float64(row.ResultsPercentage) if resp.Questions[row.QuestionsTitle] == nil {