diff options
| -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. |
