Skipped locations from unknown cities when processing cities stats for map

This commit is contained in:
Alejandro Celaya 2019-01-07 21:11:09 +01:00
parent 4870801f8f
commit 00d386f19f
2 changed files with 12 additions and 9 deletions

View file

@ -9,7 +9,7 @@ const propTypes = {
isOpen: PropTypes.bool, isOpen: PropTypes.bool,
title: PropTypes.string, title: PropTypes.string,
locations: PropTypes.arrayOf(PropTypes.shape({ locations: PropTypes.arrayOf(PropTypes.shape({
city: PropTypes.string.isRequired, cityName: PropTypes.string.isRequired,
latLong: PropTypes.arrayOf(PropTypes.number).isRequired, latLong: PropTypes.arrayOf(PropTypes.number).isRequired,
count: PropTypes.number.isRequired, count: PropTypes.number.isRequired,
})), })),
@ -31,9 +31,9 @@ const MapModal = ({ toggle, isOpen, title, locations }) => (
<ModalBody className="map-modal__modal-body"> <ModalBody className="map-modal__modal-body">
<Map center={[ 0, 0 ]} zoom="3"> <Map center={[ 0, 0 ]} zoom="3">
<OpenStreetMapTile /> <OpenStreetMapTile />
{locations.map(({ city, latLong, count }, index) => ( {locations.map(({ cityName, latLong, count }, index) => (
<Marker key={index} position={latLong}> <Marker key={index} position={latLong}>
<Popup><b>{count}</b> visit{count > 1 ? 's' : ''} from <b>{city}</b></Popup> <Popup><b>{count}</b> visit{count > 1 ? 's' : ''} from <b>{cityName}</b></Popup>
</Marker> </Marker>
))} ))}
</Map> </Map>

View file

@ -100,17 +100,20 @@ export const processCitiesStats = buildLocationStatsProcessorByProperty('cityNam
export const processCitiesStatsForMap = (visits) => export const processCitiesStatsForMap = (visits) =>
reduce( reduce(
(stats, { visitLocation }) => { (stats, { visitLocation }) => {
const hasCity = visitLocationHasProperty(visitLocation, 'cityName'); if (!visitLocationHasProperty(visitLocation, 'cityName')) {
const city = hasCity ? visitLocation.cityName : 'unknown'; return stats;
const currentCity = stats[city] || { }
city,
const { cityName, latitude, longitude } = visitLocation;
const currentCity = stats[cityName] || {
cityName,
count: 0, count: 0,
latLong: hasCity ? [ parseFloat(visitLocation.latitude), parseFloat(visitLocation.longitude) ] : [ 0, 0 ], latLong: [ parseFloat(latitude), parseFloat(longitude) ],
}; };
currentCity.count++; currentCity.count++;
return assoc(city, currentCity, stats); return assoc(cityName, currentCity, stats);
}, },
{}, {},
visits, visits,