init methid for new device statistics
This commit is contained in:
parent
720cbfb405
commit
4cc8709891
@ -24,21 +24,41 @@ func NewStatisticsRepo(deps Deps) *StatisticsRepository {
|
||||
}
|
||||
|
||||
type DeviceStatReq struct {
|
||||
QuizId string
|
||||
QuizId int64
|
||||
From uint64
|
||||
To uint64
|
||||
}
|
||||
|
||||
type DeviceStatResp struct {
|
||||
Device map[string]float64
|
||||
//ключ DeviceType значение процент
|
||||
Device map[string]float64 // процентное соотношение DeviceType по всем ответам на опроc c res==true
|
||||
// тоже самое тут только по OS и BROWSER
|
||||
OS map[string]float64
|
||||
Browser map[string]float64
|
||||
}
|
||||
|
||||
func (r *StatisticsRepository) GetDeviceStatistics(ctx context.Context, req DeviceStatReq) DeviceStatResp {
|
||||
func (r *StatisticsRepository) GetDeviceStatistics(ctx context.Context, req DeviceStatReq) (DeviceStatResp, error) {
|
||||
resp := DeviceStatResp{
|
||||
Device: make(map[string]float64),
|
||||
OS: make(map[string]float64),
|
||||
Browser: make(map[string]float64),
|
||||
}
|
||||
|
||||
//todo подумать как в sqlc сделать не int32 а float64
|
||||
allStatistics, err := r.queries.DeviceStatistics(ctx, sqlcgen.DeviceStatisticsParams{
|
||||
QuizID: req.QuizId,
|
||||
ToTimestamp: float64(req.From),
|
||||
ToTimestamp_2: float64(req.To),
|
||||
})
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
for _, stat := range allStatistics {
|
||||
resp.Device[stat.DeviceType] = float64(stat.DevicePercentage)
|
||||
resp.OS[stat.Os] = float64(stat.OsPercentage)
|
||||
resp.Browser[stat.Browser] = float64(stat.BrowserPercentage)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user