Permalink
Browse files

Merge pull request #198 from ideal-postcodes/fix_lon_lat

Fixes geolocation regression for `postcode` and `terminated_postcode` points with no geolocation. Fixes #197
  • Loading branch information...
cblanc committed Jun 18, 2018
2 parents 6ecd61b + 556c560 commit 6f31063cb7c56d2e8035a82cd736d3e0513d8e19
View
@@ -17,10 +17,11 @@ jobs:
- run: POSTGRES_USER=postgres npm run setup_test_db
- restore_cache:
keys:
- npm-deps-{{ checksum "package-lock.json" }}
- nodemodules-deps-{{ checksum "package-lock.json" }}
- nodemodules-deps-
- run: npm install
- save_cache:
key: npm-deps-{{ checksum "package-lock.json" }}
key: nodemodules-deps-{{ checksum "package-lock.json" }}
paths:
- node_modules/
- run: npm run test
@@ -44,10 +45,11 @@ jobs:
- run: POSTGRES_USER=postgres npm run setup_test_db
- restore_cache:
keys:
- npm-deps-{{ checksum "package-lock.json" }}
- nodemodules-deps-{{ checksum "package-lock.json" }}
- nodemodules-deps-
- run: npm install
- save_cache:
key: npm-deps-{{ checksum "package-lock.json" }}
key: nodemodules-deps-{{ checksum "package-lock.json" }}
paths:
- node_modules/
- run: npm run test
@@ -69,10 +71,11 @@ jobs:
- run: POSTGRES_USER=postgres npm run setup_test_db
- restore_cache:
keys:
- npm-deps-{{ checksum "package-lock.json" }}
- nodemodules-deps-{{ checksum "package-lock.json" }}
- nodemodules-deps-
- run: npm install
- save_cache:
key: npm-deps-{{ checksum "package-lock.json" }}
key: nodemodules-deps-{{ checksum "package-lock.json" }}
paths:
- node_modules/
- run: npm run test
View
@@ -2,14 +2,22 @@
Any changes, including backwards incompatible changes will be listed here
## 9.0.1 (18/6/2018)
- Fixed regression. WGS84 geolocations for points with no assigned geolocation (in `postcodes` and `terminated_postcodes` relations) returned `0` and `99.9999` (ONSPD default identifiers for no geolocation) instead of `null` and `null`.
- Updated `pg_dump` released in 9.0.0 to incorporate above fix
- Updated noticeboard
## 9.0.0 (8/6/2018)
- *Breaking Change* Updated `postcode` and `terminated_postcode` models for the new schema in ONSPD CSV file. This means `>9.0.0` will not be able to import ONSPD CSV files produced before May 2018. `pg_dump` imports will not be affected
- Added package.lock file
- Updated wards, districts, nuts, ccgs GSS Codes
- Updated ONSPD dataset to May 2018
- Updated OS Names dataset to April 2018
## 8.0.0 (6/3/2018)
- *Breaking Change* Terminated Postcode schema has been updated to include geolocation attributes: `longitude`, `latitude`, `northings`, `eastings` and `location`
- Extended `/terminated_postcodes` endpoint to include `longitude` and `latitude`
- Updated parishes GSS Codes
View
@@ -642,8 +642,20 @@ Postcode.prototype.seedPostcodes = function (filepath, callback) {
{ column: "pc_compact", method: row => row.extract("pcds").replace(/\s/g, "") },
{ column: "eastings", method: row => row.extract("oseast1m") },
{ column: "northings", method: row => row.extract("osnrth1m") },
{ column: "longitude", method: row => row.extract("long") },
{ column: "latitude", method: row => row.extract("lat") },
{
column: "longitude",
method: row => {
const longitude = row.extract("long");
return (parseInt(longitude, 10) === 0) ? null : longitude;
},
},
{
column: "latitude",
method: row => {
const latitude = row.extract("lat");
return (parseInt(latitude, 10) > 98) ? null : latitude;
},
},
{ column: "country", method: row => countries[row.extract("ctry")] },
{ column: "nhs_ha", method: row => nhsHa[row.extract("oshlthau")] },
{ column: "admin_county_id", method: row => row.extract("oscty") },
@@ -72,8 +72,20 @@ TerminatedPostcode.prototype.seedPostcodes = function (filepath, callback) {
{ column: "month_terminated", method: row => row.extract("doterm").slice(-2) },
{ column: "eastings", method: row => row.extract("oseast1m") },
{ column: "northings", method: row => row.extract("osnrth1m") },
{ column: "longitude", method: row => row.extract("long") },
{ column: "latitude", method: row => row.extract("lat") },
{
column: "longitude",
method: row => {
const longitude = row.extract("long");
return (parseInt(longitude, 10) === 0) ? null : longitude;
},
},
{
column: "latitude",
method: row => {
const latitude = row.extract("lat");
return (parseInt(latitude, 10) > 98) ? null : latitude;
},
}
]);
this._csvSeed({
@@ -39,7 +39,7 @@
<h3>Noticeboard for 2018</h3>
<p>Any updates or disruptions will be listed below.</p>
<ul>
<li>Nothing to date</li>
<li><strong>14-18 June</strong> Following the switch to the new ONSPD CSV schema, <code>longitude</code> and <code>latitude</code> for entities with no geolocation were returned as <code>0</code> and <code>99.9999...</code> instead of <code>null</code> and <code>null</code>. Old behaviour has been restored as at 19th June (version 9.0.1)</li>
</ul>
<hr />
<h3>Email</h3>
View
2 latest
@@ -1 +1 @@
https://postcodesio.s3.amazonaws.com/public/postcodesio-2018-06-14-1444.sql.gz
https://postcodesio.s3.amazonaws.com/public/postcodesio-2018-06-18-1611.sql.gz
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
{
"name": "postcodes.io",
"version": "9.0.0",
"version": "9.0.1",
"description": "A postcode lookup API",
"main": "app.js",
"directories": {
@@ -0,0 +1,105 @@
"use strict";
const async = require("async");
const assert = require("chai").assert;
const helper = require("./helper/index.js");
const Postcode = helper.Postcode;
describe("Postcode data regression testing", function () {
before(function (done) {
this.timeout(0);
async.series([
helper.clearPostcodeDb,
helper.seedPostcodeDb
], done);
});
after(helper.clearPostcodeDb);
// Ordinary case
it ("contains correct data for AB123BS", done => {
Postcode.find("AB123BS", (error, result) => {
if (error) return done(error);
delete result.id;
assert.deepEqual({
postcode: 'AB12 3BS',
pc_compact: 'AB123BS',
quality: 1,
eastings: 395299,
northings: 804021,
country: 'Scotland',
nhs_ha: 'Grampian',
admin_county_id: 'S99999999',
admin_district_id: 'S12000033',
admin_ward_id: 'S13002847',
longitude: -2.079282,
latitude: 57.127089,
location: '0101000020E6100000B24AE9995EA200C03657CD7344904C40',
european_electoral_region: 'Scotland',
primary_care_trust: 'Aberdeen City Community Health Partnership',
region: null,
parish_id: 'S99999999',
lsoa: 'Cove North - 05',
msoa: 'Cove North',
nuts_id: 'S31000944',
incode: '3BS',
outcode: 'AB12',
ccg_id: 'S03000012',
constituency_id: 'S14000002',
parliamentary_constituency: 'Aberdeen South',
admin_district: 'Aberdeen City',
parish: null,
admin_county: null,
admin_ward: 'Kincorth/Nigg/Cove',
ccg: 'Aberdeen City Community Health Partnership',
nuts: 'Aberdeen City and Aberdeenshire',
nuts_code: 'UKM50',
}, result);
done();
});
});
// Case: Does not contain geolocation
// https://github.com/ideal-postcodes/postcodes.io/issues/197
it ("contains correct data for JE24WD", done => {
Postcode.find("JE24WD", (error, result) => {
if (error) return done(error);
delete result.id;
assert.deepEqual({
postcode: 'JE2 4WD',
pc_compact: 'JE24WD',
quality: 9,
eastings: null,
northings: null,
country: 'Channel Islands',
nhs_ha: 'Jersey Health Authority',
admin_county_id: 'L99999999',
admin_district_id: 'L99999999',
admin_ward_id: 'L99999999',
longitude: null,
latitude: null,
location: null,
european_electoral_region: null,
primary_care_trust: '(pseudo) Channel Islands',
region: null,
parish_id: 'L99999999',
lsoa: null,
msoa: null,
nuts_id: 'L99999999',
incode: '4WD',
outcode: 'JE2',
ccg_id: 'L99999999',
constituency_id: 'L99999999',
parliamentary_constituency: null,
admin_district: null,
parish: null,
admin_county: null,
admin_ward: null,
ccg: null,
nuts: null,
nuts_code: null,
}, result);
done();
});
});
});
View
@@ -97,7 +97,7 @@ describe("Postcode Model", function () {
describe("#populateLocation", () => {
it ("populates location collumn with geohashes", done => {
const query = `SELECT location from ${Postcode.relation}`;
const query = `SELECT location from ${Postcode.relation} WHERE location IS NOT NULL`;
Postcode._query(query, (error, result) => {
if (error) return done(error);
result.rows.forEach(row => assert.equal(row.location.length, 50));
View
@@ -5166,3 +5166,4 @@ pcd,pcd2,pcds,dointr,doterm,oscty,ced,oslaua,osward,parish,usertype,oseast1m,osn
"AB140YL","AB14 0YL","AB14 0YL","200207","200307","S99999999","S99999999","S12000034","S13002860","S99999999","1","382623","0806444","5","S08000020","S99999999","S92000003","S99999999","0","S14000058","S15000001","S09000001","S22000047","S03000013","S31000994","99ZZ00","S00002397","02C47","S99999999","S01000346","S02000063","2","4B2","S00091657","S01006941","S02001310","S34000054","S03000013","S99999999","S99999999","2","1B1",57.148547,-2.288824,"S99999999","S99999999","S23000009",6090,"S99999999","S99999999"
"AB140YN","AB14 0YN","AB14 0YN","200305","200406","S99999999","S99999999","S12000034","S13002860","S99999999","1","382623","0806444","5","S08000020","S99999999","S92000003","S99999999","0","S14000058","S15000001","S09000001","S22000047","S03000013","S31000994","99ZZ00","S00002397","02C47","S99999999","S01000346","S02000063","2","4B2","S00091657","S01006941","S02001310","S34000054","S03000013","S99999999","S99999999","2","1B1",57.148547,-2.288824,"S99999999","S99999999","S23000009",6090,"S99999999","S99999999"
"AB140YP","AB14 0YP","AB14 0YP","200306","200705","S99999999","S99999999","S12000034","S13002860","S99999999","1","382623","0806444","1","S08000020","S99999999","S92000003","S99999999","0","S14000058","S15000001","S09000001","S22000047","S03000013","S31000994","99ZZ00","S00002397","02C47","S99999999","S01000346","S02000063","2","4B2","S00091657","S01006941","S02001310","S34000054","S03000013","S99999999","S99999999","2","1B1",57.148547,-2.288824,"S99999999","S99999999","S23000009",6090,"S99999999","S99999999"
"JE2 4WD","JE2 4WD","JE2 4WD","199507","","L99999999","L99999999","L99999999","L99999999","L99999999","0","","","9","L00000001","L99999999","L93000001","L99999999","0","L99999999","L99999999","L99999999","L99999999","L99999999","L99999999","99ZZ00","L99999999","99ZZ00","L99999999","L99999999","L99999999","9","9Z9","L99999999","L99999999","L99999999","L99999999","L99999999","L99999999","L99999999","Z9","9Z9",99.999999,0.000000,"L99999999","L99999999","L99999999",0,"L99999999","L99999999"
@@ -0,0 +1,62 @@
"use strict";
const async = require("async");
const assert = require("chai").assert;
const helper = require("./helper/index.js");
const TerminatedPostcode = helper.TerminatedPostcode;
const resetTerminatedPostcodeRelation = done => {
async.series([
helper.clearTerminatedPostcodesDb,
helper.seedTerminatedPostcodeDb
], done);
};
describe("Terminated postcode data regression testing", function () {
before(function(done) {
this.timeout(0);
resetTerminatedPostcodeRelation(done);
});
after(helper.clearTerminatedPostcodesDb);
it ("contains correct data for AB115TP", done => {
TerminatedPostcode.find("AB115TP", (error, result) => {
if (error) return done(error);
delete result.id;
assert.deepEqual({
postcode: 'AB11 5TP',
pc_compact: 'AB115TP',
year_terminated: 1996,
month_terminated: 7,
eastings: 394290,
northings: 806210,
longitude: -2.095999,
latitude: 57.146741,
location: '0101000020E6100000F296AB1F9BC400C0BDFDB968C8924C40',
}, result);
done();
});
});
// Case: Does not contain geolocation
// https://github.com/ideal-postcodes/postcodes.io/issues/197
it ("contains correct data for AB113AG", done => {
TerminatedPostcode.find("AB113AG", (error, result) => {
if (error) return done(error);
delete result.id;
assert.deepEqual({
postcode: 'AB11 3AG',
pc_compact: 'AB113AG',
year_terminated: 1997,
month_terminated: 7,
eastings: null,
northings: null,
longitude: null,
latitude: null,
location: null,
}, result);
done();
});
});
});

0 comments on commit 6f31063

Please sign in to comment.