-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchCSVs_1.js
79 lines (72 loc) · 1.5 KB
/
fetchCSVs_1.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
list('/DataExport');
getCSV(
'/DataExport/PMISPMFexport.csv',
'latin1',
{
quote: 'off',
delimiter: ';',
noheader: true,
colParser:{
"field10": "number",
"field11": "number",
"field12": "number",
"field13": "number",
"field14": "number",
"field15": "number",
"field16": "number",
},
}
);
alterState(state => {
// NOTE: Choose countries to include here.
// WARNING: The longer this list becomes, the longer the execution will take.
state.selectedCountries = [
'BD',
'VE',
'CO',
'CD',
'CF',
'CM',
'DJ',
'ER',
'ET',
'IQ',
];
state.projects = state.data.filter(p => (
state.selectedCountries.some(x => (p.field1.startsWith(x)))
));
state.data = {};
return state;
});
getCSV(
'/DataExport/PMISTXexport.csv',
'utf8',
{
quote: 'off',
delimiter: ';',
noheader: true,
colParser:{
"field8": "number",
"field9": "number",
"field10": "number",
"field11": "number",
},
}
);
alterState(state => {
const filteredFinancials = state.data.filter(f => (
state.selectedCountries.some(x => (f.field1.startsWith(x)))
));
const preparedFinancials = _.groupBy(filteredFinancials, 'field1');
const mergedProjects = state.projects.map((p) => {
if (preparedFinancials[p.field1] != null) {
p.financials = preparedFinancials[p.field1];
} else {
p.financials = [];
}
return p;
});
return {
data: { projects: mergedProjects }
};
});