V1_0.java [src/java/m/cfa/durationcurve] Revision: fae2c38c5ab71042ad506de8b970cded23828934  Date: Tue Nov 20 11:38:25 MST 2018
package m.cfa.durationcurve;

import csip.ModelDataService;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.Resource;
import csip.annotations.VersionInfo;
import static csip.annotations.ResourceType.FILE;
import java.io.File;
import javax.ws.rs.Path;

@Name("durationcurve")
@Description("Time Series: Flow and Load Duration Curve Analysis")
@VersionInfo("1.0")
@Path("m/cfa/durationcurve/1.0")
@Resource(file = "/python/driver.py", type = FILE, id = "driver")
public class V1_0 extends ModelDataService {

    guiDC_Model model = new guiDC_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.setWaterQualityTest(getStringParam("wq_test"));
        model.setWaterQualityTarget(getDoubleParam("wq_target"));
        model.setStartDate(getStringParam("begin_date"));
        model.setEndDate(getStringParam("end_date"));
        model.setSeasonBegin(getStringParam("season_begin"));
        model.setSeasonEnd(getStringParam("season_end"));
        model.setSeasonalAnalysisOnlyTF(getBooleanParam("seasonal_only"));
        model.setPeriod1Begin(getStringParam("period1_begin"));
        model.setPeriod1End(getStringParam("period1_end"));
        model.setPeriod2Begin(getStringParam("period2_begin"));
        model.setPeriod2End(getStringParam("period2_end"));
        model.setPeriod3Begin(getStringParam("period3_begin"));
        model.setPeriod3End(getStringParam("period3_end"));
        model.setHighPercentile(getDoubleParam("highPercentile"));
        model.setLowPercentile(getDoubleParam("lowPercentile"));
        model.setShowMonthlyStatsTF(getBooleanParam("showMonthlyStatsTF"));
        model.setCalcFlowStatisticsFileTF(getBooleanParam("calcFlowStatisticsFileTF"));
        model.setMQNperiod(getStringParam("mqn_period"));
        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();
        if(model.getCalcFlowStatisticsFileTF()){
            putResult(new File(wd, model.getGraph()),
                      model.getDurationCurve_results(),
                      model.getFlowStatistics_summary(),
                      //Below are the result graph files for use by JHighCharts on eRAMS for duplicating the above graphs
                      model.getDCgraphOutput());
        }else{
            putResult(new File(wd, model.getGraph()),
                      model.getDurationCurve_results(),
                      //Below are the result graph files for use by JHighCharts on eRAMS for duplicating the above graphs
                      model.getDCgraphOutput());
        }

        // values
        putResult("flow_len", model.getFlowLen());
        putResult("flow_median", model.getMedian(), null, "cfs");
        putResult("flow_mean", model.getMean(), null, "cfs");
        putResult("flow_len_period1", model.getFlowLen_period1());
        putResult("flow_len_period2", model.getFlowLen_period2());
        putResult("flow_len_period3", model.getFlowLen_period3());
        putResult("wq_len", model.getWQLen());
        putResult("wq_units", model.getWQUnits());
        putResult("start", model.getStart());
        putResult("end", model.getEnd());
        putResult("duration_curve_summary", model.getSummaryParagraph());
        putResult("duration_curve_table", model.getSummaryTable());
        putResult("data_source", model.getDataSource());
        putResult("mqn_val", model.getMQNval(), null, "cfs");
        putResult("low_flow_error_message", model.getLowFlowErrorMessage());
        putResult("graph", model.getGraph());
        putResult("result_file", model.getDurationCurve_results().getName());
        putResult("flow_statistics_summary",model.getFlowStatistics_summary().getName());
        
        //Get result files for JSHighCharts
        String graphDataFiles = model.getDCgraphOutput().getName();
        putResult("graph_data_files", graphDataFiles);
    }
}