Issue #1394: Reduce GFE Grid Database calls

Change-Id: I7462cca18b1b46169b25611dddbad844895be0cd

Former-commit-id: ac41861f0b [formerly 3c3c695f24] [formerly 0670ac79fa [formerly bc127f06236cb1e09dc0c87fee578e4a0cb60063]]
Former-commit-id: 0670ac79fa
Former-commit-id: 0cdb86b6ac
This commit is contained in:
Richard Peter 2012-12-07 11:17:22 -06:00
parent 17b9e0077c
commit 912b2ec928
5 changed files with 325 additions and 244 deletions

View file

@ -90,12 +90,12 @@ public class IFPServerConfigManager {
*/
public static IFPServerConfig getServerConfig(String siteID)
throws GfeConfigurationException {
if (configMap.containsKey(siteID)) {
return configMap.get(siteID);
} else {
IFPServerConfig config = configMap.get(siteID);
if (config == null) {
throw new GfeConfigurationException("Site " + siteID
+ " has no active GFE configuration.");
}
return config;
}
/**

View file

@ -31,18 +31,16 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
@ -74,7 +72,6 @@ import com.raytheon.uf.common.dataplugin.gfe.type.Pair;
import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil;
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
import com.raytheon.uf.common.dataplugin.grid.GridInfoConstants;
import com.raytheon.uf.common.dataplugin.grid.GridInfoRecord;
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
@ -106,14 +103,27 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
* 08/07/09 #2763 njensen Refactored queryByD2DParmId
* 09/10/12 DR15137 ryu Changed for MOSGuide D2D mxt/mnt grids for consistency
* with A1.
* 10/10/12 #1260 randerso Added check to ensure db can be created before
* 10/10/12 #1260 randerso Added check to ensure db can be created before
* adding it to the inventory
* 12/06/12 #1394 rjpeter Optimized D2D grid access.
* </pre>
*
* @author bphillip
* @version 1.0
*/
public class GFEDao extends DefaultPluginDao {
// hibernate query to find grid info record for the given datasetId and
// parameter
private static final String HQL_D2D_GRID_PARM_QUERY = "select parameter.abbreviation, id from GridInfoRecord "
+ "where datasetId = :datasetId AND (lower(parameter.abbreviation) = :abbrev OR lower(parameter_abbreviation) like :hourAbbrev)";
// hibernate query to find the times for the GridRecord for the given
// info.id, id returned to allow easy lookup of the record associated with
// the time
private static final String HQL_D2D_GRID_TIME_QUERY = "select dataTime, id from GridRecord "
+ "where info.id = :info_id AND dataTime.refTime = :refTime order by dataTime.fcstTime";
private static final Pattern WIND_PATTERN = Pattern.compile("wind");
public GFEDao() throws PluginException {
super("gfe");
@ -300,7 +310,12 @@ public class GFEDao extends DefaultPluginDao {
}
}
if (sess != null) {
sess.close();
try {
sess.close();
} catch (Exception e) {
statusHandler.error(
"Error occurred closing database session", e);
}
}
}
@ -611,53 +626,75 @@ public class GFEDao extends DefaultPluginDao {
}
/**
* Retrieves a GridRecord from the grib metadata database based on a ParmID
* and a TimeRange
* Retrieves a GridRecord from the grib metadata database based on a ParmID,
* TimeRange, and GridParmInfo.
*
* @param id
* The parmID of the desired GridRecord
* @param timeRange
* The timeRange of the desired GridRecord
* @param info
* The GridParmInfo for the requested d2d grid.
* @return The GridRecord from the grib metadata database
* @throws DataAccessLayerException
* If errors occur while querying the metadata database
*/
public GridRecord getD2DGrid(ParmID id, TimeRange timeRange,
GridParmInfo info) throws DataAccessLayerException {
List<GridRecord> records = queryByD2DParmId(id);
List<TimeRange> gribTimes = new ArrayList<TimeRange>();
for (GridRecord record : records) {
gribTimes.add(record.getDataTime().getValidPeriod());
}
Session s = null;
try {
s = getHibernateTemplate().getSessionFactory().openSession();
// TODO: clean up so we only make one db query
SortedMap<DataTime, Integer> rawTimes = queryByD2DParmId(id, s);
List<TimeRange> gribTimes = new ArrayList<TimeRange>();
for (DataTime dt : rawTimes.keySet()) {
gribTimes.add(dt.getValidPeriod());
}
for (int i = 0; i < records.size(); i++) {
TimeRange gribTime = records.get(i).getDataTime().getValidPeriod();
try {
if (isMos(id)) {
TimeRange time = info.getTimeConstraints().constraintTime(
gribTime.getEnd());
if (timeRange.getEnd().equals(time.getEnd())
|| !info.getTimeConstraints().anyConstraints()) {
GridRecord retVal = records.get(i);
retVal.setPluginName(GridConstants.GRID);
return retVal;
for (Map.Entry<DataTime, Integer> timeEntry : rawTimes
.entrySet()) {
TimeRange gribTime = timeEntry.getKey()
.getValidPeriod();
TimeRange time = info.getTimeConstraints()
.constraintTime(gribTime.getEnd());
if (timeRange.getEnd().equals(time.getEnd())
|| !info.getTimeConstraints().anyConstraints()) {
GridRecord retVal = (GridRecord) s.get(
GridRecord.class, timeEntry.getValue());
retVal.setPluginName(GridConstants.GRID);
return retVal;
}
}
} else if (D2DGridDatabase.isNonAccumDuration(id, gribTimes)) {
if (timeRange.getStart().equals(gribTime.getEnd())
|| timeRange.equals(gribTime)) {
GridRecord retVal = records.get(i);
retVal.setPluginName(GridConstants.GRID);
return retVal;
for (Map.Entry<DataTime, Integer> timeEntry : rawTimes
.entrySet()) {
TimeRange gribTime = timeEntry.getKey()
.getValidPeriod();
if (timeRange.getStart().equals(gribTime.getEnd())
|| timeRange.equals(gribTime)) {
GridRecord retVal = (GridRecord) s.get(
GridRecord.class, timeEntry.getValue());
retVal.setPluginName(GridConstants.GRID);
return retVal;
}
}
} else {
TimeRange time = info.getTimeConstraints().constraintTime(
gribTime.getStart());
if ((timeRange.getStart().equals(time.getStart()) || !info
.getTimeConstraints().anyConstraints())) {
GridRecord retVal = records.get(i);
retVal.setPluginName(GridConstants.GRID);
return retVal;
for (Map.Entry<DataTime, Integer> timeEntry : rawTimes
.entrySet()) {
TimeRange gribTime = timeEntry.getKey()
.getValidPeriod();
TimeRange time = info.getTimeConstraints()
.constraintTime(gribTime.getStart());
if ((timeRange.getStart().equals(time.getStart()) || !info
.getTimeConstraints().anyConstraints())) {
GridRecord retVal = (GridRecord) s.get(
GridRecord.class, timeEntry.getValue());
retVal.setPluginName(GridConstants.GRID);
return retVal;
}
}
}
} catch (GfeConfigurationException e) {
@ -665,219 +702,219 @@ public class GFEDao extends DefaultPluginDao {
"Error getting configuration for "
+ id.getDbId().getSiteId(), e);
}
} finally {
if (s != null) {
try {
s.close();
} catch (Exception e) {
statusHandler.error(
"Error occurred closing database session", e);
}
}
}
return null;
}
/**
* Gets a list of GridRecords from the grib metadata database which match
* the given ParmID
* Gets a SortedMap of DataTime and GridRecord ids from the grib metadata
* database which match the given ParmID. Session passed to allow reuse
* across multiple calls.
*
* @param id
* The ParmID to search with
* @param s
* The database session to use
* @return The list of GridRecords from the grib metadata database which
* match the given ParmID
* @throws DataAccessLayerException
* If errors occur while querying the metadata database
*/
@SuppressWarnings("unchecked")
public List<GridRecord> queryByD2DParmId(ParmID id)
public SortedMap<DataTime, Integer> queryByD2DParmId(ParmID id, Session s)
throws DataAccessLayerException {
Session s = null;
String levelName = GridTranslator.getLevelName(id.getParmLevel());
double[] levelValues = GridTranslator.getLevelValue(id.getParmLevel());
boolean levelOnePresent = (levelValues[0] != Level
.getInvalidLevelValue());
boolean levelTwoPresent = (levelValues[1] != Level
.getInvalidLevelValue());
Level level = null;
// to have a level 2, must have a level one
try {
String levelName = GridTranslator.getLevelName(id.getParmLevel());
if (levelOnePresent && levelTwoPresent) {
level = LevelFactory.getInstance().getLevel(levelName,
levelValues[0], levelValues[1]);
} else if (levelOnePresent) {
level = LevelFactory.getInstance().getLevel(levelName,
levelValues[0]);
} else {
level = LevelFactory.getInstance().getLevel(levelName, 0.0);
}
} catch (CommunicationException e) {
logger.error(e.getLocalizedMessage(), e);
}
if (level == null) {
logger.warn("Unable to query D2D parms, ParmID " + id
+ " does not map to a level");
return new TreeMap<DataTime, Integer>();
}
double[] levelValues = GridTranslator.getLevelValue(id
.getParmLevel());
boolean levelOnePresent = (levelValues[0] != Level
.getInvalidLevelValue());
boolean levelTwoPresent = (levelValues[1] != Level
.getInvalidLevelValue());
Level level = null;
Query modelQuery = s.createQuery(HQL_D2D_GRID_PARM_QUERY);
// to have a level 2, must have a level one
try {
if (levelOnePresent && levelTwoPresent) {
level = LevelFactory.getInstance().getLevel(levelName,
levelValues[0], levelValues[1]);
} else if (levelOnePresent) {
level = LevelFactory.getInstance().getLevel(levelName,
levelValues[0]);
DatabaseID dbId = id.getDbId();
try {
IFPServerConfig config = IFPServerConfigManager
.getServerConfig(dbId.getSiteId());
modelQuery.setString(GridInfoConstants.DATASET_ID,
config.d2dModelNameMapping(dbId.getModelName()));
} catch (GfeConfigurationException e) {
throw new DataAccessLayerException(
"Error occurred looking up model name mapping", e);
}
String abbreviation = DataFieldTableLookup.getInstance()
.lookupDataName(id.getParmName());
if (abbreviation == null) {
abbreviation = id.getParmName();
}
abbreviation = abbreviation.toLowerCase();
modelQuery.setString("abbrev", abbreviation);
modelQuery.setString("hourAbbrev", abbreviation + "%hr");
List<?> results = modelQuery.list();
Integer modelId = null;
if (results.size() == 0) {
return new TreeMap<DataTime, Integer>();
} else if (results.size() > 1) {
// hours matched, take hour with least number that matches exact
// param
Pattern p = Pattern.compile("^" + abbreviation + "(\\d+)hr$");
int lowestHr = -1;
for (Object[] rows : (List<Object[]>) results) {
String param = ((String) rows[0]).toLowerCase();
if (param.equals(abbreviation) && (lowestHr < 0)) {
modelId = (Integer) rows[1];
} else {
level = LevelFactory.getInstance().getLevel(levelName, 0.0);
}
} catch (CommunicationException e) {
logger.error(e.getLocalizedMessage(), e);
}
if (level == null) {
logger.warn("Unable to query D2D parms, ParmID " + id
+ " does not map to a level");
return new ArrayList<GridRecord>();
}
s = getHibernateTemplate().getSessionFactory().openSession();
Criteria modelCrit = s.createCriteria(GridInfoRecord.class);
Criterion baseCrit = Restrictions
.eq(GridInfoConstants.LEVEL, level);
DatabaseID dbId = id.getDbId();
try {
IFPServerConfig config = IFPServerConfigManager
.getServerConfig(dbId.getSiteId());
baseCrit = Restrictions.and(baseCrit, Restrictions.eq(
GridInfoConstants.DATASET_ID,
config.d2dModelNameMapping(dbId.getModelName())));
} catch (GfeConfigurationException e) {
throw new DataAccessLayerException(
"Error occurred looking up model name mapping", e);
}
String abbreviation = DataFieldTableLookup.getInstance()
.lookupDataName(id.getParmName());
if (abbreviation == null) {
abbreviation = id.getParmName();
}
abbreviation = abbreviation.toLowerCase();
Criterion abbrevCrit = Restrictions
.and(baseCrit,
Restrictions.or(
Restrictions
.sqlRestriction("lower(parameter_abbreviation) = '"
+ abbreviation + "'"),
Restrictions
.sqlRestriction("lower(parameter_abbreviation) like '"
+ abbreviation + "%hr'")));
modelCrit.add(abbrevCrit);
List<?> results = modelCrit.list();
GridInfoRecord model = null;
if (results.size() == 0) {
return new ArrayList<GridRecord>(0);
} else if (results.size() > 1) {
// hours matched, take hour with least number that matches exact
// param
Pattern p = Pattern.compile("^" + abbreviation + "(\\d+)hr$");
int lowestHr = -1;
for (GridInfoRecord m : (List<GridInfoRecord>) results) {
String param = m.getParameter().getAbbreviation()
.toLowerCase();
if (param.equals(abbreviation) && (lowestHr < 0)) {
model = m;
} else {
Matcher matcher = p.matcher(param);
if (matcher.matches()) {
int hr = Integer.parseInt(matcher.group(1));
if ((lowestHr < 0) || (hr < lowestHr)) {
model = m;
lowestHr = hr;
}
Matcher matcher = p.matcher(param);
if (matcher.matches()) {
int hr = Integer.parseInt(matcher.group(1));
if ((lowestHr < 0) || (hr < lowestHr)) {
modelId = (Integer) rows[1];
lowestHr = hr;
}
}
}
} else {
model = (GridInfoRecord) results.get(0);
}
Criteria recordCrit = s.createCriteria(GridRecord.class);
baseCrit = Restrictions.eq("info", model);
baseCrit = Restrictions.and(
baseCrit,
Restrictions.eq("dataTime.refTime",
dbId.getModelTimeAsDate()));
recordCrit.add(baseCrit);
recordCrit.addOrder(Order.asc("dataTime.fcstTime"));
return recordCrit.list();
} finally {
if (s != null) {
s.flush();
s.close();
}
} else {
modelId = (Integer) ((Object[]) results.get(0))[1];
}
Query timeQuery = s.createQuery(HQL_D2D_GRID_TIME_QUERY);
timeQuery.setInteger("info_id", modelId);
timeQuery.setParameter("refTime", dbId.getModelTimeAsDate());
List<Object[]> timeResults = timeQuery.list();
if (timeResults.isEmpty()) {
return new TreeMap<DataTime, Integer>();
}
SortedMap<DataTime, Integer> dataTimes = new TreeMap<DataTime, Integer>();
for (Object[] rows : timeResults) {
dataTimes.put((DataTime) rows[0], (Integer) rows[1]);
}
return dataTimes;
}
public List<TimeRange> queryTimeByD2DParmId(ParmID id)
throws DataAccessLayerException {
List<TimeRange> timeList = new ArrayList<TimeRange>();
if (id.getParmName().equalsIgnoreCase("wind")) {
ParmID uWindId = new ParmID(id.toString().replace("wind", "uW"));
List<TimeRange> uTimeList = new ArrayList<TimeRange>();
List<DataTime> results = executeD2DParmQuery(uWindId);
for (DataTime o : results) {
uTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
Session s = null;
try {
s = getHibernateTemplate().getSessionFactory().openSession();
ParmID vWindId = new ParmID(id.toString().replace("wind", "vW"));
List<TimeRange> vTimeList = new ArrayList<TimeRange>();
results = executeD2DParmQuery(vWindId);
for (DataTime o : results) {
vTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
if (id.getParmName().equalsIgnoreCase("wind")) {
String idString = id.toString();
Matcher idWindMatcher = WIND_PATTERN.matcher(idString);
for (TimeRange tr : uTimeList) {
if (vTimeList.contains(tr)) {
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
ParmID uWindId = new ParmID(idWindMatcher.replaceAll("uW"));
SortedMap<DataTime, Integer> results = queryByD2DParmId(
uWindId, s);
List<TimeRange> uTimeList = new ArrayList<TimeRange>(
results.size());
for (DataTime o : results.keySet()) {
uTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
}
if (!timeList.isEmpty()) {
return timeList;
}
ParmID sWindId = new ParmID(id.toString().replace("wind", "ws"));
List<TimeRange> sTimeList = new ArrayList<TimeRange>();
results = executeD2DParmQuery(sWindId);
for (DataTime o : results) {
sTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
ParmID dWindId = new ParmID(id.toString().replace("wind", "wd"));
List<TimeRange> dTimeList = new ArrayList<TimeRange>();
results = executeD2DParmQuery(dWindId);
for (DataTime o : results) {
dTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
for (TimeRange tr : sTimeList) {
if (dTimeList.contains(tr)) {
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
ParmID vWindId = new ParmID(idWindMatcher.replaceAll("vW"));
results = queryByD2DParmId(vWindId, s);
Set<TimeRange> vTimeList = new HashSet<TimeRange>(
results.size(), 1);
for (DataTime o : results.keySet()) {
vTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
}
if (!timeList.isEmpty()) {
return timeList;
}
} else {
List<DataTime> results = executeD2DParmQuery(id);
for (DataTime o : results) {
for (TimeRange tr : uTimeList) {
if (vTimeList.contains(tr)) {
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
}
}
if (!timeList.isEmpty()) {
return timeList;
}
ParmID sWindId = new ParmID(idWindMatcher.replaceAll("ws"));
results = queryByD2DParmId(sWindId, s);
List<TimeRange> sTimeList = new ArrayList<TimeRange>(
results.size());
for (DataTime o : results.keySet()) {
sTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
ParmID dWindId = new ParmID(idWindMatcher.replaceAll("wd"));
results = queryByD2DParmId(dWindId, s);
Set<TimeRange> dTimeList = new HashSet<TimeRange>(
results.size(), 1);
for (DataTime o : results.keySet()) {
dTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
3600 * 1000));
}
for (TimeRange tr : sTimeList) {
if (dTimeList.contains(tr)) {
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
}
}
} else {
SortedMap<DataTime, Integer> results = queryByD2DParmId(id, s);
if (isMos(id)) {
timeList.add(new TimeRange(o.getValidPeriod().getEnd(), o
.getValidPeriod().getDuration()));
for (DataTime o : results.keySet()) {
timeList.add(new TimeRange(o.getValidPeriod().getEnd(),
o.getValidPeriod().getDuration()));
}
} else {
timeList.add(o.getValidPeriod());
for (DataTime o : results.keySet()) {
timeList.add(o.getValidPeriod());
}
}
}
} finally {
if (s != null) {
try {
s.close();
} catch (Exception e) {
statusHandler.error(
"Error occurred closing database session", e);
}
}
}
return timeList;
}
private List<DataTime> executeD2DParmQuery(ParmID id)
throws DataAccessLayerException {
List<DataTime> times = new ArrayList<DataTime>();
List<GridRecord> records = queryByD2DParmId(id);
for (GridRecord record : records) {
times.add(record.getDataTime());
}
return times;
}
public void purgeGFEGrids(final DatabaseID dbId) {
txTemplate.execute(new TransactionCallbackWithoutResult() {
@Override

View file

@ -108,12 +108,12 @@ public class D2DGridDatabase extends VGridDatabase {
.getNamedHandler("GFEPerformanceLogger");
/** The remap object used for resampling grids */
private Map<Integer, RemapGrid> remap = new HashMap<Integer, RemapGrid>();
private final Map<Integer, RemapGrid> remap = new HashMap<Integer, RemapGrid>();
/** The destination GridLocation (The local GFE grid coverage) */
private GridLocation outputLoc;
private List<ParmID> parms;
private final List<ParmID> parms;
public static final String GRID_LOCATION_CACHE_KEY = "GfeLocations";
@ -394,7 +394,7 @@ public class D2DGridDatabase extends VGridDatabase {
public ServerResponse<List<IGridSlice>> getGridData(ParmID id,
List<TimeRange> timeRanges) {
List<IGridSlice> data = new ArrayList<IGridSlice>();
List<IGridSlice> data = new ArrayList<IGridSlice>(timeRanges.size());
ServerResponse<List<IGridSlice>> sr = new ServerResponse<List<IGridSlice>>();
for (TimeRange tr : timeRanges) {
GridParmInfo gpi = getGridParmInfo(id).getPayload();
@ -415,7 +415,7 @@ public class D2DGridDatabase extends VGridDatabase {
public ServerResponse<List<IGridSlice>> getGridData(ParmID id,
List<TimeRange> timeRanges, boolean convertUnit) {
List<IGridSlice> data = new ArrayList<IGridSlice>();
List<IGridSlice> data = new ArrayList<IGridSlice>(timeRanges.size());
ServerResponse<List<IGridSlice>> sr = new ServerResponse<List<IGridSlice>>();
for (TimeRange tr : timeRanges) {
GridParmInfo gpi = getGridParmInfo(id).getPayload();
@ -429,6 +429,7 @@ public class D2DGridDatabase extends VGridDatabase {
+ " TimeRange: " + tr, e);
}
}
sr.setPayload(data);
return sr;
}
@ -550,7 +551,7 @@ public class D2DGridDatabase extends VGridDatabase {
RemapGrid remap = getOrCreateRemap(d2dRecord.getLocation());
retVal = remap.remap(bdata, fillV, gpi.getMaxValue(),
gpi.getMinValue(), gpi.getMinValue());
if (convertUnit && d2dRecord != null) {
if (convertUnit && (d2dRecord != null)) {
convertUnits(d2dRecord, retVal, gpi.getUnitObject());
}
} catch (Exception e) {
@ -651,7 +652,7 @@ public class D2DGridDatabase extends VGridDatabase {
String mappedModel = config.d2dModelNameMapping(dbId.getModelName());
if (uRecord != null && vRecord != null) {
if ((uRecord != null) && (vRecord != null)) {
// Gets the raw grid data from the D2D grib HDF5 files
Grid2DFloat uData = getRawGridData(uRecord);
Grid2DFloat vData = getRawGridData(vRecord);
@ -688,7 +689,7 @@ public class D2DGridDatabase extends VGridDatabase {
"Unable to retrieve wind grids from D2D database", e);
}
if (sRecord != null && dRecord != null) {
if ((sRecord != null) && (dRecord != null)) {
// Gets the raw grid data from the D2D grib HDF5 files
Grid2DFloat sData = getRawGridData(sRecord);
Grid2DFloat dData = getRawGridData(dRecord);
@ -914,8 +915,8 @@ public class D2DGridDatabase extends VGridDatabase {
// no-op
}
public static boolean isNonAccumDuration(ParmID id, List<TimeRange> times)
throws GfeConfigurationException {
public static boolean isNonAccumDuration(ParmID id,
Collection<TimeRange> times) throws GfeConfigurationException {
boolean isAccum = false;
try {
isAccum = IFPServerConfigManager
@ -925,14 +926,19 @@ public class D2DGridDatabase extends VGridDatabase {
} catch (GfeConfigurationException e) {
throw e;
}
boolean isDuration = false;
for (TimeRange time : times) {
if (time.getDuration() > 0) {
isDuration = true;
break;
if (!isAccum) {
boolean isDuration = false;
for (TimeRange time : times) {
if (time.getDuration() > 0) {
isDuration = true;
break;
}
}
return !isAccum && isDuration;
}
return !isAccum && isDuration;
return !isAccum;
}
}

View file

@ -21,6 +21,7 @@ package com.raytheon.edex.plugin.gfe.util;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
@ -34,7 +35,7 @@ import com.raytheon.uf.common.dataplugin.level.LevelFactory;
* ------------ ---------- ----------- --------------------------
* May 5, 2008 njensen Initial creation
* Aug 22, 2008 1502 dglazesk Changed to JAXB unmarshalling
*
* Dec 06, 2012 1394 rjpeter Attend static compiled patterns.
* </pre>
*
* @author njensen
@ -45,15 +46,19 @@ public class GridTranslator {
private static final List<String> NEEDS_ZERO = Arrays.asList("BLD", "WBZ");
private static final Pattern ANY_NUMBER = Pattern.compile("[0-9]");
private static final Pattern NOT_NUMBER = Pattern.compile("[^0-9]");
private GridTranslator() {
}
public static String getLevelName(String shorthand) {
return shorthand.replaceAll("[0-9]*", "");
return ANY_NUMBER.matcher(shorthand).replaceAll("");
}
public static double[] getLevelValue(String shorthand) {
String levelString = shorthand.replaceAll("[^0-9]", "");
String levelString = NOT_NUMBER.matcher(shorthand).replaceAll("");
int length = levelString.length();
double[] retVal = new double[2];
retVal[0] = Level.getInvalidLevelValue();
@ -126,9 +131,9 @@ public class GridTranslator {
} else {
tmp.append(name);
if (levelOne != Level.getInvalidLevelValue()
&& (levelOne != 0
|| levelTwo != Level.getInvalidLevelValue() || NEEDS_ZERO
if ((levelOne != Level.getInvalidLevelValue())
&& ((levelOne != 0)
|| (levelTwo != Level.getInvalidLevelValue()) || NEEDS_ZERO
.contains(name))) {
tmp.append(String.valueOf(Math.round(levelOne)));
}
@ -166,7 +171,7 @@ public class GridTranslator {
+ level
+ " "
+ Arrays.toString(levels)
+ (l1 == levels[0] && l2 == levels[1] ? " passed"
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
: " failed"));
}
}
@ -187,7 +192,7 @@ public class GridTranslator {
+ level
+ " "
+ Arrays.toString(levels)
+ (l1 == levels[0] && l2 == levels[1] ? " passed"
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
: " failed"));
}
}
@ -197,26 +202,50 @@ public class GridTranslator {
l2 = -999999;
level = GridTranslator.getShortLevelName(levelName, l1, l2);
levels = GridTranslator.getLevelValue(level);
System.out.println(levelName + " " + l1 + " " + l2 + ": " + level + " "
System.out.println(levelName
+ " "
+ l1
+ " "
+ l2
+ ": "
+ level
+ " "
+ Arrays.toString(levels)
+ (l1 == levels[0] && l2 == levels[1] ? " passed" : " failed"));
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
: " failed"));
levelName = "BLD";
l1 = 0;
l2 = -999999;
level = GridTranslator.getShortLevelName(levelName, l1, l2);
levels = GridTranslator.getLevelValue(level);
System.out.println(levelName + " " + l1 + " " + l2 + ": " + level + " "
System.out.println(levelName
+ " "
+ l1
+ " "
+ l2
+ ": "
+ level
+ " "
+ Arrays.toString(levels)
+ (l1 == levels[0] && l2 == levels[1] ? " passed" : " failed"));
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
: " failed"));
levelName = "WBZ";
l1 = 0;
l2 = -999999;
level = GridTranslator.getShortLevelName(levelName, l1, l2);
levels = GridTranslator.getLevelValue(level);
System.out.println(levelName + " " + l1 + " " + l2 + ": " + level + " "
System.out.println(levelName
+ " "
+ l1
+ " "
+ l2
+ ": "
+ level
+ " "
+ Arrays.toString(levels)
+ (l1 == levels[0] && l2 == levels[1] ? " passed" : " failed"));
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
: " failed"));
}
}

View file

@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
@ -56,11 +57,19 @@ public class DataFieldTableLookup {
private static DataFieldTableLookup instance;
private Map<String, String> data2cdl = new HashMap<String, String>();
private final Pattern DASH = Pattern.compile("-");
private Map<String, String> cdl2data = new HashMap<String, String>();
private final Pattern UNDERSCORE = Pattern.compile("_");
private Map<String, String> data2name = new HashMap<String, String>();
private final Pattern NEWLINE = Pattern.compile("\n");
private final Pattern PIPE = Pattern.compile("\\|");
private final Map<String, String> data2cdl = new HashMap<String, String>();
private final Map<String, String> cdl2data = new HashMap<String, String>();
private final Map<String, String> data2name = new HashMap<String, String>();
public static synchronized DataFieldTableLookup getInstance() {
if (instance == null) {
@ -87,13 +96,13 @@ public class DataFieldTableLookup {
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
for (String line : contents.split("\n")) {
for (String line : NEWLINE.split(contents)) {
line = line.trim();
if (line.startsWith("//") || line.startsWith("#")) {
// ignore comments
continue;
}
String[] parts = line.split("\\|");
String[] parts = PIPE.split(line);
if (parts.length < 2) {
// invalid line
continue;
@ -121,7 +130,7 @@ public class DataFieldTableLookup {
public String lookupCdlName(String dataField) {
String retVal = data2cdl.get(dataField);
if (retVal == null) {
retVal = data2cdl.get(dataField.replace("-", "_"));
retVal = data2cdl.get(DASH.matcher(dataField).replaceAll("_"));
if (retVal == null) {
retVal = dataField;
}
@ -132,7 +141,7 @@ public class DataFieldTableLookup {
public String lookupDataName(String cdlField) {
String retVal = cdl2data.get(cdlField);
if (retVal != null) {
retVal = retVal.replace("_", "-");
retVal = UNDERSCORE.matcher(retVal).replaceAll("-");
}
return retVal;
}
@ -140,7 +149,7 @@ public class DataFieldTableLookup {
public String lookupName(String dataField) {
String retVal = data2name.get(dataField);
if (retVal == null) {
retVal = data2name.get(dataField.replace("-", "_"));
retVal = data2name.get(DASH.matcher(dataField).replaceAll("_"));
}
return retVal;
}