DurationCurve_V1_0.java [src/java/m/cfa] Revision: 6efa097d82c340adb6e5707386c221a404c4eaa5  Date: Tue Aug 05 09:08:26 MDT 2014
package m.cfa;

import cfa.guiDC_Model;
import csip.AbstractModelService;
import java.util.Map;
import java.util.concurrent.Callable;
import javax.ws.rs.Path;
import oms3.annotations.Description;
import oms3.annotations.Name;
import oms3.annotations.VersionInfo;
import org.codehaus.jettison.json.*;
import csip.utils.JSONUtils;
import csip.utils.Services;
import java.io.File;

@Name("durationcurve")
@Description("durationcurve")
@VersionInfo("1.0")
@Path("m/cfa/durationcurve/1.0")
public class DurationCurve_V1_0 extends AbstractModelService {

    guiDC_Model model = new guiDC_Model();

    @Override
    protected Callable<String> createCallable() throws Exception {
        return new Callable<String>() {
            @Override
            public String call() throws Exception {
                Map<String, JSONObject> m = getParamMap();

                model.setMainFolder(getWorkspaceDir().toString());
                model.setDatabase(m.get("database").getString(VALUE));
                model.setOrganizationName(m.get("org").getString(VALUE));
                model.setStationID(m.get("station_id").getString(VALUE));
                model.setStationName(m.get("station_name").getString(VALUE));
                model.setModelType(m.get("model_type").getString(VALUE));
                model.setWaterQualityTest(m.get("wq_test").getString(VALUE));
                model.setWaterQualityTarget(m.get("wq_target").getDouble(VALUE));
                model.setBeginDate(m.get("begin_date").getString(VALUE));
                model.setEndDate(m.get("end_date").getString(VALUE));
                model.setSeasonBegin(m.get("season_begin").getString(VALUE));
                model.setSeasonEnd(m.get("season_end").getString(VALUE));
                model.setHighPercentile(m.get("highPercentile").getDouble(VALUE));
                model.setLowPercentile(m.get("lowPercentile").getDouble(VALUE));
                model.setMQNperiod(m.get("mqn_period").getString(VALUE));
                model.setUserData(m.get("user_data").getString(VALUE));
                model.setMergeDatasets(m.get("merge_datasets").getBoolean(VALUE));
                model.setMergeMethod(m.get("merge_method").getString(VALUE));
                
                model.run();
                return EXEC_OK;
            }
        };
    }

    @Override
    public File[] postprocess() throws Exception {
        return Services.toFiles(model.getGraph(),
                                model.getDurationCurve_results().getName(),
                                model.getFlowStatistics_summary().getName(),
                                //Below are the result graph files for use by JHighCharts on eRAMS for duplicating the above graphs
                                model.getDCgraphOutput().getName());
    }

    @Override
    protected JSONArray createResults() throws Exception {
        JSONArray result = new JSONArray();
        result.put(JSONUtils.data("flow_len", model.getFlowLen()));
        result.put(JSONUtils.data("wq_len", model.getWQLen()));
        result.put(JSONUtils.data("wq_units", model.getWQUnits()));
        result.put(JSONUtils.data("start", model.getStart()));
        result.put(JSONUtils.data("end", model.getEnd()));
        result.put(JSONUtils.data("duration_curve_summary", model.getSummaryParagraph()));
        result.put(JSONUtils.data("duration_curve_table", model.getSummaryTable()));
        result.put(JSONUtils.data("data_source", model.getDataSource()));
        result.put(JSONUtils.data("mqn_val", model.getMQNval()));
        result.put(JSONUtils.data("low_flow_error_message", model.getLowFlowErrorMessage()));
        result.put(JSONUtils.data("graph", model.getGraph()));
        result.put(JSONUtils.data("result_file", model.getDurationCurve_results().getName()));
        result.put(JSONUtils.data("flow_statistics_summary",model.getFlowStatistics_summary().getName()));
        
        //Get result files for JSHighCharts
        String graphDataFiles = model.getDCgraphOutput().getName();
        result.put(JSONUtils.data("graph_data_files", graphDataFiles));
        return result;
    }

}