Skip to content

Commit

Permalink
[TEST] Minimal partial assignment (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation authored Jan 3, 2025
1 parent 635707d commit 67fd367
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
6 changes: 6 additions & 0 deletions app/src/app/store/mapStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Assignment,
DistrictrMap,
DocumentObject,
lastSentAssignments,
P1TotPopSummaryStats,
P4TotPopSummaryStats,
ShatterResult,
Expand Down Expand Up @@ -409,6 +410,7 @@ export const useMapStore = createWithMiddlewares<MapStore>(
const initialMapOptions = useMapStore.getInitialState().mapOptions;
parentIdCache.clear();
allPainted.clear();
lastSentAssignments.clear();
setFreshMap(true);
resetZoneAssignments();

Expand Down Expand Up @@ -776,6 +778,7 @@ export const useMapStore = createWithMiddlewares<MapStore>(
if (resetResponse.document_id === document_id) {
const initialState = useMapStore.getInitialState();
useMapStore.temporal.getState().clear()
lastSentAssignments.clear();
resetZoneColors({
zoneAssignments,
mapRef: getMapRef(),
Expand Down Expand Up @@ -905,6 +908,7 @@ export const useMapStore = createWithMiddlewares<MapStore>(
});
},
loadZoneAssignments: assignments => {
lastSentAssignments.clear();
const zoneAssignments = new Map<string, number>();
const shatterIds = {
parents: new Set<string>(),
Expand All @@ -914,6 +918,8 @@ export const useMapStore = createWithMiddlewares<MapStore>(

assignments.forEach(assignment => {
zoneAssignments.set(assignment.geo_id, assignment.zone);
// preload last sent assignments with last fetched assignments
lastSentAssignments.set(assignment.geo_id, assignment.zone);
if (assignment.parent_path) {
if (!shatterMappings[assignment.parent_path]) {
shatterMappings[assignment.parent_path] = new Set([assignment.geo_id]);
Expand Down
29 changes: 18 additions & 11 deletions app/src/app/utils/api/apiHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {getEntryTotal} from '../summaryStats';
import {useChartStore} from '@/app/store/chartStore';
import {NullableZone} from '@/app/constants/types';

export const lastSentAssignments = new Map<string, NullableZone>();
export const FormatAssignments = () => {
// track the geoids that have been painted, but are now not painted
const allPainted = useMapStore.getState().allPainted;
Expand All @@ -19,22 +20,28 @@ export const FormatAssignments = () => {
zone: NullableZone;
} => {
assignmentsVisited.delete(geo_id);
assignments.push({
document_id: useMapStore.getState().mapDocument?.document_id || '',
geo_id,
zone,
});
if (lastSentAssignments.get(geo_id) !== zone) {
lastSentAssignments.set(geo_id, zone);
assignments.push({
document_id: useMapStore.getState().mapDocument?.document_id || '',
geo_id,
zone,
});
}
}
);
// fill in with nulls removes assignments from backend
// otherwise the previous assignment remains
assignmentsVisited.forEach(geo_id => {
assignments.push({
document_id: useMapStore.getState().mapDocument?.document_id || '',
geo_id,
// @ts-ignore assignment wants to be number
zone: null,
});
if (lastSentAssignments.get(geo_id) !== null) {
lastSentAssignments.set(geo_id, null);
assignments.push({
document_id: useMapStore.getState().mapDocument?.document_id || '',
geo_id,
// @ts-ignore assignment wants to be number
zone: null,
});
}
});
return assignments;
};
Expand Down

0 comments on commit 67fd367

Please sign in to comment.