-
Notifications
You must be signed in to change notification settings - Fork 2
/
minimize.js
49 lines (45 loc) · 1.38 KB
/
minimize.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
var map = function() {
var lat, lng, coordinates;
if (this && this.geo && this.geo.coordinates) {
coordinates = this.geo.coordinates;
lat = coordinates[0];
lng = coordinates[1];
}
else if (this && this.place && this.place.bounding_box && this.place.bounding_box.coordinates) {
lat = 0;
lng = 0;
var c = this.place.bounding_box.coordinates;
for (var i in c) {
lat += c[i][1];
lng += c[i][0];
}
coordinates = [
lat / c.length,
lng / c.length,
];
}
if (lat && lng) {
emit(this.id, {
text: this.text,
user_id: this.user.id,
created_at: this.created_at,
geo: {
coordinates: [ lat, lng ]
}
});
}
};
var reduce = function(key, values) {
return values[0];
}
if (db[input].count() == 0) {
print("Input collection (" + db[input] + ") is empty.");
}
else {
print("Input collection (" + input + ") pre-count: " + db[input].count());
print("Output collection (" + output + ") pre-count: " + db[output].count());
db[input].mapReduce(map, reduce, output);
print("Output collection (" + output + ") post-count: " + db[output].count());
//db[input].remove({});
print("Input collection (" + input + ") post-count: " + db[input].count());
}