Add motivational training challenges and shared club goals
This commit is contained in:
1 parent
27dcbd92aa
commit
694aba5f3d
11 files changed
+799
-13
No files matched your search
@@ -77,13 +77,34 @@ const messages = {
|
||||
nextAchievement: "Nästa delmål",
|
||||
achievement_first_session: "Första träningspasset",
|
||||
achievement_laps_100: "100 träningsvarv",
|
||||
achievement_laps_250: "250 träningsvarv",
|
||||
achievement_laps_500: "500 träningsvarv",
|
||||
achievement_laps_1000: "1 000 träningsvarv",
|
||||
achievement_laps_1500: "1 500 träningsvarv",
|
||||
achievement_days_3: "3 träningsdagar",
|
||||
achievement_days_10: "10 träningsdagar",
|
||||
achievement_sessions_5: "5 fullföljda träningspass",
|
||||
achievement_controlled_5: "5 kontrollerade varv i rad",
|
||||
achievement_controlled_10: "10 kontrollerade varv i rad",
|
||||
achievement_five_minute: "Fullföljd femminutersstint",
|
||||
achievement_five_minutes_3: "3 fullföljda femminutersstintar",
|
||||
achievement_consistency_5: "Jämnhet under 5 procent",
|
||||
achievement_pace_gain: "Förbättrat snittempo",
|
||||
creditTitle: "Din träning räknas",
|
||||
creditBody: "Varje genomfört varv bygger erfarenhet. Du jämförs med din egen utveckling, inte med andra förare.",
|
||||
todayLapsCredit: "{laps} giltiga varv idag",
|
||||
paceCredit: "Snittempot är {lap} snabbare per varv",
|
||||
consistencyCredit: "{value} procentenheter jämnare körning",
|
||||
controlledCredit: "{laps} kontrollerade varv i rad",
|
||||
fiveMinuteCredit: "Du har fullföljt en femminutersstint",
|
||||
buildingCredit: "{laps} varv har redan byggt din erfarenhet",
|
||||
readyCredit: "Första giltiga varvet startar din utvecklingsresa",
|
||||
challenges: "Små utmaningar",
|
||||
challengesHint: "Valfria mål som ger kredit för mängd, kontroll och uthållighet.",
|
||||
challengeLaps: "Samla 20 varv idag",
|
||||
challengeControlled: "Kör 5 kontrollerade varv i rad",
|
||||
challengeFive: "Fullfölj en femminutersstint",
|
||||
challengeProgress: "{current} / {target}",
|
||||
},
|
||||
en: {
|
||||
loading: "Loading training profile...",
|
||||
@@ -153,13 +174,34 @@ const messages = {
|
||||
nextAchievement: "Next milestone",
|
||||
achievement_first_session: "First practice session",
|
||||
achievement_laps_100: "100 practice laps",
|
||||
achievement_laps_250: "250 practice laps",
|
||||
achievement_laps_500: "500 practice laps",
|
||||
achievement_laps_1000: "1,000 practice laps",
|
||||
achievement_laps_1500: "1,500 practice laps",
|
||||
achievement_days_3: "3 practice days",
|
||||
achievement_days_10: "10 practice days",
|
||||
achievement_sessions_5: "5 completed practice sessions",
|
||||
achievement_controlled_5: "5 controlled laps in a row",
|
||||
achievement_controlled_10: "10 controlled laps in a row",
|
||||
achievement_five_minute: "Completed five-minute stint",
|
||||
achievement_five_minutes_3: "3 completed five-minute stints",
|
||||
achievement_consistency_5: "Consistency below 5 percent",
|
||||
achievement_pace_gain: "Improved average pace",
|
||||
creditTitle: "Your practice counts",
|
||||
creditBody: "Every completed lap builds experience. You are compared with your own development, not other drivers.",
|
||||
todayLapsCredit: "{laps} valid laps today",
|
||||
paceCredit: "Average pace is {lap} faster per lap",
|
||||
consistencyCredit: "{value} percentage points more consistent",
|
||||
controlledCredit: "{laps} controlled laps in a row",
|
||||
fiveMinuteCredit: "You completed a five-minute stint",
|
||||
buildingCredit: "{laps} laps have already built your experience",
|
||||
readyCredit: "Your first valid lap starts the development journey",
|
||||
challenges: "Small challenges",
|
||||
challengesHint: "Optional goals that recognize volume, control, and endurance.",
|
||||
challengeLaps: "Collect 20 laps today",
|
||||
challengeControlled: "Run 5 controlled laps in a row",
|
||||
challengeFive: "Complete a five-minute stint",
|
||||
challengeProgress: "{current} / {target}",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -212,6 +254,39 @@ function recommendationCopy(recommendation) {
|
||||
};
|
||||
}
|
||||
|
||||
function getLocalDayKey(timestamp) {
|
||||
const date = new Date(Number(timestamp || 0));
|
||||
if (Number.isNaN(date.getTime())) return "";
|
||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function buildProfileMotivation(stats) {
|
||||
const todayKey = getLocalDayKey(Date.now());
|
||||
const today = (Array.isArray(stats?.dailySummaries) ? stats.dailySummaries : []).find((day) => day.dateKey === todayKey);
|
||||
const activeToday = Boolean(today);
|
||||
const todayLaps = Number(today?.laps || 0);
|
||||
const controlled = activeToday ? Number(stats?.controlledLapStreak || 0) : 0;
|
||||
const completedFive = stats?.bestFiveMinuteResult ? 1 : 0;
|
||||
const challenges = [
|
||||
{ id: "Laps", current: todayLaps, target: 20 },
|
||||
{ id: "Controlled", current: controlled, target: 5 },
|
||||
{ id: "Five", current: completedFive, target: 1 },
|
||||
].map((challenge) => ({
|
||||
...challenge,
|
||||
percent: Math.min(100, Math.max(0, (challenge.current / challenge.target) * 100)),
|
||||
completed: challenge.current >= challenge.target,
|
||||
}));
|
||||
const credits = [];
|
||||
if (todayLaps) credits.push(t("todayLapsCredit", { laps: todayLaps }));
|
||||
if (stats?.trendSampleReady && Number(stats.averageTrendMs || 0) > 0) credits.push(t("paceCredit", { lap: formatLap(stats.averageTrendMs) }));
|
||||
if (stats?.trendSampleReady && Number(stats.consistencyTrendPct || 0) > 0.1) credits.push(t("consistencyCredit", { value: Number(stats.consistencyTrendPct).toFixed(1) }));
|
||||
if (controlled >= 5) credits.push(t("controlledCredit", { laps: controlled }));
|
||||
if (completedFive) credits.push(t("fiveMinuteCredit"));
|
||||
if (!credits.length && Number(stats?.totalLaps || 0) > 0) credits.push(t("buildingCredit", { laps: stats.totalLaps }));
|
||||
if (!credits.length) credits.push(t("readyCredit"));
|
||||
return { challenges, credits: credits.slice(0, 3) };
|
||||
}
|
||||
|
||||
function renderProfile(data) {
|
||||
profileData = data;
|
||||
const { profile, branding } = data;
|
||||
@@ -224,6 +299,7 @@ function renderProfile(data) {
|
||||
const recommendation = activeClass?.recommendation || data.recommendation;
|
||||
const goals = activeClass?.goals || data.goals || [];
|
||||
const currentSession = activeClass?.currentSession || data.currentSession;
|
||||
const motivation = buildProfileMotivation(stats);
|
||||
const recommendationText = recommendationCopy(recommendation);
|
||||
const timerState = readTimerState();
|
||||
const timerConfig = getTimerConfig(timerState);
|
||||
@@ -239,6 +315,17 @@ function renderProfile(data) {
|
||||
<div><strong>${escapeHtml(t(`achievement_${achievement.id}`))}</strong><small>${escapeHtml(t(achievement.unlocked ? "unlocked" : "nextAchievement"))}</small></div>
|
||||
</article>
|
||||
`).join("");
|
||||
const creditMarkup = motivation.credits.map((credit) => `<li><span>+</span><strong>${escapeHtml(credit)}</strong></li>`).join("");
|
||||
const challengeMarkup = motivation.challenges.map((challenge) => `
|
||||
<article class="profile-challenge ${challenge.completed ? "is-complete" : ""}">
|
||||
<span>${challenge.completed ? "OK" : `${Math.round(challenge.percent)}%`}</span>
|
||||
<div>
|
||||
<strong>${escapeHtml(t(`challenge${challenge.id}`))}</strong>
|
||||
<small>${escapeHtml(t("challengeProgress", { current: challenge.current, target: challenge.target }))}</small>
|
||||
<div class="profile-progress"><span style="width:${challenge.percent.toFixed(2)}%"></span></div>
|
||||
</div>
|
||||
</article>
|
||||
`).join("");
|
||||
const paceTrend = !stats.trendSampleReady
|
||||
? t("collectingTrend")
|
||||
: stats.averageTrendMs > 0
|
||||
@@ -303,6 +390,19 @@ function renderProfile(data) {
|
||||
${renderStat(t("consistency"), stats.recentLapCount ? `${Number(stats.consistencySpreadPct).toFixed(1)}%` : "-")}
|
||||
</section>
|
||||
|
||||
<section class="profile-motivation-grid">
|
||||
<article class="profile-card profile-credit-card">
|
||||
<span class="profile-mini-label">${escapeHtml(t("creditTitle"))}</span>
|
||||
<p>${escapeHtml(t("creditBody"))}</p>
|
||||
<ul>${creditMarkup}</ul>
|
||||
</article>
|
||||
<article class="profile-card profile-challenge-card">
|
||||
<div class="profile-growth-head"><span class="profile-mini-label">${escapeHtml(t("challenges"))}</span><strong>${motivation.challenges.filter((challenge) => challenge.completed).length}/${motivation.challenges.length}</strong></div>
|
||||
<p>${escapeHtml(t("challengesHint"))}</p>
|
||||
<div class="profile-challenges">${challengeMarkup}</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="profile-growth-grid">
|
||||
<article class="profile-card profile-growth-card">
|
||||
<span class="profile-mini-label">${escapeHtml(t("recentProgress"))}</span>
|
||||
|
||||
Reference in new issue
Block a user