@@ -82,10 +82,11 @@ |
String end_date = getStringParam("end_date", null); |
boolean metadata_only = getBooleanParam("metadata_only", true); |
boolean compute_stats = getBooleanParam("compute_stats", false); |
+ boolean compute_stats_local = getBooleanParam("compute_stats_local", false); |
String search_id = getStringParam("search_id", null); |
JSONObject search_feature = getJSONParam("search_feature", null); |
|
- run(mongo_uri, mongo_collection, search_feature, search_id, start_date, end_date, metadata_only, compute_stats); |
+ run(mongo_uri, mongo_collection, search_feature, search_id, start_date, end_date, metadata_only, compute_stats, compute_stats_local); |
} |
|
|
@@ -96,7 +97,7 @@ |
|
|
void run(String mongo_uri, String mongo_collection, JSONObject search_feature, String search_id, |
- String start_date_str, String end_date_str, boolean metadata_only, boolean compute_stats) throws JSONException, ServiceException { |
+ String start_date_str, String end_date_str, boolean metadata_only, boolean compute_stats, boolean compute_stats_local) throws JSONException, ServiceException { |
|
open(mongo_uri); |
MongoCollection<Document> collection = db.getCollection(mongo_collection); |
@@ -127,7 +128,7 @@ |
} |
} |
for (Document doc : c) { |
- JSONObject res = getResult(collection, doc, start_date, end_date, metadata_only, compute_stats); |
+ JSONObject res = getResult(collection, doc, start_date, end_date, metadata_only, compute_stats, compute_stats_local); |
results.put(res); |
} |
} else { |
@@ -142,7 +143,7 @@ |
} |
AggregateIterable<Document> c = collection.aggregate(agg_match); |
for (Document doc : c) { |
- JSONObject res = getResult(collection, doc, start_date, end_date, metadata_only, compute_stats); |
+ JSONObject res = getResult(collection, doc, start_date, end_date, metadata_only, compute_stats, compute_stats_local); |
results.put(res); |
} |
} |
@@ -152,7 +153,7 @@ |
|
|
private JSONObject getResult(MongoCollection<Document> c, Document doc, Date start_date, Date end_date, |
- boolean metadata_only, boolean compute_stats) throws JSONException { |
+ boolean metadata_only, boolean compute_stats, boolean compute_stats_local) throws JSONException { |
String date_fmt = (String) doc.get("date_fmt"); |
SimpleDateFormat ft = new SimpleDateFormat(date_fmt); |
ft.setTimeZone(TimeZone.getTimeZone("UTC")); |
@@ -206,7 +207,7 @@ |
} |
} |
|
- if (compute_stats) { |
+ if (compute_stats || compute_stats_local) { |
Document statsDoc = new Document("_id", null); |
List<String> stats = Arrays.asList("min", "max", "avg", "stdDevPop"); |
for (String stat: stats) { |
@@ -222,29 +223,33 @@ |
Aggregates.project(project), |
new Document("$group", statsDoc) |
); |
- iter = c.aggregate(aggList).allowDiskUse(true); |
- for (Document d: iter) { |
- for (String stat: stats) { |
- for (int i=1; i<header.size(); i++) { |
- String key = header.get(i) + "_" + stat; |
- statResult.put(key, d.get(key)); |
+ if (compute_stats) { |
+ iter = c.aggregate(aggList).allowDiskUse(true); |
+ for (Document d: iter) { |
+ for (String stat: stats) { |
+ for (int i=1; i<header.size(); i++) { |
+ String key = header.get(i) + "_" + stat; |
+ statResult.put(key, d.get(key)); |
+ } |
} |
} |
} |
|
// Add locally computed stats |
- for (List<Object> objList: filtered) { |
- for (int i=1; i<header.size(); i++) { |
- double[] vals = new double[filtered.size()]; |
- for (int j=0; j<filtered.size(); j++) { |
- vals[j] = (double) filtered.get(j).get(i); |
- } |
- for (String stat : stats) { |
- String key = header.get(i) + "_" + stat; |
- if ("min".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.min(vals)); |
- if ("max".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.max(vals)); |
- if ("avg".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.mean(vals)); |
- if ("stdDevPop".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.stddev(vals)); |
+ if (compute_stats_local) { |
+ for (List<Object> objList: filtered) { |
+ for (int i=1; i<header.size(); i++) { |
+ double[] vals = new double[filtered.size()]; |
+ for (int j=0; j<filtered.size(); j++) { |
+ vals[j] = (double) filtered.get(j).get(i); |
+ } |
+ for (String stat : stats) { |
+ String key = header.get(i) + "_" + stat; |
+ if ("min".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.min(vals)); |
+ if ("max".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.max(vals)); |
+ if ("avg".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.mean(vals)); |
+ if ("stdDevPop".equals(stat)) statResultLocal.put(key, oms3.util.Statistics.stddev(vals)); |
+ } |
} |
} |
} |
@@ -340,6 +345,6 @@ |
+ " ]\n" |
+ " }"); |
String search_id = null; |
- timeseries.run("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll", searchFeature, search_id, "2014-04-04", "2014-05-08", false, true); |
+ timeseries.run("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll", searchFeature, search_id, "2014-04-04", "2014-05-08", false, true, false); |
} |
} |