Skip to content

Commit

Permalink
nih
Browse files Browse the repository at this point in the history
  • Loading branch information
trevlenb2 committed Oct 5, 2023
1 parent df5a923 commit f1a92d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
45 changes: 43 additions & 2 deletions src/features/planSimulation/components/Simulation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export interface Stats {
[key: string]: Metadata;
}

export interface StatsLayer {
[layer: string]: Stats;
}

export interface SimulationRequestData {
hierarchyIdentifier: string | undefined;
hierarchyType: string | undefined;
Expand Down Expand Up @@ -168,6 +172,9 @@ const Simulation = () => {
const levelsLoaded = useRef<string[]>([]);
const [showUploadModal, setShowUploadModal] = useState(false);
const [statsMetadata, setStatsMetadata] = useState<Stats>({});

const [statsLayerMetadata, setStatsLayerMetadata] = useState<StatsLayer>({});

const [aggregationSummary, setAggregationSummary] = useState<LocationMetadataObj>({});
const [aggregationSummaryDefinition, setAggregationSummaryDefinition] = useState<MetadataDefinition>({});
const [submitSimulationRequestData, setSubmitSimulationRequestData] = useState<SimulationRequestData>();
Expand Down Expand Up @@ -389,7 +396,7 @@ const Simulation = () => {
closeConnHandler,
openHandler,
(e: any) => parentHandlerAfterAnalysis(e, analysisLayer),
statsHandler,
(e: any) => statsHandlerAfterAnalysis(e, analysisLayer),
locationAggregationHandler,
locationAggregationDefinitionHandler,
resultsErrorHandler
Expand Down Expand Up @@ -468,6 +475,40 @@ const Simulation = () => {
});
};

const statsHandlerAfterAnalysis = (message: MessageEvent, analysisLayer: AnalysisLayer) => {
// const statsIncoming = JSON.parse(message.data);
// setStatsMetadata(statsMetadata => {
// let newStats: Stats = {};
// Object.keys(statsMetadata).forEach(key => {
// newStats[key] = statsMetadata[key];
// });
// Object.keys(statsIncoming).forEach(key => {
// if (!newStats[key]) {
// newStats[key] = statsIncoming[key];
// }
// });
// return newStats;
// });

const statsIncoming = JSON.parse(message.data);
setStatsLayerMetadata(statsLayerMetadata => {
let newStats: StatsLayer = {};
Object.keys(statsLayerMetadata).forEach(layer => {
// Object.keys(statsLayerMetadata[layer]).forEach(key => {
newStats[layer] = statsLayerMetadata[layer];
// });
});
Object.keys(statsIncoming).forEach(key => {
let newStatsIncoming: Stats = {};
if (!newStats[key]) {
newStatsIncoming[key] = statsIncoming[key];
}
newStats[analysisLayer.labelName] = newStatsIncoming;
});
return newStats;
});
};

const locationAggregationHandler = useCallback(
(message: MessageEvent) => {
const locationList = JSON.parse(message.data);
Expand Down Expand Up @@ -1491,7 +1532,7 @@ const Simulation = () => {
chunkedData={mapDataLoad}
resetMap={resetMap}
setResetMap={setResetMap}
stats={statsMetadata}
stats={statsLayerMetadata}
resultsLoadingState={resultsLoadingState}
parentsLoadingState={parentsLoadingState}
map={map}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import { ColorPicker, Color, useColor } from 'react-color-palette';
import 'react-color-palette/lib/css/styles.css';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Children, Stats } from '../Simulation';
import { Children, Stats, StatsLayer } from '../Simulation';
import ActionDialog from '../../../../components/Dialogs/ActionDialog';
import MapboxDraw from '@mapbox/mapbox-gl-draw';
import { AnalysisLayer } from '../Simulation';
Expand All @@ -51,7 +51,7 @@ interface Props {
setResetMap: (resetMap: boolean) => void;
resultsLoadingState: 'notstarted' | 'error' | 'started' | 'complete';
parentsLoadingState: 'notstarted' | 'error' | 'started' | 'complete';
stats: Stats;
stats: StatsLayer;
map: MutableRefObject<MapBoxMap | undefined>;
updateMarkedLocations: (identifier: string, ancestry: string[], marked: boolean) => void;
parentChild: { [parent: string]: Children };
Expand Down Expand Up @@ -621,7 +621,7 @@ const SimulationMapView = ({
'circle-opacity': [
'case',
['==', ['get', 'selectedTagValuePercent'], null],
0.1,
0,
['==', ['get', 'selectedTagValuePercent'], 0],
0.1,
['get', 'selectedTagValuePercent']
Expand All @@ -646,8 +646,10 @@ const SimulationMapView = ({
paint: {
'fill-color': [
'case',
['>', ['length', ['get', 'metadata']], 0],
['case', ['==', ['get', 'selectedColor'], null], geoColor.hex, ['get', 'selectedColor']],
['==', ['get', 'selectedTagValue'], null],
geoColor.hex,
'black',
['<', ['get', 'selectedTagValue'], 0],
geoColor.hex,
['==', ['get', 'selectedTagValue'], 0],
Expand All @@ -656,6 +658,10 @@ const SimulationMapView = ({
],
'fill-opacity': [
'case',
['==', ['get', 'selectedTagValue'], null],
0.2,
['==', ['get', 'selectedTagValue'], 0],
0,
['==', ['get', 'selectedTransparency'], null],
0.1,
['/', ['get', 'selectedTransparency'], 100]
Expand Down Expand Up @@ -1841,9 +1847,10 @@ const SimulationMapView = ({
}
return false;
})
.filter((meta: any) => stats[userDefinedLayer.key] && stats[userDefinedLayer.key][meta])
.map((meta: any) => (
<p key={meta}>
<b>{meta}:</b> {stats[meta]}
<b>{meta}:</b> {stats[userDefinedLayer.key] ? stats[userDefinedLayer.key][meta] : ''}
</p>
));
})}
Expand Down

0 comments on commit f1a92d7

Please sign in to comment.