forked from ColadaFF/PrototypeUdeA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.js
More file actions
70 lines (60 loc) · 2.66 KB
/
Query.js
File metadata and controls
70 lines (60 loc) · 2.66 KB
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
/**
* Created by barcode on 13/04/15.
*/
db.colombia_format_3.mapReduce(function () {
if (this.properties.DEPNAME === 'Antioquia') {
emit(this._id, this);
}
}, function (id, value) {
futureCollection = {"type": "FeatureCollection"};
if (!futureCollection.features) {
futureCollection.features = []
}
futureCollection.push({type: 'Feature', properties: value.properties, geometry: value.geometry})
}, {out: {inline: 1}});
db.colombia_format_3.mapReduce(function () {
if (this.properties.DEPNAME === 'Antioquia') {
emit(this.properties.DEPNAME, {type: 'Feature', properties: this.properties, geometry: this.geometry});
}
}, function (key, values) {
var featureCollection = {"depName": key, "type": "FeatureCollection", "lenght": values.length};
values.forEach(function (value) {
for (var idx in value.features) {
featureCollection.features++;
}
});
return featureCollection;
}, {out: 'Antioquia_Municipios'});
var functionMap = function () {
if (this.properties.DEPNAME === 'Antioquia') {
emit(this.properties.DEPNAME, {type: 'Feature', properties: this.properties, geometry: this.geometry});
}
};
var functionReduce = function (key, values) {
var featureCollection = {"depName": key, "type": "FeatureCollection", "lenght": values.length, "features": []};
var i = 0;
values.forEach(function (value) {
for (var idx in value.features) {
featureCollection.features[i++] = value.features[idx];
}
});
return featureCollection;
};
db.colombia_format_3.mapReduce(functionMap, functionReduce, {out: 'Antioquia_Municipios'});
// mongoimport --host 192.168.1.52 --port 27017 --jsonArray --file Documents/colombia_format_3.json
db.colombia_format_3.find({'properties.DEPNAME': 'Antioquia'}, {_id: 0, properties: 1, geometry: 1});
var getRand = function(min, max){
return Math.floor(Math.random() * (max - min)) + min;
}
db.colombia_format_3.find({'properties.DEPNAME': 'Antioquia'}).forEach(function(departamento){
departamento.properties.indicators = [];
var deseases = ['Aterosclerosis', 'Bronquitis, enfisema y otras enfermedades pulmonares obstructivas crónicas', 'Cirrosis y otras enfermedades crónicas del hígado', 'Diabetes mellitus', 'Enfermedades cerebrovasculares'];
for(var i = 0; i < deseases.length; i++){
var indicator = {description: deseases[i], deathRates: []};
departamento.properties.indicators[i] = indicator;
for(var j = 0; j < 10; j++){
indicator.deathRates[j] = {year: 2004+j, male: getRand(1, 40), female: getRand(1, 40)};
}
}
db.colombia_format_3.save(departamento);
});