From c408afc8797b0da5e1d73d190a8f5884870b510c Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 13 May 2025 12:50:20 +0200 Subject: style(files): reorganize everything --- exp/functions.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 exp/functions.go (limited to 'exp/functions.go') diff --git a/exp/functions.go b/exp/functions.go new file mode 100644 index 0000000..da535c4 --- /dev/null +++ b/exp/functions.go @@ -0,0 +1,45 @@ +package exp + +import ( + "github.com/anhgelus/gokord" + "math" +) + +func MessageXP(length uint, diversity uint) uint { + return uint(math.Floor( + 0.025*math.Pow(float64(length), 1.25)*math.Sqrt(float64(diversity)) + 1, + )) +} + +func VocalXP(time uint) uint { + return uint(math.Floor( + 0.01*math.Pow(float64(time), 1.3) + 1, + )) +} + +// 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)), + )) +} + +// LevelXP gives the XP required to get this level. +// See Level to get the level with the given XP. +func LevelXP(level uint) uint { + return uint(math.Floor( + math.Pow(float64(5*level), 2), + )) +} + +func Lose(time uint, xp uint) uint { + if gokord.Debug { + return uint(math.Floor( + math.Pow(float64(time), 3) * math.Pow(10, -2+math.Log(float64(time))) * math.Floor(float64(xp/500)+1), + )) // a little bit faster to lose exp + } + return uint(math.Floor( + math.Pow(float64(time), 2) * math.Pow(10, -2+math.Log(float64(time/85))) * math.Floor(float64(xp/500)+1), + )) +} -- cgit v1.2.3 From 5af6bd672c342fc4e7c4cc7bf61efd5026433ead Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 13 May 2025 13:19:59 +0200 Subject: style(event): move calcdiversity in exp --- exp/functions.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'exp/functions.go') diff --git a/exp/functions.go b/exp/functions.go index da535c4..c69ef26 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -3,6 +3,7 @@ package exp import ( "github.com/anhgelus/gokord" "math" + "slices" ) func MessageXP(length uint, diversity uint) uint { @@ -11,6 +12,16 @@ func MessageXP(length uint, diversity uint) uint { )) } +func CalcDiversity(msg string) uint { + var chars []rune + for _, c := range []rune(msg) { + if !slices.Contains(chars, c) { + chars = append(chars, c) + } + } + return uint(len(chars)) +} + func VocalXP(time uint) uint { return uint(math.Floor( 0.01*math.Pow(float64(time), 1.3) + 1, -- cgit v1.2.3 From e0a8f6634424f10a22b0a0740e0bbc17534eaa0e Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 13 May 2025 13:26:32 +0200 Subject: refactor(xp): remove reducer --- exp/functions.go | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'exp/functions.go') diff --git a/exp/functions.go b/exp/functions.go index c69ef26..2cbe7bf 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -1,7 +1,6 @@ package exp import ( - "github.com/anhgelus/gokord" "math" "slices" ) @@ -43,14 +42,3 @@ func LevelXP(level uint) uint { math.Pow(float64(5*level), 2), )) } - -func Lose(time uint, xp uint) uint { - if gokord.Debug { - return uint(math.Floor( - math.Pow(float64(time), 3) * math.Pow(10, -2+math.Log(float64(time))) * math.Floor(float64(xp/500)+1), - )) // a little bit faster to lose exp - } - return uint(math.Floor( - math.Pow(float64(time), 2) * math.Pow(10, -2+math.Log(float64(time/85))) * math.Floor(float64(xp/500)+1), - )) -} -- cgit v1.2.3 From eaf9fa51cdd9509c5d075633b712ec9b5ea712c7 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 13 May 2025 17:35:03 +0200 Subject: perf(db): remove useless XP data --- exp/functions.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'exp/functions.go') diff --git a/exp/functions.go b/exp/functions.go index 2cbe7bf..720a755 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -1,8 +1,11 @@ package exp import ( + "fmt" + "github.com/anhgelus/gokord" "math" "slices" + "time" ) func MessageXP(length uint, diversity uint) uint { @@ -42,3 +45,15 @@ func LevelXP(level uint) uint { math.Pow(float64(5*level), 2), )) } + +// TimeStampNDaysBefore returns the timestamp (year-month-day) n days before today +func TimeStampNDaysBefore(n uint) string { + var y, d int + var m time.Month + if gokord.Debug { + y, m, d = time.Unix(time.Now().Unix()-int64(24*60*60), 0).Date() // reduce time for debug + } else { + y, m, d = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0).Date() + } + return fmt.Sprintf("%d-%d-%d", y, m, d) +} -- cgit v1.2.3