Skip to content

Commit

Permalink
Move event type pretty parsing to backend.
Browse files Browse the repository at this point in the history
Make event types JSON compat too.
  • Loading branch information
mayfield committed Dec 21, 2024
1 parent b63c889 commit ac4d287
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pages/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<div class="type">
<select name="type">
<option value="">All</option>
<option value="GROUP_RIDE">Group Ride</option>
<option value="GROUP_RIDE">Group</option>
<option value="GROUP_WORKOUT">Workout</option>
<option value="RACE">Race</option>
<option value="FONDO">Fondo</option>
<option value="EFONDO">Fondo</option>
<option value="TIME_TRIAL">Time Trial</option>
<option value="TEAM_TIME_TRIAL">Team Time Trial</option>
</select>
Expand Down
9 changes: 6 additions & 3 deletions pages/src/events.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 1 addition & 4 deletions pages/templates/events/summary.html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
<ms title="Allows joining late">acute</ms>
<% } %>
</td>
<% const prettyType = (typeof event.eventType === 'string') ? event.eventType.replace(/_/g, ' ').replace(/GROUP WORKOUT/, 'WORKOUT') : event.eventType; %>
<td class="type">
{{event.prettyTypeShort}}
<% if (event.sport === 'running') { %>
{{prettyType.replace(/RIDE/, 'RUN')}}
<ms title="Run">directions_run</ms>
<% } else { %>
{{prettyType}}
<% } %>
</td>
<td class="name" title="{{event.name}}">{{event.name}}</td>
Expand Down
12 changes: 12 additions & 0 deletions src/stats.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/zwift.proto
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ enum ActivityPrivacyType {
FRIENDS = 2;
}

// NOTE: JSON endpoints are uppercase..
enum Sport {
cycling = 0;
running = 1;
Expand Down Expand Up @@ -1388,7 +1389,7 @@ message EventTimeTrialOptions {

// Match JSON...
enum EventType {
FONDO = 0;
EFONDO = 0;
RACE = 1;
GROUP_RIDE = 2;
GROUP_WORKOUT = 3;
Expand Down

0 comments on commit ac4d287

Please sign in to comment.