V1_0.java [src/java/m/cfa/loadest] Revision: 584e7fe964a63c82a57c1c2693e9bb6fadc00272  Date: Thu Feb 04 15:37:35 MST 2016
package m.cfa.loadest;

import csip.Executable;
import csip.ModelDataService;
import csip.annotations.Resource;
import csip.annotations.ResourceType;
import javax.ws.rs.Path;
import oms3.annotations.Description;
import oms3.annotations.Name;
import oms3.annotations.VersionInfo;

@Name("loadest")
@Description("loadest")
@VersionInfo("1.0")
@Path("m/cfa/loadest/1.0")
@Resource(file="/bin/win-x86/loadest.exe", wine=true, id="ld", type=ResourceType.EXECUTABLE)
public class V1_0 extends ModelDataService {

    guiLOADEST_Model model = new guiLOADEST_Model();

    @Override
    protected String process() throws Exception {
        model.setMainFolder(getWorkspaceDir().toString());
        model.setDatabase(getStringParam("database"));
        model.setOrganizationName(getStringParam("org"));
        model.setStationID(getStringParam("station_id"));
        model.setStationName(getStringParam("station_name"));
        model.setWQtest(getStringParam("wq_test"));
        model.setPTOPT(getIntParam("ptopt"));
        model.setSEOPT(getIntParam("seopt"));
        model.setLDOPT(getIntParam("ldopt"));
        model.setmodelNumber(getIntParam("modelnumber"));
        model.setPBMON(getIntParam("pbmon"));
        model.setPEMON(getIntParam("pemon"));
        model.setULFLAG(getIntParam("ulflag"));
        model.setBeginDate(getStringParam("begin_date"));
        model.setEndDate(getStringParam("end_date"));
        model.setUseSTORETretrieval(getBooleanParam("useSTORETretrieval"));
        model.setSTORETdata(getStringParam("STORETdata"));
        model.setMergeDatasets(getBooleanParam("merge_datasets"));
        model.setMergeMethod(getStringParam("merge_method"));
        model.setUserData(getStringParam("user_data"));

        Executable e = getResourceExe("ld");  // looking up the resource by id.
        model.run(e);
        return EXEC_OK;
    }
    
    @Override
    protected void postProcess() throws Exception {
        // files
        putResult(model.getDailyTimeseries(),
                  model.getDailyBoxplot(),
                  model.getMonthlyTimeseries(),
                  model.getMonthlyBoxplot(),
                  model.getYearlyTimeseries(),
                  model.getYearlyBoxplot(),
                  //Graphs no longer handled with Java
                  //new File(model.getDailyGraph()),
                  //new File(model.getDailyBoxplotGraph()),
                  //new File(model.getMonthlyGraph()),
                  //new File(model.getMonthlyBoxplotGraph()),
                  //new File(model.getYearlyGraph()),
                  //new File(model.getYearlyBoxplotGraph()),
                  //Results files desired by the user as output of the model
                  model.getOutputResult1(),
                  model.getOutputResult2(),
                  model.getOutputResult3());

        // values
        putResult("flow_len", model.getFlowLen());
        putResult("wq_len", model.getWQLen());
        putResult("wq_units", model.getWQUnits());
        putResult("start", model.getStart());
        putResult("end", model.getEnd());
        putResult("data_source", model.getDataSource());
        //Daily Data
        putResult("daily_max", model.getDailyMax(), null, "cfs");
        putResult("daily_min", model.getDailyMin(), null, "cfs");
        putResult("daily_upper_quartile", model.getDailyUpperQuartile(), null, "cfs");
        putResult("daily_lower_quartile", model.getDailyLowerQuartile(), null, "cfs");
        putResult("daily_median", model.getDailyMedian(), null, "cfs");
        putResult("daily_mean", model.getDailyMean(), null, "cfs");
        putResult("daily_standard_deviation", model.getDailyStandardDeviation(), null, "cfs");
        //Monthly Data
        putResult("monthly_max", model.getMonthlyMax(), null, "cfs");
        putResult("monthly_min", model.getMonthlyMin(), null, "cfs");
        putResult("monthly_upper_quartile", model.getMonthlyUpperQuartile(), null, "cfs");
        putResult("monthly_lower_quartile", model.getMonthlyLowerQuartile(), null, "cfs");
        putResult("monthly_median", model.getMonthlyMedian(), null, "cfs");
        putResult("monthly_mean", model.getMonthlyMean(), null, "cfs");
        putResult("monthly_standard_deviation", model.getMonthlyStandardDeviation(), null, "cfs");
        //Yearly Data
        putResult("yearly_max", model.getYearlyMax(), null, "cfs");
        putResult("yearly_min", model.getYearlyMin(), null, "cfs");
        putResult("yearly_upper_quartile", model.getYearlyUpperQuartile(), null, "cfs");
        putResult("yearly_lower_quartile", model.getYearlyLowerQuartile(), null, "cfs");
        putResult("yearly_median", model.getYearlyMedian(), null, "cfs");
        putResult("yearly_mean", model.getYearlyMean(), null, "cfs");
        putResult("yearly_standard_deviation", model.getYearlyStandardDeviation(), null, "cfs");
        //Get other results
        putResult("user_resultFile1", model.getOutputResult1().getName());
        putResult("user_resultFile2", model.getOutputResult2().getName());
        putResult("user_resultFile3", model.getOutputResult3().getName());
        
        //Get result files for JSHighCharts
        String graphDataFiles = model.getDailyTimeseries().getName() + "|" +  
                      model.getDailyBoxplot().getName() + "|" + 
                      model.getMonthlyTimeseries().getName() + "|" + 
                      model.getMonthlyBoxplot().getName() + "|" + 
                      model.getYearlyTimeseries().getName() + "|" + 
                      model.getYearlyBoxplot().getName();
        putResult("graph_data_files", graphDataFiles);
    }
}