From 8d6fa726069bd5364ada1521b400bb5eb7865d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sat, 20 Sep 2025 14:01:39 +0200 Subject: feat(stats): custom scale for Y to show level --- exp/functions.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'exp') 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. -- cgit v1.2.3 From a0e93b4e031857e7379e2ab2d7bdae24561f4e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sat, 20 Sep 2025 15:39:51 +0200 Subject: feat(stats): better style for the graph --- exp/functions.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'exp') diff --git a/exp/functions.go b/exp/functions.go index 363aed8..681c135 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -11,6 +11,8 @@ import ( "github.com/anhgelus/gokord" ) +const DebugFactor = 30 + func MessageXP(length uint, diversity uint) uint { return uint(math.Floor( 0.025*math.Pow(float64(length), 1.25)*math.Sqrt(float64(diversity)) + 1, @@ -67,7 +69,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), 0) // reduce time for debug + unix = time.Unix(time.Now().Unix()-int64(DebugFactor*n), 0) // reduce time for debug } else { unix = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0) } -- cgit v1.2.3