LOADEST_V1_0.java [src/java/m/cfa] Revision: a4cafa17609dccf465be70c05ea2c0eb461c7bb8  Date: Fri Jun 06 11:22:44 MDT 2014
package m.cfa;

import cfa.guiLOADEST_Model;
import java.util.Map;
import java.util.concurrent.Callable;
import javax.ws.rs.Path;
import csip.AbstractModelService;
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("loadest")
@Description("loadest")
@VersionInfo("1.0")
@Path("m/cfa/loadest/1.0")
public class LOADEST_V1_0 extends AbstractModelService {

    guiLOADEST_Model model = new guiLOADEST_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.setOrganizationName(m.get("org").getString(VALUE));
                model.setStationName(m.get("station_name").getString(VALUE));
                model.setStationID(m.get("station_id").getString(VALUE));
                model.setWQtest(m.get("wq_test").getString(VALUE));
                model.setPTOPT(m.get("ptopt").getInt(VALUE));
                model.setSEOPT(m.get("seopt").getInt(VALUE));
                model.setLDOPT(m.get("ldopt").getInt(VALUE));
                model.setmodelNumber(m.get("modelnumber").getInt(VALUE));
                model.setPBMON(m.get("pbmon").getInt(VALUE));
                model.setPEMON(m.get("pemon").getInt(VALUE));
                model.setULFLAG(m.get("ulflag").getInt(VALUE));
                model.setBeginDate(m.get("begin_date").getString(VALUE));
                model.setEndDate(m.get("end_date").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(//Results files needed for JavaScript graphing with JHighCharts
                             model.getDailyTimeseries().getName(),
                             model.getDailyBoxplot().getName(),
                             model.getMonthlyTimeseries().getName(),
                             model.getMonthlyBoxplot().getName(),
                             model.getYearlyTimeseries().getName(),
                             model.getYearlyBoxplot().getName(),
                             //Graphs no longer handled with Java
//                             model.getDailyGraph(),
//                             model.getDailyBoxplotGraph(),
//                             model.getMonthlyGraph(),
//                             model.getMonthlyBoxplotGraph(),
//                             model.getYearlyGraph(),
//                             model.getYearlyBoxplotGraph(),
                             //Results files desired by the user as output of the model
                             model.getOutputResult1().getName(),
                             model.getOutputResult2().getName(),
                             model.getOutputResult3().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("daily_graph", model.getDailyGraph()));
//        result.put(JSONUtils.data("daily_boxplot", model.getDailyBoxplotGraph()));
        result.put(JSONUtils.data("daily_max", model.getDailyMax()));
        result.put(JSONUtils.data("daily_min", model.getDailyMin()));
        result.put(JSONUtils.data("daily_upper_quartile", model.getDailyUpperQuartile()));
        result.put(JSONUtils.data("daily_lower_quartile", model.getDailyLowerQuartile()));
        result.put(JSONUtils.data("daily_median", model.getDailyMedian()));
        result.put(JSONUtils.data("daily_mean", model.getDailyMean()));
        result.put(JSONUtils.data("daily_standard_deviation", model.getDailyStandardDeviation()));
        
//        result.put(JSONUtils.data("monthly_graph", model.getMonthlyGraph()));
//        result.put(JSONUtils.data("monthly_boxplot", model.getMonthlyBoxplotGraph()));
        result.put(JSONUtils.data("monthly_max", model.getMonthlyMax()));
        result.put(JSONUtils.data("monthly_min", model.getMonthlyMin()));
        result.put(JSONUtils.data("monthly_upper_quartile", model.getMonthlyUpperQuartile()));
        result.put(JSONUtils.data("monthly_lower_quartile", model.getMonthlyLowerQuartile()));
        result.put(JSONUtils.data("monthly_median", model.getMonthlyMedian()));
        result.put(JSONUtils.data("monthly_mean", model.getMonthlyMean()));
        result.put(JSONUtils.data("monthly_standard_deviation", model.getMonthlyStandardDeviation()));
        
//        result.put(JSONUtils.data("yearly_graph", model.getYearlyGraph()));
//        result.put(JSONUtils.data("yearly_boxplot", model.getYearlyBoxplotGraph()));
        result.put(JSONUtils.data("yearly_max", model.getYearlyMax()));
        result.put(JSONUtils.data("yearly_min", model.getYearlyMin()));
        result.put(JSONUtils.data("yearly_upper_quartile", model.getYearlyUpperQuartile()));
        result.put(JSONUtils.data("yearly_lower_quartile", model.getYearlyLowerQuartile()));
        result.put(JSONUtils.data("yearly_median", model.getYearlyMedian()));
        result.put(JSONUtils.data("yearly_mean", model.getYearlyMean()));
        result.put(JSONUtils.data("yearly_standard_deviation", model.getYearlyStandardDeviation()));
        
        String graphDataFiles = model.getDailyTimeseries().getName() + "|" +  
                      model.getDailyBoxplot().getName() + "|" + 
                      model.getMonthlyTimeseries().getName() + "|" + 
                      model.getMonthlyBoxplot().getName() + "|" + 
                      model.getYearlyTimeseries().getName() + "|" + 
                      model.getYearlyBoxplot().getName();
        result.put(JSONUtils.data("graph_data_files", graphDataFiles));
        
//        result.put(JSONUtils.data("summaryFile", model.getOutputSummary().getName()));
        result.put(JSONUtils.data("user_resultFile1", model.getOutputResult1().getName()));
        result.put(JSONUtils.data("user_resultFile2", model.getOutputResult2().getName()));
        result.put(JSONUtils.data("user_resultFile3", model.getOutputResult3().getName()));
        return result;
    }

}