V1_0.java [src/java/m/cfa/loadest] Revision: default Date:
package m.cfa.loadest;
import csip.api.server.Executable;
import csip.ModelDataService;
import csip.api.server.PayloadParameter;
import csip.api.server.PayloadResults;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.Resource;
import csip.annotations.ResourceType;
import csip.annotations.VersionInfo;
import javax.ws.rs.Path;
@Name("loadest")
@Description("Time Series: Load Estimation Analysis (LOADEST)")
@VersionInfo("1.0")
@Path("m/cfa/loadest/1.0")
@Resource(file="/bin/win-x86/loadest.exe", wine=true, id="ld", type=ResourceType.EXECUTABLE)
public class V1_0 extends ModelDataService {
guiLOADEST_Model model = new guiLOADEST_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.setWQtest(inputPayload.getString("wq_test"));
model.setPTOPT(inputPayload.getInt("ptopt"));
model.setSEOPT(inputPayload.getInt("seopt"));
model.setLDOPT(inputPayload.getInt("ldopt"));
model.setmodelNumber(inputPayload.getInt("modelnumber"));
model.setPBMON(inputPayload.getInt("pbmon"));
model.setPEMON(inputPayload.getInt("pemon"));
model.setULFLAG(inputPayload.getInt("ulflag"));
model.setStartDate(inputPayload.getString("begin_date", ""));
model.setEndDate(inputPayload.getString("end_date", ""));
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 {
Executable e = resources().getExe("ld"); // looking up the resource by id.
model.run(e);
}
@Override
protected void postProcess() throws Exception {
PayloadResults resultPayload = results();
// files
resultPayload.put(model.getDailyTimeseries(),
model.getDailyBoxplot(),
model.getMonthlyTimeseries(),
model.getMonthlyBoxplot(),
model.getYearlyTimeseries(),
model.getYearlyBoxplot(),
//Graphs no longer handled with Java
//new File(model.getDailyGraph()),
//new File(model.getDailyBoxplotGraph()),
//new File(model.getMonthlyGraph()),
//new File(model.getMonthlyBoxplotGraph()),
//new File(model.getYearlyGraph()),
//new File(model.getYearlyBoxplotGraph()),
//Results files desired by the user as output of the model
model.getOutputResult1(),
model.getOutputResult2(),
model.getOutputResult3());
// values
resultPayload.put("flow_len", model.getFlowLen());
resultPayload.put("wq_len", model.getWQLen());
resultPayload.put("wq_units", model.getWQUnits());
resultPayload.put("start", model.getStart());
resultPayload.put("end", model.getEnd());
resultPayload.put("data_source", model.getDataSource());
//Daily Data
resultPayload.put("daily_max", model.getDailyMax(), null, "cfs");
resultPayload.put("daily_min", model.getDailyMin(), null, "cfs");
resultPayload.put("daily_upper_quartile", model.getDailyUpperQuartile(), null, "cfs");
resultPayload.put("daily_lower_quartile", model.getDailyLowerQuartile(), null, "cfs");
resultPayload.put("daily_median", model.getDailyMedian(), null, "cfs");
resultPayload.put("daily_mean", model.getDailyMean(), null, "cfs");
resultPayload.put("daily_standard_deviation", model.getDailyStandardDeviation(), null, "cfs");
//Monthly Data
resultPayload.put("monthly_max", model.getMonthlyMax(), null, "cfs");
resultPayload.put("monthly_min", model.getMonthlyMin(), null, "cfs");
resultPayload.put("monthly_upper_quartile", model.getMonthlyUpperQuartile(), null, "cfs");
resultPayload.put("monthly_lower_quartile", model.getMonthlyLowerQuartile(), null, "cfs");
resultPayload.put("monthly_median", model.getMonthlyMedian(), null, "cfs");
resultPayload.put("monthly_mean", model.getMonthlyMean(), null, "cfs");
resultPayload.put("monthly_standard_deviation", model.getMonthlyStandardDeviation(), null, "cfs");
//Yearly Data
resultPayload.put("yearly_max", model.getYearlyMax(), null, "cfs");
resultPayload.put("yearly_min", model.getYearlyMin(), null, "cfs");
resultPayload.put("yearly_upper_quartile", model.getYearlyUpperQuartile(), null, "cfs");
resultPayload.put("yearly_lower_quartile", model.getYearlyLowerQuartile(), null, "cfs");
resultPayload.put("yearly_median", model.getYearlyMedian(), null, "cfs");
resultPayload.put("yearly_mean", model.getYearlyMean(), null, "cfs");
resultPayload.put("yearly_standard_deviation", model.getYearlyStandardDeviation(), null, "cfs");
//Get other results
resultPayload.put("user_resultFile1", model.getOutputResult1().getName());
resultPayload.put("user_resultFile2", model.getOutputResult2().getName());
resultPayload.put("user_resultFile3", model.getOutputResult3().getName());
//Get result files for JSHighCharts
String graphDataFiles = model.getDailyTimeseries().getName() + "|" +
model.getDailyBoxplot().getName() + "|" +
model.getMonthlyTimeseries().getName() + "|" +
model.getMonthlyBoxplot().getName() + "|" +
model.getYearlyTimeseries().getName() + "|" +
model.getYearlyBoxplot().getName();
resultPayload.put("graph_data_files", graphDataFiles);
}
}