forked from labexp/data_scripts_lascallesdelasmujeres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_final.js
151 lines (109 loc) · 4.34 KB
/
parse_final.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
'use strict';
const LineByLineReader = require('line-by-line');
const fs = require('fs');
const args = require('yargs').argv;
const path = require('path');
const folder = (args.ciudad ? args.ciudad : 'ciudad');
const streeMap = new Map();
const lr = new LineByLineReader(path.join(__dirname, `data/${folder}/${folder}_finalCSV.csv`), { encoding: 'utf8', skipEmptyLines: true });
lr.on('error', function (err) { });
lr.on('line', function (line) {
lr.pause();
var splitLine = line.split(';');
//Male case
if(splitLine[5].toLowerCase() === "male" ){
streeMap.set(splitLine[0], {
url: '',
gender: splitLine[5],
scale: splitLine[4]
});
lr.resume();
}else if(splitLine[5].toLowerCase() === "female"){ //Female case
var url = '';
if(splitLine.length > 6) url = splitLine[6];
streeMap.set(splitLine[0], {
url: url,
gender: splitLine[5],
scale: splitLine[4]
});
lr.resume();
}else{
lr.resume();
}
});
lr.on('end', function () {
readGeojson();
});
/* stats vars*/
const stats = {
numLink: 0,
pcLink: 0,
numNoLink: 0,
pcNoLink: 0,
numMale: 0,
numFemale: 0,
pcMale: 0,
pcFemale: 0,
totalNames: 0
};
let noLinkList = '';
const tratadosList = new Set();
function readGeojson(file, tilecount){
fs.readFile(path.join(__dirname, `data/${folder}/${folder}_streets.geojson`), 'utf8', (err, data) => {
if (err) throw err;
var geojson = JSON.parse(data);
var finalGeojson = {
"type": "FeatureCollection",
"features": []
};
for (var key in geojson.features) {
if(streeMap.has(geojson.features[key].properties.name)){
var objValues = streeMap.get(geojson.features[key].properties.name);
geojson.features[key].properties.wikipedia_link = objValues.url;
geojson.features[key].properties.gender = objValues.gender;
geojson.features[key].properties.scale = objValues.scale;
if(!tratadosList.has(geojson.features[key].properties.name)){
tratadosList.add(geojson.features[key].properties.name);
if (objValues.url !== ('' && null && undefined) && objValues.gender.toLowerCase() === 'female'){
stats.numLink++;
stats.numFemale++;
}else if (objValues.gender.toLowerCase() === 'female'){
stats.numFemale++;
stats.numNoLink++;
noLinkList += `\n${geojson.features[key].properties.name}`;
}else{
stats.numMale++;
}
}
finalGeojson.features.push(geojson.features[key]);
}
}
fs.writeFileSync( path.join(__dirname, `data/${folder}/final_tile.geojson`), JSON.stringify(finalGeojson), 'utf8', (err) => {
if (err) {
throw err;
console.error(err);
}
console.log('final_tile.geojson has been saved!');
});
stats.totalNames = stats.numMale + stats.numFemale;
stats.pcMale = ((stats.numMale * 100) / (stats.totalNames)).toFixed(1);
stats.pcFemale = ((stats.numFemale * 100) / (stats.totalNames)).toFixed(1);
const totalLinks = stats.numLink + stats.numNoLink;
stats.pcLink = ((stats.numLink * 100) / totalLinks).toFixed(1);
stats.pcNoLink = ((stats.numNoLink * 100) / totalLinks).toFixed(1);
fs.writeFileSync( path.join(__dirname,`data/${folder}/stats.txt`), JSON.stringify(stats), 'utf8', (err) => {
if (err) {
throw err;
console.error(err);
}
console.log('stat.txt has been saved!');
});
fs.writeFileSync(path.join(__dirname, `data/${folder}/noLinkList.txt`), noLinkList, 'utf8', (err) => {
if (err) {
throw err;
console.error(err);
}
console.log('noLinkList.txt been saved!');
});
});
}