Merge "Issue #1781 - Fix Hydro Time Series slow table loads" into omaha_13.3.1
Former-commit-id: 1df2884be78544697f629fca8c7fd0d09ce78aac
This commit is contained in:
commit
28d74d91b0
1 changed files with 284 additions and 249 deletions
|
@ -29,6 +29,7 @@ import com.raytheon.viz.hydrocommon.HydroConstants;
|
|||
|
||||
/**
|
||||
* Utility class for Stage/Discharge conversions.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
|
@ -39,6 +40,8 @@ import com.raytheon.viz.hydrocommon.HydroConstants;
|
|||
* May 11,2011 9281 lbousaid nothing get display in right y-axis when
|
||||
* there is no rating curve
|
||||
* Jan 03,2013 15652 wkwock Fix stage to discharge
|
||||
* Mar 12, 2013 1781 mpduff Fix stage2discharge flag preventing multiple db queries.
|
||||
*
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
|
@ -49,6 +52,7 @@ import com.raytheon.viz.hydrocommon.HydroConstants;
|
|||
|
||||
public class StageDischargeUtils {
|
||||
private static String previousLid = null;
|
||||
|
||||
private static Rating ratingData = null;
|
||||
|
||||
private static String RATING_QUERY = "select lid,stage,discharge from rating where lid=':lid' order by stage asc";
|
||||
|
@ -60,8 +64,10 @@ public class StageDischargeUtils {
|
|||
/**
|
||||
* Returns the corresponding stage value for the discharge value passed in.
|
||||
*
|
||||
* @param gd the Graph Data
|
||||
* @param stage the Discharge Value
|
||||
* @param gd
|
||||
* the Graph Data
|
||||
* @param stage
|
||||
* the Discharge Value
|
||||
* @return the corresponding stage value
|
||||
*/
|
||||
public static double getStageFromDischarge(GraphData gd, double stage) {
|
||||
|
@ -79,10 +85,14 @@ public class StageDischargeUtils {
|
|||
public static boolean checkRatingTable(String lid) {
|
||||
boolean retVal = false;
|
||||
try {
|
||||
if ((ratingData == null) || !ratingData.getLid().equalsIgnoreCase(lid)) {
|
||||
if ((ratingData == null)
|
||||
|| !ratingData.getLid().equalsIgnoreCase(lid)) {
|
||||
ratingData = queryRatingData(lid);
|
||||
needToFindShiftAmount = true;
|
||||
/* Check the Rating object for data and return true if data are available*/
|
||||
/*
|
||||
* Check the Rating object for data and return true if data are
|
||||
* available
|
||||
*/
|
||||
if (ratingData.getStage().size() > 2) {
|
||||
retVal = true;
|
||||
}
|
||||
|
@ -114,16 +124,19 @@ public class StageDischargeUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert the stage to discharge for the location and stage value passed in.
|
||||
* Convert the stage to discharge for the location and stage value passed
|
||||
* in.
|
||||
*
|
||||
* @param lid The Location ID
|
||||
* @param stage The Stage Value
|
||||
* @param lid
|
||||
* The Location ID
|
||||
* @param stage
|
||||
* The Stage Value
|
||||
* @return the corresponding discharge
|
||||
*/
|
||||
public static double stage2discharge(String lid, double stage) {
|
||||
/*
|
||||
* Check to determine if the stage value is missing.
|
||||
* If it is then return a flow value of missing.
|
||||
* Check to determine if the stage value is missing. If it is then
|
||||
* return a flow value of missing.
|
||||
*/
|
||||
if (stage == HydroConstants.MISSING_VALUE) {
|
||||
return HydroConstants.RATING_CONVERT_FAILED;
|
||||
|
@ -132,14 +145,15 @@ public class StageDischargeUtils {
|
|||
double discharge = HydroConstants.MISSING_VALUE;
|
||||
|
||||
/*
|
||||
* If the lid passed in is NOT the same as the previous lid
|
||||
* then copy lid passed in to previous and get the rating curve
|
||||
* If the lid passed in is NOT the same as the previous lid then copy
|
||||
* lid passed in to previous and get the rating curve
|
||||
*/
|
||||
if (!lid.equals(previousLid)) {
|
||||
previousLid = lid;
|
||||
|
||||
try {
|
||||
if ((ratingData == null) || !ratingData.getLid().equalsIgnoreCase(lid)) {
|
||||
if ((ratingData == null)
|
||||
|| !ratingData.getLid().equalsIgnoreCase(lid)) {
|
||||
needToFindShiftAmount = true;
|
||||
ratingData = queryRatingData(lid);
|
||||
}
|
||||
|
@ -154,19 +168,20 @@ public class StageDischargeUtils {
|
|||
}
|
||||
|
||||
/*
|
||||
* if the pointer to the head is NULL then that means there
|
||||
* is NO rating curve for that location
|
||||
* if the pointer to the head is NULL then that means there is NO rating
|
||||
* curve for that location
|
||||
*/
|
||||
if (ratingData == null) {
|
||||
return HydroConstants.RATING_CONVERT_FAILED;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there are less than 2 points (ie. one) then that means there
|
||||
* is NO usable rating curve for that location
|
||||
* If there are less than 2 points (ie. one) then that means there is NO
|
||||
* usable rating curve for that location
|
||||
*/
|
||||
if (ratingData.getDischarge().size() < 2) {
|
||||
//TODO - Log this message printf("Rating table has less than 2 points for LID=%s\n", lid);
|
||||
// TODO - Log this message
|
||||
// printf("Rating table has less than 2 points for LID=%s\n", lid);
|
||||
return HydroConstants.RATING_CONVERT_FAILED;
|
||||
}
|
||||
|
||||
|
@ -175,9 +190,8 @@ public class StageDischargeUtils {
|
|||
ArrayList<Double> stageRatingCurve = ratingData.getStage();
|
||||
|
||||
/*
|
||||
* Determine if there is a shift factor for this rating curve.
|
||||
* If there is, then shift each point in the rating curve by this
|
||||
* factor.
|
||||
* Determine if there is a shift factor for this rating curve. If there
|
||||
* is, then shift each point in the rating curve by this factor.
|
||||
*/
|
||||
if (needToFindShiftAmount) {
|
||||
ratingShiftArray = queryRatingShift(lid);
|
||||
|
@ -192,8 +206,8 @@ public class StageDischargeUtils {
|
|||
stageRatingCurve.set(i, d);
|
||||
}
|
||||
ratingData.setStage(stageRatingCurve);
|
||||
needToFindShiftAmount = false;
|
||||
}
|
||||
needToFindShiftAmount = false;
|
||||
}
|
||||
|
||||
ArrayList<Double> dischargeList = ratingData.getDischarge();
|
||||
|
@ -213,8 +227,8 @@ public class StageDischargeUtils {
|
|||
if (stageDifference == 0) {
|
||||
discharge = minDischarge;
|
||||
} else {
|
||||
discharge = minDischarge - ((dischargeDifference/stageDifference) *
|
||||
(minStage - stage));
|
||||
discharge = minDischarge
|
||||
- ((dischargeDifference / stageDifference) * (minStage - stage));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,13 +237,16 @@ public class StageDischargeUtils {
|
|||
* rating table then extrapolate the discharge
|
||||
*/
|
||||
if (stage > maxStage) {
|
||||
double prevStage = stageRatingCurve.get(stageRatingCurve.size() - 2);
|
||||
double dischargeDifference = maxDischarge - dischargeList.get(dischargeList.size() - 2);
|
||||
double prevStage = stageRatingCurve
|
||||
.get(stageRatingCurve.size() - 2);
|
||||
double dischargeDifference = maxDischarge
|
||||
- dischargeList.get(dischargeList.size() - 2);
|
||||
double stageDifference = maxStage - prevStage;
|
||||
if (stageDifference == 0) {
|
||||
discharge = maxDischarge;
|
||||
} else {
|
||||
discharge = maxDischarge + ((dischargeDifference/stageDifference) * (stage - maxStage));
|
||||
discharge = maxDischarge
|
||||
+ ((dischargeDifference / stageDifference) * (stage - maxStage));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,8 +266,8 @@ public class StageDischargeUtils {
|
|||
if (stageDifference == 0) {
|
||||
discharge = lowerDischarge;
|
||||
} else {
|
||||
discharge = lowerDischarge + ((dischargeDifference/stageDifference) *
|
||||
(stage - lowerStage));
|
||||
discharge = lowerDischarge
|
||||
+ ((dischargeDifference / stageDifference) * (stage - lowerStage));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -268,16 +285,19 @@ public class StageDischargeUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert the discharge to stage for the location and discharge value passed in.
|
||||
* Convert the discharge to stage for the location and discharge value
|
||||
* passed in.
|
||||
*
|
||||
* @param lid The Location ID
|
||||
* @param stage The Stage Value
|
||||
* @param lid
|
||||
* The Location ID
|
||||
* @param stage
|
||||
* The Stage Value
|
||||
* @return the corresponding discharge
|
||||
*/
|
||||
public static double discharge2stage(String lid, double discharge) {
|
||||
/*
|
||||
* Check to see if the discharge value is bad, i.e. missing.
|
||||
* If it is bad, then return a stage value of missing.
|
||||
* Check to see if the discharge value is bad, i.e. missing. If it is
|
||||
* bad, then return a stage value of missing.
|
||||
*/
|
||||
if (discharge < 0) {
|
||||
return HydroConstants.RATING_CONVERT_FAILED;
|
||||
|
@ -286,15 +306,16 @@ public class StageDischargeUtils {
|
|||
boolean needToFindShiftAmount = false;
|
||||
|
||||
/*
|
||||
* If the lid passed in is NOT the same as the previous lid
|
||||
* then copy lid passed in to previous and get the rating curve
|
||||
* If the lid passed in is NOT the same as the previous lid then copy
|
||||
* lid passed in to previous and get the rating curve
|
||||
*/
|
||||
if (!lid.equals(previousLid)) {
|
||||
previousLid = lid;
|
||||
needToFindShiftAmount = true;
|
||||
|
||||
try {
|
||||
if ((ratingData == null) || !ratingData.getLid().equalsIgnoreCase(lid)) {
|
||||
if ((ratingData == null)
|
||||
|| !ratingData.getLid().equalsIgnoreCase(lid)) {
|
||||
ratingData = queryRatingData(lid);
|
||||
needToFindShiftAmount = true;
|
||||
}
|
||||
|
@ -307,19 +328,20 @@ public class StageDischargeUtils {
|
|||
}
|
||||
|
||||
/*
|
||||
* if the pointer to the head is NULL then that means there
|
||||
* is NO rating curve for that location
|
||||
* if the pointer to the head is NULL then that means there is NO rating
|
||||
* curve for that location
|
||||
*/
|
||||
if (ratingData == null) {
|
||||
return HydroConstants.RATING_CONVERT_FAILED;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there are less than 2 points (ie. one) then that means there
|
||||
* is NO usable rating curve for that location
|
||||
* If there are less than 2 points (ie. one) then that means there is NO
|
||||
* usable rating curve for that location
|
||||
*/
|
||||
if (ratingData.getDischarge().size() < 2) {
|
||||
//TODO - Log this message printf("Rating table has less than 2 points for LID=%s\n", lid);
|
||||
// TODO - Log this message
|
||||
// printf("Rating table has less than 2 points for LID=%s\n", lid);
|
||||
return HydroConstants.RATING_CONVERT_FAILED;
|
||||
}
|
||||
|
||||
|
@ -328,9 +350,8 @@ public class StageDischargeUtils {
|
|||
ArrayList<Double> dischargeRatingCurve = ratingData.getDischarge();
|
||||
|
||||
/*
|
||||
* Determine if there is a shift factor for this rating curve.
|
||||
* If there is, then shift each point in the rating curve by this
|
||||
* factor.
|
||||
* Determine if there is a shift factor for this rating curve. If there
|
||||
* is, then shift each point in the rating curve by this factor.
|
||||
*/
|
||||
if (needToFindShiftAmount) {
|
||||
ratingShiftArray = queryRatingShift(lid);
|
||||
|
@ -343,7 +364,8 @@ public class StageDischargeUtils {
|
|||
|
||||
ArrayList<Double> stageList = ratingData.getStage();
|
||||
double minDischarge = dischargeRatingCurve.get(0);
|
||||
double maxDischarge = dischargeRatingCurve.get(dischargeRatingCurve.size() - 1);
|
||||
double maxDischarge = dischargeRatingCurve.get(dischargeRatingCurve
|
||||
.size() - 1);
|
||||
double minStage = stageList.get(0);
|
||||
double maxStage = stageList.get(stageList.size() - 1);
|
||||
|
||||
|
@ -358,34 +380,35 @@ public class StageDischargeUtils {
|
|||
if (dischargeDifference == 0) {
|
||||
stage = minStage;
|
||||
} else {
|
||||
stage = minStage - ((stageDifference/dischargeDifference) *
|
||||
(minDischarge - discharge));
|
||||
stage = minStage
|
||||
- ((stageDifference / dischargeDifference) * (minDischarge - discharge));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if the discharge value passed in is greater then the highest discharge
|
||||
* in the rating table then extrapolate the stage
|
||||
* if the discharge value passed in is greater then the highest
|
||||
* discharge in the rating table then extrapolate the stage
|
||||
*/
|
||||
if (discharge > maxDischarge) {
|
||||
double prevDischarge = dischargeRatingCurve.get(dischargeRatingCurve.size() - 2);
|
||||
double prevDischarge = dischargeRatingCurve
|
||||
.get(dischargeRatingCurve.size() - 2);
|
||||
double dischargeDifference = maxDischarge - prevDischarge;
|
||||
double stageDifference = maxStage - stageList.get(stageList.size() - 2);
|
||||
double stageDifference = maxStage
|
||||
- stageList.get(stageList.size() - 2);
|
||||
|
||||
if (dischargeDifference == 0) {
|
||||
stage = maxStage;
|
||||
} else {
|
||||
stage = maxStage + ((stageDifference/dischargeDifference) *
|
||||
(discharge - maxDischarge));
|
||||
stage = maxStage
|
||||
+ ((stageDifference / dischargeDifference) * (discharge - maxDischarge));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if the discharge value passed in is between the lowest and highest
|
||||
discharge in the rating table then interpolate the stage
|
||||
* if the discharge value passed in is between the lowest and highest
|
||||
* discharge in the rating table then interpolate the stage
|
||||
*/
|
||||
if ((discharge <= maxDischarge) && (discharge >= minDischarge))
|
||||
{
|
||||
if ((discharge <= maxDischarge) && (discharge >= minDischarge)) {
|
||||
double lowerStage = minStage;
|
||||
double lowerDischarge = minDischarge;
|
||||
|
||||
|
@ -393,15 +416,16 @@ public class StageDischargeUtils {
|
|||
double nextDischarge = dischargeRatingCurve.get(i);
|
||||
double nextStage = stageList.get(i);
|
||||
|
||||
if ((discharge >= lowerDischarge) && (discharge <= nextDischarge)) {
|
||||
if ((discharge >= lowerDischarge)
|
||||
&& (discharge <= nextDischarge)) {
|
||||
double dischargeDifference = nextDischarge - lowerDischarge;
|
||||
double stageDifference = nextStage - lowerStage;
|
||||
|
||||
if (dischargeDifference == 0) {
|
||||
stage = lowerStage;
|
||||
} else {
|
||||
stage = lowerStage + ((stageDifference/dischargeDifference) *
|
||||
(discharge - lowerDischarge));
|
||||
stage = lowerStage
|
||||
+ ((stageDifference / dischargeDifference) * (discharge - lowerDischarge));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -417,23 +441,29 @@ public class StageDischargeUtils {
|
|||
/**
|
||||
* Get the data from the IHFS Rating table for the specified Location Id.
|
||||
*
|
||||
* @param lid The Location ID
|
||||
* @param lid
|
||||
* The Location ID
|
||||
* @return The data from the rating table in IHFS
|
||||
* @throws VizException
|
||||
*/
|
||||
private static Rating queryRatingData(String lid) throws VizException, NullPointerException {
|
||||
private static Rating queryRatingData(String lid) throws VizException,
|
||||
NullPointerException {
|
||||
/* Query the rating table */
|
||||
|
||||
Rating rating = new Rating(lid);
|
||||
|
||||
List<Object[]> results = DirectDbQuery.executeQuery(RATING_QUERY.replace(":lid", lid), HydroConstants.IHFS, QueryLanguage.SQL);
|
||||
List<Object[]> results = DirectDbQuery.executeQuery(
|
||||
RATING_QUERY.replace(":lid", lid), HydroConstants.IHFS,
|
||||
QueryLanguage.SQL);
|
||||
if (results != null) {
|
||||
//the Rating constructor already add stage and discharge to it. so clear it...
|
||||
// the Rating constructor already add stage and discharge to it. so
|
||||
// clear it...
|
||||
rating.getStage().clear();
|
||||
rating.getDischarge().clear();
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
Object[] sa = results.get(i);
|
||||
if (((sa[1] != null) || (sa[1] != "")) && ((sa[2] != null) || (sa[2] != ""))) {
|
||||
if (((sa[1] != null) || (sa[1] != ""))
|
||||
&& ((sa[2] != null) || (sa[2] != ""))) {
|
||||
rating.addStage((Double) sa[1]);
|
||||
rating.addDischarge((Double) sa[2]);
|
||||
}
|
||||
|
@ -444,17 +474,22 @@ public class StageDischargeUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the data from the IHFS RatingShift table for the specified Location Id.
|
||||
* Get the data from the IHFS RatingShift table for the specified Location
|
||||
* Id.
|
||||
*
|
||||
* @param lid The Location ID
|
||||
* @return The data from the ratingShift table in IHFS, null if no data available
|
||||
* @param lid
|
||||
* The Location ID
|
||||
* @return The data from the ratingShift table in IHFS, null if no data
|
||||
* available
|
||||
* @throws VizException
|
||||
*/
|
||||
private static ArrayList<Object[]> queryRatingShift(String lid) {
|
||||
/* Query the ratingShift table */
|
||||
ArrayList<Object[]> results = null;
|
||||
try {
|
||||
results = (ArrayList<Object[]>)DirectDbQuery.executeQuery(RATING_SHIFT_QUERY.replace(":lid", lid), HydroConstants.IHFS, QueryLanguage.SQL);
|
||||
results = (ArrayList<Object[]>) DirectDbQuery.executeQuery(
|
||||
RATING_SHIFT_QUERY.replace(":lid", lid),
|
||||
HydroConstants.IHFS, QueryLanguage.SQL);
|
||||
} catch (VizException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NullPointerException e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue