Skip to content

Commit

Permalink
feat(data): Update to 2016j map data
Browse files Browse the repository at this point in the history
- also refactor some stuff that should’ve been fixed in data refactor
  • Loading branch information
evansiroky committed Nov 27, 2016
1 parent 919ec3b commit f864e3d
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 35 deletions.
83 changes: 83 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# project exclusions
downloads
data.zip
Binary file modified data.zip
Binary file not shown.
12 changes: 7 additions & 5 deletions lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ module.exports = function (cfg, callback) {
if (!callback) {
if (typeof cfg === 'function') {
callback = cfg
cfg = {}
} else {
callback = function () {}
}
}

var dataDir = __dirname + '/../' + cfg.dataDir || __dirname + '/../data'
var dataDir = cfg.dataDir || 'data'
var resolvedDataDir = cfg.dataDir ? __dirname + '/../' + cfg.dataDir : __dirname + '/../data'

async.auto({
// download latest geojson data
Expand All @@ -100,7 +102,7 @@ module.exports = function (cfg, callback) {
},
deleteIndexFoldersAndFiles: ['downloadData', function (results, cb) {
async.each(['a', 'b', 'c', 'd', 'index.json'], function (fileOrFolder, eachCb) {
rimraf(dataDir + '/' + fileOrFolder, eachCb)
rimraf(resolvedDataDir + '/' + fileOrFolder, eachCb)
}, cb)
}],
unzipGeoJson: ['downloadData', function (results, cb) {
Expand Down Expand Up @@ -130,14 +132,14 @@ module.exports = function (cfg, callback) {
})
}],
createIndex: ['deleteIndexFoldersAndFiles', 'unzipGeoJson', function (results, cb) {
indexGeoJSON(require(tzFile), dataDir, TARGET_INDEX_PERCENT, cb)
indexGeoJSON(require(tzFile), resolvedDataDir, TARGET_INDEX_PERCENT, cb)
}],
zipData: ['createIndex', function (results, cb) {
var zipfile = new yazl.ZipFile()
// recursively add all files in data directory to zip file
zipDir(zipfile, path.resolve(__dirname + '/../'), cfg.dataDir, cfg.dataDir, function (err) {
zipDir(zipfile, path.resolve(__dirname + '/../'), dataDir, dataDir, function (err) {
if (err) return cb(err)
zipfile.outputStream.pipe(fs.createWriteStream(dataDir + '.zip')).on('close', cb)
zipfile.outputStream.pipe(fs.createWriteStream(resolvedDataDir + '.zip')).on('close', cb)
zipfile.end()
})
}]
Expand Down
23 changes: 0 additions & 23 deletions tests/data/issues.json

This file was deleted.

4 changes: 2 additions & 2 deletions tests/find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var assert = require('chai').assert

var geoTz = require('../index.js')
var issueCoords = require('./data/issues.json')
var issueCoords = require('./fixtures/issues.json')

process.chdir('/tmp')

Expand Down Expand Up @@ -43,7 +43,7 @@ describe('find tests', function () {

describe('issue cases', function () {
issueCoords.forEach(function (spot) {
it('should find ' + spot.zid, function () {
it('should find ' + spot.zid + ' (' + spot.description + ')', function () {
var tz = geoTz.tz(spot.lat, spot.lon)
assert.isString(tz)
assert.equal(tz, spot.zid)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions tests/fixtures/issues.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[
{
"zid": "Atlantic/Bermuda",
"lat": 32.359658,
"lon": -64.701434,
"description": "#10: find a point on land that efele.net shapefile says is in water"
}, {
"zid": "Asia/Famagusta",
"lat": 35.128174,
"lon": 33.935573,
"description": "#34: 2016i update"
}, {
"zid": "Asia/Nicosia",
"lat": 34.671412,
"lon": 33.043626,
"description": "#34: 2016i update"
}, {
"zid": "Australia/Adelaide",
"lat": -34.9286,
"lon": 138.6,
"description": "#32: subarea lookup bug"
}, {
"zid": "Europe/London",
"lat": 53.539677,
"lon": -2.714855,
"description": "#32: subarea lookup bug"
}, {
"zid": "Asia/Atyrau",
"lat": 47.086125,
"lon": 51.908557,
"description": "#37: 2016j update"
}, {
"zid": "Asia/Aqtau",
"lat": 43.625114,
"lon": 51.192965,
"description": "#37: 2016j update"
}, {
"zid": "Europe/Saratov",
"lat": 51.541768,
"lon": 45.998798,
"description": "#37: 2016j update"
}, {
"zid": "Europe/Volgograd",
"lat": 48.712475,
"lon": 44.513414,
"description": "#37: 2016j update"
}
]
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/geo-index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var util = require('./util.js')
var createGeoIndex = require('../lib/geo-index')

var TEST_DATA_DIR = __dirname + '/../data-test-geoindex'
var testTzData = require('./data/largeTz.json')
var expectedIndexData = require('./data/expectedIndexData.json')
var testTzData = require('./fixtures/largeTz.json')
var expectedIndexData = require('./fixtures/expectedIndexData.json')

describe('geoindex', function () {
beforeEach(function (done) {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('geoindex', function () {
assert.isNotOk(err)
var data = new Pbf(fs.readFileSync(TEST_DATA_DIR + '/b/b/d/c/d/d/geo.buf'))

assert.deepEqual(geobuf.decode(data), require('./data/expectedSubzone.json'))
assert.deepEqual(geobuf.decode(data), require('./fixtures/expectedSubzone.json'))
done()
}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unzip-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('unzip-data', function () {
beforeEach(function (done) {
util.destroyDataDir(EXPECTED_DATA_DIR, function (err) {
if (err) return done(err)
fs.copy(__dirname + '/data/data-test-unzip.zip', EXPECTED_DATA_DIR + '.zip', done)
fs.copy(__dirname + '/fixtures/data-test-unzip.zip', EXPECTED_DATA_DIR + '.zip', done)
})
})

Expand Down
2 changes: 1 addition & 1 deletion tests/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var update = require('../lib/update.js')

var TEST_DATA_DIR = './data-test-update'
var resolvedDataDir = __dirname + '/../' + TEST_DATA_DIR
var LOCAL_FOLDER = __dirname + '/../tests/data/'
var LOCAL_FOLDER = __dirname + '/../tests/fixtures/'

describe('data update', function () {
this.timeout(4000)
Expand Down

0 comments on commit f864e3d

Please sign in to comment.