@@ -1,8 +1,11 @@ |
package cfa; |
import java.io.IOException; |
+import java.text.DateFormat; |
+import java.text.SimpleDateFormat; |
+import java.util.Date; |
|
/** |
-* Last Updated: 26-August-2013 |
+* Last Updated: 8-November-2013 |
* @author Tyler Wible |
* @since 12-July-2012 |
*/ |
@@ -67,8 +70,11 @@ |
return headers; |
} |
/** |
- * Opens and reads out the contents of the specified file to be used as flow data. The expected format of the file is |
- * a tab-delimited text file with dates in the first column and daily average cfs values in the second column. |
+ * Opens and reads out the contents of the specified file to be used as flow and water quality data. |
+ * @param userData_string The tab-delimited contents of the user data file |
+ * with header The expected format of the string is a tab-delimited text |
+ * file (\n separating lines) with dates in the first column and daily |
+ * average cfs values in the second column (\t separating columns). |
* (Acceptable date formats for the first column are: |
* yyyy-mm-dd, |
* yyyy-mm-d, |
@@ -78,7 +84,7 @@ |
* yyyy/mm/d, |
* yyyy/m/dd, |
* yyyy/m/d) |
- * @param stationID the station ID of the current station, used only for the error catch |
+ * (ex. "Date\tFlow\n1999-04-29\t8.3\n1999-05-09\t60.2\n1999-05-29\t20.1") |
* @param beginDate the user specified begin date, used to minimize the data returned |
* @param endDate the user specified end date, used to minimize the data returned |
* @return and object containing two of the following in returnArray[0] and |
@@ -88,7 +94,7 @@ |
* mg/L) |
* @throws IOException |
*/ |
- public Object[] readUserFileLDC(String userData_string, String stationID, String beginDate, String endDate) throws IOException{ |
+ public Object[] readUserFileLDC(String userData_string, String beginDate, String endDate) throws IOException{ |
|
String[] userData_types = userData_string.split("\\$\\$"); |
String userData_flow = userData_types[0]; |
@@ -101,8 +107,11 @@ |
return returnArray; |
} |
/** |
- * Opens and reads out the contents of the specified file to be used as flow data. The expected format of the file is |
- * a tab-delimited text file with dates in the first column and daily average cfs values in the second column. |
+ * Opens and reads out the contents of the specified file to be used as flow data. |
+ * @param userData_string The tab-delimited contents of the user data file |
+ * with header The expected format of the string is a tab-delimited text |
+ * file (\n separating lines) with dates in the first column and daily |
+ * average cfs values in the second column (\t separating columns). |
* (Acceptable date formats for the first column are: |
* yyyy-mm-dd, |
* yyyy-mm-d, |
@@ -112,7 +121,7 @@ |
* yyyy/mm/d, |
* yyyy/m/dd, |
* yyyy/m/d) |
- * @param stationID the station ID of the current station, used only for the error catch |
+ * (ex. "Date\tFlow\n1999-04-29\t8.3\n1999-05-09\t60.2\n1999-05-29\t20.1") |
* @param beginDate the user specified begin date, used to minimize the data returned |
* @param endDate the user specified end date, used to minimize the data returned |
* @return a string[][] with the contents of the user uploaded file formatted as: column1 = dates (yyyy-mm-dd), |
@@ -135,10 +144,7 @@ |
boolean valueExists = true; |
try{ |
double value = Double.parseDouble(currentColumns[1]); |
- }catch(NullPointerException e){ |
- valueExists = false; |
- }catch(NumberFormatException e){ |
- //If the user has enterd "null" don't keep the data |
+ }catch(NullPointerException | NumberFormatException e){ |
valueExists = false; |
} |
|
@@ -161,10 +167,7 @@ |
boolean valueExists = true; |
try{ |
double value = Double.parseDouble(currentColumns[1]); |
- }catch(NullPointerException e){ |
- valueExists = false; |
- }catch(NumberFormatException e){ |
- //If the user has enterd "null" don't keep the data |
+ }catch(NullPointerException | NumberFormatException e){ |
valueExists = false; |
} |
|
@@ -252,22 +255,43 @@ |
* @throws IOException |
*/ |
public String[][] minimizeUserData(String[][] allData, String beginDate, String endDate) throws IOException{ |
+ //Get today's date |
+ DateFormat desiredDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
+ Date currentDate = new Date(); |
+ String todaysDate = desiredDateFormat.format(currentDate); |
+ |
int ctr = 0; |
for(int i=0; i<allData.length; i++){ |
- //Check if the current data is within the date range, if so keep it |
- if((allData[i][0].compareTo(beginDate) >= 0) && (allData[i][0].compareTo(endDate) <= 0)){ |
- ctr++; |
+ if(todaysDate.equals(endDate)){ |
+ //If the end limit is today, keep future forcasted data as well |
+ if((allData[i][0].compareTo(beginDate) >= 0)){ |
+ ctr++; |
+ } |
+ }else{ |
+ //Check if the current data is within the date range, if so keep it |
+ if((allData[i][0].compareTo(beginDate) >= 0) && (allData[i][0].compareTo(endDate) <= 0)){ |
+ ctr++; |
+ } |
} |
} |
|
String[][] reducedData = new String[ctr][2]; |
ctr=0; |
for(int i=0; i<allData.length; i++){ |
- //Check if the current data is within the date range, if so keep it |
- if((allData[i][0].compareTo(beginDate) >= 0) && (allData[i][0].compareTo(endDate) <= 0)){ |
- reducedData[ctr][0] = allData[i][0];//date |
- reducedData[ctr][1] = allData[i][1];//value |
- ctr++; |
+ if(todaysDate.equals(endDate)){ |
+ //If the end limit is today, keep future forcasted data as well |
+ if((allData[i][0].compareTo(beginDate) >= 0)){ |
+ reducedData[ctr][0] = allData[i][0];//date |
+ reducedData[ctr][1] = allData[i][1];//value |
+ ctr++; |
+ } |
+ }else{ |
+ //Check if the current data is within the date range, if so keep it |
+ if((allData[i][0].compareTo(beginDate) >= 0) && (allData[i][0].compareTo(endDate) <= 0)){ |
+ reducedData[ctr][0] = allData[i][0];//date |
+ reducedData[ctr][1] = allData[i][1];//value |
+ ctr++; |
+ } |
} |
} |
return reducedData; |
@@ -9,7 +9,7 @@ |
import java.util.Date; |
|
/**' |
-* Last Updated: 26-August-2013 |
+* Last Updated: 8-November-2013 |
* @author Tyler Wible |
* @since 12-June-2011 |
*/ |
@@ -306,15 +306,14 @@ |
sortableData = usgs_Data.USGS_read_FDC(stationID, beginDate, endDate); |
|
//Retrieve WQ data from USGS website |
- USGS_Data usgs_data = new USGS_Data(); |
- WQdata = usgs_data.USGS_read_LDC(stationID); |
+ WQdata = usgs_Data.USGS_read_LDC(stationID); |
|
//If there is minimal flow data try getting WQ-flow data |
if(sortableData.length < 10){ |
//Extract USGS water quality code 00061 for dischage in cfs |
- String[][] WQFlow1 = usgs_data.minimizeUSGSWQdata(WQdata, "00061", beginDate, endDate); |
+ String[][] WQFlow1 = usgs_Data.minimizeUSGSWQdata(WQdata, "00061", beginDate, endDate); |
//Extract USGS water quality code 30209 for discharge test in m^3/s (cms) |
- String[][] WQFlow2 = usgs_data.minimizeUSGSWQdata(WQdata, "30209", beginDate, endDate); |
+ String[][] WQFlow2 = usgs_Data.minimizeUSGSWQdata(WQdata, "30209", beginDate, endDate); |
|
//Convert the m^3 to ft^3/s |
for(int i=0; i<WQFlow2.length; i++){ |
@@ -322,18 +321,18 @@ |
} |
|
//combine the WQ flows (cfs and converted cms) into a single variable to be used with the Flowdata |
- String[][] WQDataflows = usgs_data.mergeMinimizedWQdata(WQFlow1, WQFlow2); |
+ String[][] WQDataflows = usgs_Data.mergeMinimizedWQdata(WQFlow1, WQFlow2); |
|
//Combine flow data and WQ flow data into a variable of dates and flow values to be sorted |
- sortableData = usgs_data.mergeMinimizedWQdata(sortableData, WQDataflows); |
+ sortableData = usgs_Data.mergeMinimizedWQdata(sortableData, WQDataflows); |
} |
//Extract USGS water quality code for current wqTest only |
- WQdata = usgs_data.minimizeUSGSWQdata(WQdata, wqTest, beginDate, endDate); |
+ WQdata = usgs_Data.minimizeUSGSWQdata(WQdata, wqTest, beginDate, endDate); |
|
}else if(organizationName.equalsIgnoreCase("UserData")){ |
//Find the user uploaded data file and uses this for a timeseries graph |
User_Data user_Data = new User_Data(); |
- Object[] returnArray = user_Data.readUserFileLDC(userData, stationID, beginDate, endDate); |
+ Object[] returnArray = user_Data.readUserFileLDC(userData, beginDate, endDate); |
sortableData = (String[][]) returnArray[0]; |
WQdata = (String[][]) returnArray[1]; |
|
@@ -357,7 +356,7 @@ |
String[][] WQdata_user = new String[0][0]; |
if(mergeDatasets){ |
User_Data user_Data = new User_Data(); |
- Object[] returnArray = user_Data.readUserFileLDC(userData, stationID, beginDate, endDate); |
+ Object[] returnArray = user_Data.readUserFileLDC(userData, beginDate, endDate); |
sortableData_user = (String[][]) returnArray[0]; |
WQdata_user = (String[][]) returnArray[1]; |
if(sortableData_user.length==0){ |
@@ -16,7 +16,7 @@ |
import utils.BinUtils; |
|
/** |
-* Last Updated: 26-August-2013 |
+* Last Updated: 8-November-2013 |
* @author Tyler Wible & Tyler Dell |
* @since 27-March-2013 |
*/ |
@@ -971,7 +971,7 @@ |
}else if(organizationName.equalsIgnoreCase("UserData")){ |
//Find the user uploaded data file and uses this for a timeseries graph |
User_Data user_Data = new User_Data(); |
- Object[] returnArray = user_Data.readUserFileLDC(userData, stationID, beginDate, endDate); |
+ Object[] returnArray = user_Data.readUserFileLDC(userData, beginDate, endDate); |
sortableData = (String[][]) returnArray[0]; |
WQdata = (String[][]) returnArray[1]; |
|
@@ -992,7 +992,7 @@ |
|
if(mergeDatasets){ |
User_Data user_Data = new User_Data(); |
- Object[] returnArray = user_Data.readUserFileLDC(userData, stationID, beginDate, endDate); |
+ Object[] returnArray = user_Data.readUserFileLDC(userData, beginDate, endDate); |
sortableData_user = (String[][]) returnArray[0]; |
WQdata_user = (String[][]) returnArray[1]; |
if(sortableData_user.length==0){ |