V1_0.java [src/java/m/cfa/timeseries] Revision: Date:
package m.cfa.timeseries;
import csip.api.server.Executable;
import csip.ModelDataService;
import csip.api.server.PayloadParameter;
import csip.api.server.PayloadResults;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.Resource;
import csip.annotations.ResourceType;
import csip.annotations.VersionInfo;
import java.io.File;
import javax.ws.rs.Path;
@Name("timeseries")
@Description("Time Series: Daily Statistics and Data Visualization")
@VersionInfo("1.0")
@Path("m/cfa/timeseries/1.0")
@Resource(file="/bin/win-x86/dflow.exe", wine=true, id="dflow", type=ResourceType.EXECUTABLE)
public class V1_0 extends ModelDataService {
guiTimeseries_Model model = new guiTimeseries_Model();
@Override
protected void preProcess() throws Exception {
model.setDirectory(workspace().getDir().toString());
PayloadParameter inputPayload = parameter();
model.setDatabase(inputPayload.getString("database"));
model.setOrganizationID(inputPayload.getString("org_id"));
model.setStationId(inputPayload.getString("station_id"));
model.setStationName(inputPayload.getString("station_name"));
model.setWQtest(inputPayload.getString("wq_test", "flow"));
model.setStartDate(inputPayload.getString("begin_date", ""));
model.setEndDate(inputPayload.getString("end_date", ""));
model.setTimeStep(inputPayload.getString("time_step"));
model.setMethod(inputPayload.getString("method"));
model.setNumberOfBins(inputPayload.getInt("numBins"));
model.setLogarithmicHistogramBins(inputPayload.getBoolean("logarithmicTF"));
model.setSeasonBegin(inputPayload.getString("season_begin"));
model.setSeasonEnd(inputPayload.getString("season_end"));
model.setPeriod1Begin(inputPayload.getString("period1_begin", ""));
model.setPeriod1End(inputPayload.getString("period1_end", ""));
model.setPeriod2Begin(inputPayload.getString("period2_begin", ""));
model.setPeriod2End(inputPayload.getString("period2_end", ""));
model.setPeriod3Begin(inputPayload.getString("period3_begin", ""));
model.setPeriod3End(inputPayload.getString("period3_end", ""));
model.setMedianTF(inputPayload.getBoolean("medianTF", true));
model.setEnvelopeTF(inputPayload.getBoolean("envelopeTF", false));
model.setRasterTF(inputPayload.getBoolean("rasterTF", false));
model.setRasterLogarithmicBinsTF(inputPayload.getBoolean("rasterLogarithmicBinsTF", false));
model.setHighPercentile(inputPayload.getDouble("highPercentile"));
model.setLowPercentile(inputPayload.getDouble("lowPercentile"));
model.setCalcFlowStatisticsFileTF(inputPayload.getBoolean("calcFlowStatisticsFileTF", false));
model.setShowMonthlyStatsTF(inputPayload.getBoolean("showMonthlyStatsTF", false));
model.setWaterYear_TF(inputPayload.getBoolean("waterYearTF", false));
model.setCalcCDPHElowflowTF(inputPayload.getBoolean("calcCDPHElowflowTF", false));
model.setCDPHE_lowFlowType(inputPayload.getString("CDPHE_lowFlowType"));
model.setCDPHE_m(inputPayload.getInt("CDPHE_m"));
model.setCDPHE_R(inputPayload.getInt("CDPHE_R"));
model.setCDPHE_waterYearBegin(inputPayload.getString("CDPHE_waterYearBegin"));
model.setCDPHE_clusterLength(inputPayload.getInt("CDPHE_clusterLength"));
model.setCDPHE_clusterCountMax(inputPayload.getInt("CDPHE_clusterCountMax"));
model.setMergeDatasets(inputPayload.getBoolean("merge_datasets", false));
model.setMergeMethod(inputPayload.getString("merge_method", "user"));
model.setUserData(inputPayload.getString("user_data", ""));
}
@Override
protected void doProcess() throws Exception {
Executable e = resources().getExe("dflow");
model.run(e);
}
@Override
protected void postProcess() throws Exception {
PayloadParameter inputPayload = parameter();
PayloadResults resultPayload = results();
// files
File wd = workspace().getDir();
resultPayload.put(new File(wd, model.getGraph()),
new File(wd, model.getBoxplot()),
new File(wd, model.getMonthlyGraph()),
new File(wd, model.getHistogram()),
new File(wd, 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
resultPayload.put("len", model.getLen());
resultPayload.put("start", model.getStart());
resultPayload.put("end", model.getEnd());
resultPayload.put("units", model.getUnits());
resultPayload.put("data_source", model.getDataSource());
//Get all data results
resultPayload.put("max", model.getMax(), null, model.getUnits());
resultPayload.put("min", model.getMin(), null, model.getUnits());
resultPayload.put("upperQuartile", model.getUpperQuartile(), null, model.getUnits());
resultPayload.put("lowerQuartile", model.getLowerQuartile(), null, model.getUnits());
resultPayload.put("median", model.getMedian(), null, model.getUnits());
resultPayload.put("mean", model.getMean(), null, model.getUnits());
resultPayload.put("standardDeviation", model.getStandardDeviation(), null, model.getUnits());
resultPayload.put("variance", model.getVariance());
resultPayload.put("skewness", model.getSkewness());
resultPayload.put("coefficientOfVariation", model.getCoefficientOfVariation());
resultPayload.put("kendalCorrelationCoefficient", model.getKendallCorrelationCoefficient());
//Get seasonal results
resultPayload.put("len_seasonal", model.getLen_seasonal());
resultPayload.put("max_seasonal", model.getMax_seasonal(), null, model.getUnits());
resultPayload.put("min_seasonal", model.getMin_seasonal(), null, model.getUnits());
resultPayload.put("upperQuartile_seasonal", model.getUpperQuartile_seasonal(), null, model.getUnits());
resultPayload.put("lowerQuartile_seasonal", model.getLowerQuartile_seasonal(), null, model.getUnits());
resultPayload.put("median_seasonal", model.getMedian_seasonal(), null, model.getUnits());
resultPayload.put("mean_seasonal", model.getMean_seasonal(), null, model.getUnits());
resultPayload.put("standardDeviation_seasonal", model.getStandardDeviation_seasonal(), null, model.getUnits());
resultPayload.put("variance_seasonal", model.getVariance_seasonal());
resultPayload.put("skewness_seasonal", model.getSkewness_seasonal());
resultPayload.put("coefficientOfVariation_seasonal", model.getCoefficientOfVariation_seasonal());
resultPayload.put("kendalCorrelationCoefficient_seasonal", model.getKendallCorrelationCoefficient_seasonal());
//Get other results
resultPayload.put("flow_statistics_summary",model.getFlowStatistics_summary().getName());
resultPayload.put("graph", model.getGraph());
resultPayload.put("boxplot", model.getBoxplot());
resultPayload.put("histogram", model.getHistogram());
resultPayload.put("cdf_graph", model.getCDF());
resultPayload.put("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(!inputPayload.getString("period1_begin").equalsIgnoreCase("") && !inputPayload.getString("period1_end").equalsIgnoreCase("")){
resultPayload.put("len_period1", model.getLen_period1());
resultPayload.put("max_period1", model.getMax_period1(), null, model.getUnits());
resultPayload.put("min_period1", model.getMin_period1(), null, model.getUnits());
resultPayload.put("upperQuartile_period1", model.getUpperQuartile_period1(), null, model.getUnits());
resultPayload.put("lowerQuartile_period1", model.getLowerQuartile_period1(), null, model.getUnits());
resultPayload.put("median_period1", model.getMedian_period1(), null, model.getUnits());
resultPayload.put("mean_period1", model.getMean_period1(), null, model.getUnits());
resultPayload.put("standardDeviation_period1", model.getStandardDeviation_period1(), null, model.getUnits());
resultPayload.put("variance_period1", model.getVariance_period1());
resultPayload.put("skewness_period1", model.getSkewness_period1());
resultPayload.put("coefficientOfVariation_period1", model.getCoefficientOfVariation_period1());
resultPayload.put("kendalCorrelationCoefficient_period1", model.getKendallCorrelationCoefficient_period1());
}
//Get Period 2 results
if(!inputPayload.getString("period2_begin").equalsIgnoreCase("") && !inputPayload.getString("period2_end").equalsIgnoreCase("")){
resultPayload.put("len_period2", model.getLen_period2());
resultPayload.put("max_period2", model.getMax_period2(), null, model.getUnits());
resultPayload.put("min_period2", model.getMin_period2(), null, model.getUnits());
resultPayload.put("upperQuartile_period2", model.getUpperQuartile_period2(), null, model.getUnits());
resultPayload.put("lowerQuartile_period2", model.getLowerQuartile_period2(), null, model.getUnits());
resultPayload.put("median_period2", model.getMedian_period2(), null, model.getUnits());
resultPayload.put("mean_period2", model.getMean_period2(), null, model.getUnits());
resultPayload.put("standardDeviation_period2", model.getStandardDeviation_period2(), null, model.getUnits());
resultPayload.put("variance_period2", model.getVariance_period2());
resultPayload.put("skewness_period2", model.getSkewness_period2());
resultPayload.put("coefficientOfVariation_period2", model.getCoefficientOfVariation_period2());
resultPayload.put("kendalCorrelationCoefficient_period2", model.getKendallCorrelationCoefficient_period2());
}
//Get Period 3 results
if(!inputPayload.getString("period3_begin").equalsIgnoreCase("") && !inputPayload.getString("period3_end").equalsIgnoreCase("")){
resultPayload.put("len_period3", model.getLen_period3());
resultPayload.put("max_period3", model.getMax_period3(), null, model.getUnits());
resultPayload.put("min_period3", model.getMin_period3(), null, model.getUnits());
resultPayload.put("upperQuartile_period3", model.getUpperQuartile_period3(), null, model.getUnits());
resultPayload.put("lowerQuartile_period3", model.getLowerQuartile_period3(), null, model.getUnits());
resultPayload.put("median_period3", model.getMedian_period3(), null, model.getUnits());
resultPayload.put("mean_period3", model.getMean_period3(), null, model.getUnits());
resultPayload.put("standardDeviation_period3", model.getStandardDeviation_period3(), null, model.getUnits());
resultPayload.put("variance_period3", model.getVariance_period3());
resultPayload.put("skewness_period3", model.getSkewness_period3());
resultPayload.put("coefficientOfVariation_period3", model.getCoefficientOfVariation_period3());
resultPayload.put("kendalCorrelationCoefficient_period3", model.getKendallCorrelationCoefficient_period3());
}
//Get flow stats file
if(inputPayload.getBoolean("calcFlowStatisticsFileTF") && inputPayload.getString("wq_test").equalsIgnoreCase("flow")){
resultPayload.put(model.getFlowStatistics_summary());
}
//Get flow envelope graph
if(inputPayload.getString("wq_test").equalsIgnoreCase("flow") && inputPayload.getBoolean("envelopeTF")){
resultPayload.put(new File(wd, model.getTimeseriesEnvelope()), model.getTimeseriesEnvelopeOutput());
resultPayload.put("envelope_graph", model.getTimeseriesEnvelope());
graphDataFiles = graphDataFiles + "|" + model.getTimeseriesEnvelopeOutput().getName();
}
//Get flow raster graph
if(inputPayload.getString("wq_test").equalsIgnoreCase("flow") && inputPayload.getBoolean("rasterTF")){
resultPayload.put(new File(wd, model.getTimeseriesRaster()));
resultPayload.put("raster_graph", model.getTimeseriesRaster());
if(!inputPayload.getBoolean("envelopeTF")){//Highcharts' raster graph uses the same result file as the envelope plot
resultPayload.put(model.getTimeseriesEnvelopeOutput());
graphDataFiles = graphDataFiles + "|" + model.getTimeseriesEnvelopeOutput().getName();
}
}
//Get CDPHE low flow results
if(inputPayload.getBoolean("calcCDPHElowflowTF")){
resultPayload.put("cdphe_extremeValueDFLOW", model.getCDPHE_ExtremeValueDFLOW(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_all", model.getCDPHE_BiologicalDFLOW_all(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_jan", model.getCDPHE_BiologicalDFLOW_jan(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_feb", model.getCDPHE_BiologicalDFLOW_feb(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_mar", model.getCDPHE_BiologicalDFLOW_mar(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_apr", model.getCDPHE_BiologicalDFLOW_apr(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_may", model.getCDPHE_BiologicalDFLOW_may(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_jun", model.getCDPHE_BiologicalDFLOW_jun(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_jul", model.getCDPHE_BiologicalDFLOW_jul(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_aug", model.getCDPHE_BiologicalDFLOW_aug(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_sep", model.getCDPHE_BiologicalDFLOW_sep(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_oct", model.getCDPHE_BiologicalDFLOW_oct(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_nov", model.getCDPHE_BiologicalDFLOW_nov(), null, "cfs");
resultPayload.put("cdphe_biologicalDFLOW_dec", model.getCDPHE_BiologicalDFLOW_dec(), null, "cfs");
resultPayload.put("cdphe_biologicalYear_jan", model.getCDPHE_BiologicalYear_jan());
resultPayload.put("cdphe_biologicalYear_feb", model.getCDPHE_BiologicalYear_feb());
resultPayload.put("cdphe_biologicalYear_mar", model.getCDPHE_BiologicalYear_mar());
resultPayload.put("cdphe_biologicalYear_apr", model.getCDPHE_BiologicalYear_apr());
resultPayload.put("cdphe_biologicalYear_may", model.getCDPHE_BiologicalYear_may());
resultPayload.put("cdphe_biologicalYear_jun", model.getCDPHE_BiologicalYear_jun());
resultPayload.put("cdphe_biologicalYear_jul", model.getCDPHE_BiologicalYear_jul());
resultPayload.put("cdphe_biologicalYear_aug", model.getCDPHE_BiologicalYear_aug());
resultPayload.put("cdphe_biologicalYear_sep", model.getCDPHE_BiologicalYear_sep());
resultPayload.put("cdphe_biologicalYear_oct", model.getCDPHE_BiologicalYear_oct());
resultPayload.put("cdphe_biologicalYear_nov", model.getCDPHE_BiologicalYear_nov());
resultPayload.put("cdphe_biologicalYear_dec", model.getCDPHE_BiologicalYear_dec());
resultPayload.put("cdphe_humanHealthDFLOW", model.getCDPHE_HumanHealthDFLOW(), null, "cfs");
resultPayload.put("cdphe_reg31DFLOWsummary", model.getCDPHE_Reg31DFLOWsummary());
}
resultPayload.put("graph_data_files", graphDataFiles);
}
}