mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
181 lines
4.4 KiB
Go
181 lines
4.4 KiB
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
)
|
|
|
|
// EngagementHelpers provides utility functions for engagement system
|
|
|
|
// ComputeLevelProgress returns the progress percentage within current level
|
|
func ComputeLevelProgress(xp int64, level int) (int, int64, int64) {
|
|
if level < 1 {
|
|
level = 1
|
|
}
|
|
// Total XP needed to reach level L: 50 * (L-1) * L
|
|
totalToLevel := int64(50 * (level - 1) * level)
|
|
nextIncrement := int64(100 * level)
|
|
|
|
inLevel := xp - totalToLevel
|
|
if inLevel < 0 {
|
|
inLevel = 0
|
|
}
|
|
|
|
percentage := 0
|
|
if nextIncrement > 0 {
|
|
percentage = int(math.Floor(float64(inLevel) / float64(nextIncrement) * 100))
|
|
if percentage > 100 {
|
|
percentage = 100
|
|
}
|
|
if percentage < 0 {
|
|
percentage = 0
|
|
}
|
|
}
|
|
|
|
return percentage, inLevel, nextIncrement
|
|
}
|
|
|
|
// GetLevelTitle returns a descriptive title for a level
|
|
func GetLevelTitle(level int) string {
|
|
switch {
|
|
case level >= 100:
|
|
return "Legenda"
|
|
case level >= 80:
|
|
return "Mistr"
|
|
case level >= 60:
|
|
return "Expert"
|
|
case level >= 40:
|
|
return "Veterán"
|
|
case level >= 25:
|
|
return "Zkušený fanoušek"
|
|
case level >= 15:
|
|
return "Oddaný příznivec"
|
|
case level >= 10:
|
|
return "Aktivní člen"
|
|
case level >= 5:
|
|
return "Nováček"
|
|
default:
|
|
return "Začátečník"
|
|
}
|
|
}
|
|
|
|
// GetLevelColor returns a color scheme for level badge
|
|
func GetLevelColor(level int) string {
|
|
switch {
|
|
case level >= 80:
|
|
return "gold"
|
|
case level >= 60:
|
|
return "purple"
|
|
case level >= 40:
|
|
return "blue"
|
|
case level >= 20:
|
|
return "cyan"
|
|
case level >= 10:
|
|
return "green"
|
|
default:
|
|
return "gray"
|
|
}
|
|
}
|
|
|
|
// FormatPoints formats points with thousands separator
|
|
func FormatPoints(points int64) string {
|
|
if points < 1000 {
|
|
return fmt.Sprintf("%d", points)
|
|
}
|
|
if points < 1000000 {
|
|
return fmt.Sprintf("%.1fk", float64(points)/1000)
|
|
}
|
|
return fmt.Sprintf("%.1fM", float64(points)/1000000)
|
|
}
|
|
|
|
// GetNextLevelXP returns XP needed for next level
|
|
func GetNextLevelXP(currentXP int64, currentLevel int) int64 {
|
|
totalToLevel := int64(50 * (currentLevel - 1) * currentLevel)
|
|
nextIncrement := int64(100 * currentLevel)
|
|
return (totalToLevel + nextIncrement) - currentXP
|
|
}
|
|
|
|
// GetRewardTypeDisplayName returns localized display name for reward type
|
|
func GetRewardTypeDisplayName(rewardType string) string {
|
|
names := map[string]string{
|
|
"avatar_static": "Avatar (statický)",
|
|
"avatar_animated": "Avatar (animovaný)",
|
|
"avatar_upload_unlock": "Odemknutí vlastního avataru",
|
|
"merch_coupon": "Slevový kupon",
|
|
"merch_physical": "Fyzické zboží",
|
|
"merch_digital": "Digitální odměna",
|
|
"custom": "Vlastní",
|
|
}
|
|
if name, ok := names[rewardType]; ok {
|
|
return name
|
|
}
|
|
return rewardType
|
|
}
|
|
|
|
// GetPointsReasonDisplayName returns localized display name for transaction reason
|
|
func GetPointsReasonDisplayName(reason string) string {
|
|
names := map[string]string{
|
|
"comment_create": "Nový komentář",
|
|
"comment_reacted": "Reakce na komentář",
|
|
"poll_vote": "Hlasování v anketě",
|
|
"newsletter_subscribe": "Odběr newsletteru",
|
|
"redeem": "Uplatnění odměny",
|
|
"redeem_refund": "Vrácení bodů",
|
|
"admin_adjust": "Manuální úprava",
|
|
}
|
|
if name, ok := names[reason]; ok {
|
|
return name
|
|
}
|
|
// Achievement reasons start with "achievement:"
|
|
if len(reason) > 12 && reason[:12] == "achievement:" {
|
|
return "Úspěch odemknut"
|
|
}
|
|
return reason
|
|
}
|
|
|
|
// GetRedemptionStatusDisplayName returns localized display name for redemption status
|
|
func GetRedemptionStatusDisplayName(status string) string {
|
|
names := map[string]string{
|
|
"pending": "Čeká na vyřízení",
|
|
"approved": "Schváleno",
|
|
"rejected": "Zamítnuto",
|
|
"fulfilled": "Vydáno",
|
|
}
|
|
if name, ok := names[status]; ok {
|
|
return name
|
|
}
|
|
return status
|
|
}
|
|
|
|
// GetRedemptionStatusColor returns color scheme for redemption status
|
|
func GetRedemptionStatusColor(status string) string {
|
|
colors := map[string]string{
|
|
"pending": "yellow",
|
|
"approved": "blue",
|
|
"rejected": "red",
|
|
"fulfilled": "green",
|
|
}
|
|
if color, ok := colors[status]; ok {
|
|
return color
|
|
}
|
|
return "gray"
|
|
}
|
|
|
|
// CalculateBadgeLevel returns badge tier based on points/level
|
|
func CalculateBadgeLevel(level int) string {
|
|
switch {
|
|
case level >= 80:
|
|
return "diamond"
|
|
case level >= 60:
|
|
return "platinum"
|
|
case level >= 40:
|
|
return "gold"
|
|
case level >= 20:
|
|
return "silver"
|
|
case level >= 10:
|
|
return "bronze"
|
|
default:
|
|
return "none"
|
|
}
|
|
}
|