update repo method
This commit is contained in:
parent
df74226004
commit
d3c21151d3
@ -3,6 +3,7 @@ package statistics
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -98,6 +99,7 @@ func (r *StatisticsRepository) GetGeneralStatistics(ctx context.Context, req Dev
|
|||||||
}
|
}
|
||||||
|
|
||||||
type QuestionsStatsResp struct {
|
type QuestionsStatsResp struct {
|
||||||
|
// PS это / не или а делить а то я спустя пару часов только догнал
|
||||||
//Funnel 3 отдельных метрики
|
//Funnel 3 отдельных метрики
|
||||||
// 0 - количество сессий с любым ответом кроме start == true / количество сессий с ответом start == true
|
// 0 - количество сессий с любым ответом кроме start == true / количество сессий с ответом start == true
|
||||||
// 1 - количество сессий с result == false, но тип вопроса, на который ответ == result / количество сессий с ответом start == true
|
// 1 - количество сессий с result == false, но тип вопроса, на который ответ == result / количество сессий с ответом start == true
|
||||||
@ -112,5 +114,34 @@ type QuestionsStatsResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req DeviceStatReq) (QuestionsStatsResp, error) {
|
func (r *StatisticsRepository) GetQuestionsStatistics(ctx context.Context, req DeviceStatReq) (QuestionsStatsResp, error) {
|
||||||
|
resp := QuestionsStatsResp{
|
||||||
|
Funnel: [3]float64{},
|
||||||
|
Results: make(map[string]float64),
|
||||||
|
Questions: make(map[string]map[string]float64),
|
||||||
|
}
|
||||||
|
|
||||||
|
queStatistics, err := r.queries.QuestionsStatistics(ctx, sqlcgen.QuestionsStatisticsParams{
|
||||||
|
QuizID: req.QuizId,
|
||||||
|
ToTimestamp: float64(req.From),
|
||||||
|
ToTimestamp_2: float64(req.To),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, row := range queStatistics {
|
||||||
|
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)
|
||||||
|
|
||||||
|
fmt.Println(resp.Funnel)
|
||||||
|
resp.Results[row.ResultsTitle] = float64(row.ResultsPercentage)
|
||||||
|
|
||||||
|
if resp.Questions[row.QuestionsTitle] == nil {
|
||||||
|
resp.Questions[row.QuestionsTitle] = make(map[string]float64)
|
||||||
|
}
|
||||||
|
resp.Questions[row.QuestionsTitle][row.AnswerContent.String] = float64(row.QuestionsPercentage)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user