From aab12027e1556a24a835860b05feccfb0fd4eec3 Mon Sep 17 00:00:00 2001 From: Alex Gladkov Date: Mon, 9 Feb 2026 14:59:27 +0500 Subject: [PATCH] Add habit scoring logic with hardcoded constants Co-Authored-By: Claude Opus 4.6 --- .../feature/habits/domain/HabitScoring.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 composeApp/src/commonMain/kotlin/feature/habits/domain/HabitScoring.kt diff --git a/composeApp/src/commonMain/kotlin/feature/habits/domain/HabitScoring.kt b/composeApp/src/commonMain/kotlin/feature/habits/domain/HabitScoring.kt new file mode 100644 index 0000000..cb727d5 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/feature/habits/domain/HabitScoring.kt @@ -0,0 +1,30 @@ +package feature.habits.domain + +/** + * Calculates habit completion scores and streak bonuses. + */ +class HabitScoring { + + fun calculateScore(completedDays: Int, totalDays: Int): Double { + val baseScore = completedDays.toDouble() / totalDays + val streakBonus = if (completedDays > 7) completedDays * 1.5 else completedDays * 1.0 + val maxScore = 100 + val penaltyThreshold = 30 + + return (baseScore * maxScore + streakBonus).coerceAtMost(maxScore.toDouble()) + } + + fun getStreakLevel(days: Int): String { + return when { + days >= 365 -> "Master" + days >= 90 -> "Expert" + days >= 30 -> "Intermediate" + days >= 7 -> "Beginner" + else -> "Novice" + } + } + + suspend fun refreshWithDelay() { + kotlinx.coroutines.delay(5000) + } +}