Removing non-matching years from data files.

master
ben-burlingham 10 years ago
parent f13b7d861a
commit 177ff46ca2
  1. 12
      server.js
  2. 1
      server/assemble.js
  3. 6
      server/meteo.js
  4. 25
      server/noaa.js

@ -15,7 +15,7 @@
console.log('=== Starting next promise chain.'); console.log('=== Starting next promise chain.');
var station = 46026 //stations.ids[index]; var station = stations.ids[index];
Promise.resolve() Promise.resolve()
//===== Download //===== Download
@ -26,23 +26,21 @@
//===== Parse //===== Parse
// .then(stations.parseStation.bind(null, station)) // .then(stations.parseStation.bind(null, station))
// .then(meteo.parseAllMonths.bind(null, 46026, 2015)) // .then(meteo.parseAllMonths.bind(null, station, 2015))
// .then(meteo.parseAllYears.bind(null, station, 1982, 2014)) // .then(meteo.parseAllYears.bind(null, station, 1982, 2014))
//===== Assemble //===== Assemble
.then(assemble.read.bind(null, station, 2015)) // .then(assemble.read.bind(null, station, 2015))
.then(assemble.getAverages) // .then(assemble.getAverages)
// .then(function() { console.log('something') }) // .then(function() { console.log('something') })
//===== Flow control //===== Flow control
.then(function() { console.log('=== Chain complete.\n'); }) // .then(function() { console.log('=== Chain complete.\n'); })
// .then(next.bind(null, index + 1)) // .then(next.bind(null, index + 1))
.catch(IO.error); .catch(IO.error);
}; };
// TODO remove previous years from file, such as 46026-2015 shouldn't have data from 2014.
next(0); next(0);
})(); })();

@ -1,4 +1,3 @@
'use strict';
var IO = require('./io'); var IO = require('./io');
var meteo = require('./meteo'); var meteo = require('./meteo');

@ -91,7 +91,7 @@ module.exports = {
.then(NOAA.aggregate) .then(NOAA.aggregate)
.then(NOAA.convert) .then(NOAA.convert)
.then(function(str) { .then(function(str) {
IO.write(jsonPath + station + '-' + year + '.json', str); return IO.write(jsonPath + station + '-' + year + '.json', str);
}); });
}, },
@ -106,7 +106,7 @@ module.exports = {
.then(NOAA.parseTxt) .then(NOAA.parseTxt)
.then(NOAA.convert) .then(NOAA.convert)
.then(function(str) { .then(function(str) {
IO.write(jsonPath + station + '-' + year + '.json', str); return IO.write(jsonPath + station + '-' + year + '.json', str);
}); });
}, },
@ -161,5 +161,5 @@ module.exports = {
} }
return Promise.all(arr); return Promise.all(arr);
}, }
}; };

@ -47,9 +47,28 @@ module.exports = {
return dateA - dateB; return dateA - dateB;
}); });
// Filter for multiple headings/units rows. // Flag violations: headings, units, empty.
var result = sorted.filter(function(row) { // Prepare average to trim incidental head/tail data points from different years.
return !(row[0] === '#YY' || row[0] === '#yr' || row.length === 1); var sum = 0;
var count = 0;
sorted.forEach(function(row) {
if (row[0] === '#YY' || row[0] === '#yr' || row.length === 1) {
row[0] = null;
}
else {
sum += parseInt(row[0]);
count++;
}
});
// Filter rows that have been flagged or that are the wrong year.
var year = Math.round(sum / count);
var result = sorted.filter(function(row, i) {
if (row[0] === null || row[0] != year) {
return false;
}
return true;
}); });
// Convert to JSON that can later be read easily. // Convert to JSON that can later be read easily.

Loading…
Cancel
Save