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

Hack: restrict CDI date selection for lag; COUNTRY=jordan #1326

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c015a37
Adding support for custom seasons in validity configuration
gislawill Jul 30, 2024
fece4d0
Fixing season bounds
gislawill Jul 30, 2024
92f5fb6
fixing tests
gislawill Jul 30, 2024
78cbd13
Fixing past season bug
gislawill Jul 31, 2024
a1681ff
CDI - configure seasons as quarters
wadhwamatic Aug 4, 2024
131e842
Ensure query dates are availables for composite requests
gislawill Aug 5, 2024
680ff15
Test updates
gislawill Aug 5, 2024
3ad7808
Better handle timezones
gislawill Aug 6, 2024
dbdabc4
adjust bounding box
wadhwamatic Aug 6, 2024
c2eaabe
remove layers available through shared config
wadhwamatic Aug 6, 2024
779d38d
Merge branch 'master' into feat/allow-flexible-season-validity
gislawill Aug 6, 2024
b2e960b
Merge branch 'feat/allow-flexible-season-validity' of https://github.…
gislawill Aug 6, 2024
07afa32
Accomodate leap years in constructDateFromSeason
gislawill Aug 6, 2024
67b8fe7
Adding hacky-ish expected data lag
gislawill Aug 6, 2024
200e675
TS fix
gislawill Aug 6, 2024
4ac8b61
revert bbox
wadhwamatic Aug 7, 2024
7d6bccc
Merge branch 'feat/allow-flexible-season-validity' into hack/restrict…
wadhwamatic Aug 7, 2024
05a7719
update CDI date lag for demo
wadhwamatic Aug 7, 2024
e141dd8
temporary arabic translations
wadhwamatic Aug 7, 2024
c451b57
additional temporary translations
wadhwamatic Aug 7, 2024
f55e9a0
remove forecast layers
wadhwamatic Aug 7, 2024
a36c41e
Merge branch 'master' into hack/restrict-day-selection-for-lag
wadhwamatic Sep 6, 2024
39c0ce2
Merge branch 'master' into hack/restrict-day-selection-for-lag
wadhwamatic Sep 13, 2024
de88004
Merge branch 'master' into hack/restrict-day-selection-for-lag
wadhwamatic Sep 16, 2024
8a951b7
extend date lag and modify CDI params based on Sara's input
wadhwamatic Sep 17, 2024
6a012cf
Initial aggregation layer for CDI. Only monthly v1 currently
gislawill Sep 19, 2024
2d3a0a8
Merge branch 'master' into 1337-feature-request-aggregate-cdi-results…
ericboucher Sep 25, 2024
562df56
Merge branch 'master' into 1337-feature-request-aggregate-cdi-results…
wadhwamatic Oct 28, 2024
65fbbce
Adding additional layers
gislawill Oct 30, 2024
7fbbd0e
Merge branch '1337-feature-request-aggregate-cdi-results-by-admin-are…
gislawill Oct 30, 2024
97b35fa
updating the CDI reference dates
gislawill Nov 1, 2024
6b8cd99
Pointing to deployed server
gislawill Nov 1, 2024
2a74f62
reorganize layers in prism.json
wadhwamatic Nov 2, 2024
ef4dae3
Updating reference period
gislawill Nov 2, 2024
607aefa
Merge branch '1337-feature-request-aggregate-cdi-results-by-admin-are…
gislawill Nov 2, 2024
8be4d67
Adding expected lag to all layers
gislawill Nov 2, 2024
fb7c382
extend lag for CDI layers
wadhwamatic Nov 2, 2024
bf5ccb8
cleanup CDI configuration (wip)
wadhwamatic Nov 3, 2024
e8a2796
Merge branch 'master' into hack/restrict-day-selection-for-lag
wadhwamatic Dec 17, 2024
dcccdde
cleanup CDI layer configs
wadhwamatic Dec 18, 2024
1eca78c
extend lag
wadhwamatic Dec 18, 2024
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
138 changes: 103 additions & 35 deletions frontend/src/components/MapView/Layers/CompositeLayer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { CompositeLayerProps, LegendDefinition } from 'config/types';
import {
CompositeLayerProps,
LegendDefinition,
MapEventWrapFunctionProps,
} from 'config/types';
import { LayerData, loadLayerData } from 'context/layers/layer-data';
import { layerDataSelector } from 'context/mapStateSlice/selectors';
import { memo, useEffect, useMemo, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Source, Layer } from 'react-map-gl/maplibre';
import { getLayerMapId } from 'utils/map-utils';
import { FillLayerSpecification } from 'maplibre-gl';
import {
findFeature,
getEvtCoords,
getLayerMapId,
useMapCallback,
} from 'utils/map-utils';
import { FillLayerSpecification, MapLayerMouseEvent } from 'maplibre-gl';
import { Point } from 'geojson';
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
import { availableDatesSelector } from 'context/serverStateSlice';
Expand All @@ -14,6 +23,7 @@ import { getRequestDateItem } from 'utils/server-utils';
import { safeCountry } from 'config';
import { geoToH3, h3ToGeoBoundary } from 'h3-js'; // ts-ignore
import { opacitySelector } from 'context/opacityStateSlice';
import { addPopupData } from 'context/tooltipStateSlice';
import { legendToStops } from '../layer-utils';

interface Props {
Expand All @@ -40,7 +50,12 @@ const paintProps: (
const CompositeLayer = memo(({ layer, before }: Props) => {
// look to refacto with impactLayer and maybe other layers
const [adminBoundaryLimitPolygon, setAdminBoundaryPolygon] = useState(null);
const selectedDate = useDefaultDate(layer.dateLayer);
const selectedDate = useDefaultDate(
layer.dateLayer,
layer.expectedDataLagDays,
);
const [aggregationBoundariesPolygon, setAggregationBoundariesPolygon] =
useState(null);
const serverAvailableDates = useSelector(availableDatesSelector);
const opacityState = useSelector(opacitySelector(layer.id));
const dispatch = useDispatch();
Expand Down Expand Up @@ -68,47 +83,100 @@ const CompositeLayer = memo(({ layer, before }: Props) => {
}, []);

useEffect(() => {
if (requestDate) {
if (layer.aggregationBoundaryPath) {
fetch(layer.aggregationBoundaryPath)
.then(response => response.json())
.then(polygonData => setAggregationBoundariesPolygon(polygonData))
.catch(error => console.error('Error:', error));
}
}, [layer.aggregationBoundaryPath]);

useEffect(() => {
if (
(requestDate &&
layer.aggregationBoundaryPath &&
aggregationBoundariesPolygon) ||
!layer.aggregationBoundaryPath
) {
dispatch(
loadLayerData({
layer,
date: requestDate,
availableDates: layerAvailableDates,
aggregationBoundariesPolygon,
}),
);
}
}, [dispatch, layer, layerAvailableDates, requestDate]);
}, [
dispatch,
layer,
layerAvailableDates,
requestDate,
aggregationBoundariesPolygon,
]);

// Investigate performance impact of hexagons for large countries
const finalFeatures =
data &&
data.features
.map(feature => {
const point = feature.geometry as Point;
if (
!adminBoundaryLimitPolygon ||
booleanPointInPolygon(
point.coordinates,
adminBoundaryLimitPolygon as any,
)
) {
// Convert the point to a hexagon
const hexagon = geoToH3(
point.coordinates[1],
point.coordinates[0],
6, // resolution, adjust as needed
);
return {
...feature,
geometry: {
type: 'Polygon',
coordinates: [h3ToGeoBoundary(hexagon, true)], // Convert the hexagon to a GeoJSON polygon
},
};
}
return null;
})
.filter(Boolean);
const finalFeatures = layer.aggregationBoundaryPath
? data?.features
: !layer.aggregationBoundaryPath &&
data &&
data?.features
.map(feature => {
const point = feature.geometry as Point;
if (
!adminBoundaryLimitPolygon ||
booleanPointInPolygon(
point.coordinates,
adminBoundaryLimitPolygon as any,
)
) {
// Convert the point to a hexagon
const hexagon = geoToH3(
point.coordinates[1],
point.coordinates[0],
6, // resolution, adjust as needed
);
return {
...feature,
geometry: {
type: 'Polygon',
coordinates: [h3ToGeoBoundary(hexagon, true)], // Convert the hexagon to a GeoJSON polygon
},
};
}
return null;
})
.filter(Boolean);

const layerId = getLayerMapId(layer.id);

const onClick =
({
dispatch: providedDispatch,
}: MapEventWrapFunctionProps<CompositeLayerProps>) =>
(evt: MapLayerMouseEvent) => {
const coordinates = getEvtCoords(evt);

const feature = findFeature(layerId, evt);
if (!feature) {
return;
}

const popupData = {
[layer.title]: {
data: feature.properties.value.toFixed(3),
coordinates,
},
};
providedDispatch(addPopupData(popupData));
};

useMapCallback<'click', CompositeLayerProps>(
'click',
layerId,
layer,
onClick,
);

if (selectedDate && data && adminBoundaryLimitPolygon) {
const filteredData = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/config/jordan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default {
rawTables,
rawReports,
translation,
defaultBoundariesFile: 'jor_admbnda_adm2_jdos.json',
defaultBoundariesFile: 'jor_admbnda_adm3_jdos_merged.json',
};
Loading
Loading