From a095b367e9414b602b9420966d2d62d684b79d06 Mon Sep 17 00:00:00 2001 From: griffinbaker12 <96966609+griffinbaker12@users.noreply.github.com> Date: Sat, 13 Jul 2024 14:52:43 -0500 Subject: [PATCH 1/3] updated engagement --- src/api/derived.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/derived.ts b/src/api/derived.ts index 6d834068..b2bc6011 100644 --- a/src/api/derived.ts +++ b/src/api/derived.ts @@ -47,7 +47,7 @@ type UserFlagDriveEvent = IDriveEvent & { data: Record } -type DriveEvent = EventDriveEvent | StateDriveEvent | UserFlagDriveEvent +export type DriveEvent = EventDriveEvent | StateDriveEvent | UserFlagDriveEvent type EngagedTimelineEvent = { type: 'engaged' @@ -151,7 +151,8 @@ const generateTimelineEvents = ( lastAlert = ev } - if (lastOverride && !isOverriding(ev.data.state)) { + // Modified overriding logic + if (lastOverride && !isOverriding(state)) { res.push({ type: 'overriding', route_offset_millis: lastOverride.route_offset_millis, @@ -162,6 +163,16 @@ const generateTimelineEvents = ( if (!lastOverride && isOverriding(state)) { lastOverride = ev } + + // If we're overriding, end the current engagement + if (isOverriding(state) && lastEngaged) { + res.push({ + type: 'engaged', + route_offset_millis: lastEngaged.route_offset_millis, + end_route_offset_millis: ev.route_offset_millis, + } as EngagedTimelineEvent) + lastEngaged = undefined + } } else if (ev.type === 'user_flag') { res.push({ type: 'user_flag', From f46f38873fef06c774ef38c4b4078dad0b996b42 Mon Sep 17 00:00:00 2001 From: griffinbaker12 <96966609+griffinbaker12@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:29:08 -0500 Subject: [PATCH 2/3] fixed up to ensure no double counting --- src/api/derived.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/api/derived.ts b/src/api/derived.ts index b2bc6011..9befe939 100644 --- a/src/api/derived.ts +++ b/src/api/derived.ts @@ -103,7 +103,7 @@ export const getCoords = (route: Route): Promise => export const getDriveEvents = (route: Route): Promise => getDerived(route, 'events.json').then((events) => events.flat()) -const generateTimelineEvents = ( +export const generateTimelineEvents = ( route: Route, events: DriveEvent[], ): TimelineEvent[] => { @@ -151,27 +151,28 @@ const generateTimelineEvents = ( lastAlert = ev } - // Modified overriding logic - if (lastOverride && !isOverriding(state)) { + if (isOverriding(state)) { + if (lastEngaged) { + res.push({ + type: 'engaged', + route_offset_millis: lastEngaged.route_offset_millis, + end_route_offset_millis: ev.route_offset_millis, + } as EngagedTimelineEvent) + lastEngaged = undefined + } + if (!lastOverride) { + lastOverride = ev + } + } else if (lastOverride) { res.push({ type: 'overriding', route_offset_millis: lastOverride.route_offset_millis, end_route_offset_millis: ev.route_offset_millis, } as OverridingTimelineEvent) lastOverride = undefined - } - if (!lastOverride && isOverriding(state)) { - lastOverride = ev - } - - // If we're overriding, end the current engagement - if (isOverriding(state) && lastEngaged) { - res.push({ - type: 'engaged', - route_offset_millis: lastEngaged.route_offset_millis, - end_route_offset_millis: ev.route_offset_millis, - } as EngagedTimelineEvent) - lastEngaged = undefined + if (enabled) { + lastEngaged = ev + } } } else if (ev.type === 'user_flag') { res.push({ @@ -211,7 +212,7 @@ const generateTimelineEvents = ( export const getTimelineEvents = (route: Route): Promise => getDriveEvents(route).then((events) => generateTimelineEvents(route, events)) -const generateTimelineStatistics = ( +export const generateTimelineStatistics = ( route: Route, timeline: TimelineEvent[], ): TimelineStatistics => { From b560a2293f2bb94a74e3a9a8688442dee7ab53a2 Mon Sep 17 00:00:00 2001 From: griffinbaker12 <96966609+griffinbaker12@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:33:43 -0500 Subject: [PATCH 3/3] fix export --- src/api/derived.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/derived.ts b/src/api/derived.ts index 9befe939..4ab3e51f 100644 --- a/src/api/derived.ts +++ b/src/api/derived.ts @@ -47,7 +47,7 @@ type UserFlagDriveEvent = IDriveEvent & { data: Record } -export type DriveEvent = EventDriveEvent | StateDriveEvent | UserFlagDriveEvent +type DriveEvent = EventDriveEvent | StateDriveEvent | UserFlagDriveEvent type EngagedTimelineEvent = { type: 'engaged' @@ -103,7 +103,7 @@ export const getCoords = (route: Route): Promise => export const getDriveEvents = (route: Route): Promise => getDerived(route, 'events.json').then((events) => events.flat()) -export const generateTimelineEvents = ( +const generateTimelineEvents = ( route: Route, events: DriveEvent[], ): TimelineEvent[] => { @@ -212,7 +212,7 @@ export const generateTimelineEvents = ( export const getTimelineEvents = (route: Route): Promise => getDriveEvents(route).then((events) => generateTimelineEvents(route, events)) -export const generateTimelineStatistics = ( +const generateTimelineStatistics = ( route: Route, timeline: TimelineEvent[], ): TimelineStatistics => {