aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-08-31 14:30:14 +0200
committerWilliam Hergès <william@herges.fr>2025-08-31 14:30:14 +0200
commitd63203709f421c2b0f093d8ee0045f0854f77dc0 (patch)
tree4e2d13d457daed7e0b3b9d292b7565d2ef5bbcf8
parent26643cd271b7efeaab9a00d829e182297082555c (diff)
refactor(stats): rewrite data creation
-rw-r--r--commands/stats.go30
-rw-r--r--exp/functions.go2
2 files changed, 19 insertions, 13 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)
diff --git a/exp/functions.go b/exp/functions.go
index a8b0350..ebd0761 100644
--- a/exp/functions.go
+++ b/exp/functions.go
@@ -53,7 +53,7 @@ func LevelXP(level uint) uint {
func TimeStampNDaysBefore(n uint) string {
var unix time.Time
if gokord.Debug {
- unix = time.Unix(time.Now().Unix()-int64(n)*6, 0) // reduce time for debug
+ unix = time.Unix(time.Now().Unix()-int64(n*6), 0) // reduce time for debug
} else {
unix = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0)
}