Debian Codegraph @

tasks/data-dedupe.js

raw symbols SCIP
1 "use strict";
2
3 function dedupe(zone) {
4 var abbrs = [],
5 untils = [],
6 offsets = [],
7 length = zone.abbrs.length,
8 i;
9
10 for (i = length - 1; i >= 0; i--) {
11 if (abbrs[0] === zone.abbrs[i] &&
12 offsets[0] === zone.offsets[i]) { continue;}
13
14 untils.unshift(i === length - 1 ? Infinity : zone.untils[i + 1]);
15 abbrs.unshift(zone.abbrs[i]);
16 offsets.unshift(zone.offsets[i]);
17 }
18
19 return {
20 name : zone.name,
21 abbrs : abbrs,
22 untils : untils,
23 offsets : offsets,
24 population : zone.population,
25 countries : zone.countries
26 };
27 }
28
29 function addCountries(countries) {
30 var result = [];
31
32 for (var country in countries) {
33 result.push({
34 name : countries[country].abbr,
35 zones : countries[country].zones
36 });
37 }
38
39 return result;
40 }
41
42 module.exports = function (grunt) {
43 grunt.registerTask('data-dedupe', '6. Remove duplicate entries from data-collect.', function (version) {
44 version = version || 'latest';
45
46 var zones = grunt.file.readJSON('temp/collect/' + version + '.json'),
47 meta = grunt.file.readJSON('data/meta/' + version + '.json'),
48 output = {
49 version : meta.version,
50 zones : zones.map(dedupe),
51 links : [],
52 countries : addCountries(meta.countries)
53 };
54
55 grunt.file.write('data/unpacked/' + version + '.json', JSON.stringify(output, null, 2));
56 if (version === 'latest') {
57 grunt.file.copy('data/unpacked/' + version + '.json', 'data/unpacked/' + output.version + '.json');
58 }
59
60 grunt.log.ok('Deduped data for ' + version);
61 });
62 };