Timeseries_V1_0.java [src/java/m/cfa] Revision: 9ba74a12b8cbf35e1447b770cd8365fc0eb5b676  Date: Tue Jan 12 09:20:50 MST 2016
package m.cfa;

import cfa.guiTimeseries_Model;
import csip.ModelDataService;
import java.io.File;
import javax.ws.rs.Path;
import oms3.annotations.Description;
import oms3.annotations.Name;
import oms3.annotations.VersionInfo;

@Name("timeseries")
@Description("timeseries")
@VersionInfo("1.0")
@Path("m/cfa/timeseries/1.0")
public class Timeseries_V1_0 extends ModelDataService {

    guiTimeseries_Model model = new guiTimeseries_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.setBeginDate(getStringParam("begin_date"));
        model.setEndDate(getStringParam("end_date"));
        model.setTimeStep(getStringParam("time_step"));
        model.setMethod(getStringParam("method"));
        model.setNumberOfBins(getIntParam("numBins"));
        model.setLogarithmicHistogramBins(getBooleanParam("logarithmicTF"));
        model.setSeasonBegin(getStringParam("season_begin"));
        model.setSeasonEnd(getStringParam("season_end"));
        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.setMedianTF(getBooleanParam("medianTF"));
        model.setEnvelopeTF(getBooleanParam("envelopeTF"));
        model.setRasterTF(getBooleanParam("rasterTF"));
        model.setRasterLogarithmicBinsTF(getBooleanParam("rasterLogarithmicBinsTF"));
        model.setHighPercentile(getDoubleParam("highPercentile"));
        model.setLowPercentile(getDoubleParam("lowPercentile"));
        model.setShowMonthlyStatsTF(getBooleanParam("showMonthlyStatsTF"));
        model.setCalcFlowStatisticsFileTF(getBooleanParam("calcFlowStatisticsFileTF"));
        model.setCalcCDPHElowflowTF(getBooleanParam("calcCDPHElowflowTF"));
        model.setCDPHE_lowFlowType(getStringParam("CDPHE_lowFlowType"));
        model.setCDPHE_m(getIntParam("CDPHE_m"));
        model.setCDPHE_R(getIntParam("CDPHE_R"));
        model.setCDPHE_waterYearBegin(getStringParam("CDPHE_waterYearBegin"));
        model.setCDPHE_clusterLength(getIntParam("CDPHE_clusterLength"));
        model.setCDPHE_clusterCountMax(getIntParam("CDPHE_clusterCountMax"));
        model.setUseSTORETretrieval(getBooleanParam("useSTORETretrieval"));
        model.setSTORETdata(getStringParam("STORETdata"));
        model.setMergeDatasets(getBooleanParam("merge_datasets"));
        model.setMergeMethod(getStringParam("merge_method"));
        model.setUserData(getStringParam("user_data"));

        model.run();
        return EXEC_OK;
    }
    
    @Override
    protected void postProcess() throws Exception {
        // files
        putResult(new File(model.getGraph()),
                  new File(model.getBoxplot()),
                  new File(model.getMonthlyGraph()),
                  new File(model.getHistogram()),
                  new File(model.getCDF()),
                  //Below are the result graph files for use by JHighCharts on eRAMS for duplicating the above graphs
                  model.getTimeseriesOutput(),
                  model.getBoxplotOutput(),
                  model.getMonthlyTimeseriesOutput(),
                  //model.getMonthlyBoxplotOutput(),
                  model.getHistogramOutput(),
                  model.getCDFoutput());
        // values
        putResult("len", model.getLen());
        putResult("start", model.getStart());
        putResult("end", model.getEnd());
        putResult("units", model.getUnits());
        putResult("data_source", model.getDataSource());
        //Get all data results
        putResult("max", model.getMax(), null, model.getUnits());
        putResult("min", model.getMin(), null, model.getUnits());
        putResult("upperQuartile", model.getUpperQuartile(), null, model.getUnits());
        putResult("lowerQuartile", model.getLowerQuartile(), null, model.getUnits());
        putResult("median", model.getMedian(), null, model.getUnits());
        putResult("mean", model.getMean(), null, model.getUnits());
        putResult("standardDeviation", model.getStandardDeviation(), null, model.getUnits());
        putResult("variance", model.getVariance());
        putResult("skewness", model.getSkewness());
        putResult("coefficientOfVariation", model.getCoefficientOfVariation());
        putResult("kendalCorrelationCoefficient", model.getKendallCorrelationCoefficient());
        //Get seasonal results
        putResult("len_seasonal", model.getLen_seasonal());
        putResult("max_seasonal", model.getMax_seasonal(), null, model.getUnits());
        putResult("min_seasonal", model.getMin_seasonal(), null, model.getUnits());
        putResult("upperQuartile_seasonal", model.getUpperQuartile_seasonal(), null, model.getUnits());
        putResult("lowerQuartile_seasonal", model.getLowerQuartile_seasonal(), null, model.getUnits());
        putResult("median_seasonal", model.getMedian_seasonal(), null, model.getUnits());
        putResult("mean_seasonal", model.getMean_seasonal(), null, model.getUnits());
        putResult("standardDeviation_seasonal", model.getStandardDeviation_seasonal(), null, model.getUnits());
        putResult("variance_seasonal", model.getVariance_seasonal());
        putResult("skewness_seasonal", model.getSkewness_seasonal());
        putResult("coefficientOfVariation_seasonal", model.getCoefficientOfVariation_seasonal());
        putResult("kendalCorrelationCoefficient_seasonal", model.getKendallCorrelationCoefficient_seasonal());
        //Get other results
        putResult("flow_statistics_summary",model.getFlowStatistics_summary().getName());
        putResult("graph", model.getGraph());
        putResult("boxplot", model.getBoxplot());
        putResult("histogram", model.getHistogram());
        putResult("cdf_graph", model.getCDF());
        putResult("monthlyAverage_graph", model.getMonthlyGraph());
        //Get result files for JSHighCharts
        String graphDataFiles = model.getTimeseriesOutput().getName() + "|" +  
                      model.getBoxplotOutput().getName() + "|" + 
                      model.getMonthlyTimeseriesOutput().getName() + "|" + 
                      //model.getMonthlyBoxplotOutput().getName() + "|" +
                      model.getHistogramOutput().getName() + "|" +
                      model.getCDFoutput().getName();
        
        //Get Period 1 results
        if(!getStringParam("period1_begin").equalsIgnoreCase("") && !getStringParam("period1_end").equalsIgnoreCase("")){
            putResult("len_period1", model.getLen_period1());
            putResult("max_period1", model.getMax_period1(), null, model.getUnits());
            putResult("min_period1", model.getMin_period1(), null, model.getUnits());
            putResult("upperQuartile_period1", model.getUpperQuartile_period1(), null, model.getUnits());
            putResult("lowerQuartile_period1", model.getLowerQuartile_period1(), null, model.getUnits());
            putResult("median_period1", model.getMedian_period1(), null, model.getUnits());
            putResult("mean_period1", model.getMean_period1(), null, model.getUnits());
            putResult("standardDeviation_period1", model.getStandardDeviation_period1(), null, model.getUnits());
            putResult("variance_period1", model.getVariance_period1());
            putResult("skewness_period1", model.getSkewness_period1());
            putResult("coefficientOfVariation_period1", model.getCoefficientOfVariation_period1());
            putResult("kendalCorrelationCoefficient_period1", model.getKendallCorrelationCoefficient_period1());
        }
        //Get Period 2 results
        if(!getStringParam("period2_begin").equalsIgnoreCase("") && !getStringParam("period2_end").equalsIgnoreCase("")){
            putResult("len_period2", model.getLen_period2());
            putResult("max_period2", model.getMax_period2(), null, model.getUnits());
            putResult("min_period2", model.getMin_period2(), null, model.getUnits());
            putResult("upperQuartile_period2", model.getUpperQuartile_period2(), null, model.getUnits());
            putResult("lowerQuartile_period2", model.getLowerQuartile_period2(), null, model.getUnits());
            putResult("median_period2", model.getMedian_period2(), null, model.getUnits());
            putResult("mean_period2", model.getMean_period2(), null, model.getUnits());
            putResult("standardDeviation_period2", model.getStandardDeviation_period2(), null, model.getUnits());
            putResult("variance_period2", model.getVariance_period2());
            putResult("skewness_period2", model.getSkewness_period2());
            putResult("coefficientOfVariation_period2", model.getCoefficientOfVariation_period2());
            putResult("kendalCorrelationCoefficient_period2", model.getKendallCorrelationCoefficient_period2());
        }
        //Get Period 3 results
        if(!getStringParam("period3_begin").equalsIgnoreCase("") && !getStringParam("period3_end").equalsIgnoreCase("")){
            putResult("len_period3", model.getLen_period3());
            putResult("max_period3", model.getMax_period3(), null, model.getUnits());
            putResult("min_period3", model.getMin_period3(), null, model.getUnits());
            putResult("upperQuartile_period3", model.getUpperQuartile_period3(), null, model.getUnits());
            putResult("lowerQuartile_period3", model.getLowerQuartile_period3(), null, model.getUnits());
            putResult("median_period3", model.getMedian_period3(), null, model.getUnits());
            putResult("mean_period3", model.getMean_period3(), null, model.getUnits());
            putResult("standardDeviation_period3", model.getStandardDeviation_period3(), null, model.getUnits());
            putResult("variance_period3", model.getVariance_period3());
            putResult("skewness_period3", model.getSkewness_period3());
            putResult("coefficientOfVariation_period3", model.getCoefficientOfVariation_period3());
            putResult("kendalCorrelationCoefficient_period3", model.getKendallCorrelationCoefficient_period3());
        }
        //Get flow stats file
        if(getBooleanParam("calcFlowStatisticsFileTF") && getStringParam("wq_test").equalsIgnoreCase("flow")){
            putResult(model.getFlowStatistics_summary());
        }
        //Get flow envelope graph
        if(getStringParam("wq_test").equalsIgnoreCase("flow") && getBooleanParam("envelopeTF")){
            putResult(new File(model.getTimeseriesEnvelope()), model.getTimeseriesEnvelopeOutput());
            putResult("envelope_graph", model.getTimeseriesEnvelope());
            graphDataFiles = graphDataFiles + "|" + model.getTimeseriesEnvelopeOutput().getName();
        }
        //Get flow raster graph
        if(getStringParam("wq_test").equalsIgnoreCase("flow") && getBooleanParam("rasterTF")){
            putResult(new File(model.getTimeseriesRaster()));
            putResult("raster_graph", model.getTimeseriesRaster());
            if(!getBooleanParam("envelopeTF")){//Highcharts' raster graph uses the same result file as the envelope plot
                putResult(model.getTimeseriesEnvelopeOutput());
                graphDataFiles = graphDataFiles + "|" + model.getTimeseriesEnvelopeOutput().getName();
            }
        }
        //Get CDPHE low flow results
        if(getBooleanParam("calcCDPHElowflowTF")){
            putResult("cdphe_extremeValueDFLOW", model.getCDPHE_ExtremeValueDFLOW(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_all", model.getCDPHE_BiologicalDFLOW_all(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_jan", model.getCDPHE_BiologicalDFLOW_jan(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_feb", model.getCDPHE_BiologicalDFLOW_feb(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_mar", model.getCDPHE_BiologicalDFLOW_mar(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_apr", model.getCDPHE_BiologicalDFLOW_apr(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_may", model.getCDPHE_BiologicalDFLOW_may(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_jun", model.getCDPHE_BiologicalDFLOW_jun(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_jul", model.getCDPHE_BiologicalDFLOW_jul(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_aug", model.getCDPHE_BiologicalDFLOW_aug(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_sep", model.getCDPHE_BiologicalDFLOW_sep(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_oct", model.getCDPHE_BiologicalDFLOW_oct(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_nov", model.getCDPHE_BiologicalDFLOW_nov(), null, "cfs");
            putResult("cdphe_biologicalDFLOW_dec", model.getCDPHE_BiologicalDFLOW_dec(), null, "cfs");
            putResult("cdphe_humanHealthDFLOW", model.getCDPHE_HumanHealthDFLOW(), null, "cfs");
            putResult("cdphe_reg31DFLOWsummary", model.getCDPHE_Reg31DFLOWsummary());
        }
        putResult("graph_data_files", graphDataFiles);
    }
}