@@ -1,6 +1,11 @@ |
package cfa; |
+import java.io.File; |
+import java.io.FileWriter; |
+import java.io.IOException; |
+import java.io.PrintWriter; |
import java.util.ArrayList; |
import java.util.Arrays; |
+import java.util.Calendar; |
import java.util.Collections; |
import java.util.Comparator; |
|
@@ -1015,6 +1020,164 @@ |
return newData; |
} |
/** |
+ * Writes out the formatted output file as expected by eRAMS to be used for a JHighchart timeseries |
+ * @param mainFolder |
+ * @param data |
+ * @param timeStep |
+ * @param outputFileName |
+ * @param loadestTF |
+ * @throws IOException |
+ */ |
+ public void writeTimeSeries(String mainFolder, String[][] data, String timeStep, String outputFileName, boolean loadestTF) throws IOException { |
+ //Convert Date formate for output |
+ DoubleArray doubleArray = new DoubleArray(); |
+ String[] date = new String[0]; |
+ if(loadestTF){ |
+ date = doubleArray.changeDate2JHighChart_loadest(data, timeStep); |
+ }else{ |
+ date = doubleArray.changeDate2JHighChart(data, timeStep); |
+ } |
+ |
+ // open the file writer and set path |
+ String path = mainFolder + File.separator + outputFileName + "_graph.out"; |
+ FileWriter writer = new FileWriter(path, false); |
+ PrintWriter print_line = new PrintWriter(writer); |
+ |
+ // Print the needed values |
+ for (int i = 0; i < date.length; i++){ |
+ print_line.printf("%s" + "%n", date[i] + "\t" + data[i][1]); |
+ } |
+ |
+ // Close the file writer |
+ print_line.close(); |
+ writer.close(); |
+ System.out.println("Text File located at:\t" + path); |
+ } |
+ /** |
+ * This function will prepare the data that is needed for the use on eRAMS |
+ * with JHighCharts (date format: yyyy-MM-dd) |
+ * @param data |
+ * @param timeStep |
+ * @return |
+ */ |
+ private String[] changeDate2JHighChart(String[][] data, String timeStep){ |
+ String[] date = new String[data.length]; |
+ if (timeStep.equalsIgnoreCase("daily")){ |
+ for (int i = 0; i < data.length; i++){ |
+ double d = Double.parseDouble(data[i][0].substring(8)); |
+ double m = Double.parseDouble(data[i][0].substring(5,7)); |
+ double y = Double.parseDouble(data[i][0].substring(0,4)); |
+ int year = (int) y; |
+ int month = (int) m; |
+ int day = (int) d; |
+ Calendar newDate = Calendar.getInstance(); |
+ newDate.set(year, month - 1, day, 12, 0, 0); |
+ date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
+ } |
+ }else if (timeStep.equalsIgnoreCase("monthly")){ |
+ for (int i = 0; i < data.length; i++){ |
+ double m = Double.parseDouble(data[i][0].substring(5,7)); |
+ double y = Double.parseDouble(data[i][0].substring(0,4)); |
+ int year = (int) y; |
+ int month = (int) m; |
+ Calendar newDate = Calendar.getInstance(); |
+ newDate.set(year, month - 1, 1, 12, 0, 0); |
+ date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
+ } |
+ }else{ |
+ for (int i = 0; i < data.length; i++){ |
+ double y = Double.parseDouble(data[i][0].substring(0,4)); |
+ int year = (int) y; |
+ Calendar newDate = Calendar.getInstance(); |
+ newDate.set(year, 0, 1, 12, 0, 0); |
+ date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
+ } |
+ } |
+ return date; |
+ } |
+ /** |
+ * This function will prepare the data that is needed for the use on eRAMS |
+ * with JHighCharts using LOADEST output data (date format: yyyyMMdd) |
+ * @param data |
+ * @param timeStep |
+ * @return |
+ */ |
+ private String[] changeDate2JHighChart_loadest(String[][] data, String timeStep){ |
+ String[] date = new String[data.length]; |
+ if (timeStep.equalsIgnoreCase("daily")){ |
+ for (int i = 0; i < data.length; i++){ |
+ double y = Double.parseDouble(data[i][0].substring(0,4)); |
+ double m = Double.parseDouble(data[i][0].substring(4,6)); |
+ double d = Double.parseDouble(data[i][0].substring(6)); |
+ int year = (int) y; |
+ int month = (int) m; |
+ int day = (int) d; |
+ Calendar newDate = Calendar.getInstance(); |
+ newDate.set(year, month - 1, day, 12, 0, 0); |
+ date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
+ } |
+ }else if (timeStep.equalsIgnoreCase("monthly")){ |
+ for (int i = 0; i < data.length; i++){ |
+ double y = Double.parseDouble(data[i][0].substring(0,4)); |
+ double m = Double.parseDouble(data[i][0].substring(4,6)); |
+ int year = (int) y; |
+ int month = (int) m; |
+ Calendar newDate = Calendar.getInstance(); |
+ newDate.set(year, month - 1, 1, 12, 0, 0); |
+ date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
+ } |
+ }else{ |
+ for (int i = 0; i < data.length; i++){ |
+ double y = Double.parseDouble(data[i][0].substring(0,4)); |
+ int year = (int) y; |
+ Calendar newDate = Calendar.getInstance(); |
+ newDate.set(year, 0, 1, 12, 0, 0); |
+ date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
+ } |
+ } |
+ return date; |
+ } |
+ /** |
+ * Writes out the formatted output file as expected by eRAMS to be used for a JHighchart boxplot |
+ * @param mainFolder the location of the output file |
+ * @param lowerQuartile |
+ * @param upperQuartile |
+ * @param outliers |
+ * @param median |
+ * @param minOfData |
+ * @param outputFileName |
+ * @throws IOException |
+ */ |
+ public void writeBoxplot(String mainFolder, |
+ double lowerQuartile, |
+ double upperQuartile, |
+ ArrayList<Double> outliers, |
+ double median, |
+ double minOfData, |
+ String outputFileName) throws IOException { |
+ // open the file writer and set path |
+ String path = mainFolder + File.separator + outputFileName + "_boxplot.out"; |
+ FileWriter writer = new FileWriter(path, false); |
+ PrintWriter print_line = new PrintWriter(writer); |
+ double IQR = upperQuartile - lowerQuartile; |
+ double low = lowerQuartile - 1.5 * IQR; |
+ double high = upperQuartile + 1.5 * IQR; |
+ |
+ // Print the needed values |
+ for (int i = 0; i < outliers.size(); i ++){ |
+ print_line.printf("%s" + "%n", outliers.get(i)); |
+ } |
+ if (low < minOfData){ |
+ low = minOfData; |
+ } |
+ print_line.printf("%s" + "%n", low + "\t" + lowerQuartile + "\t" + median + "\t" + upperQuartile + "\t" + high); |
+ |
+ // Close the file writer |
+ print_line.close(); |
+ writer.close(); |
+ System.out.println("Text File located at:\t" + path); |
+ } |
+ /** |
* Checks if the provided dates are subsequent dates, aka nextDate = date + 1day. |
* This check includes December 31st to January 1st catchs, 4-year leap-year catches, |
* 100-year non-leap-year catches and 400-year leap-year catches |
@@ -12,7 +12,6 @@ |
import java.text.DateFormat; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
-import java.util.Calendar; |
import java.util.Date; |
import oms3.util.ProcessComponent; |
|
@@ -47,9 +46,6 @@ |
|
//Global variable but not an input |
String fileName = ""; |
- int dailyctr = 0; |
- int monthlyctr = 0; |
- int yearlyctr = 0; |
|
//Outputs |
String flowLen = "-1"; |
@@ -65,6 +61,7 @@ |
double dailymedian = -1; |
double dailymean = -1; |
double dailystandardDeviation = -1; |
+ |
double monthlymax = -1; |
double monthlymin = -1; |
double monthlyupperQuartile = -1; |
@@ -72,6 +69,7 @@ |
double monthlymedian = -1; |
double monthlymean = -1; |
double monthlystandardDeviation = -1; |
+ |
double yearlymax = -1; |
double yearlymin = -1; |
double yearlyupperQuartile = -1; |
@@ -79,9 +77,6 @@ |
double yearlymedian = -1; |
double yearlymean = -1; |
double yearlystandardDeviation = -1; |
- |
- |
- |
|
//Gets |
// public File getOutputSummary() { |
@@ -364,9 +359,33 @@ |
/** |
* Calibration File Writer: |
* This function will write the calibration file that is needed for LOADEST |
+ * @param sortedData_combined the flow data, sortedData_combined[i][0] = date (yyyy-mm-dd), sortedData_combined[i][1] = value (cfs) |
+ * @param WQdata_combined the water quality data, WQdata_combined[i][0] = date (yyyy-mm-dd), WQdata_combined[i][1] = value (units) |
+ * @param units the units of the water quality data |
* @throws IOException |
*/ |
- private void writeCalibration(ArrayList<String> CDATE, ArrayList<String> CTIME, ArrayList<String> CFLOW, ArrayList<String> CCONC) throws IOException { |
+ private void writeCalibration(String[][] sortedData_combined, String[][] WQdata_combined, String units) throws IOException { |
+ //Convert data for Calibration file |
+ ArrayList<String> CDATE = new ArrayList<String>(); |
+ ArrayList<String> CTIME = new ArrayList<String>(); |
+ ArrayList<String> CFLOW = new ArrayList<String>(); |
+ ArrayList<String> CCONC = new ArrayList<String>(); |
+ for(int i=0;i<WQdata_combined.length;i++){ |
+ for(int j=0; j<sortedData_combined.length;j++){ |
+ if(WQdata_combined[i][0].equalsIgnoreCase(sortedData_combined[j][0])){ |
+ //Keep the data with both a water quality test and a flow value |
+ CDATE.add(WQdata_combined[i][0]); |
+ CTIME.add("1200"); |
+ CFLOW.add(sortedData_combined[j][1]); |
+ CCONC.add(WQdata_combined[i][1]); // need to make sure that CCONC is in mg/L |
+ } |
+ } |
+ } |
+ CCONC = convertToLOADESTunits(units,CCONC); |
+ //Store result for analysis summary |
+ this.wqLen = String.valueOf(CCONC.size()); |
+ |
+ |
String path = mainFolder + File.separator + "CALIB.INP"; |
FileWriter writer = new FileWriter(path, false); |
PrintWriter print_line = new PrintWriter(writer); |
@@ -410,7 +429,17 @@ |
* This function will write the estimation file needed for LOADEST |
* @throws IOException |
*/ |
- private void writeEstimation(String[] EDATE, String[] ETIME, String[] EFLOW) throws IOException { |
+ private void writeEstimation(String[][] sortedData_combined) throws IOException { |
+ //Convert data for Estimation file |
+ String[] EDATE = new String[sortedData_combined.length]; |
+ String[] ETIME = new String[sortedData_combined.length]; |
+ String[] EFLOW = new String[sortedData_combined.length]; |
+ for(int i=0; i<sortedData_combined.length; i++){ |
+ EDATE[i] = sortedData_combined[i][0]; |
+ ETIME[i] = "1200"; |
+ EFLOW[i] = sortedData_combined[i][1]; |
+ } |
+ |
// open the file writer and set path |
String path = mainFolder + File.separator + "EST.INP"; |
FileWriter writer = new FileWriter(path, false); |
@@ -514,7 +543,7 @@ |
* @return returns the entire text file in textData |
* @throws IOException |
*/ |
- private String[] OpenFile(String path) throws IOException { |
+ private String[][] OpenLOADESTresultFile(String path) throws IOException { |
|
FileReader fr = new FileReader(path); |
BufferedReader textReader = new BufferedReader(fr); |
@@ -529,13 +558,22 @@ |
String[] textData = new String[numberOfLines]; |
|
for (int i = 0; i < numberOfLines; i++){ |
- textData[i]=textReader.readLine(); |
+ textData[i]=textReader.readLine(); |
} |
|
textReader.close(); |
fr.close(); |
- return textData; |
- |
+ |
+ |
+ // rctr is used to remove 8 lines of header from the file |
+ int rctr = textData.length - 8; |
+ String[][] dailyData = new String[rctr][2]; |
+ for (int i = 0; i < rctr; i++){ |
+ dailyData[i][0] = textData[(i+8)].substring(1,9); |
+ dailyData[i][1] = textData[(i+8)].substring(28,38); |
+ } |
+ |
+ return dailyData; |
} |
/** |
* This will determine how many lines contain total data. Used to in OpenFile |
@@ -572,238 +610,53 @@ |
} |
throw new IOException("Error encountered. Please see the following message for details: \n" + errorContents); |
} |
- /** |
- * This will calculate the max for statistics |
- * @param sortedData data by given time step |
- * @return the max |
+ /** |
+ * Main statistics function calls other functions to calculate each statistic value then stores the results as global variables |
+ * @param sortedData data on which statistical values are desired, sortedData[i][0] = date, soredData[i][1] = value |
+ * @param timeStep a flag for which results the statistics will be stored to, either "daily", "monthly", or "yearly" |
*/ |
- private double CalculateMax(String[][] sortedData){ |
- DoubleMath doubleMath = new DoubleMath(); |
- //get data |
- double[] dataList = new double[sortedData.length]; |
+ private void CalculateStatistics(String[][] sortedData, String timeStep) { |
+ //convert Data into proper format for calculations |
+ ArrayList<Double> dataList = new ArrayList<Double>(); |
for(int i=0; i<sortedData.length; i++){ |
- dataList[i] = Double.parseDouble(sortedData[i][1]); |
+ dataList.add(Double.parseDouble(sortedData[i][1])); |
} |
- //Call Max function |
- double max = Math.round(doubleMath.Min_Max(dataList, true)*1000); |
- max = max/1000; |
|
- return max; |
- } |
- /** |
- * This will calculate the min for statistics |
- * @param sortedData data by given time step |
- * @return the min |
- */ |
- private double CalculateMin(String[][] sortedData){ |
- DoubleMath doubleMath = new DoubleMath(); |
- //get data |
- double[] dataList = new double[sortedData.length]; |
- for(int i=0; i<sortedData.length; i++){ |
- dataList[i] = Double.parseDouble(sortedData[i][1]); |
+ //Calculate statistics |
+ DoubleMath doubleMath = new DoubleMath(); |
+ double temp1 = doubleMath.round(doubleMath.Min_Max(dataList, true),3);//Call Max function |
+ double temp2 = doubleMath.round(doubleMath.Min_Max(dataList, false),3);//Call Min function |
+ double temp3 = doubleMath.round(doubleMath.Percentile_function(dataList,0.75),3);//Call Upper Quartile function |
+ double temp4 = doubleMath.round(doubleMath.Percentile_function(dataList,0.25),3);//Call Lower Quartile function |
+ double temp5 = doubleMath.round(doubleMath.Median(dataList),3);//Call Median function |
+ double temp6 = doubleMath.round(doubleMath.Average(dataList),3);//Call Mean function |
+ double temp7 = doubleMath.round(doubleMath.StandardDeviationSample(dataList),3);//Call standard deviation |
+ |
+ if(timeStep.equalsIgnoreCase("daily")){ |
+ dailymax = temp1; |
+ dailymin = temp2; |
+ dailyupperQuartile = temp3; |
+ dailylowerQuartile = temp4; |
+ dailymedian = temp5; |
+ dailymean = temp6; |
+ dailystandardDeviation = temp7; |
+ }else if(timeStep.equalsIgnoreCase("monthly")){ |
+ monthlymax = temp1; |
+ monthlymin = temp2; |
+ monthlyupperQuartile = temp3; |
+ monthlylowerQuartile = temp4; |
+ monthlymedian = temp5; |
+ monthlymean = temp6; |
+ monthlystandardDeviation = temp7; |
+ }else if(timeStep.equalsIgnoreCase("yearly")){ |
+ yearlymax = temp1; |
+ yearlymin = temp2; |
+ yearlyupperQuartile = temp3; |
+ yearlylowerQuartile = temp4; |
+ yearlymedian = temp5; |
+ yearlymean = temp6; |
+ yearlystandardDeviation = temp7; |
} |
- //Call Min function |
- double min = Math.round(doubleMath.Min_Max(dataList, false)*1000); |
- min = min/1000; |
- return min; |
- } |
- /** |
- * This will calculate the upper quartile for statistics |
- * @param sortedData data by given time step |
- * @return the upperquartile |
- */ |
- private double CalculateUQ(String[][] sortedData){ |
- DoubleMath doubleMath = new DoubleMath(); |
- //get data |
- double[] dataList = new double[sortedData.length]; |
- for(int i=0; i<sortedData.length; i++){ |
- dataList[i] = Double.parseDouble(sortedData[i][1]); |
- } |
- //Call Upper Quartile function |
- double upperQuartile = Math.round(doubleMath.Percentile_function(dataList,0.75)*1000); |
- upperQuartile = upperQuartile/1000; |
- return upperQuartile; |
- } |
- /** |
- * This will calculate the lower quartile for statistics |
- * @param sortedData data by given time step |
- * @return the lower quartile |
- */ |
- private double CalculateLQ(String[][] sortedData){ |
- DoubleMath doubleMath = new DoubleMath(); |
- //get data |
- double[] dataList = new double[sortedData.length]; |
- for(int i=0; i<sortedData.length; i++){ |
- dataList[i] = Double.parseDouble(sortedData[i][1]); |
- } |
- //Call Lower Quartile function |
- double lowerQuartile = Math.round(doubleMath.Percentile_function(dataList,0.25)*1000); |
- lowerQuartile = lowerQuartile/1000; |
- return lowerQuartile; |
- } |
- /** |
- * This will calculate the median for statistics |
- * @param sortedData data by given time step |
- * @return the median |
- */ |
- private double CalculateMedian(String[][] sortedData){ |
- DoubleMath doubleMath = new DoubleMath(); |
- //get data |
- double[] dataList = new double[sortedData.length]; |
- for(int i=0; i<sortedData.length; i++){ |
- dataList[i] = Double.parseDouble(sortedData[i][1]); |
- } |
- //Call Lower Quartile function |
- //Call Median function |
- double median = Math.round(doubleMath.Median(dataList)*1000); |
- median = median/1000; |
- return median; |
- } |
- /** |
- * This will calculate the mean for statistics |
- * @param sortedData data by given time step |
- * @return the mean |
- */ |
- private double CalculateMean(String[][] sortedData){ |
- DoubleMath doubleMath = new DoubleMath(); |
- //get data |
- double[] dataList = new double[sortedData.length]; |
- for(int i=0; i<sortedData.length; i++){ |
- dataList[i] = Double.parseDouble(sortedData[i][1]); |
- } |
- //Call Mean function |
- double mean = Math.round(doubleMath.Average(dataList)*1000); |
- mean = mean/1000; |
- return mean; |
- } |
- /** |
- * This will calculate the standard deviation for statistics |
- * @param sortedData data by given time step |
- * @return the Standard deviation |
- */ |
- private double CalculateSTDEV(String[][] sortedData){ |
- DoubleMath doubleMath = new DoubleMath(); |
- //get data |
- double[] dataList = new double[sortedData.length]; |
- for(int i=0; i<sortedData.length; i++){ |
- dataList[i] = Double.parseDouble(sortedData[i][1]); |
- } |
- //Call standard deviation |
- double standardDeviation = Math.round(doubleMath.StandardDeviationSample(dataList)*1000); |
- standardDeviation = standardDeviation/1000; |
- return standardDeviation; |
- } |
- /** |
- * This function will prepare the data that is needed for the filewriters |
- * @param data |
- * @param timeStep |
- * @return |
- */ |
- private String[] changeDate2(String[][] data, String timeStep){ |
- String[] date = new String[data.length]; |
- if (timeStep.equalsIgnoreCase("daily")){ |
- for (int i = 0; i < data.length; i++){ |
- double y = Double.parseDouble(data[i][0].substring(0,4)); |
- double m = Double.parseDouble(data[i][0].substring(4,6)); |
- double d = Double.parseDouble(data[i][0].substring(6)); |
- int year = (int) y; |
- int month = (int) m; |
- int day = (int) d; |
- Calendar newDate = Calendar.getInstance(); |
- newDate.set(year, month - 1, day, 12, 0, 0); |
- date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
- } |
- }else if (timeStep.equalsIgnoreCase("monthly")){ |
- for (int i = 0; i < data.length; i++){ |
- double y = Double.parseDouble(data[i][0].substring(0,4)); |
- double m = Double.parseDouble(data[i][0].substring(4,6)); |
- int year = (int) y; |
- int month = (int) m; |
- Calendar newDate = Calendar.getInstance(); |
- newDate.set(year, month - 1, 1, 12, 0, 0); |
- date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
- } |
- }else{ |
- for (int i = 0; i < data.length; i++){ |
- double y = Double.parseDouble(data[i][0].substring(0,4)); |
- int year = (int) y; |
- Calendar newDate = Calendar.getInstance(); |
- newDate.set(year, 0, 1, 12, 0, 0); |
- date[i] = String.valueOf(newDate.getTimeInMillis()/1000); |
- } |
- } |
- return date; |
- } |
- /** |
- * |
- * @param date |
- * @param data |
- * @param timeStep |
- * @throws IOException |
- */ |
- private void writeTimeSeries(String[] date, String[][] data, String timeStep) throws IOException { |
- // open the file writer and set path |
- String path = mainFolder + File.separator + timeStep + "_graph.out"; |
- FileWriter writer = new FileWriter(path, false); |
- PrintWriter print_line = new PrintWriter(writer); |
- |
- // Print the needed values |
- for (int i = 0; i < date.length; i++){ |
- print_line.printf("%s" + "%n", date[i] + "\t" + data[i][1]); |
- } |
- |
- // Close the file writer |
- print_line.close(); |
- writer.close(); |
- System.out.println("Text File located at:\t" + path); |
- } |
- /** |
- * |
- * @param lowerQuartile |
- * @param upperQuartile |
- * @param outliers |
- * @param median |
- * @param timeStep |
- * @throws IOException |
- */ |
- private void writeBoxplot(double lowerQuartile, double upperQuartile, double[] outliers, double median, String timeStep) throws IOException { |
- // open the file writer and set path |
- String path = mainFolder + File.separator + timeStep + "_boxplot.out"; |
- FileWriter writer = new FileWriter(path, false); |
- PrintWriter print_line = new PrintWriter(writer); |
- double IQR = upperQuartile - lowerQuartile; |
- double low = lowerQuartile - 1.5 * IQR; |
- double high = upperQuartile + 1.5 * IQR; |
- |
- // Print the needed values |
- if (timeStep.equalsIgnoreCase("daily")){ |
- for (int i = 0; i < dailyctr; i ++){ |
- print_line.printf("%s" + "%n", outliers[i]); |
- } |
- if (low < dailymin){ |
- low = dailymin; |
- } |
- }else if(timeStep.equalsIgnoreCase("monthly")){ |
- for (int i = 0; i < monthlyctr; i ++){ |
- print_line.printf("%s" + "%n", outliers[i]); |
- } |
- if (low < monthlymin){ |
- low = monthlymin; |
- } |
- }else if(timeStep.equalsIgnoreCase("yearly")){ |
- for (int i = 0; i < yearlyctr; i ++){ |
- print_line.printf("%s" + "%n", outliers[i]); |
- } |
- if (low < yearlymin){ |
- low = yearlymin; |
- } |
- } |
- print_line.printf("%s" + "%n", low + "\t" + lowerQuartile + "\t" + median + "\t" + upperQuartile + "\t" + high); |
- |
- // Close the file writer |
- print_line.close(); |
- writer.close(); |
- System.out.println("Text File located at:\t" + path); |
} |
/** |
* Primary LOADEST function |
@@ -911,40 +764,13 @@ |
writeHeader(); |
|
// write the calibration variables based on the number of concentration values with a associated flow value |
- ArrayList<String> CDATE = new ArrayList<String>(); |
- ArrayList<String> CTIME = new ArrayList<String>(); |
- ArrayList<String> CFLOW = new ArrayList<String>(); |
- ArrayList<String> CCONC = new ArrayList<String>(); |
- for(int i=0;i<WQdata_combined.length;i++){ |
- for(int j=0; j<sortedData_combined.length;j++){ |
- if(WQdata_combined[i][0].equalsIgnoreCase(sortedData_combined[j][0])){ |
- //Keep the data with both a water quality test and a flow value |
- CDATE.add(WQdata_combined[i][0]); |
- CTIME.add("1200"); |
- CFLOW.add(sortedData_combined[j][1]); |
- CCONC.add(WQdata_combined[i][1]); // need to make sure that CCONC is in mg/L |
- } |
- } |
- } |
- CCONC = convertToLOADESTunits(units,CCONC); |
- writeCalibration(CDATE, CTIME, CFLOW, CCONC); |
- |
+ writeCalibration(sortedData_combined, WQdata_combined, units); |
|
//Get estimation dates for LOADEST variables |
- String[] EDATE = new String[sortedData_combined.length]; |
- String[] ETIME = new String[sortedData_combined.length]; |
- String[] EFLOW = new String[sortedData_combined.length]; |
- for(int i=0; i<sortedData_combined.length; i++){ |
- EDATE[i] = sortedData_combined[i][0]; |
- ETIME[i] = "1200"; |
- EFLOW[i] = sortedData_combined[i][1]; |
- } |
- writeEstimation(EDATE, ETIME, EFLOW); |
- |
+ writeEstimation(sortedData_combined); |
|
//Set results |
- this.flowLen = String.valueOf(EFLOW.length); |
- this.wqLen = String.valueOf(CCONC.size()); |
+ this.flowLen = String.valueOf(sortedData_combined.length); |
this.wqUnits = units; |
this.start = sortedData_combined[0][0]; |
this.end = sortedData_combined[sortedData_combined.length - 1][0]; |
@@ -980,131 +806,56 @@ |
throw new FileNotFoundException(fileName + ".res"); |
} |
System.out.println("Finished LOADEST.exe"); |
- |
- //call file reader for results |
- // need to determine the length of data given by LOADEST |
- // grab dailyData using file reader |
- |
- // Run the path |
- String file = mainFolder + File.separator + fileName + ".ind"; |
- // |
- String[] aryLines = OpenFile(file); |
- |
- |
- // rctr is used to remove 8 lines of header from the file |
- int rctr = aryLines.length - 8; |
- String[][] dailyData = new String[rctr][2]; |
- for (int i = 0; i < rctr; i++){ |
- dailyData[i][0] = aryLines[(i+8)].substring(1,9); |
- dailyData[i][1] = aryLines[(i+8)].substring(28,38); |
- } |
+ |
+ // Daily result data |
+ String[][] dailyData = OpenLOADESTresultFile(mainFolder + File.separator + fileName + ".ind"); |
|
//convert results to daily,monthly,yearly |
String[][] dailyresultData = doubleArray.computeFlowMethod(dailyData, "daily", "total", true); |
String[][] monthlyresultData = doubleArray.computeFlowMethod(dailyData, "monthly", "total", true); |
String[][] yearlyresultData = doubleArray.computeFlowMethod(dailyData, "yearly", "total", true); |
- String[] dailydate = changeDate2(dailyresultData,"daily"); |
- String[] monthlydate = changeDate2(monthlyresultData, "monthly"); |
- String[] yearlydate = changeDate2(yearlyresultData, "yearly"); |
|
- |
- //Calculate stats of data |
- // Daily stats |
- dailymax = CalculateMax(dailyresultData); |
- dailymin = CalculateMin(dailyresultData); |
- dailyupperQuartile = CalculateUQ(dailyresultData); |
- dailylowerQuartile = CalculateLQ(dailyresultData); |
- dailymedian = CalculateMedian(dailyresultData); |
- dailymean = CalculateMean(dailyresultData); |
- dailystandardDeviation = CalculateSTDEV(dailyresultData); |
- // Monthly stats |
- monthlymax = CalculateMax(monthlyresultData); |
- monthlymin = CalculateMin(monthlyresultData); |
- monthlyupperQuartile = CalculateUQ(monthlyresultData); |
- monthlylowerQuartile = CalculateLQ(monthlyresultData); |
- monthlymedian = CalculateMedian(monthlyresultData); |
- monthlymean = CalculateMean(monthlyresultData); |
- monthlystandardDeviation = CalculateSTDEV(monthlyresultData); |
- // Yearly stats |
- yearlymax = CalculateMax(yearlyresultData); |
- yearlymin = CalculateMin(yearlyresultData); |
- yearlyupperQuartile = CalculateUQ(yearlyresultData); |
- yearlylowerQuartile = CalculateLQ(yearlyresultData); |
- yearlymedian = CalculateMedian(yearlyresultData); |
- yearlymean = CalculateMean(yearlyresultData); |
- yearlystandardDeviation = CalculateSTDEV(yearlyresultData); |
- |
- |
- // Get daily outliers |
- // Find IQR and min and max |
- double dailyIQR = dailyupperQuartile - dailylowerQuartile; |
- // Get the loads into a double variable and compare to the limits for outliers |
- for (int i = 0; i < dailyresultData.length; i++){ |
- double value = Double.parseDouble(dailyresultData[i][1]); |
- if(value < (dailylowerQuartile - 1.5 * dailyIQR) || value > (dailyupperQuartile + 1.5 * dailyIQR)){ |
- dailyctr = dailyctr + 1; |
- } |
- } |
- double[] dailyoutliers = new double[dailyctr]; |
- int dailyctr2 = 0; |
+ // Calculate Daily stats |
+ CalculateStatistics(dailyresultData, "daily"); |
+ double dailyIQR = dailyupperQuartile - dailylowerQuartile;// Find IQR |
+ ArrayList<Double> dailyoutliers = new ArrayList<Double>();// Get daily outliers |
for (int i = 0; i < dailyresultData.length; i++){ |
double value = Double.parseDouble(dailyresultData[i][1]); |
if(value < (dailylowerQuartile - 1.5 * dailyIQR) || value > (dailyupperQuartile + 1.5 * dailyIQR)){ |
- dailyoutliers[dailyctr2] = value; |
- dailyctr2 = dailyctr2 + 1; |
+ dailyoutliers.add(value); |
} |
} |
|
- // Get monthly outliers |
- // Find IQR and min and max |
- double monthlyIQR = monthlyupperQuartile - monthlylowerQuartile; |
- // Get the loads into a double variable and compare to the limits for outliers |
- for (int i = 0; i < monthlyresultData.length; i++){ |
- double value = Double.parseDouble(monthlyresultData[i][1]); |
- if(value < (monthlylowerQuartile - 1.5 * monthlyIQR) || value > (monthlyupperQuartile + 1.5 * monthlyIQR)){ |
- monthlyctr = monthlyctr + 1; |
- } |
- } |
- double[] monthlyoutliers = new double[monthlyctr]; |
- int monthlyctr2 = 0; |
+ // Calculate Monthly stats |
+ CalculateStatistics(monthlyresultData, "monthly"); |
+ double monthlyIQR = monthlyupperQuartile - monthlylowerQuartile;// Find IQR |
+ ArrayList<Double> monthlyoutliers = new ArrayList<Double>();// Get monthly outliers |
for (int i = 0; i < monthlyresultData.length; i++){ |
double value = Double.parseDouble(monthlyresultData[i][1]); |
if(value < (monthlylowerQuartile - 1.5 * monthlyIQR) || value > (monthlyupperQuartile + 1.5 * monthlyIQR)){ |
- monthlyoutliers[monthlyctr2] = value; |
- monthlyctr2 = monthlyctr2 + 1; |
+ monthlyoutliers.add(value); |
} |
} |
|
- // Get yearly outliers |
- // Find IQR and min and max |
- double yearlyIQR = yearlyupperQuartile - yearlylowerQuartile; |
- // Get the loads into a double variable and compare to the limits for outliers |
- for (int i = 0; i < yearlyresultData.length; i++){ |
- double value = Double.parseDouble(yearlyresultData[i][1]); |
- if(value < (yearlylowerQuartile - 1.5 * yearlyIQR) || value > (yearlyupperQuartile + 1.5 * yearlyIQR)){ |
- yearlyctr = yearlyctr + 1; |
- } |
- } |
- double[] yearlyoutliers = new double[yearlyctr]; |
- int yearlyctr2 = 0; |
+ // Calculate Yearly stats |
+ CalculateStatistics(yearlyresultData, "yearly"); |
+ double yearlyIQR = yearlyupperQuartile - yearlylowerQuartile;// Find IQR |
+ ArrayList<Double> yearlyoutliers = new ArrayList<Double>();// Get yearly outliers |
for (int i = 0; i < yearlyresultData.length; i++){ |
double value = Double.parseDouble(yearlyresultData[i][1]); |
if(value < (yearlylowerQuartile - 1.5 * yearlyIQR) || value > (yearlyupperQuartile + 1.5 * yearlyIQR)){ |
- yearlyoutliers[yearlyctr2] = value; |
- yearlyctr2 = yearlyctr2 + 1; |
+ yearlyoutliers.add(value); |
} |
} |
- |
|
//Put graph file writer call here |
- writeTimeSeries(dailydate, dailyresultData, "daily"); |
- writeTimeSeries(monthlydate, monthlyresultData, "monthly"); |
- writeTimeSeries(yearlydate, yearlyresultData, "yearly"); |
+ doubleArray.writeTimeSeries(mainFolder, dailyresultData, "daily", "daily", true); |
+ doubleArray.writeTimeSeries(mainFolder, monthlyresultData, "monthly", "monthly", true); |
+ doubleArray.writeTimeSeries(mainFolder, yearlyresultData, "yearly", "yearly", true); |
|
- writeBoxplot(dailylowerQuartile,dailyupperQuartile, dailyoutliers, dailymedian, "daily"); |
- writeBoxplot(monthlylowerQuartile,monthlyupperQuartile, monthlyoutliers, monthlymedian, "monthly"); |
- writeBoxplot(yearlylowerQuartile,yearlyupperQuartile, yearlyoutliers, yearlymedian, "yearly"); |
- |
+ doubleArray.writeBoxplot(mainFolder, dailylowerQuartile, dailyupperQuartile, dailyoutliers, dailymedian, dailymin, "daily"); |
+ doubleArray.writeBoxplot(mainFolder, monthlylowerQuartile, monthlyupperQuartile, monthlyoutliers, monthlymedian, monthlymin, "monthly"); |
+ doubleArray.writeBoxplot(mainFolder, yearlylowerQuartile, yearlyupperQuartile, yearlyoutliers, yearlymedian, yearlymin, "yearly"); |
|
// Find what units that LOADEST has given the Load in |
if (ULFLAG == 1){ |