@@ -5,6 +5,7 @@ |
*/ |
package m.timeseries.aggregate; |
|
+import com.mongodb.CommandResult; |
import com.mongodb.MongoClient; |
import com.mongodb.MongoClientURI; |
import com.mongodb.client.AggregateIterable; |
@@ -30,6 +31,7 @@ |
import java.util.Date; |
import java.util.List; |
import java.util.TimeZone; |
+import org.bson.BsonDocument; |
import org.bson.Document; |
import org.bson.types.ObjectId; |
import org.bson.conversions.Bson; |
@@ -162,27 +164,26 @@ |
} |
|
private JSONObject getResult(MongoCollection<Document> c, Document locationDoc, Date startDate, Date endDate, |
- String aggregationLevel) throws JSONException { |
- /* |
- db.getCollection("bigdata test series").aggregate([ |
- { "$match": { "location_id": "big_yearlychunks" } }, |
- { "$unwind": "$data" }, |
- { "$project": { |
- "tmin": { "$arrayElemAt": ["$data", 1] }, |
- "month": { $month: { "$arrayElemAt": ["$data", 0] } }, |
- "year": { $year: { "$arrayElemAt": ["$data", 0] } }, |
- } }, |
- { "$group": { |
- "_id": { month: "$month", year: "$year" }, |
- "tmin_avg": { "$avg": "$tmin" }, |
- "tmin_min": { "$min": "$tmin" }, |
- "tmin_max": { "$max": "$tmin" }, |
- "month": { "$first": "$month" }, |
- "year": { "$first": "$year" }, |
- } }, |
- { "$sort": { "year": 1, "month": 1 } }, |
- ]) |
- */ |
+ String aggregationLevel) throws JSONException, ServiceException { |
+ String testJS = "db.getCollection(\"bigdata test series\").aggregate([" + |
+" { \"$match\": { \"location_id\": \"big_yearlychunks\" } }," + |
+" { \"$unwind\": \"$data\" }," + |
+" { \"$project\": {" + |
+" \"tmin\": { \"$arrayElemAt\": [\"$data\", 1] }," + |
+" \"month\": { $month: { \"$arrayElemAt\": [\"$data\", 0] } }," + |
+" \"year\": { $year: { \"$arrayElemAt\": [\"$data\", 0] } }," + |
+" } }," + |
+" { \"$group\": {" + |
+" \"_id\": { month: \"$month\", year: \"$year\" }," + |
+" \"tmin_avg\": { \"$avg\": \"$tmin\" }," + |
+" \"tmin_min\": { \"$min\": \"$tmin\" }," + |
+" \"tmin_max\": { \"$max\": \"$tmin\" }," + |
+" \"month\": { \"$first\": \"$month\" }," + |
+" \"year\": { \"$first\": \"$year\" }," + |
+" } }," + |
+" { \"$sort\": { \"year\": 1, \"month\": 1 } }," + |
+"])"; |
+ |
List<String> header = (ArrayList) locationDoc.get("header"); |
List<List<Object>> filtered = new ArrayList(); |
|
@@ -195,7 +196,7 @@ |
new Document("$group", groupData(header)), |
sort(new Document("year", 1).append("month", 1)) |
); |
- |
+ |
AggregateIterable<Document> iter = c.aggregate(aggList).allowDiskUse(true); |
for (Document d : iter) { |
List<Object> row = new ArrayList<>(); |