V1_0.java [src/java/m/cfa/regionalfdc] Revision: default  Date:
package m.cfa.regionalfdc;

import csip.ModelDataService;
import csip.api.server.PayloadParameter;
import csip.api.server.PayloadResults;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.VersionInfo;
import java.io.File;
import javax.ws.rs.Path;

@Name("regionalfdc")
@Description("Time Series: Regional Flow Duration Curve Calculation")
@VersionInfo("1.0")
@Path("m/cfa/regionalfdc/1.0")
public class V1_0 extends ModelDataService {

    guiRegionalFDC_Model model = new guiRegionalFDC_Model();
    
    @Override
    protected void preProcess() throws Exception {
        model.setDirectory(workspace().getDir().toString());
        
        PayloadParameter inputPayload = parameter();
        model.setDatabases(inputPayload.getString("databases"));
        model.setStationIds(inputPayload.getString("station_ids"));
        model.setStationNames(inputPayload.getString("station_names"));
        model.setNormalizingMetricName(inputPayload.getString("normalizing_metric_name"));
        model.setNormalizingMetrics(inputPayload.getString("normalizing_metrics"));
        model.setFlowDurationCurves(inputPayload.getString("flow_duration_curves"));
    }

    @Override
    protected void doProcess() throws Exception {
        model.run();
    }
    
    @Override
    protected void postProcess() throws Exception {
        PayloadResults resultPayload = results();
        // files
        File wd = workspace().getDir();
        resultPayload.put(new File(wd, model.getGraph()),
                  model.getRegionalFDC_results(),
                  //Below are the result graph files for use by JHighCharts on eRAMS for duplicating the above graphs
                  model.getRegionalFDCgraphOutput());

        // values
        resultPayload.put("summary_table", model.getSummaryTable());
        resultPayload.put("regional_flow_duration_curve", model.getRegionalFDC());
        resultPayload.put("units", model.getUnits());
        resultPayload.put("graph", model.getGraph());
        resultPayload.put("result_file", model.getRegionalFDC_results().getName());
        
        //Get result files for JSHighCharts
        String graphDataFiles = model.getRegionalFDCgraphOutput().getName();
        resultPayload.put("graph_data_files", graphDataFiles);
    }
}