From 00d386f19f8ead56a0dfc9c6473a4f939e15f395 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 7 Jan 2019 21:11:09 +0100 Subject: [PATCH] Skipped locations from unknown cities when processing cities stats for map --- src/visits/helpers/MapModal.js | 6 +++--- src/visits/services/VisitsParser.js | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/visits/helpers/MapModal.js b/src/visits/helpers/MapModal.js index 773bdadc..3f8407fa 100644 --- a/src/visits/helpers/MapModal.js +++ b/src/visits/helpers/MapModal.js @@ -9,7 +9,7 @@ const propTypes = { isOpen: PropTypes.bool, title: PropTypes.string, locations: PropTypes.arrayOf(PropTypes.shape({ - city: PropTypes.string.isRequired, + cityName: PropTypes.string.isRequired, latLong: PropTypes.arrayOf(PropTypes.number).isRequired, count: PropTypes.number.isRequired, })), @@ -31,9 +31,9 @@ const MapModal = ({ toggle, isOpen, title, locations }) => ( - {locations.map(({ city, latLong, count }, index) => ( + {locations.map(({ cityName, latLong, count }, index) => ( - {count} visit{count > 1 ? 's' : ''} from {city} + {count} visit{count > 1 ? 's' : ''} from {cityName} ))} diff --git a/src/visits/services/VisitsParser.js b/src/visits/services/VisitsParser.js index 6ff5662b..174291d1 100644 --- a/src/visits/services/VisitsParser.js +++ b/src/visits/services/VisitsParser.js @@ -100,17 +100,20 @@ export const processCitiesStats = buildLocationStatsProcessorByProperty('cityNam export const processCitiesStatsForMap = (visits) => reduce( (stats, { visitLocation }) => { - const hasCity = visitLocationHasProperty(visitLocation, 'cityName'); - const city = hasCity ? visitLocation.cityName : 'unknown'; - const currentCity = stats[city] || { - city, + if (!visitLocationHasProperty(visitLocation, 'cityName')) { + return stats; + } + + const { cityName, latitude, longitude } = visitLocation; + const currentCity = stats[cityName] || { + cityName, count: 0, - latLong: hasCity ? [ parseFloat(visitLocation.latitude), parseFloat(visitLocation.longitude) ] : [ 0, 0 ], + latLong: [ parseFloat(latitude), parseFloat(longitude) ], }; currentCity.count++; - return assoc(city, currentCity, stats); + return assoc(cityName, currentCity, stats); }, {}, visits,