From d63203709f421c2b0f093d8ee0045f0854f77dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sun, 31 Aug 2025 14:30:14 +0200 Subject: refactor(stats): rewrite data creation --- commands/stats.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'commands') 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) -- cgit v1.2.3