progress

package
v0.0.0-...-7eeefe3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package progress implements mastery scoring, SM-2 spaced repetition, streaks, and XP tracking.

Index

Constants

View Source
const (
	XPSession         = 10  // per teaching session message exchange
	XPQuizCorrect     = 20  // per correct quiz answer
	XPMasteryUp       = 50  // when mastery threshold crossed for a topic
	XPStreakMilestone = 100 // on streak milestones (3, 7, 14, 30, etc.)
	XPChallengeWin    = 30  // winning a peer challenge
	XPReviewCompleted = 50  // completing post-challenge review
)

XP award amounts.

View Source
const MasteryThreshold = 0.75

MasteryThreshold is the score at or above which a topic is considered mastered.

Variables

This section is empty.

Functions

func DeltaToQuality

func DeltaToQuality(delta float64) int

DeltaToQuality converts a mastery delta (0.0-1.0) to an SM-2 quality rating (0-5).

func FormatProgressBar

func FormatProgressBar(score float64, width int) string

FormatProgressBar creates a Unicode progress bar.

func FormatProgressReport

func FormatProgressReport(items []ProgressItem, totalXP int, streak int) string

FormatProgressReport creates a text report of all progress items.

func IsMastered

func IsMastered(score float64) bool

IsMastered returns true if the score meets or exceeds MasteryThreshold.

func IsStreakMilestone

func IsStreakMilestone(days int) bool

IsStreakMilestone returns true if the streak count is a milestone worth celebrating.

func StreakMilestoneMessage

func StreakMilestoneMessage(days int) string

StreakMilestoneMessage returns a celebration message for milestone streaks.

Types

type MemoryStreakTracker

type MemoryStreakTracker struct {
	// contains filtered or unexported fields
}

MemoryStreakTracker is an in-memory implementation for testing.

func NewMemoryStreakTracker

func NewMemoryStreakTracker() *MemoryStreakTracker

NewMemoryStreakTracker creates a new in-memory streak tracker.

func (*MemoryStreakTracker) GetStreak

func (t *MemoryStreakTracker) GetStreak(userID string) (Streak, error)

func (*MemoryStreakTracker) RecordActivity

func (t *MemoryStreakTracker) RecordActivity(userID string, at time.Time) error

func (*MemoryStreakTracker) ResetAll

func (t *MemoryStreakTracker) ResetAll(userID string) error

ResetAll removes all streak data for a user.

type MemoryTracker

type MemoryTracker struct {
	// contains filtered or unexported fields
}

MemoryTracker is an in-memory implementation of Tracker for testing and development.

func NewMemoryTracker

func NewMemoryTracker() *MemoryTracker

NewMemoryTracker creates a new in-memory tracker.

func (*MemoryTracker) GetAllProgress

func (m *MemoryTracker) GetAllProgress(userID string) ([]ProgressItem, error)

func (*MemoryTracker) GetDueReviews

func (m *MemoryTracker) GetDueReviews(userID string) ([]ProgressItem, error)

func (*MemoryTracker) GetMastery

func (m *MemoryTracker) GetMastery(userID, syllabusID, topicID string) (float64, error)

func (*MemoryTracker) ResetAll

func (m *MemoryTracker) ResetAll(userID string) error

ResetAll removes all progress data for a user.

func (*MemoryTracker) SetMastery

func (m *MemoryTracker) SetMastery(userID, syllabusID, topicID string, score float64) error

SetMastery directly sets a topic's mastery score (dev/testing only).

func (*MemoryTracker) UpdateMastery

func (m *MemoryTracker) UpdateMastery(userID, syllabusID, topicID string, delta float64) error

type MemoryXPTracker

type MemoryXPTracker struct {
	// contains filtered or unexported fields
}

MemoryXPTracker is an in-memory implementation for testing.

func NewMemoryXPTracker

func NewMemoryXPTracker() *MemoryXPTracker

NewMemoryXPTracker creates a new in-memory XP tracker.

func (*MemoryXPTracker) Award

func (t *MemoryXPTracker) Award(userID string, source XPSource, amount int, metadata map[string]any) error

func (*MemoryXPTracker) GetTotal

func (t *MemoryXPTracker) GetTotal(userID string) (int, error)

func (*MemoryXPTracker) ResetAll

func (t *MemoryXPTracker) ResetAll(userID string) error

ResetAll removes all XP entries for a user.

type PostgresTracker

type PostgresTracker struct {
	// contains filtered or unexported fields
}

PostgresTracker is a PostgreSQL-backed implementation of Tracker.

func NewPostgresTracker

func NewPostgresTracker(pool *pgxpool.Pool, tenantID string) *PostgresTracker

NewPostgresTracker creates a new PostgreSQL-backed tracker. tenantID is the UUID of the tenant for row-level isolation.

func (*PostgresTracker) GetAllProgress

func (p *PostgresTracker) GetAllProgress(userID string) ([]ProgressItem, error)

func (*PostgresTracker) GetDueReviews

func (p *PostgresTracker) GetDueReviews(userID string) ([]ProgressItem, error)

func (*PostgresTracker) GetMastery

func (p *PostgresTracker) GetMastery(userID, syllabusID, topicID string) (float64, error)

func (*PostgresTracker) SetMastery

func (p *PostgresTracker) SetMastery(userID, syllabusID, topicID string, score float64) error

SetMastery directly sets a topic's mastery score (dev/testing only).

func (*PostgresTracker) UpdateMastery

func (p *PostgresTracker) UpdateMastery(userID, syllabusID, topicID string, delta float64) error

type ProgressItem

type ProgressItem struct {
	UserID       string
	SyllabusID   string
	TopicID      string
	MasteryScore float64
	EaseFactor   float64
	IntervalDays int
	Repetitions  int
	NextReviewAt time.Time
	LastStudied  time.Time
}

ProgressItem represents a student's progress on a single topic.

type SM2Result

type SM2Result struct {
	Repetitions  int
	EaseFactor   float64
	IntervalDays int
}

SM2Result holds the output of an SM-2 calculation.

func SM2Calculate

func SM2Calculate(quality, repetitions int, easeFactor float64, intervalDays int) SM2Result

SM2Calculate implements the SuperMemo 2 algorithm. quality: 0-5 (0=blackout, 5=perfect)

type Streak

type Streak struct {
	UserID         string
	CurrentStreak  int
	LongestStreak  int
	LastActiveDate time.Time // truncated to date
}

Streak holds a user's streak data.

type StreakTracker

type StreakTracker interface {
	RecordActivity(userID string, at time.Time) error
	GetStreak(userID string) (Streak, error)
}

StreakTracker defines the interface for streak tracking.

type Tracker

type Tracker interface {
	UpdateMastery(userID, syllabusID, topicID string, delta float64) error
	GetMastery(userID, syllabusID, topicID string) (float64, error)
	GetAllProgress(userID string) ([]ProgressItem, error)
	GetDueReviews(userID string) ([]ProgressItem, error)
}

Tracker defines the interface for mastery progress tracking.

type XPEntry

type XPEntry struct {
	UserID   string
	Source   XPSource
	Amount   int
	Metadata map[string]any
}

XPEntry represents a single XP award.

type XPSource

type XPSource string

XPSource identifies where XP was earned.

const (
	XPSourceSession   XPSource = "session"
	XPSourceQuiz      XPSource = "quiz"
	XPSourceMastery   XPSource = "mastery"
	XPSourceStreak    XPSource = "streak"
	XPSourceChallenge XPSource = "challenge"
	XPSourceReview    XPSource = "review"
)

type XPTracker

type XPTracker interface {
	Award(userID string, source XPSource, amount int, metadata map[string]any) error
	GetTotal(userID string) (int, error)
}

XPTracker defines the interface for XP tracking.

Jump to

Keyboard shortcuts

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