Skip to content

Commit 4bc7752

Browse files
committed
fix dupe tele graph
1 parent f9fc09c commit 4bc7752

3 files changed

Lines changed: 7 additions & 30 deletions

File tree

server/db/logbook.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,15 @@ export async function getActiveFlightByUsername(robloxUsername) {
294294
}
295295

296296
export async function storeTelemetryPoint(flightId, { x, y, altitude, speed, heading, timestamp, phase, verticalSpeed }) {
297+
// Ensure timestamp is in UTC to prevent timezone-related duplicates
298+
const utcTimestamp = timestamp instanceof Date ? timestamp.toISOString() : timestamp;
299+
297300
await pool.query(`
298301
INSERT INTO logbook_telemetry (
299302
flight_id, timestamp, x, y, altitude_ft, speed_kts, heading, flight_phase, vertical_speed_fpm
300303
)
301-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
302-
`, [flightId, timestamp, x, y, altitude, speed, heading, phase, verticalSpeed ?? 0]);
304+
VALUES ($1, $2::timestamptz, $3, $4, $5, $6, $7, $8, $9)
305+
`, [flightId, utcTimestamp, x, y, altitude, speed, heading, phase, verticalSpeed ?? 0]);
303306
}
304307

305308
export async function updateActiveFlightState(robloxUsername, { altitude, speed, heading, x, y, phase }) {

src/pages/FlightDetail.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,7 @@ export default function FlightDetail() {
141141
);
142142
if (res.ok) {
143143
const data = await res.json();
144-
145-
const seen = new Map<number, TelemetryPoint>();
146-
const deduplicated = data.filter((point: TelemetryPoint) => {
147-
const timestamp = new Date(point.timestamp).getTime();
148-
const roundedTime = Math.round(timestamp / 5000) * 5000;
149-
150-
if (!seen.has(roundedTime)) {
151-
seen.set(roundedTime, point);
152-
return true;
153-
}
154-
return false;
155-
});
156-
157-
setTelemetry(deduplicated);
144+
setTelemetry(data);
158145
}
159146
} catch (err) {
160147
console.error('Failed to load telemetry:', err);

src/pages/PublicFlightView.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,7 @@ export default function PublicFlightView() {
163163
);
164164
if (res.ok) {
165165
const data = await res.json();
166-
167-
const seen = new Map<number, TelemetryPoint>();
168-
const deduplicated = data.filter((point: TelemetryPoint) => {
169-
const timestamp = new Date(point.timestamp).getTime();
170-
const roundedTime = Math.round(timestamp / 5000) * 5000;
171-
172-
if (!seen.has(roundedTime)) {
173-
seen.set(roundedTime, point);
174-
return true;
175-
}
176-
return false;
177-
});
178-
179-
setTelemetry(deduplicated);
166+
setTelemetry(data);
180167
}
181168
} catch (err) {
182169
console.error('Failed to load telemetry:', err);

0 commit comments

Comments
 (0)