stats

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CardInnerWidth = 30
	// CardHeight is the rendered height of a single stats card in lines.
	// 7 inner lines (title + 4 stats + blank + XP bar) + 2 border lines = 9.
	CardHeight = 9
)
View Source
const CardFullWidth = CardInnerWidth + 4 // 34

CardFullWidth is the rendered width of a single card including border + padding.

Variables

View Source
var ModeXP map[ModeKey]int

ModeXP maps each mode to its base XP award per completion.

Functions

func ComputeCategoryXP

func ComputeCategoryXP(gameType string, modeStats []store.ModeStat) int

ComputeCategoryXP calculates total XP for a game category by summing XP across all modes. Daily victories earn 2x XP.

func ComputeDailyStreak

func ComputeDailyStreak(dates []time.Time, now time.Time) int

ComputeDailyStreak calculates the length of the current daily completion streak. The streak is "alive" if the most recent completion is today or yesterday (giving the player until end of day to extend it).

func ContentWidth

func ContentWidth(termWidth int) int

ContentWidth returns the inner content width for the stats panel. It snaps to the widest whole-card grid that fits the available panel space. The result never exceeds terminal width minus panel chrome.

func InitModeXP

func InitModeXP(categories []game.Category)

InitModeXP builds the ModeXP map from the provided game categories. Must be called once at startup before any stats operations.

func LevelFromXP

func LevelFromXP(xp int) int

LevelFromXP returns the level for the given total XP. Uses the inverse of XPForLevel: level = floor((xp / 5) ^ (1/1.6))

func RenderBanner

func RenderBanner(b ProfileBanner, width int) string

RenderBanner renders the profile summary banner.

func RenderCard

func RenderCard(c Card, titleColor color.Color) string

RenderCard renders a single stats card. The titleColor determines the foreground color used for the category name heading.

func RenderCardGrid

func RenderCardGrid(cards []Card, width int) string

RenderCardGrid renders just the card grid (no banner). This is the content placed inside the scrollable viewport.

func RenderView

func RenderView(banner ProfileBanner, cards []Card, width int) string

RenderView renders the full stats view (banner + card grid) as a single string. Used only by tests and the empty-state path.

func StaticHeight

func StaticHeight(cards []Card) int

StaticHeight returns the total lines consumed by non-scrollable parts of the stats view: panel chrome + banner (when cards exist).

func TruncateToDate

func TruncateToDate(t time.Time) time.Time

TruncateToDate strips the time component, returning midnight local time.

func ViewportHeight

func ViewportHeight(availableHeight int) int

ViewportHeight computes the viewport height for the card grid. Shows at most 2.5 card rows and at least 1 full card row, clamped to the available terminal height minus the static chrome.

func XPForLevel

func XPForLevel(level int) int

XPForLevel returns the total XP required to reach the given level. Formula: ceil(5 * level^1.6)

Types

type Card

type Card struct {
	GameType      string
	Level         int
	PreferredMode string
	Victories     int
	Attempts      int
	DailyPlayed   int
	CurrentXP     int
	NextLevelXP   int
}

Card holds the computed stats for a single game category.

func BuildCards

func BuildCards(catStats []store.CategoryStat, modeStats []store.ModeStat) []Card

BuildCards constructs a Card for each category the player has interacted with. Categories with zero attempts are excluded.

type ModeKey

type ModeKey struct {
	GameType string
	Mode     string
}

ModeKey identifies a specific mode within a game category.

type ProfileBanner

type ProfileBanner struct {
	ProfileLevel int
	DailyStreak  int
	TotalDailies int
	CurrentDaily bool
}

ProfileBanner holds the summary data shown above the card grid.

func BuildProfileBanner

func BuildProfileBanner(
	catStats []store.CategoryStat,
	modeStats []store.ModeStat,
	streakDates []time.Time,
	currentDaily bool,
) ProfileBanner

BuildProfileBanner constructs the summary banner shown above the card grid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL