Skip to content

Commit

Permalink
geopipe: favour cordinates in data not postcode
Browse files Browse the repository at this point in the history
Currently if raw data has both co-ordinates and postcode we use co-ordinates from postcode lookup data

Instead let's use co-ordinates from raw data on the assumption those are more accurate.

Note we still will do postcode lookup to get locality etc

#29
  • Loading branch information
odscjames committed Mar 10, 2020
1 parent 057d4b5 commit 0de11c2
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/lib/pipes/geo-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ class GeoPipe extends Pipe {

for(let idx in this.normalisedEvents) {

if ('postcode' in this.normalisedEvents[idx].body['location']) {
if ('postcode' in this.normalisedEvents[idx].body['location'] && this.normalisedEvents[idx].body['location']['postcode']) {

const postCode = this.normalisedEvents[idx].body['location']['postcode'];

if (cache.postcodes[postCode]){

Utils.log(`Geopipe cache hit ${postCode}`);

this.normalisedEvents[idx].body['location'] = Object.assign(this.normalisedEvents[idx].body['location'], cache.postcodes[postCode]);

} else {
// If not in Cache, try and get it
if (!cache.postcodes[postCode]){

Utils.log(`Geopipe looking up ${postCode}`);

Expand All @@ -41,15 +36,28 @@ class GeoPipe extends Pipe {
"country": postCodeResult.result.country
};

this.normalisedEvents[idx].body['location'] = Object.assign(this.normalisedEvents[idx].body['location'], cache.postcodes[postCode]);

}

} catch (e) {
Utils.log(`Geopipe could not get postcode ${postCode} Error \n ${e}`);
}
}

// If in Cache now, assign it to data
if (cache.postcodes[postCode]){

Utils.log(`Geopipe cache hit ${postCode}`);

this.normalisedEvents[idx].body['location']['locality'] = cache.postcodes[postCode]['locality'];
this.normalisedEvents[idx].body['location']['region'] = cache.postcodes[postCode]['region'];
this.normalisedEvents[idx].body['location']['country'] = cache.postcodes[postCode]['country'];
// If data already has coordinates, assume that's better than what postcode look up will return
if (!this.normalisedEvents[idx].body['location']['coordinates']) {
this.normalisedEvents[idx].body['location']['coordinates'] = cache.postcodes[postCode]['coordinates'];
}

}

}

}
Expand Down

0 comments on commit 0de11c2

Please sign in to comment.