Skip to content

Commit a7b32ea

Browse files
committed
Fixes measurement parsing for Live events
Updates stroke-completed checks from Simulator to Live to match current event stream Builds ShotStarting measurements from top-level fields instead of expecting a nested object Adds targeted debug logs in the inspector to trace course info and measurement rendering paths Improves reliability of tiles view by ensuring correct measurement extraction
1 parent e126ccc commit a7b32ea

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/components/WebhookInspector/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,20 @@ const WebhookInspector: React.FC<Props> = ({ userPath, selectedDeviceId = null,
416416
{/* Display course information if available for this activity session */}
417417
{(() => {
418418
const { activitySessionId } = getSessionIds(selectedEvent);
419+
console.log('[WebhookInspector] Render check - activitySessionId:', activitySessionId);
419420
if (activitySessionId) {
420421
const sessionData = getSessionData(activitySessionId);
422+
console.log('[WebhookInspector] sessionData:', sessionData ? 'found' : 'not found', sessionData);
421423
if (sessionData && (sessionData.courseInfo || sessionData.isLoadingCourse)) {
422424
// Find the most recent ChangePlayer data for this event
423425
const changePlayerData = findRecentChangePlayerData(selectedEvent, allEvents);
426+
console.log('[WebhookInspector] changePlayerData:', changePlayerData);
424427

425428
// Find all shots for the current hole
426429
const shots: ShotData[] = changePlayerData?.hole
427430
? findAllShotsForHole(selectedEvent, allEvents, changePlayerData.hole)
428431
: [];
432+
console.log('[WebhookInspector] shots found:', shots.length);
429433

430434
return (
431435
<CourseInfoBanner
@@ -444,10 +448,14 @@ const WebhookInspector: React.FC<Props> = ({ userPath, selectedDeviceId = null,
444448

445449
{/* Check if this is a measurement event - show tiles view instead of JSON */}
446450
{(() => {
451+
console.log('[WebhookInspector] Checking measurement event for:', selectedEvent.eventType);
447452
if (isMeasurementEvent(selectedEvent)) {
453+
console.log('[WebhookInspector] Is measurement event, getting data...');
448454
const measurement = getMeasurementData(selectedEvent, allEvents);
455+
console.log('[WebhookInspector] Measurement data:', measurement ? 'found' : 'not found', measurement);
449456
if (measurement) {
450457
const payload = getEventModelPayload(selectedEvent);
458+
console.log('[WebhookInspector] Rendering MeasurementTilesView');
451459
return (
452460
<MeasurementTilesView
453461
measurement={measurement}
@@ -457,6 +465,7 @@ const WebhookInspector: React.FC<Props> = ({ userPath, selectedDeviceId = null,
457465
}
458466
}
459467
// Fallback: render JSON for all other events
468+
console.log('[WebhookInspector] Fallback - rendering JSON');
460469
return (
461470
<pre className="preview-json">{JSON.stringify(getEventModelPayload(selectedEvent), null, 2)}</pre>
462471
);

src/utils/measurementDataUtils.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getSessionIds, getEventModelPayload } from './webhookEventUtils';
66
*/
77
export function isMeasurementEvent(e: EventItem): boolean {
88
return (
9-
e.eventType === 'TPS.Simulator.OnStrokeCompletedEvent' ||
9+
e.eventType === 'TPS.Live.OnStrokeCompletedEvent' ||
1010
e.eventType === 'TPS.Simulator.ShotStarting' ||
1111
e.eventType === 'TPS.Simulator.ShotFinish'
1212
);
@@ -26,15 +26,20 @@ export function getMeasurementData(event: EventItem, eventsList: EventItem[]) {
2626
const payload = getEventModelPayload(event);
2727
if (!payload) return null;
2828

29-
// For OnStrokeCompletedEvent: use Measurement directly
30-
if (event.eventType === 'TPS.Simulator.OnStrokeCompletedEvent') {
31-
console.log('[getMeasurementData] OnStrokeCompletedEvent measurement:', payload.Measurement);
32-
return payload.Measurement;
29+
// For ShotStarting: construct measurement from individual fields
30+
if (event.eventType === 'TPS.Simulator.ShotStarting') {
31+
console.log('[getMeasurementData] ShotStarting payload:', payload);
32+
// ShotStarting has BallSpeed, LaunchAngle, LaunchDirection as individual fields
33+
return {
34+
BallSpeed: payload.BallSpeed,
35+
LaunchAngle: payload.LaunchAngle,
36+
LaunchDirection: payload.LaunchDirection,
37+
};
3338
}
3439

35-
// For ShotStarting: use Measurement directly
36-
if (event.eventType === 'TPS.Simulator.ShotStarting') {
37-
console.log('[getMeasurementData] ShotStarting measurement:', payload.Measurement);
40+
// For OnStrokeCompletedEvent: use Measurement directly
41+
if (event.eventType === 'TPS.Live.OnStrokeCompletedEvent') {
42+
console.log('[getMeasurementData] OnStrokeCompletedEvent measurement:', payload.Measurement);
3843
return payload.Measurement;
3944
}
4045

@@ -62,7 +67,7 @@ export function getMeasurementData(event: EventItem, eventsList: EventItem[]) {
6267
for (let i = currentIdx + 1; i < eventsList.length; i++) {
6368
const prevEvent = eventsList[i];
6469

65-
if (prevEvent.eventType === 'TPS.Simulator.OnStrokeCompletedEvent') {
70+
if (prevEvent.eventType === 'TPS.Live.OnStrokeCompletedEvent') {
6671
const { deviceId: prevDeviceId } = getSessionIds(prevEvent);
6772

6873
if (prevDeviceId === thisDeviceId) {

0 commit comments

Comments
 (0)