-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage18kpis.js
59 lines (43 loc) · 1.63 KB
/
page18kpis.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
var utils = require("./utils/utils.js");
const getKPIs = (docsCW, discardedDocsCW, datesCW) => {
// ========= Time series Balearen vs Ibiza (tourism) ============
//discarded and not discarded news
let allDocsCW = docsCW.concat(discardedDocsCW);
// calculate Balearen time series
var balearenTimeSeriesArray = [0, 0, 0, 0, 0, 0, 0];
let balearenTourismDocs = docsCW
.filter(utils.balearenMention)
.filter(utils.tourismCategory);
let balearenTimeSeriesDocs = balearenTourismDocs;
// Add 1 per document to the corresponding timesSeriesArray position
for (i = 0; i < balearenTimeSeriesDocs.length; i++) {
balearenTimeSeriesArray[
datesCW.indexOf(balearenTimeSeriesDocs[i].publishedFormatted)
]++;
}
balearenTimeSeriesArray.unshift("Balears");
// calculate Ibiza time series
var ibizaTimeSeriesArray = [0, 0, 0, 0, 0, 0, 0];
let ibizaTourismDocs = docsCW
.filter(utils.ibizaIslandMention)
.filter(utils.tourismCategory);
let ibizaTimeSeriesDocs = ibizaTourismDocs;
// Add 1 per document to the corresponding timesSeriesArray position
for (i = 0; i < ibizaTimeSeriesDocs.length; i++) {
ibizaTimeSeriesArray[
datesCW.indexOf(ibizaTimeSeriesDocs[i].publishedFormatted)
]++;
}
ibizaTimeSeriesArray.unshift("Ibiza");
// ============= CSV creation ================
let pageRows = [];
// Balearen and Ibiza Time series (mentions to tourism)
pageRows.push([
"Evolutiu Baleares vs Ibiza (turisme)",
]);
pageRows.push([""].concat(datesCW));
pageRows.push(balearenTimeSeriesArray);
pageRows.push(ibizaTimeSeriesArray);
return pageRows;
};
module.exports = { getKPIs };