Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 1, 2013 16:56
Show Gist options
  • Save tmcw/5496576 to your computer and use it in GitHub Desktop.
Save tmcw/5496576 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var moment = require('moment');
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('sometime.sqlite');
var day = moment("01-01-2012", "MM-DD-YYYY");
var last = moment("02-01-2012", "MM-DD-YYYY");
var end = moment("01-01-2013", "MM-DD-YYYY");
var allusers = {};
db.all(('select distinct(user_id) as u '+
'FROM osm_changeset WHERE '+
'closed_at < {start}')
.replace(/{start}/g, day.unix())
.replace(/{end}/g, last.unix()),
function(err, rows) {
for (var i = 0; i < rows.length; i++) {
allusers[rows[i].u] = true;
}
console.log('unique users who edited before 01-01-2012: ' + Object.keys(allusers).length);
run();
});
function run() {
if (last.unix() > end.unix()) {
return;
}
db.all(('select distinct(user_id) as u '+
'FROM osm_changeset WHERE '+
'closed_at > {start} '+
'AND closed_at < {end}')
.replace(/{start}/g, day.unix())
.replace(/{end}/g, last.unix()),
function(err, rows) {
var added = 0;
for (var i = 0; i < rows.length; i++) {
if (!allusers[rows[i].u]) added++;
allusers[rows[i].u] = true;
}
console.log('users added in ' + day.format("MMM YY") + ': ' + added);
day.add('months', 1);
last.add('months', 1);
run();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment