This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_data.js
executable file
·115 lines (101 loc) · 5.13 KB
/
process_data.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
var MongoClient = require('mongodb').MongoClient;
var ObjectId = require('mongodb').ObjectID;
var _ = require('lodash');
// Connection URL
var url = 'mongodb://127.0.0.1:27017/wsil';
MongoClient.connect(url, function(err, db) {
if(err) throw err;
var neighborhoods = db.collection('neighborhood').find();
neighborhoods.each(function(err, neighborhood) {
if(err) throw err;
if (neighborhood != null) {
var citelibs = db.collection('citelib').find({geometry: { $geoWithin: { $geometry: neighborhood.geometry } } }).count(function(err, count) {
if(err) throw err;
db.collection('neighborhood').update({_id: neighborhood._id}, {$set: {"properties.citelib_count": count}}, function(err, doc) {
if(err) throw err;
});
});
db.collection('restaurant').find({geometry: { $geoWithin: { $geometry: neighborhood.geometry } } }).count(function(err, count) {
if(err) throw err;
db.collection('neighborhood').update({_id: neighborhood._id}, {$set: {"properties.restaurant_count": count}}, function(err, doc) {
if(err) throw err;
});
});
db.collection('supermarket').find({geometry: { $geoWithin: { $geometry: neighborhood.geometry } } }).count(function(err, count) {
if(err) throw err;
db.collection('neighborhood').update({_id: neighborhood._id}, {$set: {"properties.supermarket_count": count}}, function(err, doc) {
if(err) throw err;
});
});
db.collection("grenoble_all").findOne({"id" : "relation/80348"}, function(err, doc){
if(err) throw err;
db.collection("grenoble").remove({"id" : "relation/80348"}, function(err, docu){
if(err) throw err;
db.collection("grenoble").update({"id" : "relation/80348"}, doc, {upsert: true}, function(err, docu){
if(err) throw err;
});
});
});
var tram_count = 0;
var bus_count = 0;
var sncf_count = 0;
var autocar_count = 0;
db.collection('stop').find({geometry: { $geoWithin: { $geometry: neighborhood.geometry } } }, function(err, stops) {
stops.each(function(err, stop) {
if (stop != null) {
var lines = stop.properties.LIGNESARRET.split(',');
_.each(lines, function(line) {
if (line.match(/SEM_[ABCDE]/)) {
tram_count += 1;
} else if (_.startsWith(line, 'SEM_')) {
bus_count += 1;
} else if (_.startsWith(line, 'SNC_')) {
sncf_count += 1;
} else {
autocar_count += 1;
}
});
} else {
db.collection('neighborhood').update({_id: neighborhood._id}, {$set: {"properties.tram_count": tram_count, "properties.bus_count": bus_count, "properties.autocar_count": autocar_count, "properties.sncf_count": sncf_count}}, function(err, doc) {
if(err) throw err;
});
}
});
});
var gsm_2g_count = 0;
var gsm_3g_count = 0;
var gsm_4g_count = 0;
db.collection('gsm').find({geometry: { $geoWithin: { $geometry: neighborhood.geometry } } }, function(err, gsms) {
gsms.each(function(err, gsm) {
if (gsm != null) {
if (gsm.properties.ANT_4G == "OUI") {
gsm_4g_count += 1;
} else if (gsm.properties.ANT_3G == "OUI") {
gsm_3g_count += 1;
} else if (gsm.properties.ANT_2G == "OUI") {
gsm_2g_count += 1;
}
} else {
db.collection('neighborhood').update({_id: neighborhood._id}, {$set: {"properties.gsm_4g_count": gsm_4g_count, "properties.gsm_3g_count": gsm_3g_count, "properties.gsm_2g_count": gsm_2g_count}}, function(err, doc) {
if(err) throw err;
});
}
});
});
var length = 0;
db.collection('cyclelane').find({geometry: { $geoWithin: { $geometry: neighborhood.geometry } } }, function(err, cyclelanes) {
cyclelanes.each(function(err, cyclelane) {
if (cyclelane != null) {
length += cyclelane.properties.longueur_section_m;
} else {
db.collection('neighborhood').update({_id: neighborhood._id}, {$set: {"properties.cyclelane_length": length}}, function(err, doc) {
if(err) throw err;
});
}
});
});
} else {
// db.close();
}
});
});