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,
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 }) => (
<ModalBody className="map-modal__modal-body">
<Map center={[ 0, 0 ]} zoom="3">
<OpenStreetMapTile />
{locations.map(({ city, latLong, count }, index) => (
{locations.map(({ cityName, latLong, count }, index) => (
<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>
))}
</Map>

View file

@ -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,