Baseflow_V1_0.java [src/java/m/cfa] Revision: 61747bd3d2ada3544b1ecf1d89c57329dd5bbfd4 Date: Thu Feb 04 13:07:44 MST 2016
package m.cfa;
import cfa.guiBaseflow_Model;
import csip.Executable;
import csip.ModelDataService;
import csip.annotations.Resource;
import csip.annotations.ResourceType;
import java.io.File;
import javax.ws.rs.Path;
import oms3.annotations.Description;
import oms3.annotations.Name;
import oms3.annotations.VersionInfo;
import org.apache.commons.io.FileUtils;
@Name("baseflow")
@Description("baseflow")
@VersionInfo("1.0")
@Path("m/cfa/baseflow/1.0")
@Resource(file="/bin/win-x86/bflow.exe", wine=true, id="bf", type=ResourceType.EXECUTABLE)
public class Baseflow_V1_0 extends ModelDataService {
guiBaseflow_Model model = new guiBaseflow_Model();
@Override
protected String process() throws Exception {
model.setMainFolder(getWorkspaceDir().toString());
model.setDatabase(getStringParam("database"));
model.setOrganizationName(getStringParam("org"));
model.setStationID(getStringParam("station_id"));
model.setStationName(getStringParam("station_name"));
model.setDrainageArea(getDoubleParam("drainage_area"));
model.setModelType(getStringParam("model_type"));
model.setBeginDate(getStringParam("begin_date"));
model.setEndDate(getStringParam("end_date"));
model.setNDMIN(getIntParam("ndmin"));
model.setNDMAX(getIntParam("ndmax"));
model.setUseSTORETretrieval(getBooleanParam("useSTORETretrieval"));
model.setSTORETdata(getStringParam("STORETdata"));
model.setMergeDatasets(getBooleanParam("merge_datasets"));
model.setMergeMethod(getStringParam("merge_method"));
model.setUserData(getStringParam("user_data"));
Executable e = getResourceExe("bf"); // looking up the resource by id.
model.run(e);
return EXEC_OK;
}
@Override
protected void postProcess() throws Exception {
// files
putResult(new File(model.getGraph()),
model.getBaseflow_out(),
model.getTimeseriesOutput());
// values
putResult("len", model.getLen());
putResult("start", model.getStart());
putResult("end", model.getEnd());
putResult("data_source", model.getDataSource());
String baseflowSummary = FileUtils.readFileToString(model.getBaseflow_dat());
putResult("baseflow_summary", baseflowSummary);
putResult("baseflow_results", model.getBaseflow_out().getName());
putResult("graph", model.getGraph());
//Get BFLOW stream flow stats
putResult("streamflow_max", model.getBFLOWstream_Max(), null, "cfs");
putResult("streamflow_min", model.getBFLOWstream_Min(), null, "cfs");
putResult("streamflow_median", model.getBFLOWstream_Median(), null, "cfs");
putResult("streamflow_mean", model.getBFLOWstream_Mean(), null, "cfs");
//Get BFLOW pass 1 stats
putResult("bflowPass1_max", model.getBFLOWpass1_Max(), null, "cfs");
putResult("bflowPass1_min", model.getBFLOWpass1_Min(), null, "cfs");
putResult("bflowPass1_median", model.getBFLOWpass1_Median(), null, "cfs");
putResult("bflowPass1_mean", model.getBFLOWpass1_Mean(), null, "cfs");
//Get BFLOW pass 2 stats
putResult("bflowPass2_max", model.getBFLOWpass2_Max(), null, "cfs");
putResult("bflowPass2_min", model.getBFLOWpass2_Min(), null, "cfs");
putResult("bflowPass2_median", model.getBFLOWpass2_Median(), null, "cfs");
putResult("bflowPass2_mean", model.getBFLOWpass2_Mean(), null, "cfs");
//Get BFLOW pass 3 stats
putResult("bflowPass3_max", model.getBFLOWpass3_Max(), null, "cfs");
putResult("bflowPass3_min", model.getBFLOWpass3_Min(), null, "cfs");
putResult("bflowPass3_median", model.getBFLOWpass3_Median(), null, "cfs");
putResult("bflowPass3_mean", model.getBFLOWpass3_Mean(), null, "cfs");
//Get result files for JSHighCharts
String graphDataFiles = model.getTimeseriesOutput().getName();
putResult("graph_data_files", graphDataFiles);
}
}