update clickhouse query
This commit is contained in:
parent
46fac5b686
commit
a111b3bc3c
@ -48,12 +48,14 @@ FROM statistics WHERE message IN ('InfoQuizOpen', 'InfoAnswer', 'InfoResult')
|
||||
return nil
|
||||
}
|
||||
|
||||
type PipeLineStatsResp [][]struct {
|
||||
type Statistic struct {
|
||||
Count int64
|
||||
QuestionID int64
|
||||
}
|
||||
|
||||
func (s *StatisticClick) GetPipelinesStatistics(ctx context.Context, quizID int64, from uint64, to uint64) ([]PipeLineStatsResp, error) {
|
||||
type PipeLineStatsResp [][]Statistic
|
||||
|
||||
func (s *StatisticClick) GetPipelinesStatistics(ctx context.Context, quizID int64, from uint64, to uint64) (PipeLineStatsResp, error) {
|
||||
query := `
|
||||
SELECT
|
||||
ctxsession,ctxquestionid,count(*) as session_count
|
||||
@ -66,8 +68,8 @@ GROUP BY ctxsession, ctxquestionid ORDER BY ctxsession, ctxquestionid
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var pipelines []PipeLineStatsResp
|
||||
var currentPipeline PipeLineStatsResp
|
||||
var pipelines PipeLineStatsResp
|
||||
var currentPipeline []Statistic
|
||||
var lastSession string
|
||||
|
||||
for rows.Next() {
|
||||
@ -80,16 +82,18 @@ GROUP BY ctxsession, ctxquestionid ORDER BY ctxsession, ctxquestionid
|
||||
}
|
||||
|
||||
// новая сессия - новая воронка
|
||||
if session != lastSession && lastSession != "" {
|
||||
pipelines = append(pipelines, currentPipeline)
|
||||
currentPipeline = PipeLineStatsResp{}
|
||||
if session != lastSession {
|
||||
if lastSession != "" {
|
||||
pipelines = append(pipelines, currentPipeline)
|
||||
}
|
||||
currentPipeline = []Statistic{}
|
||||
}
|
||||
|
||||
// текущая статистика в текущую воронку
|
||||
currentPipeline = append(currentPipeline, []struct {
|
||||
Count int64
|
||||
QuestionID int64
|
||||
}{{Count: count, QuestionID: questionID}})
|
||||
currentPipeline = append(currentPipeline, Statistic{
|
||||
Count: count,
|
||||
QuestionID: questionID,
|
||||
})
|
||||
|
||||
lastSession = session
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user