Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 1 | var exec = require('child_process').exec |
| 2 | var fs = require('fs') |
evansiroky | f3bcf05 | 2020-10-17 23:10:15 -0700 | [diff] [blame] | 3 | var path = require('path') |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 4 | |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 5 | var area = require('@mapbox/geojson-area') |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 6 | var geojsonhint = require('@mapbox/geojsonhint') |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 7 | var bbox = require('@turf/bbox').default |
Evan Siroky | 8326cf0 | 2017-03-02 08:27:55 -0800 | [diff] [blame] | 8 | var helpers = require('@turf/helpers') |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 9 | var multiPolygon = helpers.multiPolygon |
Evan Siroky | 8326cf0 | 2017-03-02 08:27:55 -0800 | [diff] [blame] | 10 | var polygon = helpers.polygon |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 11 | var asynclib = require('async') |
| 12 | var jsts = require('jsts') |
Evan Siroky | b57a5b9 | 2016-11-07 10:22:34 -0800 | [diff] [blame] | 13 | var rimraf = require('rimraf') |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 14 | var overpass = require('query-overpass') |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 15 | var yargs = require('yargs') |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 16 | |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 17 | const ProgressStats = require('./progressStats') |
| 18 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 19 | var osmBoundarySources = require('./osmBoundarySources.json') |
| 20 | var zoneCfg = require('./timezones.json') |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 21 | var expectedZoneOverlaps = require('./expectedZoneOverlaps.json') |
Evan Siroky | 081648a | 2017-07-04 09:53:36 -0700 | [diff] [blame] | 22 | |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 23 | const argv = yargs |
| 24 | .option('included_zones', { |
| 25 | description: 'Include specified zones', |
| 26 | type: 'array' |
| 27 | }) |
Neil Fuller | 2b4b80a | 2020-04-30 18:20:56 +0100 | [diff] [blame] | 28 | .option('excluded_zones', { |
| 29 | description: 'Exclude specified zones', |
| 30 | type: 'array' |
| 31 | }) |
Neil Fuller | a4e7327 | 2020-04-30 18:25:44 +0100 | [diff] [blame] | 32 | .option('downloads_dir', { |
| 33 | description: 'Set the download location', |
| 34 | default: './downloads', |
| 35 | type: 'string' |
| 36 | }) |
| 37 | .option('dist_dir', { |
| 38 | description: 'Set the dist location', |
| 39 | default: './dist', |
| 40 | type: 'string' |
| 41 | }) |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 42 | .option('no_validation', { |
| 43 | description: 'Skip validation', |
| 44 | type: 'boolean' |
| 45 | }) |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 46 | .option('skip_zip', { |
| 47 | description: 'Skip zip creation', |
| 48 | type: 'boolean' |
| 49 | }) |
| 50 | .option('skip_shapefile', { |
| 51 | description: 'Skip shapefile creation', |
| 52 | type: 'boolean' |
| 53 | }) |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 54 | .help() |
| 55 | .strict() |
| 56 | .alias('help', 'h') |
| 57 | .argv |
| 58 | |
Neil Fuller | 0180319 | 2020-08-14 11:19:42 +0100 | [diff] [blame] | 59 | // Resolve the arguments with paths so relative paths become absolute. |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 60 | const downloadsDir = path.resolve(argv.downloads_dir) |
| 61 | const distDir = path.resolve(argv.dist_dir) |
Neil Fuller | 0180319 | 2020-08-14 11:19:42 +0100 | [diff] [blame] | 62 | |
Evan Siroky | 081648a | 2017-07-04 09:53:36 -0700 | [diff] [blame] | 63 | // allow building of only a specified zones |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 64 | let includedZones = [] |
Neil Fuller | 2b4b80a | 2020-04-30 18:20:56 +0100 | [diff] [blame] | 65 | let excludedZones = [] |
| 66 | if (argv.included_zones || argv.excluded_zones) { |
| 67 | if (argv.included_zones) { |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 68 | const newZoneCfg = {} |
Neil Fuller | 2b4b80a | 2020-04-30 18:20:56 +0100 | [diff] [blame] | 69 | includedZones = argv.included_zones |
| 70 | includedZones.forEach((zoneName) => { |
| 71 | newZoneCfg[zoneName] = zoneCfg[zoneName] |
| 72 | }) |
| 73 | zoneCfg = newZoneCfg |
| 74 | } |
| 75 | if (argv.excluded_zones) { |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 76 | const newZoneCfg = {} |
Neil Fuller | 2b4b80a | 2020-04-30 18:20:56 +0100 | [diff] [blame] | 77 | excludedZones = argv.excluded_zones |
| 78 | Object.keys(zoneCfg).forEach((zoneName) => { |
| 79 | if (!excludedZones.includes(zoneName)) { |
| 80 | newZoneCfg[zoneName] = zoneCfg[zoneName] |
| 81 | } |
| 82 | }) |
| 83 | zoneCfg = newZoneCfg |
| 84 | } |
Evan Siroky | 081648a | 2017-07-04 09:53:36 -0700 | [diff] [blame] | 85 | |
| 86 | // filter out unneccessary downloads |
| 87 | var newOsmBoundarySources = {} |
| 88 | Object.keys(zoneCfg).forEach((zoneName) => { |
| 89 | zoneCfg[zoneName].forEach((op) => { |
| 90 | if (op.source === 'overpass') { |
| 91 | newOsmBoundarySources[op.id] = osmBoundarySources[op.id] |
| 92 | } |
| 93 | }) |
| 94 | }) |
| 95 | |
| 96 | osmBoundarySources = newOsmBoundarySources |
| 97 | } |
| 98 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 99 | var geoJsonReader = new jsts.io.GeoJSONReader() |
| 100 | var geoJsonWriter = new jsts.io.GeoJSONWriter() |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 101 | var precisionModel = new jsts.geom.PrecisionModel(1000000) |
| 102 | var precisionReducer = new jsts.precision.GeometryPrecisionReducer(precisionModel) |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 103 | var distZones = {} |
evansiroky | 96dfadc | 2020-04-28 01:31:38 -0700 | [diff] [blame] | 104 | var lastReleaseJSONfile |
Evan Siroky | b57a5b9 | 2016-11-07 10:22:34 -0800 | [diff] [blame] | 105 | var minRequestGap = 4 |
| 106 | var curRequestGap = 4 |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 107 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 108 | var safeMkdir = function (dirname, callback) { |
| 109 | fs.mkdir(dirname, function (err) { |
| 110 | if (err && err.code === 'EEXIST') { |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 111 | callback() |
| 112 | } else { |
| 113 | callback(err) |
| 114 | } |
| 115 | }) |
| 116 | } |
| 117 | |
Evan Siroky | b173fd4 | 2017-03-08 15:16:27 -0800 | [diff] [blame] | 118 | var debugGeo = function (op, a, b, reducePrecision) { |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 119 | var result |
| 120 | |
Evan Siroky | b173fd4 | 2017-03-08 15:16:27 -0800 | [diff] [blame] | 121 | if (reducePrecision) { |
Evan Siroky | b173fd4 | 2017-03-08 15:16:27 -0800 | [diff] [blame] | 122 | a = precisionReducer.reduce(a) |
| 123 | b = precisionReducer.reduce(b) |
| 124 | } |
| 125 | |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 126 | try { |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 127 | switch (op) { |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 128 | case 'union': |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 129 | result = a.union(b) |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 130 | break |
| 131 | case 'intersection': |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 132 | result = a.intersection(b) |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 133 | break |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 134 | case 'intersects': |
| 135 | result = a.intersects(b) |
| 136 | break |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 137 | case 'diff': |
Evan Siroky | b173fd4 | 2017-03-08 15:16:27 -0800 | [diff] [blame] | 138 | result = a.difference(b) |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 139 | break |
| 140 | default: |
| 141 | var err = new Error('invalid op: ' + op) |
| 142 | throw err |
| 143 | } |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 144 | } catch (e) { |
Evan Siroky | b173fd4 | 2017-03-08 15:16:27 -0800 | [diff] [blame] | 145 | if (e.name === 'TopologyException') { |
| 146 | console.log('Encountered TopologyException, retry with GeometryPrecisionReducer') |
| 147 | return debugGeo(op, a, b, true) |
| 148 | } |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 149 | console.log('op err') |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 150 | console.log(e) |
| 151 | console.log(e.stack) |
| 152 | fs.writeFileSync('debug_' + op + '_a.json', JSON.stringify(geoJsonWriter.write(a))) |
| 153 | fs.writeFileSync('debug_' + op + '_b.json', JSON.stringify(geoJsonWriter.write(b))) |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 154 | throw e |
| 155 | } |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 156 | |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 157 | return result |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 160 | var fetchIfNeeded = function (file, superCallback, downloadCallback, fetchFn) { |
| 161 | // check for file that got downloaded |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 162 | fs.stat(file, function (err) { |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 163 | if (!err) { |
| 164 | // file found, skip download steps |
| 165 | return superCallback() |
| 166 | } |
| 167 | // check for manual file that got fixed and needs validation |
| 168 | var fixedFile = file.replace('.json', '_fixed.json') |
| 169 | fs.stat(fixedFile, function (err) { |
| 170 | if (!err) { |
| 171 | // file found, return fixed file |
| 172 | return downloadCallback(null, require(fixedFile)) |
| 173 | } |
| 174 | // no manual fixed file found, download from overpass |
| 175 | fetchFn() |
| 176 | }) |
evansiroky | 50216c6 | 2016-06-16 17:41:47 -0700 | [diff] [blame] | 177 | }) |
| 178 | } |
| 179 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 180 | var geoJsonToGeom = function (geoJson) { |
Evan Siroky | 8326cf0 | 2017-03-02 08:27:55 -0800 | [diff] [blame] | 181 | try { |
| 182 | return geoJsonReader.read(JSON.stringify(geoJson)) |
| 183 | } catch (e) { |
| 184 | console.error('error converting geojson to geometry') |
| 185 | fs.writeFileSync('debug_geojson_read_error.json', JSON.stringify(geoJson)) |
| 186 | throw e |
| 187 | } |
Evan Siroky | 5669adc | 2016-07-07 17:25:31 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 190 | var geomToGeoJson = function (geom) { |
| 191 | return geoJsonWriter.write(geom) |
| 192 | } |
| 193 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 194 | var geomToGeoJsonString = function (geom) { |
Evan Siroky | 5669adc | 2016-07-07 17:25:31 -0700 | [diff] [blame] | 195 | return JSON.stringify(geoJsonWriter.write(geom)) |
| 196 | } |
| 197 | |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 198 | const downloadProgress = new ProgressStats( |
| 199 | 'Downloading', |
| 200 | Object.keys(osmBoundarySources).length |
| 201 | ) |
| 202 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 203 | var downloadOsmBoundary = function (boundaryId, boundaryCallback) { |
| 204 | var cfg = osmBoundarySources[boundaryId] |
Evan Siroky | 1bcd477 | 2017-10-14 23:47:21 -0700 | [diff] [blame] | 205 | var query = '[out:json][timeout:60];(' |
| 206 | if (cfg.way) { |
| 207 | query += 'way' |
| 208 | } else { |
| 209 | query += 'relation' |
| 210 | } |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 211 | var boundaryFilename = downloadsDir + '/' + boundaryId + '.json' |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 212 | var debug = 'getting data for ' + boundaryId |
| 213 | var queryKeys = Object.keys(cfg) |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 214 | |
Evan Siroky | 5669adc | 2016-07-07 17:25:31 -0700 | [diff] [blame] | 215 | for (var i = queryKeys.length - 1; i >= 0; i--) { |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 216 | var k = queryKeys[i] |
Evan Siroky | 1bcd477 | 2017-10-14 23:47:21 -0700 | [diff] [blame] | 217 | if (k === 'way') continue |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 218 | var v = cfg[k] |
Evan Siroky | 5669adc | 2016-07-07 17:25:31 -0700 | [diff] [blame] | 219 | |
| 220 | query += '["' + k + '"="' + v + '"]' |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 221 | } |
| 222 | |
evansiroky | 283ebbc | 2018-07-16 15:13:07 -0700 | [diff] [blame] | 223 | query += ';);out body;>;out meta qt;' |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 224 | |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 225 | downloadProgress.beginTask(debug, true) |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 226 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 227 | asynclib.auto({ |
| 228 | downloadFromOverpass: function (cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 229 | console.log('downloading from overpass') |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 230 | fetchIfNeeded(boundaryFilename, boundaryCallback, cb, function () { |
Evan Siroky | b57a5b9 | 2016-11-07 10:22:34 -0800 | [diff] [blame] | 231 | var overpassResponseHandler = function (err, data) { |
| 232 | if (err) { |
| 233 | console.log(err) |
| 234 | console.log('Increasing overpass request gap') |
| 235 | curRequestGap *= 2 |
| 236 | makeQuery() |
| 237 | } else { |
| 238 | console.log('Success, decreasing overpass request gap') |
| 239 | curRequestGap = Math.max(minRequestGap, curRequestGap / 2) |
| 240 | cb(null, data) |
| 241 | } |
| 242 | } |
| 243 | var makeQuery = function () { |
| 244 | console.log('waiting ' + curRequestGap + ' seconds') |
| 245 | setTimeout(function () { |
| 246 | overpass(query, overpassResponseHandler, { flatProperties: true }) |
| 247 | }, curRequestGap * 1000) |
| 248 | } |
| 249 | makeQuery() |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 250 | }) |
| 251 | }, |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 252 | validateOverpassResult: ['downloadFromOverpass', function (results, cb) { |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 253 | var data = results.downloadFromOverpass |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 254 | if (!data.features) { |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 255 | var err = new Error('Invalid geojson for boundary: ' + boundaryId) |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 256 | return cb(err) |
| 257 | } |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 258 | if (data.features.length === 0) { |
| 259 | console.error('No data for the following query:') |
| 260 | console.error(query) |
| 261 | console.error('To read more about this error, please visit https://git.io/vxKQL') |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 262 | return cb(new Error('No data found for from overpass query')) |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 263 | } |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 264 | cb() |
| 265 | }], |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 266 | saveSingleMultiPolygon: ['validateOverpassResult', function (results, cb) { |
| 267 | var data = results.downloadFromOverpass |
| 268 | var combined |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 269 | |
| 270 | // union all multi-polygons / polygons into one |
| 271 | for (var i = data.features.length - 1; i >= 0; i--) { |
Evan Siroky | 5669adc | 2016-07-07 17:25:31 -0700 | [diff] [blame] | 272 | var curOsmGeom = data.features[i].geometry |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 273 | const curOsmProps = data.features[i].properties |
| 274 | if ( |
| 275 | (curOsmGeom.type === 'Polygon' || curOsmGeom.type === 'MultiPolygon') && |
| 276 | curOsmProps.type === 'boundary' // need to make sure enclaves aren't unioned |
| 277 | ) { |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 278 | console.log('combining border') |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 279 | let errors = geojsonhint.hint(curOsmGeom) |
| 280 | if (errors && errors.length > 0) { |
| 281 | const stringifiedGeojson = JSON.stringify(curOsmGeom, null, 2) |
| 282 | errors = geojsonhint.hint(stringifiedGeojson) |
| 283 | console.error('Invalid geojson received in Overpass Result') |
| 284 | console.error('Overpass query: ' + query) |
| 285 | const problemFilename = boundaryId + '_convert_to_geom_error.json' |
| 286 | fs.writeFileSync(problemFilename, stringifiedGeojson) |
| 287 | console.error('saved problem file to ' + problemFilename) |
| 288 | console.error('To read more about this error, please visit https://git.io/vxKQq') |
| 289 | return cb(errors) |
| 290 | } |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 291 | try { |
| 292 | var curGeom = geoJsonToGeom(curOsmGeom) |
| 293 | } catch (e) { |
| 294 | console.error('error converting overpass result to geojson') |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 295 | console.error(e) |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 296 | |
Evan Siroky | 1bcd477 | 2017-10-14 23:47:21 -0700 | [diff] [blame] | 297 | fs.writeFileSync(boundaryId + '_convert_to_geom_error-all-features.json', JSON.stringify(data)) |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 298 | return cb(e) |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 299 | } |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 300 | if (!combined) { |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 301 | combined = curGeom |
| 302 | } else { |
Evan Siroky | 5669adc | 2016-07-07 17:25:31 -0700 | [diff] [blame] | 303 | combined = debugGeo('union', curGeom, combined) |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | } |
Evan Siroky | 081c8e4 | 2017-05-29 14:53:52 -0700 | [diff] [blame] | 307 | try { |
| 308 | fs.writeFile(boundaryFilename, geomToGeoJsonString(combined), cb) |
| 309 | } catch (e) { |
| 310 | console.error('error writing combined border to geojson') |
| 311 | fs.writeFileSync(boundaryId + '_combined_border_convert_to_geom_error.json', JSON.stringify(data)) |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 312 | return cb(e) |
Evan Siroky | 081c8e4 | 2017-05-29 14:53:52 -0700 | [diff] [blame] | 313 | } |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 314 | }] |
| 315 | }, boundaryCallback) |
| 316 | } |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 317 | |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 318 | var getTzDistFilename = function (tzid) { |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 319 | return distDir + '/' + tzid.replace(/\//g, '__') + '.json' |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Get the geometry of the requested source data |
| 324 | * |
| 325 | * @return {Object} geom The geometry of the source |
| 326 | * @param {Object} source An object representing the data source |
| 327 | * must have `source` key and then either: |
| 328 | * - `id` if from a file |
| 329 | * - `id` if from a file |
| 330 | */ |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 331 | var getDataSource = function (source) { |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 332 | var geoJson |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 333 | if (source.source === 'overpass') { |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 334 | geoJson = require(downloadsDir + '/' + source.id + '.json') |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 335 | } else if (source.source === 'manual-polygon') { |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 336 | geoJson = polygon(source.data).geometry |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 337 | } else if (source.source === 'manual-multipolygon') { |
Evan Siroky | 8e30a2e | 2016-08-06 19:55:35 -0700 | [diff] [blame] | 338 | geoJson = multiPolygon(source.data).geometry |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 339 | } else if (source.source === 'dist') { |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 340 | geoJson = require(getTzDistFilename(source.id)) |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 341 | } else { |
| 342 | var err = new Error('unknown source: ' + source.source) |
| 343 | throw err |
| 344 | } |
Evan Siroky | 5669adc | 2016-07-07 17:25:31 -0700 | [diff] [blame] | 345 | return geoJsonToGeom(geoJson) |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 348 | /** |
| 349 | * Post process created timezone boundary. |
| 350 | * - remove small holes and exclaves |
| 351 | * - reduce geometry precision |
| 352 | * |
| 353 | * @param {Geometry} geom The jsts geometry of the timezone |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 354 | * @param {boolean} returnAsObject if true, return as object, otherwise return stringified |
| 355 | * @return {Object|String} geojson as object or stringified |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 356 | */ |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 357 | var postProcessZone = function (geom, returnAsObject) { |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 358 | // reduce precision of geometry |
| 359 | const geojson = geomToGeoJson(precisionReducer.reduce(geom)) |
| 360 | |
| 361 | // iterate through all polygons |
| 362 | const filteredPolygons = [] |
| 363 | let allPolygons = geojson.coordinates |
| 364 | if (geojson.type === 'Polygon') { |
| 365 | allPolygons = [geojson.coordinates] |
| 366 | } |
| 367 | |
| 368 | allPolygons.forEach((curPolygon, idx) => { |
| 369 | // remove any polygon with very small area |
| 370 | const polygonFeature = polygon(curPolygon) |
| 371 | const polygonArea = area.geometry(polygonFeature.geometry) |
| 372 | |
| 373 | if (polygonArea < 1) return |
| 374 | |
| 375 | // find all holes |
| 376 | const filteredLinearRings = [] |
| 377 | |
| 378 | curPolygon.forEach((curLinearRing, lrIdx) => { |
| 379 | if (lrIdx === 0) { |
| 380 | // always keep first linearRing |
| 381 | filteredLinearRings.push(curLinearRing) |
| 382 | } else { |
| 383 | const polygonFromLinearRing = polygon([curLinearRing]) |
| 384 | const linearRingArea = area.geometry(polygonFromLinearRing.geometry) |
| 385 | |
| 386 | // only include holes with relevant area |
| 387 | if (linearRingArea > 1) { |
| 388 | filteredLinearRings.push(curLinearRing) |
| 389 | } |
| 390 | } |
| 391 | }) |
| 392 | |
| 393 | filteredPolygons.push(filteredLinearRings) |
| 394 | }) |
| 395 | |
| 396 | // recompile to geojson string |
| 397 | const newGeojson = { |
| 398 | type: geojson.type |
| 399 | } |
| 400 | |
| 401 | if (geojson.type === 'Polygon') { |
| 402 | newGeojson.coordinates = filteredPolygons[0] |
| 403 | } else { |
| 404 | newGeojson.coordinates = filteredPolygons |
| 405 | } |
| 406 | |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 407 | return returnAsObject ? newGeojson : JSON.stringify(newGeojson) |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 408 | } |
| 409 | |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 410 | const buildingProgress = new ProgressStats( |
| 411 | 'Building', |
| 412 | Object.keys(zoneCfg).length |
| 413 | ) |
| 414 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 415 | var makeTimezoneBoundary = function (tzid, callback) { |
evansiroky | 3046a3d | 2019-01-05 21:19:14 -0800 | [diff] [blame] | 416 | buildingProgress.beginTask(`makeTimezoneBoundary for ${tzid}`, true) |
evansiroky | 35f6434 | 2016-06-16 22:17:04 -0700 | [diff] [blame] | 417 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 418 | var ops = zoneCfg[tzid] |
| 419 | var geom |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 420 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 421 | asynclib.eachSeries(ops, function (task, cb) { |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 422 | var taskData = getDataSource(task) |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 423 | console.log('-', task.op, task.id) |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 424 | if (task.op === 'init') { |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 425 | geom = taskData |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 426 | } else if (task.op === 'intersect') { |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 427 | geom = debugGeo('intersection', geom, taskData) |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 428 | } else if (task.op === 'difference') { |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 429 | geom = debugGeo('diff', geom, taskData) |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 430 | } else if (task.op === 'difference-reverse-order') { |
Evan Siroky | 8ccaf0b | 2016-09-03 11:36:13 -0700 | [diff] [blame] | 431 | geom = debugGeo('diff', taskData, geom) |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 432 | } else if (task.op === 'union') { |
evansiroky | 6f9d8f7 | 2016-06-21 16:27:54 -0700 | [diff] [blame] | 433 | geom = debugGeo('union', geom, taskData) |
Evan Siroky | 8ccaf0b | 2016-09-03 11:36:13 -0700 | [diff] [blame] | 434 | } else { |
| 435 | var err = new Error('unknown op: ' + task.op) |
| 436 | return cb(err) |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 437 | } |
evansiroky | 35f6434 | 2016-06-16 22:17:04 -0700 | [diff] [blame] | 438 | cb() |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 439 | }, |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 440 | function (err) { |
| 441 | if (err) { return callback(err) } |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 442 | fs.writeFile(getTzDistFilename(tzid), |
Evan Siroky | 477ece6 | 2017-08-01 07:08:51 -0700 | [diff] [blame] | 443 | postProcessZone(geom), |
evansiroky | becb56e | 2016-07-06 12:42:35 -0700 | [diff] [blame] | 444 | callback) |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 445 | }) |
| 446 | } |
| 447 | |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 448 | var loadDistZonesIntoMemory = function () { |
| 449 | console.log('load zones into memory') |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 450 | var zones = Object.keys(zoneCfg) |
| 451 | var tzid |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 452 | |
| 453 | for (var i = 0; i < zones.length; i++) { |
| 454 | tzid = zones[i] |
| 455 | distZones[tzid] = getDataSource({ source: 'dist', id: tzid }) |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | var getDistZoneGeom = function (tzid) { |
| 460 | return distZones[tzid] |
| 461 | } |
| 462 | |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 463 | var roundDownToTenth = function (n) { |
| 464 | return Math.floor(n * 10) / 10 |
| 465 | } |
| 466 | |
| 467 | var roundUpToTenth = function (n) { |
| 468 | return Math.ceil(n * 10) / 10 |
| 469 | } |
| 470 | |
| 471 | var formatBounds = function (bounds) { |
| 472 | let boundsStr = '[' |
| 473 | boundsStr += roundDownToTenth(bounds[0]) + ', ' |
| 474 | boundsStr += roundDownToTenth(bounds[1]) + ', ' |
| 475 | boundsStr += roundUpToTenth(bounds[2]) + ', ' |
| 476 | boundsStr += roundUpToTenth(bounds[3]) + ']' |
| 477 | return boundsStr |
| 478 | } |
| 479 | |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 480 | var validateTimezoneBoundaries = function () { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 481 | const numZones = Object.keys(zoneCfg).length |
| 482 | const validationProgress = new ProgressStats( |
| 483 | 'Validation', |
| 484 | numZones * (numZones + 1) / 2 |
| 485 | ) |
| 486 | |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 487 | console.log('do validation... this may take a few minutes') |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 488 | var allZonesOk = true |
| 489 | var zones = Object.keys(zoneCfg) |
evansiroky | 3046a3d | 2019-01-05 21:19:14 -0800 | [diff] [blame] | 490 | var lastPct = 0 |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 491 | var compareTzid, tzid, zoneGeom |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 492 | |
| 493 | for (var i = 0; i < zones.length; i++) { |
| 494 | tzid = zones[i] |
| 495 | zoneGeom = getDistZoneGeom(tzid) |
| 496 | |
| 497 | for (var j = i + 1; j < zones.length; j++) { |
evansiroky | 3046a3d | 2019-01-05 21:19:14 -0800 | [diff] [blame] | 498 | const curPct = Math.floor(validationProgress.getPercentage()) |
| 499 | if (curPct % 10 === 0 && curPct !== lastPct) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 500 | validationProgress.printStats('Validating zones', true) |
evansiroky | 3046a3d | 2019-01-05 21:19:14 -0800 | [diff] [blame] | 501 | lastPct = curPct |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 502 | } |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 503 | compareTzid = zones[j] |
| 504 | |
| 505 | var compareZoneGeom = getDistZoneGeom(compareTzid) |
Evan Siroky | 070bbb9 | 2017-03-07 23:48:29 -0800 | [diff] [blame] | 506 | |
| 507 | var intersects = false |
| 508 | try { |
| 509 | intersects = debugGeo('intersects', zoneGeom, compareZoneGeom) |
| 510 | } catch (e) { |
| 511 | console.warn('warning, encountered intersection error with zone ' + tzid + ' and ' + compareTzid) |
| 512 | } |
| 513 | if (intersects) { |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 514 | var intersectedGeom = debugGeo('intersection', zoneGeom, compareZoneGeom) |
| 515 | var intersectedArea = intersectedGeom.getArea() |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 516 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 517 | if (intersectedArea > 0.0001) { |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 518 | // check if the intersected area(s) are one of the expected areas of overlap |
| 519 | const allowedOverlapBounds = expectedZoneOverlaps[`${tzid}-${compareTzid}`] || expectedZoneOverlaps[`${compareTzid}-${tzid}`] |
| 520 | const overlapsGeoJson = geoJsonWriter.write(intersectedGeom) |
| 521 | |
| 522 | // these zones are allowed to overlap in certain places, make sure the |
| 523 | // found overlap(s) all fit within the expected areas of overlap |
| 524 | if (allowedOverlapBounds) { |
| 525 | // if the overlaps are a multipolygon, make sure each individual |
| 526 | // polygon of overlap fits within at least one of the expected |
| 527 | // overlaps |
| 528 | let overlapsPolygons |
| 529 | switch (overlapsGeoJson.type) { |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 530 | case 'MultiPolygon': |
| 531 | overlapsPolygons = overlapsGeoJson.coordinates.map( |
| 532 | polygonCoords => ({ |
| 533 | coordinates: polygonCoords, |
| 534 | type: 'Polygon' |
| 535 | }) |
| 536 | ) |
| 537 | break |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 538 | case 'Polygon': |
| 539 | overlapsPolygons = [overlapsGeoJson] |
| 540 | break |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 541 | case 'GeometryCollection': |
| 542 | overlapsPolygons = [] |
| 543 | overlapsGeoJson.geometries.forEach(geom => { |
| 544 | if (geom.type === 'Polygon') { |
| 545 | overlapsPolygons.push(geom) |
| 546 | } else if (geom.type === 'MultiPolygon') { |
| 547 | geom.coordinates.forEach(polygonCoords => { |
| 548 | overlapsPolygons.push({ |
| 549 | coordinates: polygonCoords, |
| 550 | type: 'Polygon' |
| 551 | }) |
| 552 | }) |
| 553 | } |
| 554 | }) |
| 555 | break |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 556 | default: |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 557 | console.error('unexpected geojson overlap type') |
| 558 | console.log(overlapsGeoJson) |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 559 | break |
| 560 | } |
| 561 | |
| 562 | let allOverlapsOk = true |
| 563 | overlapsPolygons.forEach((polygon, idx) => { |
| 564 | const bounds = bbox(polygon) |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 565 | const polygonArea = area.geometry(polygon) |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 566 | if ( |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 567 | polygonArea > 10 && // ignore small polygons |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 568 | !allowedOverlapBounds.some(allowedBounds => |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 569 | allowedBounds.bounds[0] <= bounds[0] && // minX |
| 570 | allowedBounds.bounds[1] <= bounds[1] && // minY |
| 571 | allowedBounds.bounds[2] >= bounds[2] && // maxX |
| 572 | allowedBounds.bounds[3] >= bounds[3] // maxY |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 573 | ) |
| 574 | ) { |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 575 | console.error(`Unexpected intersection (${polygonArea} area) with bounds: ${formatBounds(bounds)}`) |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 576 | allOverlapsOk = false |
| 577 | } |
| 578 | }) |
| 579 | |
| 580 | if (allOverlapsOk) continue |
| 581 | } |
| 582 | |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 583 | // at least one unexpected overlap found, output an error and write debug file |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 584 | console.error('Validation error: ' + tzid + ' intersects ' + compareTzid + ' area: ' + intersectedArea) |
evansiroky | 92c15c4 | 2018-11-15 20:58:18 -0800 | [diff] [blame] | 585 | const debugFilename = tzid.replace(/\//g, '-') + '-' + compareTzid.replace(/\//g, '-') + '-overlap.json' |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 586 | fs.writeFileSync( |
| 587 | debugFilename, |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 588 | JSON.stringify(overlapsGeoJson) |
evansiroky | 70b35fe | 2018-04-01 21:06:36 -0700 | [diff] [blame] | 589 | ) |
| 590 | console.error('wrote overlap area as file ' + debugFilename) |
| 591 | console.error('To read more about this error, please visit https://git.io/vx6nx') |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 592 | allZonesOk = false |
| 593 | } |
| 594 | } |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 595 | validationProgress.logNext() |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
| 599 | return allZonesOk ? null : 'Zone validation unsuccessful' |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 600 | } |
| 601 | |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 602 | let oceanZoneBoundaries |
evansiroky | 9fd5051 | 2019-07-07 12:06:28 -0700 | [diff] [blame] | 603 | let oceanZones = [ |
| 604 | { tzid: 'Etc/GMT-12', left: 172.5, right: 180 }, |
| 605 | { tzid: 'Etc/GMT-11', left: 157.5, right: 172.5 }, |
| 606 | { tzid: 'Etc/GMT-10', left: 142.5, right: 157.5 }, |
| 607 | { tzid: 'Etc/GMT-9', left: 127.5, right: 142.5 }, |
| 608 | { tzid: 'Etc/GMT-8', left: 112.5, right: 127.5 }, |
| 609 | { tzid: 'Etc/GMT-7', left: 97.5, right: 112.5 }, |
| 610 | { tzid: 'Etc/GMT-6', left: 82.5, right: 97.5 }, |
| 611 | { tzid: 'Etc/GMT-5', left: 67.5, right: 82.5 }, |
| 612 | { tzid: 'Etc/GMT-4', left: 52.5, right: 67.5 }, |
| 613 | { tzid: 'Etc/GMT-3', left: 37.5, right: 52.5 }, |
| 614 | { tzid: 'Etc/GMT-2', left: 22.5, right: 37.5 }, |
| 615 | { tzid: 'Etc/GMT-1', left: 7.5, right: 22.5 }, |
| 616 | { tzid: 'Etc/GMT', left: -7.5, right: 7.5 }, |
| 617 | { tzid: 'Etc/GMT+1', left: -22.5, right: -7.5 }, |
| 618 | { tzid: 'Etc/GMT+2', left: -37.5, right: -22.5 }, |
| 619 | { tzid: 'Etc/GMT+3', left: -52.5, right: -37.5 }, |
| 620 | { tzid: 'Etc/GMT+4', left: -67.5, right: -52.5 }, |
| 621 | { tzid: 'Etc/GMT+5', left: -82.5, right: -67.5 }, |
| 622 | { tzid: 'Etc/GMT+6', left: -97.5, right: -82.5 }, |
| 623 | { tzid: 'Etc/GMT+7', left: -112.5, right: -97.5 }, |
| 624 | { tzid: 'Etc/GMT+8', left: -127.5, right: -112.5 }, |
| 625 | { tzid: 'Etc/GMT+9', left: -142.5, right: -127.5 }, |
| 626 | { tzid: 'Etc/GMT+10', left: -157.5, right: -142.5 }, |
| 627 | { tzid: 'Etc/GMT+11', left: -172.5, right: -157.5 }, |
| 628 | { tzid: 'Etc/GMT+12', left: -180, right: -172.5 } |
| 629 | ] |
| 630 | |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 631 | if (includedZones.length > 0) { |
| 632 | oceanZones = oceanZones.filter(oceanZone => includedZones.indexOf(oceanZone) > -1) |
evansiroky | 9fd5051 | 2019-07-07 12:06:28 -0700 | [diff] [blame] | 633 | } |
Neil Fuller | 2b4b80a | 2020-04-30 18:20:56 +0100 | [diff] [blame] | 634 | if (excludedZones.length > 0) { |
| 635 | oceanZones = oceanZones.filter(oceanZone => excludedZones.indexOf(oceanZone) === -1) |
| 636 | } |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 637 | |
| 638 | var addOceans = function (callback) { |
| 639 | console.log('adding ocean boundaries') |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 640 | const zones = Object.keys(zoneCfg) |
| 641 | |
evansiroky | 3046a3d | 2019-01-05 21:19:14 -0800 | [diff] [blame] | 642 | const oceanProgress = new ProgressStats( |
| 643 | 'Oceans', |
| 644 | oceanZones.length |
| 645 | ) |
| 646 | |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 647 | oceanZoneBoundaries = oceanZones.map(zone => { |
evansiroky | 3046a3d | 2019-01-05 21:19:14 -0800 | [diff] [blame] | 648 | oceanProgress.beginTask(zone.tzid, true) |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 649 | const geoJson = polygon([[ |
| 650 | [zone.left, 90], |
evansiroky | 0ea1d1e | 2018-10-30 22:30:51 -0700 | [diff] [blame] | 651 | [zone.left, -90], |
| 652 | [zone.right, -90], |
| 653 | [zone.right, 90], |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 654 | [zone.left, 90] |
| 655 | ]]).geometry |
| 656 | |
| 657 | let geom = geoJsonToGeom(geoJson) |
| 658 | |
| 659 | // diff against every zone |
| 660 | zones.forEach(distZone => { |
| 661 | geom = debugGeo('diff', geom, getDistZoneGeom(distZone)) |
| 662 | }) |
| 663 | |
| 664 | return { |
| 665 | geom: postProcessZone(geom, true), |
| 666 | tzid: zone.tzid |
| 667 | } |
| 668 | }) |
| 669 | |
| 670 | callback() |
| 671 | } |
| 672 | |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 673 | var combineAndWriteZones = function (callback) { |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 674 | var stream = fs.createWriteStream(distDir + '/combined.json') |
| 675 | var streamWithOceans = fs.createWriteStream(distDir + '/combined-with-oceans.json') |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 676 | var zones = Object.keys(zoneCfg) |
| 677 | |
| 678 | stream.write('{"type":"FeatureCollection","features":[') |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 679 | streamWithOceans.write('{"type":"FeatureCollection","features":[') |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 680 | |
| 681 | for (var i = 0; i < zones.length; i++) { |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 682 | if (i > 0) { |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 683 | stream.write(',') |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 684 | streamWithOceans.write(',') |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 685 | } |
| 686 | var feature = { |
| 687 | type: 'Feature', |
| 688 | properties: { tzid: zones[i] }, |
| 689 | geometry: geomToGeoJson(getDistZoneGeom(zones[i])) |
| 690 | } |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 691 | const stringified = JSON.stringify(feature) |
| 692 | stream.write(stringified) |
| 693 | streamWithOceans.write(stringified) |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 694 | } |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 695 | oceanZoneBoundaries.forEach(boundary => { |
| 696 | streamWithOceans.write(',') |
| 697 | var feature = { |
| 698 | type: 'Feature', |
| 699 | properties: { tzid: boundary.tzid }, |
| 700 | geometry: boundary.geom |
| 701 | } |
| 702 | streamWithOceans.write(JSON.stringify(feature)) |
| 703 | }) |
| 704 | asynclib.parallel([ |
| 705 | cb => { |
| 706 | stream.end(']}', cb) |
| 707 | }, |
| 708 | cb => { |
| 709 | streamWithOceans.end(']}', cb) |
| 710 | } |
| 711 | ], callback) |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 712 | } |
| 713 | |
evansiroky | 96dfadc | 2020-04-28 01:31:38 -0700 | [diff] [blame] | 714 | var cleanDownloadsDir = function (cb) { |
| 715 | // TODO: |
| 716 | |
| 717 | // list all files in downloads dir |
| 718 | // for each file |
| 719 | // if file does not exist in osmBoundarySources.json file, then remove |
| 720 | cb() |
| 721 | } |
| 722 | |
| 723 | var downloadLastRelease = function (cb) { |
| 724 | // TODO: |
| 725 | |
| 726 | // download latest release info |
| 727 | // determine last release version name |
| 728 | lastReleaseJSONfile = `./dist/${lastReleaseName}.json` |
| 729 | |
| 730 | // check if file already downloaded, if so immediately callback |
| 731 | fetchIfNeeded(lastReleaseJSONfile, cb, cb, function () { |
| 732 | // find download link for geojson with oceans |
| 733 | // download the latest release data into the dist directory |
| 734 | // unzip geojson |
| 735 | cb() |
| 736 | }) |
| 737 | } |
| 738 | |
| 739 | var analyzeChangesFromLastRelease = function (cb) { |
| 740 | // TODO |
| 741 | |
| 742 | // load last release data into memory |
| 743 | |
| 744 | // generate set of keys from last release and current |
| 745 | |
| 746 | // for each zone |
| 747 | // diff current - last = additions |
| 748 | // diff last - current = removals |
| 749 | |
| 750 | // write file of additions |
| 751 | // write file of removals |
| 752 | cb() |
| 753 | } |
| 754 | |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 755 | const autoScript = { |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 756 | makeDownloadsDir: function (cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 757 | overallProgress.beginTask('Creating downloads dir') |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 758 | safeMkdir(downloadsDir, cb) |
evansiroky | 4be1c7a | 2016-06-16 18:23:34 -0700 | [diff] [blame] | 759 | }, |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 760 | makeDistDir: function (cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 761 | overallProgress.beginTask('Creating dist dir') |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 762 | safeMkdir(distDir, cb) |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 763 | }, |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 764 | getOsmBoundaries: ['makeDownloadsDir', function (results, cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 765 | overallProgress.beginTask('Downloading osm boundaries') |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 766 | asynclib.eachSeries(Object.keys(osmBoundarySources), downloadOsmBoundary, cb) |
evansiroky | 63d35e1 | 2016-06-16 10:08:15 -0700 | [diff] [blame] | 767 | }], |
evansiroky | f3bcf05 | 2020-10-17 23:10:15 -0700 | [diff] [blame] | 768 | cleanDownloadFolder: ['makeDistDir', 'getOsmBoundaries', function (results, cb) { |
| 769 | overallProgress.beginTask('cleanDownloadFolder') |
| 770 | const downloadedFilenames = Object.keys(osmBoundarySources).map(name => `${name}.json`) |
evansiroky | b0442ca | 2020-10-18 17:49:45 -0700 | [diff] [blame^] | 771 | fs.readdir(downloadsDir, (err, files) => { |
evansiroky | f3bcf05 | 2020-10-17 23:10:15 -0700 | [diff] [blame] | 772 | if (err) return cb(err) |
| 773 | asynclib.each( |
| 774 | files, |
| 775 | (file, fileCb) => { |
| 776 | if (downloadedFilenames.indexOf(file) === -1) { |
evansiroky | b0442ca | 2020-10-18 17:49:45 -0700 | [diff] [blame^] | 777 | return fs.unlink(path.join(downloadsDir, file), fileCb) |
evansiroky | f3bcf05 | 2020-10-17 23:10:15 -0700 | [diff] [blame] | 778 | } |
| 779 | fileCb() |
| 780 | }, |
| 781 | cb |
| 782 | ) |
| 783 | }) |
| 784 | }], |
| 785 | zipInputData: ['cleanDownloadFolder', function (results, cb) { |
evansiroky | a48b392 | 2020-04-27 15:29:06 -0700 | [diff] [blame] | 786 | overallProgress.beginTask('Zipping up input data') |
evansiroky | 7452c9b | 2020-10-18 00:27:06 -0700 | [diff] [blame] | 787 | exec('zip -j ' + distDir + '/input-data.zip ' + downloadsDir + |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 788 | '/* timezones.json osmBoundarySources.json expectedZoneOverlaps.json', cb) |
evansiroky | a48b392 | 2020-04-27 15:29:06 -0700 | [diff] [blame] | 789 | }], |
evansiroky | 96dfadc | 2020-04-28 01:31:38 -0700 | [diff] [blame] | 790 | downloadLastRelease: ['makeDistDir', function (results, cb) { |
| 791 | if (process.argv.indexOf('analyze-changes') > -1) { |
| 792 | overallProgress.beginTask('Downloading last release for analysis') |
| 793 | downloadLastRelease(cb) |
| 794 | } else { |
| 795 | overallProgress.beginTask('WARNING: Skipping download of last release for analysis!') |
| 796 | } |
| 797 | }], |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 798 | createZones: ['makeDistDir', 'getOsmBoundaries', function (results, cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 799 | overallProgress.beginTask('Creating timezone boundaries') |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 800 | asynclib.each(Object.keys(zoneCfg), makeTimezoneBoundary, cb) |
evansiroky | 50216c6 | 2016-06-16 17:41:47 -0700 | [diff] [blame] | 801 | }], |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 802 | validateZones: ['createZones', function (results, cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 803 | overallProgress.beginTask('Validating timezone boundaries') |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 804 | loadDistZonesIntoMemory() |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 805 | if (argv.no_validation) { |
Evan Siroky | 081648a | 2017-07-04 09:53:36 -0700 | [diff] [blame] | 806 | console.warn('WARNING: Skipping validation!') |
| 807 | cb() |
| 808 | } else { |
| 809 | cb(validateTimezoneBoundaries()) |
| 810 | } |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 811 | }], |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 812 | addOceans: ['validateZones', function (results, cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 813 | overallProgress.beginTask('Adding oceans') |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 814 | addOceans(cb) |
| 815 | }], |
| 816 | mergeZones: ['addOceans', function (results, cb) { |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 817 | overallProgress.beginTask('Merging zones') |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 818 | combineAndWriteZones(cb) |
| 819 | }], |
| 820 | zipGeoJson: ['mergeZones', function (results, cb) { |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 821 | if (argv.skip_zip) { |
| 822 | overallProgress.beginTask('Skipping zip') |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 823 | return cb() |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 824 | } |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 825 | overallProgress.beginTask('Zipping geojson') |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 826 | const zipFile = distDir + '/timezones.geojson.zip' |
| 827 | const jsonFile = distDir + '/combined.json' |
evansiroky | 7452c9b | 2020-10-18 00:27:06 -0700 | [diff] [blame] | 828 | exec('zip -j ' + zipFile + ' ' + jsonFile, cb) |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 829 | }], |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 830 | zipGeoJsonWithOceans: ['mergeZones', function (results, cb) { |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 831 | if (argv.skip_zip) { |
| 832 | overallProgress.beginTask('Skipping with oceans zip') |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 833 | return cb() |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 834 | } |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 835 | overallProgress.beginTask('Zipping geojson with oceans') |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 836 | const zipFile = distDir + '/timezones-with-oceans.geojson.zip' |
| 837 | const jsonFile = distDir + '/combined-with-oceans.json' |
evansiroky | 7452c9b | 2020-10-18 00:27:06 -0700 | [diff] [blame] | 838 | exec('zip -j ' + zipFile + ' ' + jsonFile, cb) |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 839 | }], |
Evan Siroky | 8b47abe | 2016-10-02 12:28:52 -0700 | [diff] [blame] | 840 | makeShapefile: ['mergeZones', function (results, cb) { |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 841 | if (argv.skip_shapefile) { |
| 842 | overallProgress.beginTask('Skipping shapefile creation') |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 843 | return cb() |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 844 | } |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 845 | overallProgress.beginTask('Converting from geojson to shapefile') |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 846 | const shapeFileGlob = distDir + '/combined-shapefile.*' |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 847 | rimraf.sync(shapeFileGlob) |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 848 | const shapeFile = distDir + '/combined-shapefile.shp' |
| 849 | const jsonFile = distDir + '/combined.json' |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 850 | exec( |
| 851 | 'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile, |
| 852 | function (err, stdout, stderr) { |
| 853 | if (err) { return cb(err) } |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 854 | const shapeFileZip = distDir + '/timezones.shapefile.zip' |
evansiroky | 7452c9b | 2020-10-18 00:27:06 -0700 | [diff] [blame] | 855 | exec('zip -j ' + shapeFileZip + ' ' + shapeFileGlob, cb) |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 856 | } |
| 857 | ) |
evansiroky | 2632584 | 2018-04-03 14:10:42 -0700 | [diff] [blame] | 858 | }], |
| 859 | makeShapefileWithOceans: ['mergeZones', function (results, cb) { |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 860 | if (argv.skip_shapefile) { |
| 861 | overallProgress.beginTask('Skipping with oceans shapefile creation') |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 862 | return cb() |
Neil Fuller | a83cc6d | 2020-04-30 18:37:08 +0100 | [diff] [blame] | 863 | } |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 864 | overallProgress.beginTask('Converting from geojson with oceans to shapefile') |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 865 | const shapeFileGlob = distDir + '/combined-shapefile-with-oceans.*' |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 866 | rimraf.sync(shapeFileGlob) |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 867 | const shapeFile = distDir + '/combined-shapefile-with-oceans.shp' |
| 868 | const jsonFile = distDir + '/combined-with-oceans.json' |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 869 | exec( |
| 870 | 'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile, |
| 871 | function (err, stdout, stderr) { |
| 872 | if (err) { return cb(err) } |
evansiroky | b7d9d79 | 2020-10-17 16:50:14 -0700 | [diff] [blame] | 873 | const shapeFileZip = distDir + '/timezones-with-oceans.shapefile.zip' |
evansiroky | 7452c9b | 2020-10-18 00:27:06 -0700 | [diff] [blame] | 874 | exec('zip -j ' + shapeFileZip + ' ' + shapeFileGlob, cb) |
Neil Fuller | 6128709 | 2020-07-29 14:46:16 +0100 | [diff] [blame] | 875 | } |
| 876 | ) |
evansiroky | 9fd5051 | 2019-07-07 12:06:28 -0700 | [diff] [blame] | 877 | }], |
| 878 | makeListOfTimeZoneNames: function (cb) { |
| 879 | overallProgress.beginTask('Writing timezone names to file') |
| 880 | let zoneNames = Object.keys(zoneCfg) |
| 881 | oceanZones.forEach(oceanZone => { |
| 882 | zoneNames.push(oceanZone.tzid) |
| 883 | }) |
Neil Fuller | c4ae49b | 2020-04-30 18:08:43 +0100 | [diff] [blame] | 884 | if (includedZones.length > 0) { |
| 885 | zoneNames = zoneNames.filter(zoneName => includedZones.indexOf(zoneName) > -1) |
evansiroky | 9fd5051 | 2019-07-07 12:06:28 -0700 | [diff] [blame] | 886 | } |
Neil Fuller | 2b4b80a | 2020-04-30 18:20:56 +0100 | [diff] [blame] | 887 | if (excludedZones.length > 0) { |
| 888 | zoneNames = zoneNames.filter(zoneName => excludedZones.indexOf(zoneName) === -1) |
| 889 | } |
evansiroky | 9fd5051 | 2019-07-07 12:06:28 -0700 | [diff] [blame] | 890 | fs.writeFile( |
Neil Fuller | dce1d04 | 2020-10-14 09:53:00 +0100 | [diff] [blame] | 891 | distDir + '/timezone-names.json', |
evansiroky | 9fd5051 | 2019-07-07 12:06:28 -0700 | [diff] [blame] | 892 | JSON.stringify(zoneNames), |
| 893 | cb |
| 894 | ) |
evansiroky | 96dfadc | 2020-04-28 01:31:38 -0700 | [diff] [blame] | 895 | }, |
| 896 | analyzeChangesFromLastRelease: ['downloadLastRelease', 'mergeZones', function (results, cb) { |
| 897 | if (process.argv.indexOf('analyze-changes') > -1) { |
| 898 | overallProgress.beginTask('Analyzing changes from last release') |
| 899 | analyzeChangesFromLastRelease(cb) |
| 900 | } else { |
| 901 | overallProgress.beginTask('WARNING: Skipping analysis of changes from last release!') |
| 902 | } |
| 903 | }] |
evansiroky | 5348a6f | 2019-01-05 15:39:28 -0800 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | const overallProgress = new ProgressStats('Overall', Object.keys(autoScript).length) |
| 907 | |
| 908 | asynclib.auto(autoScript, function (err, results) { |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 909 | console.log('done') |
Evan Siroky | 7891a6e | 2016-11-05 11:50:50 -0700 | [diff] [blame] | 910 | if (err) { |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 911 | console.log('error!', err) |
evansiroky | d401c89 | 2016-06-16 00:05:14 -0700 | [diff] [blame] | 912 | } |
Evan Siroky | 4fc596c | 2016-09-25 19:52:30 -0700 | [diff] [blame] | 913 | }) |