@@ -4,7 +4,6 @@ |
import java.util.Iterator; |
import javax.xml.soap.MessageFactory; |
import javax.xml.soap.MimeHeaders; |
-import javax.xml.soap.Name; |
import javax.xml.soap.SOAPBody; |
import javax.xml.soap.SOAPBodyElement; |
import javax.xml.soap.SOAPConnection; |
@@ -34,6 +33,16 @@ |
* @throws Exception |
*/ |
public Object[] getCDWRflowData(String stationID, String beginDate, String endDate, String dataType) throws Exception { |
+ //Artificial limit due to the touchy-ness of CDWR to begin dates before the station data begins |
+ if(dataType.equalsIgnoreCase("15-min")){ |
+ if(beginDate.compareToIgnoreCase("2007-10-01") < 0){ |
+ beginDate = "2007-10-01"; |
+ } |
+ if(endDate.compareToIgnoreCase("2007-10-01") < 0){ |
+ endDate = "2007-10-01"; |
+ } |
+ } |
+ |
// Create SOAP Connection |
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); |
SOAPConnection soapConnection = soapConnectionFactory.createConnection(); |
@@ -59,16 +68,25 @@ |
//Open <Station> |
SOAPElement child3 = (SOAPElement)iter3.next(); |
Iterator<?> iter4 = child3.getChildElements(); |
- String currentStationData = ""; |
- for(int i=0; i<7; i++){//Hopefully ever station has 7 attributes (div, wd, abbrev, variable, transDateTime, resultCount, amount) |
- SOAPElement child4 = (SOAPElement)iter4.next(); |
- if(i == 0){ |
- currentStationData = child4.getValue(); |
- }else{ |
- currentStationData = currentStationData + "\t" + child4.getValue(); |
- } |
+ //Hopefully ever station has 7 attributes (div, wd, abbrev, variable, transDateTime, resultCount, amount) |
+ SOAPElement child4_0 = (SOAPElement)iter4.next(); |
+ SOAPElement child4_1 = (SOAPElement)iter4.next(); |
+ SOAPElement child4_2 = (SOAPElement)iter4.next(); |
+ SOAPElement child4_3 = (SOAPElement)iter4.next(); |
+ SOAPElement child4_4 = (SOAPElement)iter4.next(); |
+ SOAPElement child4_5 = (SOAPElement)iter4.next(); |
+ SOAPElement child4_6 = (SOAPElement)iter4.next(); |
+ |
+ //if the result is not null or -999, keep it |
+ if(!child4_5.getValue().equalsIgnoreCase(null) && !child4_5.getValue().equalsIgnoreCase("-999")){ |
+ stationData.add(child4_0.getValue() + "\t" + |
+ child4_1.getValue() + "\t" + |
+ child4_2.getValue() + "\t" + |
+ child4_3.getValue() + "\t" + |
+ child4_4.getValue() + "\t" + |
+ child4_5.getValue() + "\t" + |
+ child4_6.getValue() + "\t"); |
} |
- stationData.add(currentStationData); |
// while (iter4.hasNext()) { |
// SOAPElement child4 = (SOAPElement)iter4.next(); |
// String content = child4.getValue(); |
@@ -108,7 +126,7 @@ |
* @param variable the variable desired from this station (ex. "DISCHRG", "GAGE_HT", "AIR_TEMP") |
* @param beginDate the start date of data desired (yyyy-mm-dd) |
* @param endDate the end date of date desired (yyyy-mm-dd) |
- * @param aggregation the aggregation of data desired (ex. "Hourly", "Daily") |
+ * @param aggregation the aggregation of data desired (ex. "Hourly", "Daily", "15-min") |
* @return the response SOAP message from CDWR |
* @throws Exception |
*/ |
@@ -153,8 +171,10 @@ |
startDate_soap.addTextNode(beginDate); |
SOAPElement endDate_soap = soapBodyMethod.addChildElement("EndDate", "dwr"); |
endDate_soap.addTextNode(endDate); |
- SOAPElement soapAggregation = soapBodyMethod.addChildElement("Aggregation", "dwr"); |
- soapAggregation.addTextNode(aggregation); |
+ if(!aggregation.equalsIgnoreCase("15-min")){ |
+ SOAPElement soapAggregation = soapBodyMethod.addChildElement("Aggregation", "dwr"); |
+ soapAggregation.addTextNode(aggregation); |
+ } |
|
MimeHeaders headers = soapMessage.getMimeHeaders(); |
headers.addHeader("SOAPAction", serverURI + "GetSMSProvisionalData"); |
@@ -181,47 +201,52 @@ |
private String reformatDate(String date, String dataType){ |
String newDate = "1900-01-01"; |
|
- //Create new date format |
- if(dataType.equalsIgnoreCase("Daily")){ |
- //Get portions of date |
- int index1 = date.indexOf("/"); |
- int index2 = date.indexOf("/", index1 + 1); |
- int index3 = date.indexOf(" "); |
- String month = date.substring(0, index1); |
- String day = date.substring(index1 + 1, index2); |
- String year = date.substring(index2 + 1, index3); |
- |
- //check month size |
+ //Get portions of date |
+ int index1 = date.indexOf("/"); |
+ int index2 = date.indexOf("/", index1 + 1); |
+ int index3 = date.indexOf(" "); |
+ String month = date.substring(0, index1); |
+ String day = date.substring(index1 + 1, index2); |
+ String year = date.substring(index2 + 1, index3); |
+ //check month size |
if(month.length() < 2){ |
month = "0" + month; |
} |
- |
//check day size |
if(day.length() < 2){ |
day = "0" + day; |
} |
+ //Create new date format |
+ if(dataType.equalsIgnoreCase("Daily")){ |
//Assemble new date format |
newDate = year + "-" + month + "-" + day; |
|
- }else if(dataType.equalsIgnoreCase("Hourly")){ |
+ }else if(dataType.equalsIgnoreCase("Hourly") || dataType.equalsIgnoreCase("15-min")){ |
//Hourly data returns as m/d/yyyy HH:mm which matches |
//USGS 15-minute data is zero-based military time (24hr day from 00:00 to 23:00) |
- newDate = date; |
-// int index4 = date.indexOf(":"); |
-// int index5 = date.indexOf(":", index4 + 1); |
-// int index6 = date.indexOf(" ", index3 + 1); |
-// String hour = date.substring(index3 + 1, index4); |
-// String minute = date.substring(index4 + 1, index5); |
-// String amPM = date.substring(index6 + 1); |
-// |
-// |
-// int hour_int = (int) Double.parseDouble(hour); |
-// if(amPM.equalsIgnoreCase("PM")){ |
-// hour = String.valueOf(hour_int-1 + 12); |
-// }else{ |
-// hour = String.valueOf(hour_int-1); |
-// } |
-// newDate = year + "-" + month + "-" + day + " " + hour + ":" + minute; |
+ int index4 = date.indexOf(":"); |
+ int index5 = date.indexOf(":", index4 + 1); |
+ int index6 = date.indexOf(" ", index3 + 1); |
+ String hour = date.substring(index3 + 1, index4); |
+ String minute = date.substring(index4 + 1, index5); |
+ String amPM = date.substring(index6 + 1); |
+ |
+ //Convert AM/PM |
+ int hour_int = (int) Double.parseDouble(hour); |
+ if(amPM.equalsIgnoreCase("PM")){ |
+ hour = String.valueOf(hour_int-1 + 12); |
+ }else{ |
+ hour = String.valueOf(hour_int-1); |
+ } |
+ //check hour size |
+ if(hour.length() < 2){ |
+ hour = "0" + hour; |
+ } |
+ //check minute size |
+ if(minute.length() < 2){ |
+ minute = "0" + minute; |
+ } |
+ newDate = year + "-" + month + "-" + day + " " + hour + ":" + minute; |
} |
return newDate; |
} |
@@ -10,7 +10,7 @@ |
import java.util.Date; |
|
/** |
-* Last Updated: 10-July-2014 |
+* Last Updated: 11-July-2014 |
* @author Tyler Wible |
* @since 21-June-2012 |
*/ |
@@ -71,7 +71,7 @@ |
CDWR_Data cdwr_Data = new CDWR_Data(); |
ArrayList<String> textData = new ArrayList<String>(); |
|
- //Determine the type of download for CDWR: flow, hourly-flow, stage-discharge |
+ //Determine the type of download for CDWR: flow, hourly-flow, no aggrigation (15-min) flow, or stage-discharge |
if(wqTest.equalsIgnoreCase("flow")){ |
//Search for CDWR flow data |
Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Daily"); |
@@ -80,22 +80,14 @@ |
start = (String) returnArray[2]; |
end = (String) returnArray[3]; |
|
- }else if(wqTest.equalsIgnoreCase("Flood Flow")){ |
+ }else if(wqTest.equalsIgnoreCase("Flood Flow") || wqTest.equalsIgnoreCase("15-min flow")){ |
//Search for CDWR flow data |
- Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Daily"); |
+ Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "15-min"); |
textData = (ArrayList<String>) returnArray[0]; |
//flowData = (String[][]) returnArray[1]; |
start = (String) returnArray[2]; |
end = (String) returnArray[3]; |
|
- }else if(wqTest.equalsIgnoreCase("15-min flow")){ |
- //Search for CDWR hourly flow data |
- Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Hourly"); |
- textData = (ArrayList<String>) returnArray[0]; |
- //String[][] flowData = (String[][]) returnArray[1]; |
- start = (String) returnArray[2]; |
- end = (String) returnArray[3]; |
- |
}else if(wqTest.equalsIgnoreCase("stage-discharge")){ |
Object[] returnArray = cdwr_Data.getCDWRratingCurve(stationID); |
textData = (ArrayList<String>) returnArray[0]; |