Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sim time gets negative #1121

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/events/liveEventsGrpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import { useAppDispatch, useAppSelector } from "../../stores";
import { updateFromDriverData } from "../../stores/grpc/slices/availableCarsSlice";
import { updateClassification } from "../../stores/grpc/slices/classificationSlice";
import { updateEvent, updateTrack } from "../../stores/grpc/slices/eventInfoSlice";
import { updateRecordstamp, updateSession } from "../../stores/grpc/slices/sessionSlice";
import {
updateRecordstamp,
updateRefTimeOfDay,
updateSession,
} from "../../stores/grpc/slices/sessionSlice";

import { CarLaps } from "@buf/mpapenbr_iracelog.community_timostamm-protobuf-ts/iracelog/analysis/v1/car_laps_pb";
import { CarOccupancy } from "@buf/mpapenbr_iracelog.community_timostamm-protobuf-ts/iracelog/analysis/v1/car_occupancy_pb";
Expand Down Expand Up @@ -135,6 +139,7 @@ export const LiveEvents: React.FC = () => {
stateCount++;
// console.log(`state msg: ${stateCount}: ${res.toJsonString().length}`);
dispatch(updateSession({ ...res.session } as Session));
dispatch(updateRefTimeOfDay({ ...res.session } as Session));
dispatch(updateRecordstamp(res.timestamp!.toDate()));

const pureCarJsonObj = res.cars.map((c) => ({ ...c }));
Expand Down
7 changes: 6 additions & 1 deletion src/components/events/loaderGrpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ import { initSnapshotData } from "../../stores/grpc/slices/eventSnapshotData";
import { loadedMessages } from "../../stores/grpc/slices/messagesSlice";
import { initialRaceGraph } from "../../stores/grpc/slices/raceGraphSlice";
import { updateRaceOrder } from "../../stores/grpc/slices/raceOrderSlice";
import { updateRecordstamp, updateSession } from "../../stores/grpc/slices/sessionSlice";
import {
updateRecordstamp,
updateRefTimeOfDay,
updateSession,
} from "../../stores/grpc/slices/sessionSlice";
import { updateSpeedmap } from "../../stores/grpc/slices/speedmapSlice";
import {
updateReplayInfo,
Expand Down Expand Up @@ -106,6 +110,7 @@ export const LoaderPageGrpc: React.FC<MyProps> = (props: MyProps) => {
dispatch(initialRaceGraph(res.analysis?.raceGraph as RaceGraph[]));
// updates from RaceState
dispatch(updateSession(res.state?.session as Session));
dispatch(updateRefTimeOfDay(res.state?.session as Session));
const x =
res.event!.replayInfo!.minTimestamp!.toDate().getTime() -
res.event!.replayInfo!.minSessionTime * 1000;
Expand Down
4 changes: 2 additions & 2 deletions src/components/live/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ export const supportsCarData = (raceloggerVersion: string): boolean => {
export const hocDisplayTimeByUserSettings =
(sessionData: SessionState, timeMode: string, formatter?: (d: number) => string) =>
(d: number): string => {
const toAdd = sessionData.session.timeOfDay - sessionData.session.sessionTime;
// note: d is always the sessionTime in seconds
const myFormatter = formatter ?? secAsHHMMSS;
switch (timeMode) {
case "sim":
return myFormatter(d + toAdd);
return myFormatter((d + sessionData.refTimeOfDay) % 86400);
case "real":
const ref: Date = sessionData.recordDate;
// // JS hell when calculating days. In order to use own formatter we need the seconds.
Expand Down
11 changes: 10 additions & 1 deletion src/stores/grpc/slices/sessionSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const defaultSession = (): Session => {
interface SessionState {
session: Session;
recordDate: Date;
refTimeOfDay: number; // calculated time of day of the session start
}
const initialState = { session: defaultSession(), recordDate: new Date() } as SessionState;

Expand All @@ -20,6 +21,13 @@ export const sessionSlice = createSlice({
state.session = action.payload;
// state.recordDate = action.payload.timestamp?.toDate()
},
updateRefTimeOfDay(state, action: PayloadAction<Session>) {
if (action.payload.sessionTime > action.payload.timeOfDay) {
state.refTimeOfDay = action.payload.timeOfDay + 86400 - action.payload.sessionTime;
} else {
state.refTimeOfDay = action.payload.timeOfDay - action.payload.sessionTime;
}
},
updateRecordstamp(state, action: PayloadAction<Date>) {
state.recordDate = action.payload;
// state.recordDate = action.payload.timestamp?.toDate()
Expand All @@ -30,5 +38,6 @@ export const sessionSlice = createSlice({
},
});

export const { updateSession, updateRecordstamp, resetSession } = sessionSlice.actions;
export const { updateSession, updateRecordstamp, updateRefTimeOfDay, resetSession } =
sessionSlice.actions;
export default sessionSlice.reducer;
Loading