Skip to content

Commit

Permalink
Merge pull request #1125 from data-for-change/dev
Browse files Browse the repository at this point in the history
merge dev into master
  • Loading branch information
atalyaalon authored Oct 6, 2024
2 parents df01fea + 688f5f9 commit b27a21f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/utils/map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ export function uniquePoints(points: IPoint[]) {
}

export function aggregatePoints(points: IPointAccident[]) : IAggregatePointAccident[] {
const sameLocationPointMap : Map<string,string[]> = new Map();
const sameLocationPointMap : Map<string,{dates : string[], severity : IAggregatePointAccident['accident_severity'] }> = new Map();
// fill only unique points (not yet included in uniqueSet)
points.reduce(( map, currentPoint) => {
const key = JSON.stringify({latitude : currentPoint.latitude ,longitude : currentPoint.longitude });
const label = map.get(key);
const mapValue = map.get(key);

if(map.get(key)){
label?.push(currentPoint.accident_timestamp);
//map.set(key, `${label},${currentPoint.accident_timestamp}`)
if(mapValue){
mapValue?.dates.push(currentPoint.accident_timestamp);
if(mapValue.severity !== "fatal" ){
mapValue.severity = currentPoint.accident_severity ;
}
}
else{
map.set(key, [currentPoint.accident_timestamp]);
map.set(key, {severity : currentPoint.accident_severity ,dates : [currentPoint.accident_timestamp]});
}
return map;
},sameLocationPointMap);
return Array.from(sameLocationPointMap.entries()).map(([key, value]) => {
// convert map to array of IAggregatePointAccident
return Array.from(sameLocationPointMap.entries()).map(([key, locationData]) => {
const point = JSON.parse(key) as IPoint;
return {latitude: point.latitude, longitude: point.longitude, accident_timestamp: value, accident_severity: "severe"};
return {latitude: point.latitude, longitude: point.longitude, accident_timestamp: locationData.dates, accident_severity: locationData.severity};
})
}

0 comments on commit b27a21f

Please sign in to comment.