add some data to funnel and filter start from questions

This commit is contained in:
skeris 2024-04-07 18:32:36 +03:00
parent 38eec37140
commit 126d5822d5
3 changed files with 10 additions and 0 deletions

@ -556,6 +556,7 @@ WITH Funnel AS (
answer
WHERE
quiz_id = $1
AND start != true
AND created_at >= TO_TIMESTAMP($2)
AND created_at <= TO_TIMESTAMP($3)
GROUP BY
@ -575,6 +576,7 @@ WITH Funnel AS (
JOIN answer a ON q.id = a.question_id
WHERE
a.quiz_id = $1
AND a.start != true
AND a.created_at >= TO_TIMESTAMP($2)
AND a.created_at <= TO_TIMESTAMP($3)
GROUP BY

@ -1739,6 +1739,7 @@ WITH Funnel AS (
answer
WHERE
quiz_id = $1
AND start != true
AND created_at >= TO_TIMESTAMP($2)
AND created_at <= TO_TIMESTAMP($3)
GROUP BY
@ -1758,6 +1759,7 @@ WITH Funnel AS (
JOIN answer a ON q.id = a.question_id
WHERE
a.quiz_id = $1
AND a.start != true
AND a.created_at >= TO_TIMESTAMP($2)
AND a.created_at <= TO_TIMESTAMP($3)
GROUP BY

@ -103,6 +103,7 @@ type QuestionsStatsResp struct {
// 1 - количество сессий с result == false, но тип вопроса, на который ответ == result / количество сессий с ответом start == true
// 2 - количество сессий с ответом result == true / количество сессий с ответом start == true
Funnel [3]float64
FunnelData [4]float64
// ключ - заголовок вопроса найденного по айдишнику вопроса в ответе result == true,
// значение - процент ответов с result == true и таким айдишником вопроса
Results map[string]float64
@ -114,6 +115,7 @@ type QuestionsStatsResp struct {
func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req DeviceStatReq) (QuestionsStatsResp, error) {
resp := QuestionsStatsResp{
Funnel: [3]float64{},
FunnelData: [4]float64{},
Results: make(map[string]float64),
Questions: make(map[string]map[string]float64),
}
@ -132,6 +134,10 @@ func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req D
resp.Funnel[0] = float64(row.CountStartFalse) / float64(row.CountStartTrue)
resp.Funnel[1] = float64(row.CountFResultWithTQuestion) / float64(row.CountStartTrue)
resp.Funnel[2] = float64(row.CountTResult) / float64(row.CountStartTrue)
resp.FunnelData[0] = float64(row.CountStartTrue)
resp.FunnelData[1] = float64(row.CountStartFalse)
resp.FunnelData[2] = float64(row.CountFResultWithTQuestion)
resp.FunnelData[3] = float64(row.CountTResult)
}
resp.Results[row.ResultsTitle] = row.ResultsPercentage