Timeseries_V1_0.java [src/java/m/cfa] Revision: 0675c0a3967d25460ed0558ab20abbd74dd135aa Date: Thu Jun 05 11:55:36 MDT 2014
package m.cfa;
import cfa.guiTimeseries_Model;
import java.util.Map;
import java.util.concurrent.Callable;
import javax.ws.rs.Path;
import oms3.annotations.Description;
import oms3.annotations.Name;
import oms3.annotations.VersionInfo;
import org.apache.commons.io.FileUtils;
import org.codehaus.jettison.json.*;
import csip.utils.JSONUtils;
import csip.AbstractModelService;
import static csip.AbstractModelService.VALUE;
import csip.utils.Services;
import java.io.File;
@Name("timeseries")
@Description("timeseries")
@VersionInfo("1.0")
@Path("m/cfa/timeseries/1.0")
public class Timeseries_V1_0 extends AbstractModelService {
guiTimeseries_Model model = new guiTimeseries_Model();
@Override
protected Callable<String> createCallable() throws Exception {
return new Callable<String>() {
@Override
public String call() throws Exception {
Map<String, JSONObject> m = getParamMap();
model.setMainFolder(getWorkspaceDir().toString());
model.setOrganizationName(m.get("org").getString(VALUE));
model.setStationID(m.get("station_id").getString(VALUE));
model.setStationName(m.get("station_name").getString(VALUE));
model.setWQtest(m.get("wq_test").getString(VALUE));
model.setBeginDate(m.get("begin_date").getString(VALUE));
model.setEndDate(m.get("end_date").getString(VALUE));
model.setTimeStep(m.get("time_step").getString(VALUE));
model.setMethod(m.get("method").getString(VALUE));
model.setNumberOfBins(m.get("numBins").getInt(VALUE));
model.setPeriod1Begin(m.get("period1_begin").getString(VALUE));
model.setPeriod1End(m.get("period1_end").getString(VALUE));
model.setPeriod2Begin(m.get("period2_begin").getString(VALUE));
model.setPeriod2End(m.get("period2_end").getString(VALUE));
model.setPeriod3Begin(m.get("period3_begin").getString(VALUE));
model.setPeriod3End(m.get("period3_end").getString(VALUE));
model.setMedianTF(m.get("medianTF").getBoolean(VALUE));
model.setUserData(m.get("user_data").getString(VALUE));
model.setMergeDatasets(m.get("merge_datasets").getBoolean(VALUE));
model.setMergeMethod(m.get("merge_method").getString(VALUE));
model.run();
return EXEC_OK;
}
};
}
@Override
public File[] postprocess() throws Exception {
return Services.toFiles(model.getGraph(), model.getBoxplot(),model.getHistogram(),
model.getMonthlyGraph(),model.getMonthlyBoxplot(),model.getCDF());
}
@Override
protected JSONArray createResults() throws Exception {
String output = FileUtils.readFileToString(model.getParagraph());
JSONArray result = new JSONArray();
result.put(JSONUtils.data("len", model.getLen()));
result.put(JSONUtils.data("start", model.getStart()));
result.put(JSONUtils.data("end", model.getEnd()));
result.put(JSONUtils.data("units", model.getUnits()));
//Get all data results
result.put(JSONUtils.data("max", model.getMax()));
result.put(JSONUtils.data("min", model.getMin()));
result.put(JSONUtils.data("upperQuartile", model.getUpperQuartile()));
result.put(JSONUtils.data("lowerQuartile", model.getLowerQuartile()));
result.put(JSONUtils.data("median", model.getMedian()));
result.put(JSONUtils.data("mean", model.getMean()));
result.put(JSONUtils.data("standardDeviation", model.getStandardDeviation()));
result.put(JSONUtils.data("variance", model.getVariance()));
result.put(JSONUtils.data("skewness", model.getSkewness()));
result.put(JSONUtils.data("coefficientOfVariation", model.getCoefficientOfVariation()));
//Get Period 1 results
result.put(JSONUtils.data("len_period1", model.getLen_period1()));
result.put(JSONUtils.data("max_period1", model.getMax_period1()));
result.put(JSONUtils.data("min_period1", model.getMin_period1()));
result.put(JSONUtils.data("upperQuartile_period1", model.getUpperQuartile_period1()));
result.put(JSONUtils.data("lowerQuartile_period1", model.getLowerQuartile_period1()));
result.put(JSONUtils.data("median_period1", model.getMedian_period1()));
result.put(JSONUtils.data("mean_period1", model.getMean_period1()));
result.put(JSONUtils.data("standardDeviation_period1", model.getStandardDeviation_period1()));
result.put(JSONUtils.data("variance_period1", model.getVariance_period1()));
result.put(JSONUtils.data("coefficientOfVariation_period1", model.getCoefficientOfVariation_period1()));
result.put(JSONUtils.data("skewness_period1", model.getSkewness_period1()));
//Get Period 2 results
result.put(JSONUtils.data("len_period2", model.getLen_period2()));
result.put(JSONUtils.data("max_period2", model.getMax_period2()));
result.put(JSONUtils.data("min_period2", model.getMin_period2()));
result.put(JSONUtils.data("upperQuartile_period2", model.getUpperQuartile_period2()));
result.put(JSONUtils.data("lowerQuartile_period2", model.getLowerQuartile_period2()));
result.put(JSONUtils.data("median_period2", model.getMedian_period2()));
result.put(JSONUtils.data("mean_period2", model.getMean_period2()));
result.put(JSONUtils.data("standardDeviation_period2", model.getStandardDeviation_period2()));
result.put(JSONUtils.data("variance_period2", model.getVariance_period2()));
result.put(JSONUtils.data("coefficientOfVariation_period2", model.getCoefficientOfVariation_period2()));
result.put(JSONUtils.data("skewness_period2", model.getSkewness_period2()));
//Get Period 3 results
result.put(JSONUtils.data("len_period3", model.getLen_period3()));
result.put(JSONUtils.data("max_period3", model.getMax_period3()));
result.put(JSONUtils.data("min_period3", model.getMin_period3()));
result.put(JSONUtils.data("upperQuartile_period3", model.getUpperQuartile_period3()));
result.put(JSONUtils.data("lowerQuartile_period3", model.getLowerQuartile_period3()));
result.put(JSONUtils.data("median_period3", model.getMedian_period3()));
result.put(JSONUtils.data("mean_period3", model.getMean_period3()));
result.put(JSONUtils.data("standardDeviation_period3", model.getStandardDeviation_period3()));
result.put(JSONUtils.data("variance_period3", model.getVariance_period3()));
result.put(JSONUtils.data("coefficientOfVariation_period3", model.getCoefficientOfVariation_period3()));
result.put(JSONUtils.data("skewness_period3", model.getSkewness_period3()));
//Get other results
result.put(JSONUtils.data("output", output));
result.put(JSONUtils.data("graph", model.getGraph()));
result.put(JSONUtils.data("boxplot", model.getBoxplot()));
result.put(JSONUtils.data("histogram", model.getHistogram()));
result.put(JSONUtils.data("cdf_graph", model.getCDF()));
result.put(JSONUtils.data("monthlyAverage_graph", model.getMonthlyGraph()));
result.put(JSONUtils.data("monthlyAverage_boxplot", model.getMonthlyBoxplot()));
return result;
}
}