feat: add ranked season window policy

This commit is contained in:
Josh Creek
2026-08-31 21:08:10 +01:00
parent e13a64756f
commit bc7136b2cb
3 changed files with 39 additions and 2 deletions
+19
View File
@@ -14,6 +14,7 @@ const (
GlickoInitialRating = 1500.0
GlickoInitialRD = 350.0
GlickoInitialVolatility = 0.06
RankedSeasonLength = 12 * 7 * 24 * time.Hour
)
type Rating struct {
@@ -64,6 +65,24 @@ type RankedProfile struct {
SeasonHistory []string
}
type RankedSeason struct {
SeasonID string
StartsAt time.Time
EndsAt time.Time
RolledOverAt time.Time
}
func NewRankedSeason(seasonID string, startsAt time.Time) (RankedSeason, error) {
if seasonID == "" || startsAt.IsZero() {
return RankedSeason{}, fmt.Errorf("invalid ranked season")
}
return RankedSeason{SeasonID: seasonID, StartsAt: startsAt, EndsAt: startsAt.Add(RankedSeasonLength)}, nil
}
func SeasonRolloverDue(season RankedSeason, now time.Time) bool {
return season.SeasonID != "" && !season.EndsAt.IsZero() && !now.Before(season.EndsAt) && season.RolledOverAt.IsZero()
}
func RankedIsProvisional(profile RankedProfile) bool { return profile.RankedGames < 10 }
// ApplySeasonRollover is idempotent by season ID. It intentionally accepts a