From d4609b08d94be4ed31dd75f8910c04b266456078 Mon Sep 17 00:00:00 2001 From: Matt Nash Date: Thu, 26 Jun 2014 16:22:11 -0500 Subject: [PATCH] Omaha #3170 get accum value from multiple times if they are requested in FFMP geometry factory Change-Id: Ia7759a942ec078ec5ce72b6c0007629e263d8a4a Former-commit-id: 983c2c71e093e75533e0961d24a7c7ce6804b00c [formerly 2f027b86244a3080a62c02cc816dcdca59e4538f] Former-commit-id: f31bf67ccad7cbc2d8cd6d9f4969127c1fbcedf3 --- .../ffmp/dataaccess/FFMPGeometryFactory.java | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/dataaccess/FFMPGeometryFactory.java b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/dataaccess/FFMPGeometryFactory.java index 51862f783c..fd380ca5a9 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/dataaccess/FFMPGeometryFactory.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/dataaccess/FFMPGeometryFactory.java @@ -50,6 +50,7 @@ import com.raytheon.uf.common.monitor.xml.SourceXML; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.common.time.TimeRange; import com.vividsolutions.jts.geom.Geometry; /** @@ -68,6 +69,7 @@ import com.vividsolutions.jts.geom.Geometry; * Jan,14, 2014 2667 mnash Remove getGridData method * May 1, 2014 3099 bkowal No longer use an empty pfaf list when the * data request locationNames list is empty. + * Jun 24, 2014 3170 mnash Get the accumulated time if multiple times are requested * * * @@ -114,10 +116,25 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory { DbQueryResponse dbQueryResponse) { List> results = dbQueryResponse.getResults(); Map cache = new HashMap(); - + FFMPRecord record = null; + TimeRange range = new TimeRange(); for (Map map : results) { for (Map.Entry es : map.entrySet()) { FFMPRecord rec = (FFMPRecord) es.getValue(); + // Adding all of the basin data to a single record so that we + // can get the accumulated values from that record + if (record == null) { + record = rec; + } + // building a time range of the earliest FFMP time (based on + // each record) to the latest FFMP time (based on each record) + if (range.getStart().after(rec.getDataTime().getRefTime())) { + range.setStart(rec.getDataTime().getRefTime()); + } + if (range.getEnd().before(rec.getDataTime().getRefTime())) { + range.setEnd(rec.getDataTime().getRefTime()); + } + try { rec.retrieveMapFromDataStore(templates); } catch (Exception e) { @@ -126,15 +143,30 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory { + rec.toString(), e); } - try { - cache = makeGeometryData(rec, request, cache); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - e.getLocalizedMessage(), e); + // loop over each pfaf id in the current record (rec) we are + // iterating. + // Add that basin data to the record that we are keeping around + // (record) + // to use to get the accumulated value. + for (Long pfaf : rec.getBasinData().getPfafIds()) { + // setValue is a misnomer here, it is actually an add + record.getBasinData() + .get(pfaf) + .setValue(rec.getDataTime().getRefTime(), + rec.getBasinData().get(pfaf).getValue()); } + } } - + // now that we have all the basin data in a single record (record), we + // can use the methods on the FFMPRecord class to get the accumulated + // value in the case of a non-guidance basin + try { + cache = makeGeometryData(record, request, cache, range); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "Unable to create the geoemtry data from the records.", e); + } return cache.values().toArray( new DefaultGeometryData[cache.values().size()]); } @@ -189,8 +221,8 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory { * @throws Exception */ private Map makeGeometryData(FFMPRecord rec, - IDataRequest request, Map cache) - throws Exception { + IDataRequest request, Map cache, + TimeRange range) throws Exception { String huc = (String) request.getIdentifiers().get(HUC); String dataKey = (String) request.getIdentifiers().get(DATA_KEY); String siteKey = (String) request.getIdentifiers().get(SITE_KEY); @@ -258,7 +290,11 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory { value = ((FFMPGuidanceBasin) basin).getValue( rec.getSourceName(), 1000); } else { - value = basin.getValue(rec.getDataTime().getRefTime()); + value = basin.getAccumValue(range.getStart(), + range.getEnd(), + sourceXml.getExpirationMinutes(rec.getSiteKey()), + false); + // value = basin.getValue(rec.getDataTime().getRefTime()); } String parameter = rec.getSourceName(); String unitStr = sourceXml.getUnit();