Timeseries_V1_0.java [src/java/m/cfa] Revision: 73a821e0732448e37f231a56c9644bff0061ea8b Date: Fri Feb 14 15:16:30 MST 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.ServiceConst;
import csip.AbstractModelService;
@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(ServiceConst.VALUE));
model.setStationID(m.get("station_id").getString(ServiceConst.VALUE));
model.setStationName(m.get("station_name").getString(ServiceConst.VALUE));
model.setWQtest(m.get("wq_test").getString(ServiceConst.VALUE));
model.setBeginDate(m.get("begin_date").getString(ServiceConst.VALUE));
model.setEndDate(m.get("end_date").getString(ServiceConst.VALUE));
model.setTimeStep(m.get("time_step").getString(ServiceConst.VALUE));
model.setMethod(m.get("method").getString(ServiceConst.VALUE));
model.setUserData(m.get("user_data").getString(ServiceConst.VALUE));
model.setMergeDatasets(m.get("merge_datasets").getBoolean(ServiceConst.VALUE));
model.setMergeMethod(m.get("merge_method").getString(ServiceConst.VALUE));
model.run();
return ServiceConst.EXEC_OK;
}
};
}
@Override
public String[] postprocess() throws Exception {
return new String[] {model.getGraph(), model.getBoxplot()};
}
@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()));
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("output", output));
result.put(JSONUtils.data("graph", model.getGraph()));
result.put(JSONUtils.data("boxplot", model.getBoxplot()));
return result;
}
}