This repository was archived by the owner on Jun 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathchangelog.js
More file actions
46 lines (40 loc) · 1.26 KB
/
Copy pathchangelog.js
File metadata and controls
46 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const _ = require('lodash');
const turf = require('turf');
const tilebelt = require('tilebelt');
// The changelog tracks how many updates/modifications
// a tile has received over the years and months
class Changelog {
constructor(tile) {
this.tile = tile;
this.years = _.fromPairs(_.range(2006, 2017).map(year => {
return [year, _.range(0, 12).map(_ => 0)];
}));
}
track(ft) {
const date = new Date(parseInt(ft.properties["@timestamp"]) * 1000);
this.years[date.getFullYear()][date.getMonth()] += 1;
}
// Create array that contains the modification count
// across all months ranging from 2006 until todaya
// The index is the month so
// 0 -> January 2006
// 13 -> February 2007
monthHistory() {
let months = [];
_.range(2006, 2017).forEach(year => {
months.push(...this.years[year])
});
return months;
}
toGeoJSON() {
let geometry = tilebelt.tileToGeoJSON(this.tile);
let properties = {
months: this.monthHistory(),
tile: this.tile,
};
properties.total = _.sum(properties.months);
return turf.feature(geometry, properties);
}
}
module.exports = Changelog;