Omaha #3235 Properly clear the coordinates map. Switch to slf4j. Update manifest. Precompile patterns. Add some Javadoc.

Change-Id: I405b8abc09fcfd5346af1880fe0807bade54af37

Former-commit-id: 3b35b9e54e [formerly 579f14356a] [formerly 3b35b9e54e [formerly 579f14356a] [formerly 229783d3b0 [formerly b8d9c02463b595ac3adef027cd1f2a03ddc95e4e]]]
Former-commit-id: 229783d3b0
Former-commit-id: 2de56a4000 [formerly 99c6d288fd]
Former-commit-id: 91d5e4fcbb
This commit is contained in:
Nathan Bowler 2014-06-24 09:28:51 -04:00
parent eed3ec1650
commit f13bc3f200
6 changed files with 203 additions and 166 deletions

View file

@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tcg Plug-in
Bundle-SymbolicName: com.raytheon.uf.edex.plugin.tcg
Bundle-Version: 1.12.1174.qualifier
Bundle-Version: 1.14.0.qualifier
Bundle-Vendor: RAYTHEON
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: com.raytheon.uf.common.dataplugin.tcg;bundle-version="1.0.0",
com.raytheon.uf.edex.decodertools,
com.raytheon.uf.common.pointdata,
@ -14,11 +14,11 @@ Require-Bundle: com.raytheon.uf.common.dataplugin.tcg;bundle-version="1.0.0",
javax.measure,
com.raytheon.uf.edex.database,
com.raytheon.uf.common.serialization,
com.raytheon.uf.common.dataplugin
com.raytheon.uf.common.dataplugin,
org.slf4j
Import-Package: com.raytheon.edex.esb,
com.raytheon.uf.common.datastorage.records,
com.raytheon.uf.common.status,
com.raytheon.uf.common.time,
com.raytheon.uf.common.wmo,
com.raytheon.uf.edex.core,
org.apache.commons.logging
com.raytheon.uf.edex.core

View file

@ -22,8 +22,8 @@ package com.raytheon.uf.edex.plugin.tcg;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.raytheon.edex.esb.Headers;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
@ -42,6 +42,7 @@ import com.raytheon.uf.edex.plugin.tcg.decoder.TCGDataAdapter;
* ------------ ---------- ----------- --------------------------
* Oct 28, 2009 jsanchez Initial creation
* May 14, 2014 2536 bclement moved WMO Header to common
* Jun 24, 2014 3235 nabowle Switch to slf4j.
*
* </pre>
*
@ -49,7 +50,8 @@ import com.raytheon.uf.edex.plugin.tcg.decoder.TCGDataAdapter;
* @version 1.0
*/
public class TCGDecoder {
private Log logger = LogFactory.getLog(getClass());
private static final Logger logger = LoggerFactory
.getLogger(TCGDecoder.class);
private final String pluginName;

View file

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -36,7 +37,8 @@ import com.raytheon.uf.edex.plugin.tcg.TropicalCycloneGuidanceDao;
import com.vividsolutions.jts.geom.Coordinate;
/**
* TODO Add Description
* Parses a subset of Tropical Cyclone Guidance data that contain multiple storm
* track predictions from various models such as BAM(S/M/D) and LBAR.
*
* <pre>
*
@ -46,6 +48,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* ------------ ---------- ----------- --------------------------
* Oct 26, 2009 jsanchez Initial creation
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
* Jun 23, 2014 3235 nabowle Clear the coordinates map properly.
*
* </pre>
*
@ -68,6 +71,7 @@ public class HURData extends TCGDataAdapter {
List<TropicalCycloneGuidance> reports = new ArrayList<TropicalCycloneGuidance>();
List<InternalReport> parts = InternalReport.identifyMessage(message);
List<Coordinate> list;
if (parts != null) {
clearData();
@ -83,8 +87,9 @@ public class HURData extends TCGDataAdapter {
} else if (InternalType.MODEL_INFO.equals(t)) {
parseModelInfo(s);
} else if (InternalType.END.equals(t)) {
for (String model : coordinates.keySet()) {
List<Coordinate> list = coordinates.get(model);
for (Entry<String, List<Coordinate>> entry : coordinates
.entrySet()) {
list = entry.getValue();
if (list.size() == forecastTimes.size()) {
for (int i = 0; i < list.size(); i++) {
TropicalCycloneGuidance rpt = new TropicalCycloneGuidance();
@ -98,7 +103,7 @@ public class HURData extends TCGDataAdapter {
rpt.setStormName(stormName);
rpt.setType(stormType);
rpt.setProductType(productType);
rpt.setModelName(model);
rpt.setModelName(entry.getKey());
rpt.setLocation(location);
rpt.setInsertTime(Calendar.getInstance(TimeZone
.getTimeZone("GMT")));
@ -131,16 +136,14 @@ public class HURData extends TCGDataAdapter {
}
private void parseModelInfo(String modelInfo) {
Pattern modelPtrn = Pattern.compile(InternalReport.MODEL_PTRN);
Pattern latlonPtrn = Pattern.compile(InternalReport.LATLON_PTRN);
Matcher m = modelPtrn.matcher(modelInfo);
Matcher m = InternalReport.MODEL_PTRN.matcher(modelInfo);
if (m.find()) {
String model = m.group();
List<Coordinate> coordinate = coordinates.get(model);
if (coordinate == null) {
coordinate = new ArrayList<Coordinate>();
}
m = latlonPtrn.matcher(modelInfo);
m = InternalReport.LATLON_PTRN.matcher(modelInfo);
while (m.find()) {
String latlon[] = m.group().split(" ");
int n = latlon.length - 1;
@ -214,16 +217,9 @@ public class HURData extends TCGDataAdapter {
}
}
private void refreshMaps() {
coordinates.put("BAMS", null);
coordinates.put("BAMD", null);
coordinates.put("BAMD", null);
coordinates.put("LBAR", null);
}
@Override
public void clearData() {
refreshMaps();
coordinates.clear();
forecastTimes.clear();
stationId = null;
stormType = TCGStormType.UNKNOWN;

View file

@ -28,8 +28,8 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* TODO Add Description
@ -41,6 +41,7 @@ import org.apache.commons.logging.LogFactory;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 26, 2009 jsanchez Initial creation
* Jun 24, 2014 3235 nabowle Switch to slf4j. Precompile patterns.
*
* </pre>
*
@ -50,82 +51,112 @@ import org.apache.commons.logging.LogFactory;
public class InternalReport {
private static Log logger = LogFactory.getLog(InternalReport.class);
private static final Logger LOGGER = LoggerFactory
.getLogger(InternalReport.class);
//CHGHUR or CHGQLM or TCEAT4
public static final String PRODUCT_PTRN = "^((CHG|TCE)(.*))";
// CHGHUR or CHGQLM or TCEAT4
public static final Pattern PRODUCT_PTRN = Pattern
.compile("^((CHG|TCE)(.*))");
/*
* Below are patterns mostly used for CHGQLM
*/
//TROPICAL STORM IDA 11L
public static final String STORM_TYPE_INFO = "^((TROPICAL|HURRICANE|TYPHOON|EXTRATROPICAL|DISTURBANCE) +(.*))";
// TROPICAL STORM IDA 11L
public static final Pattern STORM_TYPE_INFO = Pattern
.compile("^((TROPICAL|HURRICANE|TYPHOON|EXTRATROPICAL|DISTURBANCE) +(.*))");
public static final String HOUR_PTRN = "(\\d{1,2})";
public static final String MONTH_PTRN = "(\\w{3,3})";
public static final String DAY_PTRN = "(\\d{1,2})";
//INITIAL TIME 18Z NOV 4
public static final String INIT_TIME_INFO = "^((INITIAL TIME)(\\s{2,3})" + HOUR_PTRN + "Z " + MONTH_PTRN + "(\\s{1,2})" + DAY_PTRN + ")";
// INITIAL TIME 18Z NOV 4
public static final Pattern INIT_TIME_INFO = Pattern
.compile("^((INITIAL TIME)(\\s{2,3})" + HOUR_PTRN + "Z "
+ MONTH_PTRN + "(\\s{1,2})" + DAY_PTRN + ")");
// 18 12.1 82.2 47./ 1.7
public static final String FORECAST_POSITION_INFO = "^((\\s{1,3})(\\d{1,3})(\\s{12,14})((\\d{0,2}).\\d) +(.*))";
public static final Pattern FORECAST_POSITION_INFO = Pattern
.compile("^((\\s{1,3})(\\d{1,3})(\\s{12,14})((\\d{0,2}).\\d) +(.*))");
/*
* Below are patterns mostly used for CHGHUR
*/
//16.5N 102.2W
public static final String LATLON_PTRN ="(((\\d{0,2}|90).\\d{1,1}[NS])(\\s{1,4})(\\d{0,3}.\\d{1,1}[EW]))";
public static final String LATLON = "(((\\d{0,2}|90).\\d{1,1}[NS])(\\s{1,4})(\\d{0,3}.\\d{1,1}[EW]))";
//BAMS
public static final String MODEL_PTRN ="(\\w{4,4})";
// 16.5N 102.2W
public static final Pattern LATLON_PTRN = Pattern.compile(LATLON);
//BAMS 16.5N 102.2W 17.5N 102.0W 18.2N 101.7W 18.6N 102.0W
public static final String MODEL_INFO ="^(" + MODEL_PTRN + "(\\s{4,4})" + LATLON_PTRN + "+(.*))";
public static final String MODEL = "(\\w{4,4})";
//091029 1200
public static final String DATETIME= "(\\d{6,6}\\s{2,2}\\d{4,4})";
// BAMS
public static final Pattern MODEL_PTRN = Pattern.compile(MODEL);
// BAMS 16.5N 102.2W 17.5N 102.0W 18.2N 101.7W 18.6N 102.0W
public static final Pattern MODEL_INFO = Pattern.compile("^(" + MODEL
+ "(\\s{4,4})" + LATLON + "+(.*))");
// 091029 1200
public static final String DATETIME = "(\\d{6,6}\\s{2,2}\\d{4,4})";
// 091029 1200 091030 0000 091030 1200 091031 0000
public static final String DATETIME_INFO = "((.*)" + DATETIME + "+(.*))";
public static final Pattern DATETIME_INFO = Pattern.compile("((.*)"
+ DATETIME + "+(.*))");
//(EP952009)
// (EP952009)
public static final String STATIONID_PTRN = "\\(\\w{2,2}\\d{6,6}\\)";
//20091029 1200
// 20091029 1200
public static final String REFTIME_PTRN = "(\\d{8,8} \\d{4,4})";
//DISTURBANCE INVEST (EP952009) 20091029 1200 UTC
public static final String DATA_INFO = "((.*) " + STATIONID_PTRN + " " + REFTIME_PTRN + " " + "UTC)";
// DISTURBANCE INVEST (EP952009) 20091029 1200 UTC
public static final Pattern DATA_INFO = Pattern.compile("((.*) "
+ STATIONID_PTRN + " " + REFTIME_PTRN + " " + "UTC)");
// ...INITIAL CONDITIONS...
public static final String INIT_CONDITION_PTRN = "((.*)(...INITIAL CONDITIONS...)+(.*))";
public static final Pattern INIT_CONDITION_PTRN = Pattern
.compile("((.*)(...INITIAL CONDITIONS...)+(.*))");
//STORM DISSIPATED AT 54 HRS AT THE ABOVE PSN.
public static final String STORM_DISSIPATED = "^(STORM DISSIPATED +(.*))";
// STORM DISSIPATED AT 54 HRS AT THE ABOVE PSN.
public static final Pattern STORM_DISSIPATED = Pattern
.compile("^(STORM DISSIPATED +(.*))");
/*
* Below are used for TCE
*/
public static final String NWS_INFO = "^((NWS TPC)(.*)(\\w{2,2}\\d{6,6}))";
//1100 PM CDT FRI SEP 12 2008
public static final String TCE_REFTIME_INFO = "^(\\d{3,4} (AM|PM) \\w{3,3} \\w{3,3} \\w{3,3}\\s{1,2}\\d{1,2}(.*))";
public static final Pattern NWS_INFO = Pattern
.compile("^((NWS TPC)(.*)(\\w{2,2}\\d{6,6}))");
public static final String TCE_REFHOUR = "^((.*)(\\.\\.\\.\\d{4,4}Z\\.\\.\\.)(.*))";
// 1100 PM CDT FRI SEP 12 2008
public static final Pattern TCE_REFTIME_INFO = Pattern
.compile("^(\\d{3,4} (AM|PM) \\w{3,3} \\w{3,3} \\w{3,3}\\s{1,2}\\d{1,2}(.*))");
public static final String LAT_PTRN = "(LATITUDE \\d{0,2}.\\d)";
//RESERVE UNIT RECONNAISSANCE AIRCRAFT...TO BE NEAR LATITUDE 28.7
public static final String LATITUDE_INFO = "^((.*)" + LAT_PTRN + "(.*))";
public static final Pattern TCE_REFHOUR = Pattern
.compile("^((.*)(\\.\\.\\.\\d{4,4}Z\\.\\.\\.)(.*))");
public static final String LON_PTRN = "(LONGITUDE \\d{0,3}.\\d)";
//NORTH...LONGITUDE 94.5 WEST OR ABOUT 45 MILES...75 KM...
public static final String LONGITUDE_INFO = "^((.*)" + LON_PTRN + "(.*))";
//FORECASTER STEWART
public static final String FORECASTER_PTRN = "^((FORECASTER)(.*))";
public static final Pattern LAT_PTRN = Pattern
.compile("(LATITUDE \\d{0,2}.\\d)");
// RESERVE UNIT RECONNAISSANCE AIRCRAFT...TO BE NEAR LATITUDE 28.7
public static final Pattern LATITUDE_INFO = Pattern.compile("^((.*)"
+ LAT_PTRN + "(.*))");
public static final Pattern LON_PTRN = Pattern
.compile("(LONGITUDE \\d{0,3}.\\d)");
// NORTH...LONGITUDE 94.5 WEST OR ABOUT 45 MILES...75 KM...
public static final Pattern LONGITUDE_INFO = Pattern.compile("^((.*)"
+ LON_PTRN + "(.*))");
// FORECASTER STEWART
public static final Pattern FORECASTER_PTRN = Pattern
.compile("^((FORECASTER)(.*))");
private final InternalType lineType;
private final String reportLine;
private List<InternalReport> subLines = null;
@ -159,12 +190,13 @@ public class InternalReport {
/**
*
* @param buffer Buffer to receive String formatted internal data. If this
* @param buffer
* Buffer to receive String formatted internal data. If this
* reference is null, a new StringBuilder instance is created.
* @return The populated StringBuilder instance.
*/
public StringBuilder toString(StringBuilder buffer) {
if(buffer == null) {
if (buffer == null) {
buffer = new StringBuilder();
}
buffer.append("[");
@ -177,13 +209,14 @@ public class InternalReport {
/**
* Create a string representation of this class instance.
*
* @return The string representation of this class instance.
*/
@Override
public String toString() {
StringBuilder sb = toString(null);
if(subLines != null) {
for(InternalReport r : subLines) {
if (subLines != null) {
for (InternalReport r : subLines) {
sb.append(" ");
r.toString(sb);
}
@ -191,25 +224,25 @@ public class InternalReport {
return sb.toString();
}
public static List<InternalReport> identifyMessage(byte [] message) {
public static List<InternalReport> identifyMessage(byte[] message) {
List<InternalReport> reports = new ArrayList<InternalReport>();
List<String> lines = separateLines(message);
if(lines != null) {
Pattern p1 = Pattern.compile(PRODUCT_PTRN);
Pattern p2 = Pattern.compile(DATA_INFO);
Pattern p3 = Pattern.compile(DATETIME_INFO);
Pattern p4 = Pattern.compile(MODEL_INFO);
Pattern p5 = Pattern.compile(INIT_CONDITION_PTRN);
Pattern p6 = Pattern.compile(STORM_TYPE_INFO);
Pattern p7 = Pattern.compile(INIT_TIME_INFO);
Pattern p8 = Pattern.compile(FORECAST_POSITION_INFO);
Pattern p9 = Pattern.compile(STORM_DISSIPATED);
Pattern p10 = Pattern.compile(NWS_INFO);
Pattern p11 = Pattern.compile(TCE_REFTIME_INFO);
Pattern p12 = Pattern.compile(LATITUDE_INFO);
Pattern p13 = Pattern.compile(LONGITUDE_INFO);
Pattern p14 = Pattern.compile(FORECASTER_PTRN);
Pattern p15 = Pattern.compile(TCE_REFHOUR);
if (lines != null) {
Pattern p1 = PRODUCT_PTRN;
Pattern p2 = DATA_INFO;
Pattern p3 = DATETIME_INFO;
Pattern p4 = MODEL_INFO;
Pattern p5 = INIT_CONDITION_PTRN;
Pattern p6 = STORM_TYPE_INFO;
Pattern p7 = INIT_TIME_INFO;
Pattern p8 = FORECAST_POSITION_INFO;
Pattern p9 = STORM_DISSIPATED;
Pattern p10 = NWS_INFO;
Pattern p11 = TCE_REFTIME_INFO;
Pattern p12 = LATITUDE_INFO;
Pattern p13 = LONGITUDE_INFO;
Pattern p14 = FORECASTER_PTRN;
Pattern p15 = TCE_REFHOUR;
InternalType t1 = InternalType.PRODUCT;
InternalType t2 = InternalType.DATA_INFO;
@ -227,14 +260,16 @@ public class InternalReport {
InternalType t14 = InternalType.END;
InternalType t15 = InternalType.TCE_REFHOUR;
Pattern patterns[] = {p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15};
InternalType types[] = {t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15};
Pattern patterns[] = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
p11, p12, p13, p14, p15 };
InternalType types[] = { t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,
t11, t12, t13, t14, t15 };
for(String s : lines) {
for(int i = 0; i < patterns.length; i++){
for (String s : lines) {
for (int i = 0; i < patterns.length; i++) {
Matcher m = patterns[i].matcher(s);
if(m.matches()){
InternalReport rptLine = new InternalReport(types[i],s);
if (m.matches()) {
InternalReport rptLine = new InternalReport(types[i], s);
reports.add(rptLine);
break;
}
@ -266,13 +301,13 @@ public class InternalReport {
}
}
} catch (Exception e) {
logger.error("Error reading from reader",e);
LOGGER.error("Error reading from reader", e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ioe) {
logger.error("Error closing reader", ioe);
LOGGER.error("Error closing reader", ioe);
}
}
}

View file

@ -44,6 +44,8 @@ import com.raytheon.uf.edex.plugin.tcg.TropicalCycloneGuidanceDao;
* ------------ ---------- ----------- --------------------------
* Nov 12, 2009 jsanchez Initial creation
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
* Jun 24, 2014 3235 nabowle InternalReport patterns are now
* precompiled.
*
* </pre>
*
@ -52,6 +54,10 @@ import com.raytheon.uf.edex.plugin.tcg.TropicalCycloneGuidanceDao;
*/
public class TCEData extends TCGDataAdapter {
private static final Pattern STATION_ID_PATTERN = Pattern.compile("(\\w{2,2}\\d{6,6})");
private static final Pattern REF_HOUR_PATTERN = Pattern.compile("(\\d{4,4})");
private float latitude = -9999;
private float longitude = -9999;
@ -132,8 +138,7 @@ public class TCEData extends TCGDataAdapter {
}
private void parseStationIdInfo(String stationIdInfo) {
Pattern p = Pattern.compile("(\\w{2,2}\\d{6,6})");
Matcher m = p.matcher(stationIdInfo);
Matcher m = STATION_ID_PATTERN.matcher(stationIdInfo);
if (m.find()) {
stationId = m.group();
}
@ -147,8 +152,7 @@ public class TCEData extends TCGDataAdapter {
}
private void parseRefhour(String refhourInfo) {
Pattern p = Pattern.compile("(\\d{4,4})");
Matcher m = p.matcher(refhourInfo);
Matcher m = REF_HOUR_PATTERN.matcher(refhourInfo);
if (m.find()) {
hour = Integer.parseInt(m.group().substring(0, 2));
minute = Integer.parseInt(m.group().substring(2));
@ -156,8 +160,7 @@ public class TCEData extends TCGDataAdapter {
}
private void parseLatitude(String latitudeInfo) {
Pattern p = Pattern.compile(InternalReport.LAT_PTRN);
Matcher m = p.matcher(latitudeInfo);
Matcher m = InternalReport.LAT_PTRN.matcher(latitudeInfo);
if (m.find()) {
latitude = Float.parseFloat(m.group().substring(8).trim());
if (latitudeInfo.contains("SOUTH")) {
@ -168,8 +171,7 @@ public class TCEData extends TCGDataAdapter {
}
private void parseLongitude(String longitudeInfo) {
Pattern p = Pattern.compile(InternalReport.LON_PTRN);
Matcher m = p.matcher(longitudeInfo);
Matcher m = InternalReport.LON_PTRN.matcher(longitudeInfo);
if (m.find()) {
longitude = Float.parseFloat(m.group().substring(10).trim());
if (longitudeInfo.contains("WEST")) {

View file

@ -26,8 +26,8 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.raytheon.edex.esb.Headers;
import com.raytheon.uf.common.dataplugin.tcg.TCGStormType;
@ -40,7 +40,7 @@ import com.raytheon.uf.common.wmo.WMOHeader;
import com.raytheon.uf.edex.plugin.tcg.TropicalCycloneGuidanceDao;
/**
* TODO Add Description
* Base class for Tropical Cyclone Guidance (TCG) products.
*
* <pre>
*
@ -52,6 +52,7 @@ import com.raytheon.uf.edex.plugin.tcg.TropicalCycloneGuidanceDao;
* Jun 28, 2012 #826 dgilling Ensure getDataTime properly
* handles time zones.
* May 14, 2014 2536 bclement moved WMO Header to common, removed constructDataURI() call
* Jun 24, 2014 3235 nabowle Switch to slf4j.
*
* </pre>
*
@ -60,7 +61,8 @@ import com.raytheon.uf.edex.plugin.tcg.TropicalCycloneGuidanceDao;
*/
public abstract class TCGDataAdapter {
protected static Log logger = LogFactory.getLog(TCGDataAdapter.class);
protected static Logger logger = LoggerFactory
.getLogger(TCGDataAdapter.class);
protected PointDataDescription pointDataDescription;