@@ -32,8 +32,6 @@ let zoneCfg1970 = {}
3232let zoneCfgNow = { }
3333const expectedZoneOverlaps = require ( './expectedZoneOverlaps.json' )
3434
35- const fiveYearsAgo = ( new Date ( ) ) . getFullYear ( )
36-
3735const argv = yargs
3836 . option ( 'cache_dir' , {
3937 description : 'Set the cache location, for caching results' ,
@@ -114,7 +112,7 @@ function loadJsonCacheSync (filename) {
114112 )
115113 } catch ( err ) {
116114 // cache not found, return empty obj
117- return { }
115+ return { }
118116 }
119117}
120118
@@ -142,7 +140,7 @@ function getZoneCfgSinceTime (cutoffTime, cacheFilename) {
142140 tzdbInitialized = true
143141 }
144142
145- let newZoneCfg = { }
143+ const newZoneCfg = { }
146144
147145 // Iterate through all zones to determine which share same timekeeping method since cutoff time
148146 const timekeepingPatternZones = { }
@@ -165,7 +163,7 @@ function getZoneCfgSinceTime (cutoffTime, cacheFilename) {
165163 timekeepingPatternZones [ timekeepingKey ] . push ( zone )
166164 } )
167165
168- // iterate through each set of zones with the same future timekeeping method to determine
166+ // iterate through each set of zones with the same future timekeeping method to determine
169167 // which has the largest population
170168 Object . keys ( timekeepingPatternZones ) . forEach ( k => {
171169 timekeepingPatternZones [ k ] . sort ( ( a , b ) => getTimezonePopulation ( b ) - getTimezonePopulation ( a ) )
@@ -180,15 +178,15 @@ function getZoneCfgSinceTime (cutoffTime, cacheFilename) {
180178if ( ! argv . skip_now_zones ) {
181179 console . log ( 'Generating zone config for zones with the same timekeeping method since now' )
182180 zoneCfgNow = getZoneCfgSinceTime (
183- ( new Date ( ) ) . getTime ( ) ,
181+ ( new Date ( ) ) . getTime ( ) ,
184182 path . join ( cacheDir , 'zone-config-now.json' )
185183 )
186184}
187185
188186if ( ! argv . skip_1970_zones ) {
189187 console . log ( 'Generating zone config for zones with the same timekeeping method since 1970' )
190188 zoneCfg1970 = getZoneCfgSinceTime (
191- 0 ,
189+ 0 ,
192190 path . join ( cacheDir , 'zone-config-1970.json' )
193191 )
194192}
@@ -204,7 +202,7 @@ if (argv.included_zones || argv.excluded_zones) {
204202 includedZones = argv . included_zones
205203 includedZones . forEach ( ( zoneName ) => {
206204 if (
207- ! zoneCfg [ zoneName ] ||
205+ ! zoneCfg [ zoneName ] ||
208206 ( ! argv . skip_1970_zones && ! zoneCfg1970 [ zoneName ] ) ||
209207 ( ! argv . skip_now_zones && ! zoneCfgNow [ zoneName ] )
210208 ) {
@@ -226,7 +224,7 @@ if (argv.included_zones || argv.excluded_zones) {
226224 excludedZones = argv . excluded_zones
227225 Object . keys ( zoneCfg ) . forEach ( ( zoneName ) => {
228226 if (
229- ! zoneCfg [ zoneName ] ||
227+ ! zoneCfg [ zoneName ] ||
230228 ( ! argv . skip_1970_zones && ! zoneCfg1970 [ zoneName ] ) ||
231229 ( ! argv . skip_now_zones && ! zoneCfgNow [ zoneName ] )
232230 ) {
@@ -559,14 +557,14 @@ function downloadOsmTimezoneBoundary (tzId, boundaryCallback) {
559557 // the downloads directory is cleared of all timezone boundaries not downloaded from OSM (there
560558 // are still a few in here with manual definitions). Therefore, keep a copy of all OSM downloads
561559 // so they aren't redownloaded during multiple reruns of the script
562-
560+
563561 function copyToOsmDownloadFolder ( err ) {
564562 if ( err ) return boundaryCallback ( err )
565563 fs . copyFile ( boundaryFilename , workingBoundaryFilename , boundaryCallback )
566564 }
567565
568- // Before downloading from Overpass, check if there's a copy in the working folder. Since osm
569- // downloads are always after production zones, it is safe to copy an osm boundary because a
566+ // Before downloading from Overpass, check if there's a copy in the working folder. Since osm
567+ // downloads are always after production zones, it is safe to copy an osm boundary because a
570568 // production one would've already been downloaded in the event it were deleted in order to force
571569 // the retrieval of a new zone.
572570 fs . stat (
@@ -771,7 +769,7 @@ function makeTimezoneBoundaries (callback) {
771769 calculateFn : calculateCb => {
772770 console . log ( `makeTimezoneBoundary for ${ tzid } ` )
773771 asynclib . eachSeries (
774- ops ,
772+ ops ,
775773 ( task , taskCb ) => {
776774 const taskData = getDataSource ( task )
777775 console . log ( '-' , task . op , task . id )
@@ -812,23 +810,23 @@ function makeTimezoneBoundaries (callback) {
812810
813811function makeDerivedTimezoneBoundaries ( strategy , callback ) {
814812 const cfg = (
815- strategy === '1970' ?
816- {
817- cacheFilename : path . join ( cacheDir , 'derived-1970-cache.json' ) ,
818- derivedZoneConfig : zoneCfg1970 ,
819- getFinalTzFilenameFn : getFinal1970TzOutputFilename ,
820- loadZonesInMemoryFn : loadFinal1970ZonesIntoMemory ,
821- progressStatsName : 'Building 1970 zones' ,
822- progressStatsUpdatePrefix : 'make1970TimezoneBoundary for' ,
823- } :
824- {
825- cacheFilename : path . join ( cacheDir , 'derived-now-cache.json' ) ,
826- derivedZoneConfig : zoneCfgNow ,
827- getFinalTzFilenameFn : getFinalNowTzOutputFilename ,
828- loadZonesInMemoryFn : loadFinalNowZonesIntoMemory ,
829- progressStatsName : 'Building Now zones' ,
830- progressStatsUpdatePrefix : 'makeNowTimezoneBoundary for' ,
831- }
813+ strategy === '1970'
814+ ? {
815+ cacheFilename : path . join ( cacheDir , 'derived-1970-cache.json' ) ,
816+ derivedZoneConfig : zoneCfg1970 ,
817+ getFinalTzFilenameFn : getFinal1970TzOutputFilename ,
818+ loadZonesInMemoryFn : loadFinal1970ZonesIntoMemory ,
819+ progressStatsName : 'Building 1970 zones' ,
820+ progressStatsUpdatePrefix : 'make1970TimezoneBoundary for'
821+ }
822+ : {
823+ cacheFilename : path . join ( cacheDir , 'derived-now-cache.json' ) ,
824+ derivedZoneConfig : zoneCfgNow ,
825+ getFinalTzFilenameFn : getFinalNowTzOutputFilename ,
826+ loadZonesInMemoryFn : loadFinalNowZonesIntoMemory ,
827+ progressStatsName : 'Building Now zones' ,
828+ progressStatsUpdatePrefix : 'makeNowTimezoneBoundary for'
829+ }
832830 )
833831
834832 const buildingProgress = new ProgressStats (
@@ -843,32 +841,32 @@ function makeDerivedTimezoneBoundaries (strategy, callback) {
843841
844842 tzBoundaryCache . init ( ( ) => {
845843 asynclib . each (
846- Object . keys ( cfg . derivedZoneConfig ) ,
844+ Object . keys ( cfg . derivedZoneConfig ) ,
847845 ( tzid , cb ) => {
848846 const message = `${ cfg . progressStatsUpdatePrefix } ${ tzid } `
849847 buildingProgress . beginTask ( message , true )
850-
848+
851849 tzBoundaryCache . calculate ( {
852850 cacheKey : hashMd5 ( cfg . derivedZoneConfig [ tzid ] . map ( getZoneGeomHash ) ) ,
853851 outputFilename : cfg . getFinalTzFilenameFn ( tzid ) ,
854852 calculateFn : calculateCb => {
855853 console . log ( message )
856854 let geom = getDataSource ( { source : 'final' , id : tzid } )
857-
855+
858856 cfg . derivedZoneConfig [ tzid ] . forEach ( zone => {
859857 console . log ( '-' , zone )
860858 if ( zone === tzid ) return
861859 const zoneData = getDataSource ( { source : 'final' , id : zone } )
862860 geom = debugGeo ( 'union' , geom , zoneData )
863861 } )
864-
862+
865863 calculateCb ( null , postProcessZone ( geom ) )
866864 } ,
867865 callback : cb
868866 } )
869- } ,
867+ } ,
870868 err => {
871- if ( err ) return cb ( err )
869+ if ( err ) return callback ( err )
872870 cfg . loadZonesInMemoryFn ( )
873871 tzBoundaryCache . end ( callback )
874872 }
@@ -919,7 +917,7 @@ const getZoneGeomHash = memoize((tzid) => {
919917 try {
920918 fs . statSync ( zoneFilename )
921919 } catch ( err ) {
922- return `${ tzid } -filenotfound`
920+ return `${ tzid } -filenotfound`
923921 }
924922 return `${ tzid } -${ hasha . fromFileSync ( zoneFilename , { algorithm : 'md5' } ) } `
925923} )
@@ -1079,7 +1077,7 @@ function validateTimezoneBoundaries (callback) {
10791077 }
10801078 validationCache . end ( ( err ) => callback ( err || error ) )
10811079 }
1082- )
1080+ )
10831081 } )
10841082}
10851083
@@ -1144,26 +1142,26 @@ function addOceans (callback) {
11441142 [ oceanZone . right , 90 ] ,
11451143 [ oceanZone . left , 90 ]
11461144 ] ] ) . geometry
1147-
1145+
11481146 let oceanGeom = geoJsonToGeom ( geoJson )
1149-
1147+
11501148 // filter zones to those that have bounds that apply
11511149 const tzsInBounds = zones . filter ( tzid => {
1152- zoneEnvelope = finalZones [ tzid ] . getEnvelopeInternal ( )
1150+ const zoneEnvelope = finalZones [ tzid ] . getEnvelopeInternal ( )
11531151 return ! (
1154- zoneEnvelope . getMaxX ( ) < oceanZone . left ||
1152+ zoneEnvelope . getMaxX ( ) < oceanZone . left ||
11551153 zoneEnvelope . getMinX ( ) > oceanZone . right
11561154 )
11571155 } )
1158-
1156+
11591157 oceanBoundaryCache . calculate ( {
11601158 cacheKey : `${ oceanZone . tzid } -${ hashMd5 ( tzsInBounds . map ( getZoneGeomHash ) ) } ` ,
11611159 calculateFn : calculateCb => {
11621160 // diff against applicable zones
11631161 tzsInBounds . forEach ( finalZone => {
11641162 oceanGeom = debugGeo ( 'diff' , oceanGeom , finalZones [ finalZone ] )
11651163 } )
1166-
1164+
11671165 calculateCb ( null , {
11681166 geom : postProcessZone ( oceanGeom , true ) ,
11691167 tzid : oceanZone . tzid
@@ -1187,15 +1185,15 @@ function combineAndWriteZones (callback) {
11871185 let ocean1970Writer
11881186 let regularNowWriter
11891187 let oceanNowWriter
1190-
1188+
11911189 if ( ! argv . skip_1970_zones ) {
11921190 regular1970Writer = new FeatureWriterStream ( workingDir + '/combined-1970.json' )
1193- ocean1970Writer = new FeatureWriterStream ( workingDir + '/combined-with-oceans-1970.json' )
1191+ ocean1970Writer = new FeatureWriterStream ( workingDir + '/combined-with-oceans-1970.json' )
11941192 }
1195-
1193+
11961194 if ( ! argv . skip_now_zones ) {
11971195 regularNowWriter = new FeatureWriterStream ( workingDir + '/combined-now.json' )
1198- oceanNowWriter = new FeatureWriterStream ( workingDir + '/combined-with-oceans-now.json' )
1196+ oceanNowWriter = new FeatureWriterStream ( workingDir + '/combined-with-oceans-now.json' )
11991197 }
12001198
12011199 Object . keys ( zoneCfg ) . forEach ( zoneName => {
@@ -1350,7 +1348,7 @@ function zipGeoJsonFiles (cb) {
13501348 )
13511349}
13521350
1353- function makeShapefile ( config , cb ) {
1351+ function makeShapefile ( config , cb ) {
13541352 rimraf ( config . shapeFileGlob , rimrafErr => {
13551353 if ( rimrafErr ) { return cb ( rimrafErr ) }
13561354 exec (
@@ -1461,7 +1459,7 @@ function analyzeChangesFromLastRelease (cb) {
14611459 lastReleaseZone . geometry
14621460 ) . buffer ( bufferDistance )
14631461 const curDataGeom = finalZone . buffer ( bufferDistance )
1464-
1462+
14651463 // don't diff equal geometries
14661464 if ( ! curDataGeom . equals ( lastReleaseGeom ) ) {
14671465 // diff current - last = additions
@@ -1475,7 +1473,7 @@ function analyzeChangesFromLastRelease (cb) {
14751473 if ( addition . getArea ( ) > 0.0001 ) {
14761474 results . addition = geomToGeoJson ( addition )
14771475 }
1478-
1476+
14791477 // diff last - current = removals
14801478 const removal = debugGeo (
14811479 'diff' ,
@@ -1531,7 +1529,7 @@ function analyzeChangesFromLastRelease (cb) {
15311529}
15321530
15331531const autoScript = {
1534- makeCacheDirAndFns : function ( cb ) {
1532+ makeCacheDirAndFns : function ( cb ) {
15351533 overallProgress . beginTask ( `Creating downloads dir (${ downloadsDir } )` )
15361534 asynclib . series ( [
15371535 mcb => safeMkdir ( cacheDir , mcb ) ,
@@ -1650,7 +1648,7 @@ const autoScript = {
16501648 jsonFile : path . join ( workingDir , 'combined-osm-zones.json' ) ,
16511649 shapeFile : path . join ( workingDir , 'combined-osm-zone-shapefile.shp' ) ,
16521650 shapeFileGlob : path . join ( workingDir , 'combined-osm-zone-shapefile.*' )
1653- } ,
1651+ } ,
16541652 cb
16551653 )
16561654 } ] ,
0 commit comments