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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type PipeLineStatsResp [][]struct {
|
type Statistic struct {
|
||||||
Count int64
|
Count int64
|
||||||
QuestionID 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 := `
|
query := `
|
||||||
SELECT
|
SELECT
|
||||||
ctxsession,ctxquestionid,count(*) as session_count
|
ctxsession,ctxquestionid,count(*) as session_count
|
||||||
@ -66,8 +68,8 @@ GROUP BY ctxsession, ctxquestionid ORDER BY ctxsession, ctxquestionid
|
|||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var pipelines []PipeLineStatsResp
|
var pipelines PipeLineStatsResp
|
||||||
var currentPipeline PipeLineStatsResp
|
var currentPipeline []Statistic
|
||||||
var lastSession string
|
var lastSession string
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@ -80,16 +82,18 @@ GROUP BY ctxsession, ctxquestionid ORDER BY ctxsession, ctxquestionid
|
|||||||
}
|
}
|
||||||
|
|
||||||
// новая сессия - новая воронка
|
// новая сессия - новая воронка
|
||||||
if session != lastSession && lastSession != "" {
|
if session != lastSession {
|
||||||
|
if lastSession != "" {
|
||||||
pipelines = append(pipelines, currentPipeline)
|
pipelines = append(pipelines, currentPipeline)
|
||||||
currentPipeline = PipeLineStatsResp{}
|
}
|
||||||
|
currentPipeline = []Statistic{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// текущая статистика в текущую воронку
|
// текущая статистика в текущую воронку
|
||||||
currentPipeline = append(currentPipeline, []struct {
|
currentPipeline = append(currentPipeline, Statistic{
|
||||||
Count int64
|
Count: count,
|
||||||
QuestionID int64
|
QuestionID: questionID,
|
||||||
}{{Count: count, QuestionID: questionID}})
|
})
|
||||||
|
|
||||||
lastSession = session
|
lastSession = session
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user