From cf970e11ea00fa974af933203cd45adc7e05e0bb Mon Sep 17 00:00:00 2001 From: Matt Nash Date: Tue, 20 Aug 2013 09:40:47 -0500 Subject: [PATCH] Issue #2250 resolve some ffmp data factory issues and make some changes to failing function calls in FFMP, and handle new types of objects in JUtil Change-Id: If6b33d542e2a0c2744e6c906d98273f589694772 Former-commit-id: 304ef3e3b88cb043b411ff27abda6b38584f61f3 [formerly 4c8e631e228b7593c1912bf51085e26dac96aad5 [formerly 8916efbaad066e1b5dc6d01b68fa67c72ebc982b]] Former-commit-id: 4c8e631e228b7593c1912bf51085e26dac96aad5 Former-commit-id: c2da9a715294efb31b33762dd5b03cfcc11dcccb --- .../uf/common/dataplugin/ffmp/FFMPUtils.java | 39 +++++++++++-------- .../ffmp/dataaccess/FFMPGeometryFactory.java | 29 ++++++++++++-- .../common_static/base/python/JUtil.py | 21 +++++++++- 3 files changed, 68 insertions(+), 21 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPUtils.java b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPUtils.java index 9f98071a4b..87bda5ae9e 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPUtils.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPUtils.java @@ -84,7 +84,9 @@ import com.vividsolutions.jts.io.WKTWriter; * 01/02/13 DR 1569 D. Hladky constants, arraylist to list and moved common menthods here * 03/01/13 DR 13228 G. Zhang Add state for VGB query and related code * 03/18/13 1817 D. Hladky Fixed issue with BOX where only 1 HUC was showing up. + * 08/20/13 2250 mnash Fixed incorrect return types for database queries. * + * * @author dhladky * @version 1 */ @@ -199,13 +201,15 @@ public class FFMPUtils { double extent, String cwa, String mode) { LinkedHashMap virtualBasins = new LinkedHashMap(); - String sql = "SELECT lid, county, name, lat, lon, state FROM location "// DR 13228 state added + /* + * DR 13228 state added to the below query + */ + String sql = "SELECT lid, county, name, lat, lon, state FROM location " + "where lid in " + "(select distinct(lid) from IngestFilter " + "where pe in ('PC', 'PP') " + "and ingest = 'T' " + "and dur < 2000)"; CoreDao dao = new CoreDao(DaoConfig.forDatabase(ShefConstants.IHFS)); try { - Object[] results = dao.executeSQLQuery(sql.toString()); Geometry poly = getCwaGeometry(cwa, mode); PreparedGeometry pg = PreparedGeometryFactory.prepare(poly); @@ -250,7 +254,7 @@ public class FFMPUtils { if (results.length > 0) { for (int i = 0; i < results.length; i++) { - String column_name = (String) results[i]; + String column_name = (String) ((Object[]) results[i])[0]; if (column_name.startsWith("upstream")) { upstreams.add("upstream" + j); j++; @@ -311,13 +315,14 @@ public class FFMPUtils { maxDepth = depth; } } - + // do an 80% analysis to find min (startDepth) if (pfafs.length > 0) { for (int myMinDepth = maxDepth; myMinDepth > 0; myMinDepth--) { int ilevelcount = 0; for (int i = 0; i < pfafs.length; i++) { - int idepth = pfafs[i].substring(prelimstartDepth).indexOf("0"); + int idepth = pfafs[i].substring(prelimstartDepth).indexOf( + "0"); idepth = prelimstartDepth + idepth; if (idepth >= myMinDepth) { ilevelcount++; @@ -595,7 +600,8 @@ public class FFMPUtils { if (results.length > 0) { for (int i = 0; i < results.length; i++) { if (results[i] != null) { - keys.add(new Integer((String) results[i]) + keys.add(new Integer( + (String) ((Object[]) results[i])[0]) .longValue()); } } @@ -806,7 +812,8 @@ public class FFMPUtils { public static Geometry getCwaGeometry(String cwa, String mode) { // convert buffer to km, then degrees String sql = "Select asBinary(" - + ScanUtils.getHighResolutionLevel("cwa") // DR 13228.getStandardResolutionLevel("cwa") + + ScanUtils.getHighResolutionLevel("cwa") // DR + // 13228.getStandardResolutionLevel("cwa") + ") from mapdata.cwa where cwa = '" + cwa + "'"; ISpatialQuery sq = null; @@ -1220,11 +1227,11 @@ public class FFMPUtils { if ((lat != Double.NaN) && (lon != Double.NaN)) { basin.setCoordinate(new Coordinate(lon, lat)); } - + if (dbResult[5] != null) { basin.setState((String) dbResult[5]);// DR 13228 } - + return basin; } @@ -1282,8 +1289,7 @@ public class FFMPUtils { * @param guids * @return */ - public static float getMaxRatioValue(List qpes, - List guids) { + public static float getMaxRatioValue(List qpes, List guids) { float ratio = Float.NaN; if ((qpes.size() == guids.size()) && (qpes.size() > 0) @@ -1329,8 +1335,7 @@ public class FFMPUtils { * @param guids * @return */ - public static float getMaxDiffValue(List qpes, - List guids) { + public static float getMaxDiffValue(List qpes, List guids) { float diff = Float.NaN; if ((qpes.size() == guids.size()) && (qpes.size() > 0) && (guids.size() > 0)) { @@ -1348,15 +1353,17 @@ public class FFMPUtils { return diff; } - + /** * Get the file used to store aggregate records + * * @param cwa * @param sourceSiteDataKey * @return */ public static File getHdf5File(String cwa, String sourceSiteDataKey) { - return new File("ffmp" + File.separatorChar + cwa + File.separatorChar + sourceSiteDataKey + ".h5"); + return new File("ffmp" + File.separatorChar + cwa + File.separatorChar + + sourceSiteDataKey + ".h5"); } - + } 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 b2417c5d8b..cd4462fe82 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 @@ -37,6 +37,7 @@ import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil; import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil.QUERY_MODE; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasinData; +import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord; import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates; import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates.MODE; @@ -64,7 +65,8 @@ import com.vividsolutions.jts.geom.Geometry; * ------------ ---------- ----------- -------------------------- * Jan 24, 2013 1552 mpduff Initial creation * Apr 16, 2013 1912 bsteffen Initial bulk hdf5 access for ffmp - * Jul 15, 2013 2184 dhladky Remove all HUC's for storage except ALL + * Jul 15, 2013 2184 dhladky Remove all HUC's for storage except ALL + * Aug,20, 2013 2250 mnash Change some methods that were not working in all cases * * * @@ -204,14 +206,22 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory { String siteKey = (String) request.getIdentifiers().get(SITE_KEY); String cwa = (String) request.getIdentifiers().get(WFO); + if (dataKey == null) { + dataKey = siteKey; + } + FFMPBasinData basinData = rec.getBasinData(); Map basinDataMap = basinData.getBasins(); HucLevelGeometriesFactory geomFactory = HucLevelGeometriesFactory .getInstance(); + // BAL - Switched to use siteKey instead of dataKey. + // Map geomMap = geomFactory.getGeometries(templates, + // dataKey, cwa, huc); Map geomMap = geomFactory.getGeometries(templates, - dataKey, cwa, huc); + siteKey, cwa, huc); + FFMPSourceConfigurationManager srcConfigMan = FFMPSourceConfigurationManager .getInstance(); SourceXML sourceXml = srcConfigMan.getSource(rec.getSourceName()); @@ -243,10 +253,23 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory { } FFMPBasin basin = basinDataMap.get(pfaf); + Float value = null; + if (basin == null) { continue; } - Float value = basin.getValue(rec.getDataTime().getRefTime()); + + if (basin instanceof FFMPGuidanceBasin) { + /* + * Bryon L - Added test for FFMPGuidanceBasin object. + * Couldn't use getValue(Date, Sourcename) here. Odd problem + * with date key reference. + */ + value = ((FFMPGuidanceBasin) basin).getValue( + rec.getSourceName(), 1000); + } else { + value = basin.getValue(rec.getDataTime().getRefTime()); + } String parameter = rec.getSourceName(); String unitStr = sourceXml.getUnit(); diff --git a/edexOsgi/com.raytheon.uf.common.python/utility/common_static/base/python/JUtil.py b/edexOsgi/com.raytheon.uf.common.python/utility/common_static/base/python/JUtil.py index b3da59d3fc..668ec1d017 100644 --- a/edexOsgi/com.raytheon.uf.common.python/utility/common_static/base/python/JUtil.py +++ b/edexOsgi/com.raytheon.uf.common.python/utility/common_static/base/python/JUtil.py @@ -19,11 +19,15 @@ # # -from java.lang import Integer, Float, Long, Boolean, String +from java.lang import Integer, Float, Long, Boolean, String, Object, Double from java.util import HashMap, LinkedHashMap, ArrayList from java.util import Collections +from java.util import Date from collections import OrderedDict +import jep +import datetime + # # Provides convenience methods for Java-Python bridging # @@ -36,7 +40,7 @@ from collections import OrderedDict # 05/01/08 njensen Initial Creation. # 03/12/13 1759 dgilling Extend Java List types handled # by javaObjToPyVal(). -# +# 08/20/13 2250 mnash Handle Dates, doubles, and arrays # # @@ -120,6 +124,10 @@ def pyValToJavaObj(val): for i in val: tempList.add(pyValToJavaObj(i)) retObj = Collections.unmodifiableList(tempList) + elif valtype is datetime.datetime: + epoch = datetime.datetime.utcfromtimestamp(0) + delta = val - epoch + retObj = Date(long(delta.total_seconds()) * 1000) elif issubclass(valtype, dict): retObj = pyDictToJavaMap(val) elif issubclass(valtype, JavaWrapperClass): @@ -140,6 +148,15 @@ def javaObjToPyVal(obj, customConverter=None): retVal = obj.longValue() elif objtype == "java.lang.Boolean": retVal = bool(obj.booleanValue()) + elif objtype == "java.lang.Double": + retVal = obj.doubleValue() + elif objtype == "java.util.Date": + retVal = datetime.datetime.fromtimestamp(obj.getTime() / 1000) + elif isinstance(obj, type(jep.jarray(0, Object))): + retVal = [] + size = len(obj) + for i in range(size): + retVal.append(javaObjToPyVal(obj.get(i), customConverter)) elif objtype in ["java.util.ArrayList", "java.util.Arrays$ArrayList"]: retVal = [] size = obj.size()