diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFFGForceUtil.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFFGForceUtil.java index 3eeb5ec014..dac07a4582 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFFGForceUtil.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFFGForceUtil.java @@ -24,7 +24,6 @@ import java.util.List; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceInterpolation; -import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord; import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates; import com.raytheon.uf.common.monitor.config.FFFGDataMgr; import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager; @@ -44,6 +43,7 @@ import com.raytheon.uf.common.monitor.xml.SourceXML; * 01/14/13 1569 dhladky changed arraylist to list * 04/15/13 1890 dhladky Changed COUNTY to use constant * 05/10/13 1919 mpduff If there are forced pfafs then the aggregate is forced. + * 05/22/13 1902 mpduff Added methods to get forced values. * * * @@ -135,10 +135,8 @@ public class FFFGForceUtil { pfafList = ft.getAggregatePfafs(cBasin.getPfaf(), resource.getSiteKey(), resource.getHuc()); } else if (!domain.equals("NA")) { - if (!resource.getHuc().equals(FFMPRecord.ALL)) { - pfafList = ft.getAggregatePfafsByDomain(cBasin.getPfaf(), - resource.getSiteKey(), domain, resource.getHuc()); - } + pfafList = ft.getAggregatePfafsByDomain(cBasin.getPfaf(), + resource.getSiteKey(), domain, resource.getHuc()); } // else use the existing pfaf list // Add current pfaf to the list @@ -253,7 +251,7 @@ public class FFFGForceUtil { float tvalue = 0.0f; float value; int i = 0; - if (interpolation.isInterpolate() == false) { + if (!interpolation.isInterpolate()) { FFFGDataMgr dman = FFFGDataMgr.getInstance(); for (long pfaf : forcedPfafs) { long countyFips = templates.getCountyFipsByPfaf(pfaf); @@ -266,6 +264,49 @@ public class FFFGForceUtil { } return tvalue / i; + } else { + // TODO interpolated code under new ticket + } + + return Float.NaN; + } + + /** + * Get the max forced value (max is smallest number for FFG) + * + * @param pfafList + * list of pfaf ids + * @param forcedPfafs + * list of forced pfaf ids + * @param interpolation + * FFMPGuidanceInterpolation object + * @param expiration + * force expiration + * @param templates + * ffmp templates + * @return max forced value + */ + public float getMaxForcedValue(List pfafList, List forcedPfafs, + FFMPGuidanceInterpolation interpolation, long expiration, + FFMPTemplates templates) { + float tvalue = 0.0f; + float value; + if (!interpolation.isInterpolate()) { + FFFGDataMgr dman = FFFGDataMgr.getInstance(); + for (long pfaf : forcedPfafs) { + long countyFips = templates.getCountyFipsByPfaf(pfaf); + templates.getCountyFipsByPfaf(pfaf); + value = dman.adjustValue(Float.NaN, + interpolation.getStandardSource(), pfaf, countyFips); + + if (value < tvalue) { + tvalue = value; + } + } + + return tvalue; + } else { + // TODO interpolated code } return Float.NaN; @@ -315,4 +356,40 @@ public class FFFGForceUtil { public void setSliderTime(double sliderTime) { this.sliderTime = sliderTime; } + + /** + * Get the forced values for the pfaf list. + * + * @param pfafList + * list of pfaf ids + * @param forcedPfafs + * list of forced pfafs + * @param ffmpGuidanceInterpolation + * FFMPGuidanceInterpolation object + * @param guidSourceExpiration + * expiration time + * @param ft + * ffmp templates + * @return list of forced guidance values + */ + public List getForcedGuidValues(List pfafList, + List forcedPfafs, + FFMPGuidanceInterpolation ffmpGuidanceInterpolation, + long guidSourceExpiration, FFMPTemplates ft) { + List guidList = new ArrayList(); + if (pfafList != null) { + for (Long pfaf : pfafList) { + if (pfaf == null) { + continue; + } + + List pl = new ArrayList(); + pl.add(pfaf); + float val = getAvgForcedValue(pl, forcedPfafs, + ffmpGuidanceInterpolation, guidSourceExpiration, ft); + guidList.add(val); + } + } + return guidList; + } } diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java index eee705cf71..3ce931953a 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java @@ -79,6 +79,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FfmpTableConfigData; * Apr 26, 2013 1954 bsteffen Minor code cleanup throughout FFMP. * May 07, 2013 1986 njensen Removed unnecessary sort * May 10, 2013 1919 mpduff Fixed problem with VGBs + * May 22, 2013 1902 mpduff Code cleanup. * * * @@ -207,10 +208,8 @@ public class FFMPDataGenerator { setFFMPRow(fbd.get(key), tData, false, cwa); } catch (Exception e) { - statusHandler - .handle(Priority.PROBLEM, - "Couldn't create table row" - + e); + statusHandler.handle(Priority.PROBLEM, + "Couldn't create table row", e); } if (virtualBasin != null) { for (Long id : ft @@ -257,10 +256,8 @@ public class FFMPDataGenerator { setFFMPRow(fbd.get(key), tData, isVGB, null); } catch (Exception e) { - statusHandler - .handle(Priority.PROBLEM, - "Couldn't create table row" - + e); + statusHandler.handle(Priority.PROBLEM, + "Couldn't create table row", e); } } } @@ -293,10 +290,10 @@ public class FFMPDataGenerator { virtualBasin.get(id), tData, true, null); } catch (Exception e) { - statusHandler.handle( - Priority.PROBLEM, - "Couldn't create table row" - + e); + statusHandler + .handle(Priority.PROBLEM, + "Couldn't create table row", + e); } } } @@ -414,6 +411,11 @@ public class FFMPDataGenerator { if (guidCellData == null) { // check for forcing even if no data are available guidance = getForcedAvg(domain, cBasin, guidType); + boolean forced = !guidance.isNaN(); + guidCellData = new FFMPTableCellData( + FIELDS.GUIDANCE, guidance, forced); + } else { + guidance = guidCellData.getValueAsFloat(); } trd.setTableCellData(i + 4, guidCellData); @@ -440,7 +442,6 @@ public class FFMPDataGenerator { } } else { displayName = getDisplayName(cBasin); - if (displayName != null) { long cBasinPfaf = cBasin.getPfaf(); String cBasinPfafStr = Long.toString(cBasinPfaf); @@ -498,6 +499,9 @@ public class FFMPDataGenerator { if (guidCellData == null) { // check for forcing even if no data are available guidance = getForcedAvg(domain, cBasin, guidType); + boolean forced = !guidance.isNaN(); + guidCellData = new FFMPTableCellData( + FIELDS.GUIDANCE, guidance, forced); } else { guidance = guidCellData.getValueAsFloat(); } @@ -587,11 +591,13 @@ public class FFMPDataGenerator { guidance, forcedPfafs, resource.getGuidSourceExpiration(guidType)); } else { - guidance = resource.getGuidanceValue(ffmpGuidBasin, paintRefTime, - guidType); + if (ffmpGuidBasin != null) { + guidance = resource.getGuidanceValue(ffmpGuidBasin, + paintRefTime, guidType); - if (guidance < 0.0f) { - guidance = Float.NaN; + if (guidance < 0.0f) { + guidance = Float.NaN; + } } } @@ -783,31 +789,30 @@ public class FFMPDataGenerator { FFMPBasinData guidBasin = guidBasins.get(guidType); List pfafList = new ArrayList(); + if (cBasin.getAggregated()) { + pfafList = ft.getAggregatePfafs(cBasin.getPfaf(), + siteKey, huc); + pfafList.add(ft.getAggregatedPfaf(cBasin.getPfaf(), + siteKey, huc)); + } + + boolean forced = false; + List forcedPfafs = new ArrayList(); + FFFGDataMgr fdm = FFFGDataMgr.getInstance(); + + if (fdm.isForcingConfigured()) { + forceUtil.calculateForcings(pfafList, ft, cBasin); + forcedPfafs = forceUtil.getForcedPfafList(); + forced = forceUtil.isForced(); + } + + if (!forced) { + if ((forcedPfafs != null) && (!forcedPfafs.isEmpty())) { + forced = true; + } + } if ((guidBasin != null) && (!guidBasin.getBasins().isEmpty())) { - if (cBasin.getAggregated()) { - pfafList = ft.getAggregatePfafs(cBasin.getPfaf(), - siteKey, huc); - pfafList.add(ft.getAggregatedPfaf(cBasin.getPfaf(), - siteKey, huc)); - } - - boolean forced = false; - List forcedPfafs = new ArrayList(); - FFFGDataMgr fdm = FFFGDataMgr.getInstance(); - - if (fdm.isForcingConfigured()) { - forceUtil.calculateForcings(pfafList, ft, cBasin); - forcedPfafs = forceUtil.getForcedPfafList(); - forced = forceUtil.isForced(); - } - - if (!forced) { - if ((forcedPfafs != null) - && (!forcedPfafs.isEmpty())) { - forced = true; - } - } if (isWorstCase) { guidance = guidRecords @@ -830,8 +835,19 @@ public class FFMPDataGenerator { trd.setTableCellData(i + 4, new FFMPTableCellData( FIELDS.GUIDANCE, guidance, forced)); } else { + if (forced) { + // Recalculate guidance using the forced value(s) + guidance = forceUtil.getMaxForcedValue( + pfafList, + forcedPfafs, + resource.getGuidanceInterpolators().get( + guidType), resource + .getGuidSourceExpiration(guidType), + ft); + } + trd.setTableCellData(i + 4, new FFMPTableCellData( - FIELDS.GUIDANCE, Float.NaN)); + FIELDS.GUIDANCE, guidance, forced)); } // If guidance is NaN then it cannot be > 0 @@ -846,6 +862,14 @@ public class FFMPDataGenerator { guids = guidBasin.getGuidanceValues(pfafs, resource .getGuidanceInterpolators().get(guidType), resource.getGuidSourceExpiration(guidType)); + } else if (forced) { + guids = forceUtil.getForcedGuidValues( + pfafList, + forcedPfafs, + resource.getGuidanceInterpolators().get( + guidType), resource + .getGuidSourceExpiration(guidType), + ft); } if ((!qpes.isEmpty()) diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java index 79c025cc12..6128e1fb79 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java @@ -72,6 +72,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.listeners.FFMPLoaderEvent; * Apr 9, 2013 1890 dhladky removed loading of phantom Virtual template and cache file processing. * Apr 18, 2013 1912 bsteffen Increase bulk requests to pypies. * Apr 26, 2013 1954 bsteffen Minor code cleanup throughout FFMP. + * May 22, 2013 1902 mpduff Check for null times. * * * @@ -105,9 +106,9 @@ public class FFMPDataLoader extends Thread { private FFMPConfig config = null; - private ArrayList loadListeners = new ArrayList(); + private final ArrayList loadListeners = new ArrayList(); - private CountDownLatch latch; + private final CountDownLatch latch; public FFMPDataLoader(FFMPResourceData resourceData, Date timeBack, Date mostRecentTime, LOADER_TYPE loadType, List hucsToLoad) { @@ -195,9 +196,8 @@ public class FFMPDataLoader extends Thread { } if ((loadType == LOADER_TYPE.INITIAL || loadType == LOADER_TYPE.GENERAL) && !product.getRate().equals(product.getQpe())) { - Map> rateURIs = monitor - .getAvailableUris(siteKey, dataKey, product.getRate(), - mostRecentTime); + Map> rateURIs = monitor.getAvailableUris( + siteKey, dataKey, product.getRate(), mostRecentTime); if (rateURIs.containsKey(mostRecentTime)) { rateURI = rateURIs.get(mostRecentTime).get(0); } @@ -243,11 +243,13 @@ public class FFMPDataLoader extends Thread { NavigableMap> iguidURIs = null; Date guidTime = timeBack; - if (loadType == LOADER_TYPE.GENERAL) { guidTime = monitor.getPreviousQueryTime(siteKey, guidSource.getSourceName()); } + if (guidTime == null) { + continue; + } iguidURIs = monitor.getAvailableUris(siteKey, dataKey, guidSource.getSourceName(), guidTime); @@ -292,10 +294,11 @@ public class FFMPDataLoader extends Thread { SourceXML source = sourceConfig.getSource(product.getQpe()); - qpeCache = readAggregateRecord(source, dataKey, wfo); + qpeCache = readAggregateRecord(source, dataKey, wfo); if (qpeCache != null) { - monitor.insertFFMPData(qpeCache, qpeURIs, siteKey, product.getQpe()); + monitor.insertFFMPData(qpeCache, qpeURIs, siteKey, + product.getQpe()); } }