V1_0.java [src/java/m/cfa/baseflow] Revision: e17730f1469a79c99933dd778e05aa78d3cdb062  Date: Fri Feb 12 15:27:46 MST 2016
package m.cfa.baseflow;

import csip.Executable;
import csip.ModelDataService;
import csip.annotations.Resource;
import csip.annotations.ResourceType;
import static csip.annotations.ResourceType.FILE;
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)
@Resource(file = "/python/driver.py", type = FILE, id = "driver")
public class 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.setOrganizationID(getStringParam("org_id"));
        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.setMergeDatasets(getBooleanParam("merge_datasets"));
        model.setMergeMethod(getStringParam("merge_method"));
        model.setUserData(getStringParam("user_data"));

        Executable e = getResourceExe("bf");  // looking up the resource by id.
        File f = getResourceFile("driver");
        model.run(e, f);
        return EXEC_OK;
    }

    @Override
    protected void postProcess() throws Exception {
        // files
        File wd = getWorkspaceDir();
        putResult(new File(wd, 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);
    }
}