diff options
| author | William Hergès <william@herges.fr> | 2025-08-31 14:30:14 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-31 14:30:14 +0200 |
| commit | d63203709f421c2b0f093d8ee0045f0854f77dc0 (patch) | |
| tree | 4e2d13d457daed7e0b3b9d292b7565d2ef5bbcf8 /commands/stats.go | |
| parent | 26643cd271b7efeaab9a00d829e182297082555c (diff) | |
refactor(stats): rewrite data creation
Diffstat (limited to 'commands/stats.go')
| -rw-r--r-- | commands/stats.go | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/commands/stats.go b/commands/stats.go index ccc5857..5d22483 100644 --- a/commands/stats.go +++ b/commands/stats.go @@ -128,17 +128,20 @@ func statsAll(s *discordgo.Session, i *discordgo.InteractionCreate, days uint) ( } pts, ok := stats[raw.CopaingID] if !ok { - pts = &[]plotter.XY{} + t := make([]plotter.XY, days) + pts = &t stats[raw.CopaingID] = pts } - t := float64(raw.CreatedAt.Unix() - time.Now().Unix()) + t := raw.CreatedAt.Unix() - time.Now().Unix() if !gokord.Debug { - t = math.Ceil(t / (24 * 60 * 60)) + t = int64(math.Ceil(float64(t) / (24 * 60 * 60))) + } else { + t = int64(math.Ceil(float64(t) / 6)) } - *pts = append(*pts, plotter.XY{ - X: t, + (*pts)[t] = plotter.XY{ + X: float64(t), Y: float64(raw.XP), - }) + } } return generatePlot(s, i, days, copaings, stats) @@ -194,17 +197,20 @@ func statsMember(s *discordgo.Session, i *discordgo.InteractionCreate, days uint for _, raw := range rawData { pts, ok := stats[raw.CopaingID] if !ok { - pts = &[]plotter.XY{} + t := make([]plotter.XY, days) + pts = &t stats[raw.CopaingID] = pts } - t := float64(raw.CreatedAt.Unix() - time.Now().Unix()) + t := raw.CreatedAt.Unix() - time.Now().Unix() if !gokord.Debug { - t = math.Ceil(t / (24 * 60 * 60)) + t = int64(math.Ceil(float64(t) / (24 * 60 * 60))) + } else { + t = int64(math.Ceil(float64(t) / 6)) } - *pts = append(*pts, plotter.XY{ - X: t, + (*pts)[t] = plotter.XY{ + X: float64(t), Y: float64(raw.XP), - }) + } } return generatePlot(s, i, days, copaings, stats) |
