From ac4d2872a0a82577197b30cf74aeeadee6e952ea Mon Sep 17 00:00:00 2001 From: Justin Mayfield Date: Sat, 21 Dec 2024 11:59:13 -0700 Subject: [PATCH] Move event type pretty parsing to backend. Make event types JSON compat too. --- pages/events.html | 4 ++-- pages/src/events.mjs | 9 ++++++--- pages/templates/events/summary.html.tpl | 5 +---- src/stats.mjs | 12 ++++++++++++ src/zwift.proto | 3 ++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pages/events.html b/pages/events.html index 36a0c3d..83ddfe6 100644 --- a/pages/events.html +++ b/pages/events.html @@ -29,10 +29,10 @@
diff --git a/pages/src/events.mjs b/pages/src/events.mjs index 7062ebf..56dfa02 100644 --- a/pages/src/events.mjs +++ b/pages/src/events.mjs @@ -127,9 +127,12 @@ async function applyEventFilters(el) { re = new RegExp(filterText, 'i'); } catch(e) {/*no-pragma*/} for (const x of allEvents.values()) { - const text = `name:${x.name}\n` + - `type:${x.eventType.replace(/_/g, ' ')}\n` + - `description:${x.description}`; + let text = `name:${x.name}\n` + + `type:${x.prettyType}\n` + + `description:${x.description}\n`; + if (x.route?.name) { + text += `route:${x.route.name}\n`; + } if (re ? !text.match(re) : !text.toLowerCase().includes(filterText)) { hide.add('' + x.id); } diff --git a/pages/templates/events/summary.html.tpl b/pages/templates/events/summary.html.tpl index 21c9a72..cb7b493 100644 --- a/pages/templates/events/summary.html.tpl +++ b/pages/templates/events/summary.html.tpl @@ -14,13 +14,10 @@ acute <% } %> - <% const prettyType = (typeof event.eventType === 'string') ? event.eventType.replace(/_/g, ' ').replace(/GROUP WORKOUT/, 'WORKOUT') : event.eventType; %> + {{event.prettyTypeShort}} <% if (event.sport === 'running') { %> - {{prettyType.replace(/RIDE/, 'RUN')}} directions_run - <% } else { %> - {{prettyType}} <% } %> {{event.name}} diff --git a/src/stats.mjs b/src/stats.mjs index 2fa26a0..7849383 100644 --- a/src/stats.mjs +++ b/src/stats.mjs @@ -2456,6 +2456,18 @@ export class StatsProcessor extends events.EventEmitter { event.allTags = this._parseEventTags(event); event.ts = +new Date(event.eventStart); event.courseId = env.getCourseId(event.mapId); + event.prettyType = { + EFONDO: 'Fondo', + RACE: 'Race', + GROUP_RIDE: 'Group', + GROUP_WORKOUT: 'Workout', + TIME_TRIAL: 'Time Trial', + TEAM_TIME_TRIAL: 'Team Time Trial', + }[event.eventType] || event.eventType; + event.prettyTypeShort = { + TIME_TRIAL: 'TT', + TEAM_TIME_TRIAL: 'TTT', + }[event.eventType] || event.prettyType; if (!this._recentEvents.has(event.id)) { const start = new Date(event.ts).toLocaleString(); console.debug(`Event added [${event.id}] - ${start}:`, event.name); diff --git a/src/zwift.proto b/src/zwift.proto index 25b7bd3..7c9d439 100644 --- a/src/zwift.proto +++ b/src/zwift.proto @@ -448,6 +448,7 @@ enum ActivityPrivacyType { FRIENDS = 2; } +// NOTE: JSON endpoints are uppercase.. enum Sport { cycling = 0; running = 1; @@ -1388,7 +1389,7 @@ message EventTimeTrialOptions { // Match JSON... enum EventType { - FONDO = 0; + EFONDO = 0; RACE = 1; GROUP_RIDE = 2; GROUP_WORKOUT = 3;