add more stats to mobile profile
This commit is contained in:
1 parent
142c45be04
commit
4068cc7c19
13 files changed
+267
-22
No files matched your search
+44
-9
@@ -58,6 +58,12 @@ const messages = {
|
||||
switchCue: "Byt till kontrollerad körning",
|
||||
finishCue: "Träningspasset är klart",
|
||||
performance: "Stintstatistik",
|
||||
paceChart: "Tempoutveckling",
|
||||
paceChartHint: "Senaste träningsdagarnas snittempo i vald klass. Lägre är snabbare.",
|
||||
stintDetails: "Senaste stintar",
|
||||
stintNumber: "Stint",
|
||||
duration: "Tid",
|
||||
noStints: "Inga stintar registrerade ännu.",
|
||||
stints: "Stints",
|
||||
bestThree: "Bästa 3 sammanhängande",
|
||||
bestFive: "Bästa 5 min",
|
||||
@@ -164,6 +170,12 @@ const messages = {
|
||||
switchCue: "Switch to controlled driving",
|
||||
finishCue: "The training session is complete",
|
||||
performance: "Stint statistics",
|
||||
paceChart: "Pace development",
|
||||
paceChartHint: "Average pace for recent practice days in the selected class. Lower is faster.",
|
||||
stintDetails: "Recent stints",
|
||||
stintNumber: "Stint",
|
||||
duration: "Duration",
|
||||
noStints: "No stints have been recorded yet.",
|
||||
stints: "Stints",
|
||||
bestThree: "Best 3 consecutive",
|
||||
bestFive: "Best 5 min",
|
||||
@@ -308,13 +320,25 @@ function buildProfileMotivation(stats, channelStats = {}) {
|
||||
return { challenges, credits: credits.slice(0, 3) };
|
||||
}
|
||||
|
||||
function renderPaceChart(points) {
|
||||
const values = (Array.isArray(points) ? points : []).slice().reverse().filter((point) => Number(point.averageLapMs || 0) > 0);
|
||||
if (values.length < 2) return `<p class="profile-empty">${escapeHtml(t("collectingTrend"))}</p>`;
|
||||
const width = 640, height = 180, padding = 24;
|
||||
const lapTimes = values.map((point) => Number(point.averageLapMs));
|
||||
const min = Math.min(...lapTimes);
|
||||
const range = Math.max(1, Math.max(...lapTimes) - min);
|
||||
const coordinates = values.map((point, index) => ({ x: padding + (index / Math.max(1, values.length - 1)) * (width - padding * 2), y: padding + ((Number(point.averageLapMs) - min) / range) * (height - padding * 2), point }));
|
||||
const path = coordinates.map((point) => `${point.x.toFixed(1)},${point.y.toFixed(1)}`).join(" ");
|
||||
return `<div class="profile-pace-chart"><svg viewBox="0 0 ${width} ${height}" role="img" aria-label="${escapeHtml(t("paceChart"))}"><polyline class="profile-pace-line" points="${path}" />${coordinates.map((item) => `<circle cx="${item.x.toFixed(1)}" cy="${item.y.toFixed(1)}" r="5"><title>${escapeHtml(item.point.dateKey)}: ${escapeHtml(formatLap(item.point.averageLapMs))}</title></circle>`).join("")}</svg><div class="profile-chart-labels"><span>${escapeHtml(values[0].dateKey)}</span><strong>${escapeHtml(formatLap(values.at(-1).averageLapMs))}</strong><span>${escapeHtml(values.at(-1).dateKey)}</span></div></div>`;
|
||||
}
|
||||
function renderProfile(data) {
|
||||
profileData = data;
|
||||
const { profile, branding } = data;
|
||||
const visibility = { progress: true, achievements: true, performance: true, goals: true, history: true, ...(data.visibility || {}) };
|
||||
const classProfiles = Array.isArray(data.classProfiles) ? data.classProfiles : [];
|
||||
let activeClass = classProfiles.find((item) => String(item.classId || "") === selectedClassId) || classProfiles[0] || null;
|
||||
if (activeClass && selectedClassId !== activeClass.classId) selectedClassId = activeClass.classId;
|
||||
const stats = activeClass?.stats || data.stats;
|
||||
const stats = { dailySummaries: [], paceHistory: [], achievements: [], stintSummaries: [], ...(activeClass?.stats || data.stats || {}) };
|
||||
const channelStats = activeClass?.channelStats || data.channelStats || {};
|
||||
const nextMilestone = activeClass?.nextMilestone || data.nextMilestone;
|
||||
const recommendation = activeClass?.recommendation || data.recommendation;
|
||||
@@ -380,6 +404,9 @@ function renderProfile(data) {
|
||||
</tr>
|
||||
`).join("")
|
||||
: `<tr><td colspan="4">-</td></tr>`;
|
||||
const stintRows = stats.stintSummaries.length ? stats.stintSummaries.slice(0, 6).map((stint) => `
|
||||
<tr><td>${stint.number}</td><td>${escapeHtml(new Date(stint.startedAt).toLocaleString(language, { dateStyle: "short", timeStyle: "short" }))}</td><td>${stint.lapCount}</td><td>${formatLap(stint.bestLapMs)}</td><td>${formatLap(stint.averageLapMs)}</td><td>${formatRaceResultTime(stint.durationMs)}</td></tr>
|
||||
`).join("") : `<tr><td colspan="6">${escapeHtml(t("noStints"))}</td></tr>`;
|
||||
const classOptions = classProfiles.map((item) => (
|
||||
`<option value="${escapeHtml(item.classId)}" ${item.classId === selectedClassId ? "selected" : ""}>${escapeHtml(item.className || item.classId)}</option>`
|
||||
)).join("");
|
||||
@@ -424,18 +451,22 @@ function renderProfile(data) {
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="profile-growth-grid">
|
||||
<article class="profile-card profile-growth-card">
|
||||
<section class="profile-growth-grid ${visibility.progress || visibility.achievements ? "" : "is-hidden"}">
|
||||
<article class="profile-card profile-growth-card ${visibility.progress ? "" : "is-hidden"}">
|
||||
<span class="profile-mini-label">${escapeHtml(t("recentProgress"))}</span>
|
||||
<strong>${escapeHtml(t("averagePace"))}</strong>
|
||||
<p>${escapeHtml(paceTrend)}</p>
|
||||
</article>
|
||||
<article class="profile-card profile-growth-card">
|
||||
<article class="profile-card profile-growth-card ${visibility.achievements ? "" : "is-hidden"}">
|
||||
<div class="profile-growth-head"><span class="profile-mini-label">${escapeHtml(t("achievements"))}</span><strong>${unlockedAchievements.length}/${achievements.length}</strong></div>
|
||||
<div class="profile-achievements">${achievementMarkup}</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="profile-card profile-chart-card ${visibility.progress ? "" : "is-hidden"}">
|
||||
<div class="profile-card-head"><div><h2>${escapeHtml(t("paceChart"))}</h2><p>${escapeHtml(t("paceChartHint"))}</p></div></div>
|
||||
${renderPaceChart(stats.paceHistory)}
|
||||
</section>
|
||||
<div class="profile-grid">
|
||||
<section class="profile-card">
|
||||
<div class="profile-card-head"><h2>${escapeHtml(t("nextLevel"))}</h2></div>
|
||||
@@ -479,8 +510,8 @@ function renderProfile(data) {
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="profile-card profile-performance" style="margin-top:14px">
|
||||
<div class="profile-card-head"><h2>${escapeHtml(t("performance"))}</h2></div>
|
||||
<details class="profile-card profile-disclosure profile-performance ${visibility.performance ? "" : "is-hidden"}" style="margin-top:14px">
|
||||
<summary class="profile-card-head"><h2>${escapeHtml(t("performance"))}</h2><span>+</span></summary>
|
||||
<div class="profile-performance-stats">
|
||||
<div><span>${escapeHtml(t("stints"))}</span><strong>${Number(stats.stintCount || 0)}</strong></div>
|
||||
<div><span>${escapeHtml(t("controlZone"))}</span><strong>${stats.controlZoneMaxMs ? `${formatLap(stats.controlZoneMinMs)} - ${formatLap(stats.controlZoneMaxMs)}` : "-"}</strong></div>
|
||||
@@ -495,16 +526,20 @@ function renderProfile(data) {
|
||||
<div><span>${escapeHtml(t("pitStops"))}</span><strong>${Number(channelStats.pitStopCount || 0)}</strong></div>
|
||||
<div><span>${escapeHtml(t("totalPit"))}</span><strong>${channelStats.pitStopCount ? formatRaceResultTime(channelStats.totalPitMs) : "-"}</strong></div>
|
||||
</div>
|
||||
</section>
|
||||
<div class="profile-stint-table-wrap">
|
||||
<h3>${escapeHtml(t("stintDetails"))}</h3>
|
||||
<div class="profile-history-wrap"><table class="profile-history"><thead><tr><th>${escapeHtml(t("stintNumber"))}</th><th>${escapeHtml(t("date"))}</th><th>${escapeHtml(t("laps"))}</th><th>${escapeHtml(t("best"))}</th><th>${escapeHtml(t("average"))}</th><th>${escapeHtml(t("duration"))}</th></tr></thead><tbody>${stintRows}</tbody></table></div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
${goals.length ? `
|
||||
${visibility.goals && goals.length ? `
|
||||
<section class="profile-card" style="margin-top:14px">
|
||||
<div class="profile-card-head"><h2>${escapeHtml(t("goals"))}</h2></div>
|
||||
<div class="profile-card-body profile-goals">${goalMarkup}</div>
|
||||
</section>
|
||||
` : ""}
|
||||
|
||||
<details class="profile-card profile-disclosure" style="margin-top:14px">
|
||||
<details class="profile-card profile-disclosure ${visibility.history ? "" : "is-hidden"}" style="margin-top:14px">
|
||||
<summary class="profile-card-head"><h2>${escapeHtml(t("history"))}</h2><span>+</span></summary>
|
||||
<div class="profile-history-wrap">
|
||||
<table class="profile-history">
|
||||
|
||||
Reference in new issue
Block a user