V1_0.java [src/java/m/cfa/flood] Revision: 6d7e44fcd425d4c5a66c32d80df93a5314cc2fb3  Date: Fri Aug 31 14:50:33 MDT 2018
package m.cfa.flood;

import csip.ModelDataService;
import csip.annotations.Resource;
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("flood")
@Description("Time Series: Flood Frequency Analysis")
@VersionInfo("1.0")
@Path("m/cfa/flood/1.0")
@Resource(file = "/python/driver.py", type = FILE, id = "driver")
public class V1_0 extends ModelDataService {

    guiFlood_Model model = new guiFlood_Model();

    @Override
    protected void doProcess() throws Exception {
        model.setDirectory(getWorkspaceDir().toString());
        model.setDatabase(getStringParam("database"));
        model.setOrganizationID(getStringParam("org_id"));
        model.setStationID(getStringParam("station_id"));
        model.setStationName(getStringParam("station_name"));
        model.setAnalysisType(getStringParam("analysis_type"));
        model.setBeginDate(getStringParam("begin_date"));
        model.setEndDate(getStringParam("end_date"));
        model.setSkewness(getDoubleParam("skewness"));
        model.setMeanSquareError(getDoubleParam("mean_square_error"));
        model.setShowLargeFloods(getBooleanParam("show_large_floods"));
        model.setPlotType(getBooleanParam("plot_type"));
        model.setPlotReference(getBooleanParam("plot_ref"));
        model.setMergeDatasets(getBooleanParam("merge_datasets"));
        model.setMergeMethod(getStringParam("merge_method"));
        model.setUserData(getStringParam("user_data"));

        File f = getResourceFile("driver");
        model.run(f);
    }

    @Override
    protected void postProcess() throws Exception {
        // files
        File wd = getWorkspaceDir();
        putResult(new File(wd, model.getGraph()));

        // values
        putResult("len", model.getLen());
        putResult("start", model.getStart());
        putResult("end", model.getEnd());
        putResult("data_source", model.getDataSource());
        putResult("skewErrorMessage", model.getSkewErrorMessage());
        String output = FileUtils.readFileToString(model.getOutput());
        putResult("output", output);
        putResult("graph", model.getGraph());
    }
}