Skip to content

Commit

Permalink
enabling display of BSMs without MAP and SPAT
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob6838 committed Aug 14, 2024
1 parent 43d562f commit 9e3392f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 84 deletions.
2 changes: 1 addition & 1 deletion gui/src/apis/events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class EventsApi {
intersectionId: number;
startTime: Date;
endTime: Date;
test: boolean;
test?: boolean;
abortController?: AbortController;
}): Promise<MessageMonitor.MinuteCount[]> {
const queryParams = {
Expand Down
81 changes: 39 additions & 42 deletions gui/src/components/map/map-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,13 +874,12 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
queryParams.roadRegulatorId
);
return;
// } else if (queryParams.intersectionId === -1) {
// console.error("Intersection ID is -1. Not attempting to pull initial map data.");
// cleanUpMappedData();
// return;
} else if (queryParams.intersectionId === -1 && props.sourceDataType !== "exact") {
console.error("Intersection ID is -1. Not attempting to pull initial map data.");
resetMapView();
return;
}
console.debug("Pulling Initial Data");
cleanUpMappedData();
pullInitialDataAbortControllers.forEach((abortController) => abortController.abort());
let rawMap: ProcessedMap[] = [];
let rawSpat: ProcessedSpat[] = [];
Expand Down Expand Up @@ -954,6 +953,14 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
rawSpat = importedMessageData.spatData.sort((a, b) => a.utcTimeStamp - b.utcTimeStamp);
rawBsm = importedMessageData.bsmData;
}
if (props.sourceDataType == "exact") {
let bsmGeojson = parseBsmToGeojson(rawBsm);
bsmGeojson = {
...bsmGeojson,
features: [...bsmGeojson.features.sort((a, b) => b.properties.odeReceivedAt - a.properties.odeReceivedAt)],
};
renderEntireMap([], [], bsmGeojson);
}
if (!rawMap || rawMap.length == 0) {
console.info("NO MAP MESSAGES WITHIN TIME");
return;
Expand Down Expand Up @@ -1086,8 +1093,24 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
currentSpatData: ProcessedSpat[],
currentBsmData: BsmFeatureCollection
) => {
if (currentMapData.length == 0 && props.sourceDataType != "exact") {
console.error("Did not attempt to render map, no map messages available:", currentMapData);
if (props.sourceDataType == "exact") {
const uniqueIds = new Set(currentBsmData.features.map((bsm) => bsm.properties?.id).sort());
// generate equally spaced unique colors for each uniqueId
const colors = generateColorDictionary(uniqueIds);
setMapLegendColors((prevValue) => ({
...prevValue,
bsmColors: colors,
}));
// add color to each feature
const bsmLayerStyle = generateMapboxStyleExpression(colors);
setBsmLayerStyle((prevValue) => ({
...prevValue,
paint: { ...prevValue.paint, "circle-color": bsmLayerStyle },
}));
setBsmData(currentBsmData);
}
if (currentMapData.length == 0) {
console.log("Did not attempt to render map, no map messages available:", currentMapData);
return;
}
// ######################### MAP Data #########################
Expand All @@ -1113,17 +1136,6 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
const spatSignalGroupsLocal = parseSpatSignalGroups(currentSpatData);

setSpatSignalGroups(spatSignalGroupsLocal);
const uniqueIds = new Set(currentBsmData.features.map((bsm) => bsm.properties?.id).sort());
// generate equally spaced unique colors for each uniqueId
const colors = generateColorDictionary(uniqueIds);
setMapLegendColors((prevValue) => ({
...prevValue,
bsmColors: colors,
}));
// add color to each feature
const bsmLayerStyle = generateMapboxStyleExpression(colors);
setBsmLayerStyle((prevValue) => ({ ...prevValue, paint: { ...prevValue.paint, "circle-color": bsmLayerStyle } }));
setBsmData(currentBsmData);

// ######################### Message Data #########################
rawData["map"] = currentMapData;
Expand All @@ -1146,6 +1158,7 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
)
);
};

// Increment sliderValue by 1 every second when playbackModeActive is true
useEffect(() => {
if (playbackModeActive) {
Expand Down Expand Up @@ -1184,6 +1197,7 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
setFilteredSurroundingNotifications([]);
setBsmData({ type: "FeatureCollection", features: [] });
setCurrentBsms({ type: "FeatureCollection", features: [] });
console.log("1191 setCurrentBsms", { type: "FeatureCollection", features: [] });
setMapSpatTimes({ mapTime: 0, spatTime: 0 });
setRawData({});
setSliderValue(0);
Expand Down Expand Up @@ -1380,6 +1394,11 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
}, [queryParams]);

useEffect(() => {
if (props.sourceDataType == "exact") {
// In "exact" mode, always show all BSMs. Timestamps are meaningless.
setCurrentBsms(bsmData);
console.log("1391 setCurrentBsms", bsmData);
}
if (!mapSignalGroups || !spatSignalGroups) {
console.debug("BSM Loading: No map or SPAT data", mapSignalGroups, spatSignalGroups);
return;
Expand Down Expand Up @@ -1408,10 +1427,7 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
setSignalStateData(undefined);
}

if (props.sourceDataType == "exact") {
// In "exact" mode, always show all BSMs. Timestamps are meaningless.
setCurrentBsms(bsmData);
} else {
if (props.sourceDataType !== "exact") {
// retrieve filtered BSMs
const filteredBsms: BsmFeature[] = bsmData?.features?.filter(
(feature) =>
Expand Down Expand Up @@ -1445,6 +1461,7 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
}
}
setCurrentBsms({ ...bsmData, features: lastBsms });
console.log("1455 setCurrentBsms", { ...bsmData, features: lastBsms });
}

const filteredEvents: MessageMonitor.Event[] = surroundingEvents.filter(
Expand Down Expand Up @@ -1678,26 +1695,6 @@ const MapTab = forwardRef<MAP_REFERENCE_TYPE | undefined, MapProps>(
setTimeWindowSeconds(60);
};

const cleanUpMappedData = () => {
setMapData(undefined);
setMapSignalGroups(undefined);
setSpatSignalGroups(undefined);
setConnectingLanes(undefined);
setSignalStateData(undefined);
setRawData({});
setFilteredSurroundingEvents([]);
setFilteredSurroundingNotifications([]);
setBsmData({ type: "FeatureCollection", features: [] });
setCurrentBsms({ type: "FeatureCollection", features: [] });
setCurrentSignalGroups(undefined);
setMapSpatTimes({ mapTime: 0, spatTime: 0 });
setSliderValue(0);
setPlaybackModeActive(false);
setCurrentSpatData([]);
setCurrentProcessedSpatData([]);
setCurrentBsmData({ type: "FeatureCollection", features: [] });
};

useEffect(() => {
console.log("Live Data Restart:", liveDataRestart, liveDataActive);
if (liveDataRestart != -1 && liveDataRestart < 5 && liveDataActive) {
Expand Down
21 changes: 0 additions & 21 deletions gui/src/models/MapCommandTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,4 @@ type MAP_REFERENCE_TYPE = {
heading?: number;
animationDurationMs?: number;
}) => void;

/**
* Render specified MAP data on map
*
* @param mapData - MAPs to be rendered
*/
setRenderedMapData: (mapData: ProcessedMap) => void;

/**
* Render specified SPAT data on map
*
* @param spatData - SPATs to be rendered
*/
setRenderedSpatData: (spatData: ProcessedSpat[]) => void;

/**
* Render specified BSM data on map
*
* @param bsmData - BSMs to be rendered
*/
setRenderedBsmData: (bsmData: OdeBsmData[]) => void;
};
23 changes: 3 additions & 20 deletions gui/src/pages/decoder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const DecoderPage = () => {
);
const [selectedBsms, setSelectedBsms] = useState([] as string[]);
const mapRef = useRef<MAP_REFERENCE_TYPE | null>(null);
const [trigger, setTrigger] = useState(0); // Trigger state

console.log("Data", data);

Expand All @@ -42,7 +41,6 @@ const DecoderPage = () => {
});
}
setData(freshData.reduce((acc, entry) => ({ ...acc, [entry.id]: entry }), {}));
setTrigger((prev) => prev + 1);
}, []);

const submitDecoderRequest = (data: string, type: DECODER_MESSAGE_TYPE) => {
Expand Down Expand Up @@ -75,7 +73,6 @@ const DecoderPage = () => {
},
};
});
setTrigger((prev) => prev + 1);
});
let newEntry = {};
if (prevData[id].text != undefined) {
Expand All @@ -89,7 +86,6 @@ const DecoderPage = () => {
isGreyedOut: false,
decodedResponse: undefined,
};
setTrigger((prev) => prev + 1);
}
return {
...prevData,
Expand All @@ -113,7 +109,6 @@ const DecoderPage = () => {
delete prevData[id];
return { ...prevData };
});
setTrigger((prev) => prev + 1);
}
};

Expand All @@ -125,7 +120,6 @@ const DecoderPage = () => {
const rsuIp = data[id]?.decodedResponse?.processedMap?.properties?.originIp;
if (intersectionId) {
setSelectedMapMessage({ id, intersectionId, rsuIp: rsuIp! });
setTrigger((prev) => prev + 1);
}
return;
case "BSM":
Expand All @@ -136,7 +130,6 @@ const DecoderPage = () => {
return [...prevBsms, id];
}
});
setTrigger((prev) => prev + 1);
return;
}
};
Expand Down Expand Up @@ -195,7 +188,7 @@ const DecoderPage = () => {
});
};

const getIntersectionId = (decodedResponse: DecoderApiResponseGeneric | undefined) => {
const getIntersectionId = (decodedResponse: DecoderApiResponseGeneric | undefined): number | undefined => {
if (!decodedResponse) {
return undefined;
}
Expand All @@ -207,9 +200,8 @@ const DecoderPage = () => {
case "SPAT":
const spatPayload = decodedResponse.processedSpat;
return spatPayload?.intersectionId;
case "BSM":
const bsmPayload = decodedResponse.bsm;
return bsmPayload?.metadata.originIp;
default:
return undefined;
}
};

Expand All @@ -221,15 +213,6 @@ const DecoderPage = () => {
return (selectedMapMessage?.rsuIp === undefined || rsuIp !== selectedMapMessage?.rsuIp) && rsuIp != "";
};

useEffect(() => {
mapRef.current?.setRenderedBsmData(
Object.values(data)
.filter((v) => v.type === "BSM" && v.status == "COMPLETED" && selectedBsms.includes(v.id))
.map((v) => v.decodedResponse?.bsm!)
);
console.log("Setting rendered BSM data", Object.values(data));
}, [data, trigger, selectedBsms]);

return (
<>
<Head>
Expand Down

0 comments on commit 9e3392f

Please sign in to comment.