2024-06-13 12:39:18 +00:00
|
|
|
package statistics
|
|
|
|
|
2024-06-13 15:37:58 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
)
|
2024-06-13 12:39:18 +00:00
|
|
|
|
|
|
|
type DepsClick struct {
|
|
|
|
Conn *sql.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
type StatisticClick struct {
|
|
|
|
conn *sql.DB
|
|
|
|
}
|
|
|
|
|
2024-07-02 08:18:00 +00:00
|
|
|
func NewClickStatistic(deps DepsClick) *StatisticClick {
|
|
|
|
return &StatisticClick{
|
2024-06-13 12:39:18 +00:00
|
|
|
conn: deps.Conn,
|
|
|
|
}
|
2024-06-13 15:37:58 +00:00
|
|
|
}
|
|
|
|
|
2024-06-13 19:03:41 +00:00
|
|
|
type Statistic struct {
|
2024-06-13 15:37:58 +00:00
|
|
|
Count int64
|
|
|
|
QuestionID int64
|
|
|
|
}
|
|
|
|
|
2024-06-19 14:51:34 +00:00
|
|
|
type PipeLineStatsResp map[int64][]Statistic
|
2024-06-13 19:03:41 +00:00
|
|
|
|
2024-06-30 08:42:21 +00:00
|
|
|
func (s *StatisticClick) GetPipelinesStatistics(ctx context.Context, quizID int64, from uint64, to uint64) (PipeLineStatsResp, error) {
|
|
|
|
pipelines := make(PipeLineStatsResp)
|
2024-06-19 14:29:20 +00:00
|
|
|
|
2024-06-17 11:37:03 +00:00
|
|
|
query := `
|
2024-06-30 08:42:21 +00:00
|
|
|
select last_quesion, questions, count() from (select last_quesion, questions, target_quiz
|
|
|
|
from (select last_quesion, questions, target_quiz from view_pipelines_signs
|
|
|
|
join view_respondent_paths on long_sess = session array join questions)
|
|
|
|
as pipelines join mv_answers on questions=questionid and quizid=target_quiz
|
|
|
|
where target_quiz = ? AND event_time BETWEEN ? AND ? ) group by last_quesion, questions;
|
2024-06-17 11:37:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
rows, err := s.conn.QueryContext(ctx, query, quizID, from, to)
|
2024-06-13 15:37:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-06-17 11:37:03 +00:00
|
|
|
defer rows.Close()
|
2024-06-14 18:06:01 +00:00
|
|
|
|
2024-06-17 11:37:03 +00:00
|
|
|
for rows.Next() {
|
2024-06-30 08:42:21 +00:00
|
|
|
var lastQuestionID int64
|
|
|
|
var questionID int64
|
|
|
|
var count int64
|
2024-06-17 11:37:03 +00:00
|
|
|
|
2024-06-30 08:42:21 +00:00
|
|
|
if err := rows.Scan(&lastQuestionID, &questionID, &count); err != nil {
|
2024-06-19 14:51:34 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-06-14 13:51:47 +00:00
|
|
|
|
2024-06-30 08:42:21 +00:00
|
|
|
stat := Statistic{
|
|
|
|
Count: count,
|
|
|
|
QuestionID: questionID,
|
2024-06-14 13:51:47 +00:00
|
|
|
}
|
2024-06-30 08:42:21 +00:00
|
|
|
|
|
|
|
pipelines[lastQuestionID] = append(pipelines[lastQuestionID], stat)
|
2024-06-17 11:37:03 +00:00
|
|
|
}
|
2024-06-14 13:51:47 +00:00
|
|
|
|
2024-06-17 11:37:03 +00:00
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
2024-06-14 13:51:47 +00:00
|
|
|
}
|
|
|
|
|
2024-06-30 08:42:21 +00:00
|
|
|
return pipelines, nil
|
2024-06-13 12:39:18 +00:00
|
|
|
}
|