Omaha #3170 get accum value from multiple times if they are requested in FFMP geometry factory

Change-Id: Ia7759a942ec078ec5ce72b6c0007629e263d8a4a

Former-commit-id: 983c2c71e0 [formerly 2f027b86244a3080a62c02cc816dcdca59e4538f]
Former-commit-id: f31bf67cca
This commit is contained in:
Matt Nash 2014-06-26 16:22:11 -05:00
parent f1d3019bf0
commit d4609b08d9

View file

@ -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
*
* </pre>
*
@ -114,10 +116,25 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
DbQueryResponse dbQueryResponse) {
List<Map<String, Object>> results = dbQueryResponse.getResults();
Map<Long, DefaultGeometryData> cache = new HashMap<Long, DefaultGeometryData>();
FFMPRecord record = null;
TimeRange range = new TimeRange();
for (Map<String, Object> map : results) {
for (Map.Entry<String, Object> 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<Long, DefaultGeometryData> makeGeometryData(FFMPRecord rec,
IDataRequest request, Map<Long, DefaultGeometryData> cache)
throws Exception {
IDataRequest request, Map<Long, DefaultGeometryData> 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();