Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created January 23, 2014 00:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmcw/8570668 to your computer and use it in GitHub Desktop.
Save tmcw/8570668 to your computer and use it in GitHub Desktop.
var dates = require('./dates.json'),
all = require('./us-2.json'),
sys = require('sys'),
fs = require('fs'),
moment = require('moment'),
exec = require('child_process').exec;
/*
* Check for equality
console.log(
dates.map(function(_) { return _[0] }).sort().join(',') ==
all.features.map(function(_) { return _.properties.NAME }).sort().join(',')
);
*/
var a = moment('Jan 1, 2013').unix(),
b = moment('Jan 1, 2014').unix(),
ai = moment(dates[0][1]).unix(),
bi = moment(dates[dates.length - 1][1]).unix();
function interp(_) {
return (((_ - ai) / (bi - ai)) * (b - a)) + a;
}
var fc = { type: 'FeatureCollection', features: [] };
dates = dates.map(function(d) {
d[2] = moment(interp(moment(d[1]).unix()) * 1000).format('MMMM D h:mm YYYY +0100');
return d;
});
console.log(dates);
function run() {
console.log(arguments);
if (!dates.length) return;
var date = dates.shift();
var state = all.features.filter(function(f) {
return f.properties.NAME == date[0];
})[0];
fc.features.push(state);
fs.writeFileSync('us.geojson', JSON.stringify(fc, null, 4));
exec('git add us.geojson', function() {
var cmd = 'git commit -m "' + date[0] + ' joins the United States of America" --date="' + date[2] + '"';
console.log(cmd);
exec(cmd, function() {
console.log(arguments);
setTimeout(run, 1000);
});
});
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment