diff options
| author | William Hergès <william@herges.fr> | 2025-09-20 14:01:39 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-09-20 14:01:39 +0200 |
| commit | 8d6fa726069bd5364ada1521b400bb5eb7865d87 (patch) | |
| tree | 9d566cb4cdab6a7069826732ef6d602b40f71dcf | |
| parent | e8b91140fba414c2bd7e7f36e8cff95d7651732d (diff) | |
feat(stats): custom scale for Y to show level
| -rw-r--r-- | commands/stats.go | 4 | ||||
| -rw-r--r-- | exp/functions.go | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/commands/stats.go b/commands/stats.go index e2c2ba4..3156fd9 100644 --- a/commands/stats.go +++ b/commands/stats.go @@ -47,6 +47,9 @@ var colors = []color.RGBA{ func Stats(s *discordgo.Session, i *discordgo.InteractionCreate, opt cmd.OptionMap, resp *cmd.ResponseBuilder) { cfg := config.GetGuildConfig(i.GuildID) days := 15 + if gokord.Debug { + days = 90 + } if v, ok := opt["days"]; ok { in := v.IntValue() if in < 1 || uint(in) > cfg.DaysXPRemains { @@ -195,6 +198,7 @@ func generatePlot(s *discordgo.Session, i *discordgo.InteractionCreate, copaings p.X.Label.Text = "Secondes" } p.Y.Label.Text = "XP" + p.Y.Scale = exp.LevelScale{} p.Add(plotter.NewGrid()) diff --git a/exp/functions.go b/exp/functions.go index 2608094..363aed8 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -33,12 +33,26 @@ func VocalXP(time uint) uint { )) } +type LevelScale struct{} + +func (LevelScale) Normalize(min, max, x float64) float64 { + if min < 0 || max < 0 || x < 0 { + panic("Values must be positive or null for a level scale.") + } + levelMin := LevelExact(min) + return (LevelExact(x) - levelMin) / (LevelExact(max) - levelMin) +} + // Level gives the level with the given XP. // See LevelXP to get the XP required to get a level. func Level(xp uint) uint { - return uint(math.Floor( - 0.2 * math.Sqrt(float64(xp)), - )) + return uint(math.Floor(LevelExact(float64(xp)))) +} + +// LevelExact gives the exact level with the given XP. +// See Level to get the floored level. +func LevelExact(xp float64) float64 { + return 0.2 * math.Sqrt(xp) } // LevelXP gives the XP required to get this level. |
