Skip to content

Commit caa4429

Browse files
committed
save (WIP)
1 parent 94014a6 commit caa4429

File tree

10 files changed

+170
-268
lines changed

10 files changed

+170
-268
lines changed

backend/src/http_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def get_dbc(request: web.Request):
5757
dir_has_dbc = True
5858
for dbc in dbcs:
5959
db.add_dbc_file(os.path.join(dbc_path_dir, dbc))
60-
print(os.path.join(dbc_path_dir, dbc))
60+
# print(os.path.join(dbc_path_dir, dbc)) # debug
6161
else:
6262
dbc_path_dir = os.path.dirname(dbc_path_dir)
6363

frontend/app/components/FlexLayoutComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const layoutModel = Model.fromJson({
7979
"Seg0_VOLT_5",
8080
"Seg0_VOLT_6",
8181
],
82-
label: "Seg0 Temps",
82+
label: "Seg0 Voltages",
8383
units: "V",
8484
},
8585
{
@@ -92,7 +92,7 @@ export const layoutModel = Model.fromJson({
9292
"Seg0_TEMP_5",
9393
"Seg0_TEMP_6",
9494
],
95-
label: "Seg0 Voltages",
95+
label: "Seg0 Temps",
9696
units: "°C",
9797
},
9898
],

frontend/app/components/Navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export default function Navbar() {
233233
const file = files[0];
234234
setFileName(file.name);
235235
setLoading(true);
236-
await switchToRecording(file.name, file);
236+
switchToRecording(file);
237237
setLoading(false);
238238
close();
239239
}}

frontend/app/components/visualizations/GPS/GPSInternal.tsx

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
emptyLine,
1515
ChartXY,
1616
PointLineAreaSeries,
17+
PointShape,
1718
} from "@lightningchart/lcjs";
1819
import { LightningChartsContext } from "../lightning-charts/GlobalContext";
1920
import globalTheme from "../lightning-charts/GlobalTheme";
@@ -43,10 +44,12 @@ export default function GPSInternal({
4344
const {
4445
subscribeViewInterval,
4546
subscribeLatestArrays,
47+
subscribeCursorRow,
4648
subscribeReset,
4749
setCursor,
4850
dataArraysRef,
4951
viewableArraysRef,
52+
viewIntervalRef,
5053
} = useDataMethods();
5154
const id = useId();
5255
const containerRef = useRef(null);
@@ -62,8 +65,6 @@ export default function GPSInternal({
6265

6366
// Based on https://lightningchart.com/js-charts/docs/features/xy/freeform-line/
6467
useEffect(() => {
65-
// !dataArraysRef.current[LAT_COLNAME] ||
66-
// !dataArraysRef.current[LONG_COLNAME]
6768
if (!containerRef.current || !lc) return;
6869

6970
let chart = lc
@@ -83,6 +84,7 @@ export default function GPSInternal({
8384

8485
chart.engine.setBackgroundFillStyle(transparentFill);
8586

87+
// The data series for the green car line
8688
let visibleSeries = chart
8789
.addPointLineAreaSeries({
8890
dataPattern: null,
@@ -120,6 +122,7 @@ export default function GPSInternal({
120122
// splines aren't supported for freeform (non-progressive) data :/
121123
visibleSeriesRef.current = visibleSeries;
122124

125+
// The data series for the low-accuracy thick gray background track
123126
let bgSeries = chart
124127
.addPointLineAreaSeries({
125128
dataPattern: null,
@@ -135,6 +138,22 @@ export default function GPSInternal({
135138
.setPointFillStyle(emptyFill);
136139
bgSeriesRef.current = bgSeries;
137140

141+
let carSeries = chart
142+
.addPointLineAreaSeries({
143+
dataPattern: null,
144+
dataStorage: Float32Array,
145+
})
146+
.setMaxSampleCount(1)
147+
.setDrawOrder({ seriesDrawOrderIndex: 2 })
148+
// .setSamples({
149+
// xValues: [viewableArraysRef.current[LNG_COLNAME]![viewIntervalRef.current[1] - 1]],
150+
// yValues: [viewableArraysRef.current[LAT_COLNAME]![viewIntervalRef.current[1] - 1]],
151+
// })
152+
.setAreaFillStyle(emptyFill)
153+
.setPointFillStyle(new SolidFill({ color: ColorRGBA(0, 200, 200) }))
154+
.setPointShape(PointShape.Arrow)
155+
.setPointSize(15);
156+
138157
chart.forEachAxis((a) => {
139158
a.setIntervalRestrictions(undefined);
140159
a.setThickness(0);
@@ -164,22 +183,51 @@ export default function GPSInternal({
164183
});
165184
});
166185
const unsub2 = subscribeViewInterval(([left, right]) => {
186+
console.log("1", performance.now());
167187
// We reset and regenerate the fillStyle lookupValues each time
168188
// viewInterval changes. This seems to be a fairly fast operation
169189
visibleSeries.fill({ lookupValue: 0 });
190+
console.log("2", performance.now());
170191
// We need +1 as left and right from dataProvider are both inclusive
171192
const length = right - left + 1;
172193
// Generates a list of values of length `length` that are evenly
173-
// distributed from 0 to 1
174-
const gradient = Array.from({ length }, (_, i) => 0 + i / (length - 1));
194+
// distributed from 0.3 to 1 (0 through 0.3 is very hard to see)
195+
const gradient = Array.from(
196+
{ length },
197+
(_, i) => 0.3 + (i / (length - 1)) * (1 - 0.3),
198+
);
199+
console.log("3", performance.now());
175200
// Insert the above gradient array into the lookupValues dataset
176201
// channel starting at the correct index
177202
visibleSeries.alterSamples(left, {
178203
// todo: this doesn't work with data cleaning
179204
lookupValues: gradient,
180205
});
206+
console.log("4", performance.now());
181207
});
182-
const unsub3 = subscribeReset(() => {
208+
const unsub3 = subscribeCursorRow((cursorRow) => {
209+
// Always update carSeries to point to where the cursor is hovering,
210+
// and rotate it correctly according to GPS course. If no cursor row
211+
// exists, use the right-most row of viewableArrays
212+
const lng =
213+
cursorRow?.[LNG_COLNAME] ??
214+
dataArraysRef.current[LNG_COLNAME]?.[viewIntervalRef.current[1]] ??
215+
NaN;
216+
const lat =
217+
cursorRow?.[LAT_COLNAME] ??
218+
dataArraysRef.current[LAT_COLNAME]?.[viewIntervalRef.current[1]] ??
219+
NaN;
220+
carSeries.setSamples({
221+
xValues: [lng],
222+
yValues: [lat],
223+
});
224+
const trueCourse =
225+
cursorRow?.VDM_GPS_TRUE_COURSE ??
226+
dataArraysRef.current.VDM_GPS_TRUE_COURSE?.[viewIntervalRef.current[1]] ??
227+
0;
228+
carSeries.setPointRotation(trueCourse);
229+
});
230+
const unsub4 = subscribeReset(() => {
183231
bgSeries.clear();
184232
visibleSeries.clear();
185233
});
@@ -188,6 +236,7 @@ export default function GPSInternal({
188236
unsub1();
189237
unsub2();
190238
unsub3();
239+
unsub4();
191240
// unsub4();
192241
chart.dispose();
193242
// @ts-ignore: for GC
@@ -198,6 +247,9 @@ export default function GPSInternal({
198247
visibleSeries.dispose();
199248
// @ts-ignore: for GC
200249
visibleSeries = undefined;
250+
carSeries.dispose();
251+
// @ts-ignore: for GC
252+
carSeries = undefined;
201253
};
202254
}, [lc]);
203255

frontend/app/components/visualizations/GPS/Leaflet.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function Leaflet({ chartRef }: Props) {
5151
const map = L.map(containerRef.current, {
5252
zoomDelta: 0.5,
5353
zoomSnap: 0, // 0.1,
54-
}).setView([36.9905, -122.0584], 14);
54+
}).setView([36.9905, -122.0584], 14); // default to UCSC coordinates!
5555
mapRef.current = map;
5656

5757
const unsub = subscribeDataSource(() => setInitialLeafletBounds(map));

frontend/app/components/visualizations/lightning-charts/GlobalContext.tsx

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -78,117 +78,3 @@ export function LightningChartsProvider(props: PropsWithChildren) {
7878
</LightningChartsContext.Provider>
7979
);
8080
}
81-
82-
// // https://lightningchart.com/js-charts/docs/frameworks/react/#optimizing-apps-with-several-charts-visible-at-once--charts-being-initialized-often
83-
// // copy pasted from here:
84-
// // https://github.com/Arction/lcjs-react-template/blob/master/src/LC.tsx
85-
// "use client";
86-
// import React, {
87-
// createContext,
88-
// useEffect,
89-
// useRef,
90-
// useState,
91-
// PropsWithChildren,
92-
// useCallback,
93-
// useContext,
94-
// } from "react";
95-
// import {
96-
// Axis,
97-
// LightningChart,
98-
// lightningChart,
99-
// synchronizeAxisIntervals,
100-
// SynchronizeAxisIntervalsHandle,
101-
// } from "@lightningchart/lcjs";
102-
//
103-
// type LCContextObject = {
104-
// lightningChart: LightningChart | null;
105-
// synchronizeAxis: (axis: Axis) => void;
106-
// };
107-
//
108-
// export const LightningChartsContext = createContext<LCContextObject | null>(null);
109-
//
110-
// export function LightningChartsProvider(props: PropsWithChildren) {
111-
// const lcRef = useRef<LightningChart | null>(null);
112-
// const syncHandleRef = useRef<SynchronizeAxisIntervalsHandle>();
113-
// const axisListRef = useRef<Axis[]>([]);
114-
//
115-
// const synchronizeAxis = useCallback((axis: Axis) => {
116-
// console.log(axis.getTitle());
117-
//
118-
// // if (syncHandleRef.current) syncHandleRef.current.remove();
119-
// axisListRef.current.push(axis);
120-
// if (axisListRef.current.length > 1) {
121-
// console.log(axisListRef.current);
122-
//
123-
// syncHandleRef.current = synchronizeAxisIntervals(...axisListRef.current);
124-
// }
125-
//
126-
// return () => axisListRef.current.splice(axisListRef.current.indexOf(axis));
127-
// }, []);
128-
//
129-
// const [lcState, setLcState] = useState<LCContextObject>({
130-
// lightningChart: null,
131-
// synchronizeAxis,
132-
// });
133-
// // todo: add something to the state here to enable auto-synchronization of
134-
// // newly created chart axis. (maybe try just removing 2/3 first? also
135-
// // stacked axis in one chart?)
136-
//
137-
// useEffect(() => {
138-
// if (lcRef.current) return;
139-
//
140-
// // If license information from .env not available, bail early
141-
// if (
142-
// !process.env.NEXT_PUBLIC_LIGHTNING_CHART_LICENSE_KEY ||
143-
// !process.env.NEXT_PUBLIC_LIGHTNING_CHART_LICENSE_INFORMATION_APP_TITLE ||
144-
// !process.env.NEXT_PUBLIC_LIGHTNING_CHART_LICENSE_INFORMATION_COMPANY
145-
// ) {
146-
// console.warn("No LightningChart license found!");
147-
// return;
148-
// }
149-
//
150-
// try {
151-
// lcRef.current = lightningChart({
152-
// license: process.env.NEXT_PUBLIC_LIGHTNING_CHART_LICENSE_KEY,
153-
// licenseInformation: {
154-
// appTitle:
155-
// process.env.NEXT_PUBLIC_LIGHTNING_CHART_LICENSE_INFORMATION_APP_TITLE,
156-
// company:
157-
// process.env.NEXT_PUBLIC_LIGHTNING_CHART_LICENSE_INFORMATION_COMPANY,
158-
// },
159-
//
160-
// // Fixes bad Firefox performance:
161-
// // https://lightningchart.com/js-charts/docs/more-guides/optimizing-performance/#mozilla-firefox
162-
// sharedContextOptions: {
163-
// useIndividualCanvas: false,
164-
// },
165-
// });
166-
// setLcState({ lightningChart: lcRef.current, synchronizeAxis });
167-
// } catch (e) {
168-
// console.error(e);
169-
// }
170-
//
171-
// return () => {
172-
// if (lcRef.current && "dispose" in lcRef.current) {
173-
// lcRef.current.dispose();
174-
// lcRef.current = null;
175-
// setLcState({ lightningChart: null, synchronizeAxis });
176-
// }
177-
// };
178-
// }, []);
179-
//
180-
// return (
181-
// <LightningChartsContext.Provider value={lcState}>
182-
// {props.children}
183-
// </LightningChartsContext.Provider>
184-
// );
185-
// }
186-
//
187-
// export function useLightningChartsContext() {
188-
// const lcObj = useContext(LightningChartsContext);
189-
// if (!lcObj)
190-
// console.warn(
191-
// "useLightningChartsContext() can only be called from within a LightningChartsProvider!",
192-
// );
193-
// return lcObj as LCContextObject;
194-
// }

frontend/app/components/visualizations/lightning-charts/StackedLineChartInternal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export default function StackedLineChartInternal({
4242
subscribeLatestArrays,
4343
setCursor,
4444
setViewInterval,
45-
viewIntervalRef,
4645
dataSourceRef,
4746
dataArraysRef,
4847
isTimelineSyncedRef,
@@ -208,7 +207,7 @@ export default function StackedLineChartInternal({
208207
// if (!isTimelineSyncedRef.current || start - end == oldStart - oldEnd) {
209208
// }
210209

211-
// console.log("LCJS setting:", dataIndexes);
210+
// console.log("lcjs setting: ", idRef.current);
212211
setViewInterval(dataIndexes, `lcjs-${id}`);
213212
}
214213
});
@@ -243,6 +242,8 @@ export default function StackedLineChartInternal({
243242
const unsub1 = subscribeViewInterval(([left, right], setterID) => {
244243
// ATM we simply ignore updates to viewEdges from dataProvider
245244
// because lcjs automatically updates its interval on data changes
245+
246+
// console.log(`${idRef.current} receiving update: from ${setterID}, updating self? ${!(setterID === `lcjs-${idRef.current}` || setterID === "dataProvider")}`);
246247
if (setterID === `lcjs-${id}` || setterID === "dataProvider") return;
247248

248249
chart.getDefaultAxisX().setInterval({

0 commit comments

Comments
 (0)