V1_0.java [src/java/m/cfa/flood] Revision: dc6ae1f64daf0fe7cbaba1d0e799a57738d47cfb Date: Thu Feb 29 11:40:24 MST 2024
package m.cfa.flood;
import csip.ModelDataService;
import csip.api.server.PayloadParameter;
import csip.api.server.PayloadResults;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.VersionInfo;
import java.io.File;
import javax.ws.rs.Path;
import org.apache.commons.io.FileUtils;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
@Name("flood")
@Description("Time Series: Flood Frequency Analysis")
@VersionInfo("1.0")
@Path("m/cfa/flood/1.0")
public class V1_0 extends ModelDataService {
guiFlood_Model model = new guiFlood_Model();
@Override
protected void preProcess() throws Exception {
model.setDirectory(workspace().getDir().toString());
PayloadParameter inputPayload = parameter();
model.setDatabase(inputPayload.getString("database"));
model.setOrganizationID(inputPayload.getString("org_id"));
model.setStationId(inputPayload.getString("station_id"));
model.setStationName(inputPayload.getString("station_name"));
model.setAnalysisType(inputPayload.getString("analysis_type", "b17"));
model.setStartDate(inputPayload.getString("begin_date", ""));
model.setEndDate(inputPayload.getString("end_date", ""));
model.setSkewness(inputPayload.getDouble("skewness"));
model.setMeanSquareError(inputPayload.getDouble("mean_square_error"));
model.setShowLargeFloods(inputPayload.getBoolean("show_large_floods", false));
model.setPlotType(inputPayload.getBoolean("plot_type", true));
model.setPlotReference(inputPayload.getBoolean("plot_ref", true));
model.setMergeDatasets(inputPayload.getBoolean("merge_datasets", false));
model.setMergeMethod(inputPayload.getString("merge_method", "user"));
model.setUserData(inputPayload.getString("user_data", ""));
}
@Override
protected void doProcess() throws Exception {
model.run();
}
@Override
protected void postProcess() throws Exception {
PayloadResults resultPayload = results();
// files
File wd = workspace().getDir();
resultPayload.put(new File(wd, model.getGraph()));
// values
resultPayload.put("len", model.getLen());
resultPayload.put("start", model.getStart());
resultPayload.put("end", model.getEnd());
resultPayload.put("data_source", model.getDataSource());
resultPayload.put("skewErrorMessage", model.getSkewErrorMessage());
String output = FileUtils.readFileToString(model.getOutputWeightedGenSkew(), "UTF-8");
resultPayload.put("output", output);
resultPayload.put("weighted_generalized_skew", model.getWeightedGenSkew());
String output_stationSkew = FileUtils.readFileToString(model.getOutputStationSkew(), "UTF-8");
resultPayload.put("output_station_skew", output_stationSkew);
resultPayload.put("station_skew", model.getStationSkew());
resultPayload.put("graph", model.getGraph());
//Arrays
resultPayload.put("lowOutliers_station_skew", model.getLowOutliersStationSkew());
resultPayload.put("highOutliers_station_skew", model.getHighOutliersStationSkew());
resultPayload.put("lowOutliers_weighted_generalized_skew", model.getLowOutliersWeightedGenSkew());
resultPayload.put("highOutliers_weighted_generalized_skew", model.getHighOutliersWeightedGenSkew());
}
}