-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
executable file
·167 lines (147 loc) · 5.95 KB
/
Gruntfile.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*global module:false*/
var request = require('request');
var fs = require('fs');
// var tabletop = require('tabletop');
var papaparse = require('papaparse');
// File URL
var file = './Infancia.csv';
var content = fs.readFileSync(file, "utf8");
// var file = 'https://docs.google.com/spreadsheets/d/1osA88sQDYy6Q-Aw4oNbyYaMbAnQAI6t66Iv_6GLRNvA/edit?usp=sharing';
// var public_spreadsheet_url = 'https://docs.google.com/spreadsheets/d/1ccdoL4b3sxboLIj-BkOCjfRJMLVcDQcwtlv8fFCLoxQ/edit?usp=sharing';
// var public_spreadsheet_url = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vR9m-_WZjM9_jM8nXK0EPxnUaSlugsIQ65N2faj5KmcHLa1_EFyfMncBL4TwmDjcU4d_fvVI1AS0wqD/pub?gid=1823583981&single=true&output=csv';
var current_branch = 'gh-pages';
function functiontofindIndexByKeyValue(arraytosearch, key, valuetosearch) {
for (var i = 0; i < arraytosearch.length; i++) {
if (arraytosearch[i][key] == valuetosearch) {
return i;
}
}
return -1;
}
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-git');
// Project configuration.
grunt.initConfig({
gitcommit: {
data: {
options: {
'allowEmpty': true
},
files: [
{
src: ["_data/categories_by_macro.json","_data/data_categories.json", "_data/macro_areas.json", "_data/totales.json"],
expand: true,
}
]
},
},
gitadd: {
task: {
options: {
force: true
},
files: {
src: ["_data/categories_by_macro.json","_data/data_categories.json", "_data/macro_areas.json", "_data/totales.json"],
}
}
},
gitpush: {
data: {
options: {
"remote": "origin",
'branch': current_branch,
"force": true
}
}
},
gitpull: {
data: {
options: {
"remote": "origin",
"branch": current_branch
}
}
}
});
// These plugins provide necessary tasks.
// Default task.
grunt.registerTask('UpdateData', 'Va a buscar las cosas a google docs y las deja en un json', function() {
console.log("log1")
var done = this.async();
console.log("log2")
// function showInfo(data, tabletop){console.log(tabletop.models.promesas.elements)}
console.log(papaparse)
console.log("log3")
// var i = tabletop.init({key: public_spreadsheet_url, callback: function(data, tabletop){
var i = papaparse.parse(content,{complete: function(results){
console.log("log4")
console.log(results)
data = results.data;
var all_promises = data;
var totales = []
/**
Get Totales
**/
var totales_counter = 1;
for (var i=0; i < all_promises.length; i++){
if(functiontofindIndexByKeyValue(totales, "macro_area", all_promises[i].macro_area) == -1){
totales.push({
"id": totales_counter,
"macro_area": all_promises[i].macro_area,
"quality_macro_area": all_promises[i].quality_macro_area,
"fulfillment_macro_area": Number((all_promises[i].fulfillment_macro_area * 100).toFixed(1))
})
totales_counter++;
}
}
grunt.file.write("_data/totales.json", JSON.stringify(totales, null, 4))
/**
Get Macro Areas
**/
var macro_areas = []
var macro_areas_counter = 0;
for (var i=0; i < all_promises.length; i++){
if(functiontofindIndexByKeyValue(macro_areas, "macro_area", all_promises[i].macro_area) == -1){
macro_areas.push({
"id":macro_areas_counter,
"macro_area": all_promises[i].macro_area,
"quality_macro_area": all_promises[i].quality_macro_area,
"fulfillment_macro_area": Number((all_promises[i].fulfillment_macro_area * 100).toFixed(1))
})
macro_areas_counter++;
}
}
var data_string = JSON.stringify(macro_areas, null, 4);
grunt.file.write("_data/macro_areas.json", data_string)
/**
Get Categories and promises
**/
var macro_areas = []
var datas = all_promises
var macro_categories = {};
var data_categories = {};
for(var i=0; i < datas.length; i ++){
var promise = datas[i];
if(Object.keys(macro_categories).indexOf(promise.macro_area) == -1){
macro_categories[promise.macro_area] = []
}
if(Object.keys(data_categories).indexOf(promise.category) == -1){
data_categories[promise.category] = []
}
if(functiontofindIndexByKeyValue(macro_categories[promise.macro_area], "category", promise.category) == -1){
macro_categories[promise.macro_area].push({"category": promise.category})
}
data_categories[promise.category].push(promise)
}
var data_categories_as_string = JSON.stringify(data_categories, null, 4);
var data_string = JSON.stringify(macro_categories, null, 4);
grunt.file.write("_data/categories_by_macro.json", data_string)
grunt.file.write("_data/data_categories.json", data_categories_as_string)
done()
}
, download: false, header: true, delimiter: ",", skipEmptyLines: true})
console.log("nada")
});
grunt.registerTask("UpdateEverything", ['gitadd', 'gitcommit', 'gitpull', 'gitpush'])
};
/** Temporalmente está borrado 'UpdateData' del registerTask de grunt para que suba sólo los json **/