diff options
author | evansiroky <evan.siroky@yahoo.com> | 2019-01-05 21:19:14 -0800 |
---|---|---|
committer | evansiroky <evan.siroky@yahoo.com> | 2019-01-05 21:19:14 -0800 |
commit | 3046a3d284604557d8e541f50c96685cc32bd280 (patch) | |
tree | b1c1171b4fa284b852efcbf17ebc8248c765838f | |
parent | 1a0f3592d5b6a6490a82dd38d553b1e72092bc90 (diff) | |
download | timezone-boundary-builder-3046a3d284604557d8e541f50c96685cc32bd280.tar.gz |
Improve progress reporting in various areas
-rw-r--r-- | index.js | 14 | ||||
-rw-r--r-- | progressStats.js | 32 |
2 files changed, 19 insertions, 27 deletions
@@ -357,7 +357,7 @@ const buildingProgress = new ProgressStats( ) var makeTimezoneBoundary = function (tzid, callback) { - buildingProgress.beginTask('makeTimezoneBoundary for', tzid) + buildingProgress.beginTask(`makeTimezoneBoundary for ${tzid}`, true) var ops = zoneCfg[tzid] var geom @@ -431,6 +431,7 @@ var validateTimezoneBoundaries = function () { console.log('do validation... this may take a few minutes') var allZonesOk = true var zones = Object.keys(zoneCfg) + var lastPct = 0 var compareTzid, tzid, zoneGeom for (var i = 0; i < zones.length; i++) { @@ -438,8 +439,10 @@ var validateTimezoneBoundaries = function () { zoneGeom = getDistZoneGeom(tzid) for (var j = i + 1; j < zones.length; j++) { - if (Math.round(validationProgress.getPercentage()) % 10 === 0) { + const curPct = Math.floor(validationProgress.getPercentage()) + if (curPct % 10 === 0 && curPct !== lastPct) { validationProgress.printStats('Validating zones', true) + lastPct = curPct } compareTzid = zones[j] @@ -574,8 +577,13 @@ var addOceans = function (callback) { const zones = Object.keys(zoneCfg) + const oceanProgress = new ProgressStats( + 'Oceans', + oceanZones.length + ) + oceanZoneBoundaries = oceanZones.map(zone => { - console.log(zone.tzid) + oceanProgress.beginTask(zone.tzid, true) const geoJson = polygon([[ [zone.left, 90], [zone.left, -90], diff --git a/progressStats.js b/progressStats.js index a55853f..f125abf 100644 --- a/progressStats.js +++ b/progressStats.js @@ -4,16 +4,13 @@ class ProgressStats { this.trackerName = trackerName this.totalTasks = totalTasks this.taskCounter = 0 - this.referenceLength = 5 - this.timestamps = [] } logNext() { this.taskCounter++ - this.timestamps.push({ - "index": this.taskCounter, - "timestamp": Date.now() - }) + if (!this.beginTime) { + this.beginTime = new Date() + } } /** @@ -50,28 +47,15 @@ class ProgressStats { /** * calculates the time left and outputs it in human readable format - * calculation is based on a reference length, that can be defined. + * calculation is based on the average time per task so far * * @returns {string} */ getTimeLeft () { - if(this.taskCounter <= this.referenceLength) { - //number of reference downloads must exist before left time can be predicted - return "? minutes" - } - var processDurationInSeconds = (Date.now() - this.timestamps[0].timestamp) / 1000 - if(processDurationInSeconds < 60){ - //process must run longer than 60seconds before left time can be predicted - return "? minutes" - } - - var indexOfStepsBefore = this.timestamps.findIndex((t) => { - return t.index === (this.taskCounter - this.referenceLength) - }) - var lastSteps = this.timestamps[indexOfStepsBefore]; - var millisOflastSteps = Date.now() - lastSteps.timestamp - var downloadsLeft = this.totalTasks - this.taskCounter - var millisecondsLeft = (millisOflastSteps / this.referenceLength) * downloadsLeft + if (this.taskCounter === 0) return '?' + const averageTimePerTask = (Date.now() - this.beginTime.getTime()) / this.taskCounter + var tasksLeft = this.totalTasks - this.taskCounter + var millisecondsLeft = averageTimePerTask * tasksLeft return this.formatMilliseconds(millisecondsLeft) } |