Issue #2930 - Fixed error in distance.

Former-commit-id: c56753c19f8413e1094b524a9bc43bbcfc74e46f
This commit is contained in:
Slav Korolev 2014-03-25 09:20:13 -04:00
parent 386e85fce9
commit c0688f9e99
6 changed files with 104 additions and 54 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Cwa Plug-in
Bundle-SymbolicName: com.raytheon.uf.edex.plugin.cwa
Bundle-Version: 1.12.1174.qualifier
Bundle-Version: 1.14.0.qualifier
Bundle-Vendor: RAYTHEON
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: com.raytheon.uf.common.dataplugin.cwa;bundle-version="1.0.0",
@ -17,8 +17,8 @@ Require-Bundle: com.raytheon.uf.common.dataplugin.cwa;bundle-version="1.0.0",
com.raytheon.uf.common.serialization
Import-Package: com.raytheon.edex.esb,
com.raytheon.uf.common.dataplugin,
com.raytheon.uf.common.dataplugin.exception,
com.raytheon.uf.common.datastorage.records,
com.raytheon.uf.common.status,
com.raytheon.uf.common.time,
com.raytheon.uf.edex.core,
org.apache.commons.logging
com.raytheon.uf.edex.core

View file

@ -34,10 +34,14 @@
<bean ref="cwaDecoder" method="decode" />
<to uri="direct-vm:persistIndexAlert" />
</pipeline>
<doCatch>
<exception>java.lang.Throwable</exception>
<to uri="log:cwa?level=ERROR"/>
</doCatch>
<doCatch>
<exception>com.raytheon.uf.common.dataplugin.exception.MalformedDataException</exception>
<to uri="direct-vm:logFailureAsInfo" />
</doCatch>
<doCatch>
<exception>java.lang.Throwable</exception>
<to uri="direct-vm:logFailedData"/>
</doCatch>
</doTry>
</route>
</camelContext>

View file

@ -19,21 +19,22 @@
**/
package com.raytheon.uf.edex.plugin.cwa;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.raytheon.edex.esb.Headers;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.cwa.CWARecord;
import com.raytheon.uf.common.dataplugin.exception.MalformedDataException;
import com.raytheon.uf.common.pointdata.PointDataDescription;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.plugin.cwa.decoder.CWAParser;
import com.raytheon.uf.edex.plugin.cwa.util.TableLoader;
/**
*
* CWA Decoder.
*
* <pre>
*
@ -42,6 +43,7 @@ import com.raytheon.uf.edex.plugin.cwa.util.TableLoader;
* ------------ ---------- ----------- --------------------------
* Feb 01, 2010 jsanchez Initial creation
* Apr 19, 2012 #457 dgilling Minor code cleanup.
* Mar 25, 2014 2930 skorolev Fixed error in distance.
*
* </pre>
*
@ -49,7 +51,7 @@ import com.raytheon.uf.edex.plugin.cwa.util.TableLoader;
* @version 1.0
*/
public class CWADecoder {
private Log logger = LogFactory.getLog(getClass());
private IUFStatusHandler logger = UFStatus.getHandler(CWADecoder.class);
private final String pluginName;
@ -93,7 +95,8 @@ public class CWADecoder {
* @param headers
* @return
*/
public PluginDataObject[] decode(byte[] data, Headers headers) {
public PluginDataObject[] decode(byte[] data, Headers headers)
throws MalformedDataException, IOException {
String traceId = null;
PluginDataObject[] decodedData = null;

View file

@ -32,17 +32,18 @@ import javax.measure.converter.UnitConverter;
import javax.measure.unit.NonSI;
import javax.measure.unit.SI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geotools.referencing.GeodeticCalculator;
import com.raytheon.edex.esb.Headers;
import com.raytheon.uf.common.dataplugin.PluginException;
import com.raytheon.uf.common.dataplugin.cwa.CWADimension;
import com.raytheon.uf.common.dataplugin.cwa.CWARecord;
import com.raytheon.uf.common.dataplugin.exception.MalformedDataException;
import com.raytheon.uf.common.pointdata.PointDataContainer;
import com.raytheon.uf.common.pointdata.PointDataDescription;
import com.raytheon.uf.common.pointdata.PointDataView;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.edex.decodertools.time.TimeTools;
import com.raytheon.uf.edex.plugin.cwa.CWARecordDao;
@ -52,7 +53,7 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
import com.vividsolutions.jts.geom.Coordinate;
/**
* TODO Add Description
* The CWA text Parser.
*
* <pre>
*
@ -64,6 +65,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Apr 18, 2012 473 dgilling Modify parser to set DataTime based on
* ingest file name.
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
* Mar 25, 2014 2930 skorolev Fixed error in distance.
*
* </pre>
*
@ -72,7 +74,7 @@ import com.vividsolutions.jts.geom.Coordinate;
*/
public class CWAParser {
/** The logger */
private final Log logger = LogFactory.getLog(getClass());
private IUFStatusHandler logger = UFStatus.getHandler(CWAParser.class);
private final PointDataDescription pointDataDescription;
@ -84,8 +86,6 @@ public class CWAParser {
private final GeodeticCalculator gc = new GeodeticCalculator();
private final String pluginName;
private String eventId;
private String text;
@ -94,8 +94,6 @@ public class CWAParser {
private DataTime startTime;
private DataTime endTime;
private CWADimension dimension;
private final List<Coordinate> coordinates = new ArrayList<Coordinate>();
@ -117,6 +115,9 @@ public class CWAParser {
private static UnitConverter nauticalmileToMeter = NonSI.NAUTICAL_MILE
.getConverterTo(SI.METER);
// Maximum possible distance between reference points in nautical miles.
private static final double MAX_VOR_DIST = 999.0;
private Headers headers;
static {
@ -139,16 +140,15 @@ public class CWAParser {
}
/**
*
* @param message
* @param wmoHeader
* @param dao
* @param pdd
* @param name
* @param pirepTable
*/
public CWAParser(CWARecordDao dao, PointDataDescription pdd, String name,
TableLoader pirepTable) {
pointDataDescription = pdd;
cwaDao = dao;
pluginName = name;
containerMap = new HashMap<File, PointDataContainer>();
this.pirepTable = pirepTable;
}
@ -244,11 +244,12 @@ public class CWAParser {
}
/**
*
* @param start
* @return
* @param message
* @return reports
* @throws MalformedDataException
*/
private List<CWARecord> findReports(byte[] message) {
private List<CWARecord> findReports(byte[] message)
throws MalformedDataException {
List<CWARecord> reports = new ArrayList<CWARecord>();
@ -306,8 +307,11 @@ public class CWAParser {
* Raw message data.
* @param traceId
* Trace id for this data.
* @param headers
* @throws MalformedDataException
*/
public void setData(byte[] message, String traceId, Headers headers) {
public void setData(byte[] message, String traceId, Headers headers)
throws MalformedDataException {
currentReport = -1;
this.traceId = traceId;
this.headers = headers;
@ -322,6 +326,9 @@ public class CWAParser {
}
}
/**
* @param issuanceInfo
*/
private void parseIssuanceInfo(String issuanceInfo) {
String[] parts = issuanceInfo.split(" ");
if ((parts != null) && (parts[0] != null)) {
@ -336,15 +343,21 @@ public class CWAParser {
}
}
/**
* @param validToInfo
*/
private void parseValidToInfo(String validToInfo) {
Pattern p = Pattern.compile(InternalReport.TIME);
Matcher m = p.matcher(validToInfo);
if (m.find()) {
String time = m.group();
endTime = getDataTime(time);
getDataTime(time);
}
}
/**
* @param vicinityInfo
*/
private void parseVicinityInfo(String vicinityInfo) {
Pattern vicinityPtrn = Pattern.compile(InternalReport.VICINITY);
Matcher m = vicinityPtrn.matcher(vicinityInfo);
@ -358,7 +371,12 @@ public class CWAParser {
}
}
private void parseCoordinateInfo(String coordinateInfo) {
/**
* @param coordinateInfo
* @throws MalformedDataException
*/
private void parseCoordinateInfo(String coordinateInfo)
throws MalformedDataException {
String tokens[] = coordinateInfo.replace("-", " - ").split(" ");
boolean getMoreCoords = true;
@ -401,8 +419,21 @@ public class CWAParser {
if (direction > 180) {
direction -= 360;
}
this.gc.setDirection(direction,
nauticalmileToMeter.convert(distance));
// According to WSOM:
// http://www.nws.noaa.gov/wsom/manual/archives/ND259606.HTML#6.1.2%C2%A0%C2%A0%C2%A0%C2%A0%20CWSU%20Meteorologist%20Responsibilities
// ..."When using a distance in CWSU products all references are in nautical miles (NM). "
// ..."The " (n)nn". is distance and "DD(D)" is a
// 16-point compass direction (e.g., VC IAH or 40NNE
// LBB)."
if (distance > MAX_VOR_DIST) {
throw new MalformedDataException("CWA product "
+ wmoHeader.getWmoHeader()
+ " has a non-valid distance " + distance
+ " NM to " + tok + ".");
}
distance = (float) nauticalmileToMeter
.convert(distance);
this.gc.setDirection(direction, distance);
coordinates
.add(new Coordinate(
this.gc.getDestinationGeographicPoint()
@ -424,6 +455,9 @@ public class CWAParser {
}
}
/**
* @param geometryInfo
*/
private void parseGeometryInfo(String geometryInfo) {
boolean found = false;
Pattern lineGeomPtrn = Pattern.compile(InternalReport.LINE_GEOM);
@ -459,9 +493,12 @@ public class CWAParser {
text = "";
dimension = CWADimension.CANCELED;
startTime = null;
endTime = null;
}
/**
* @param timeStr
* @return DataTime from header
*/
private DataTime getDataTime(String timeStr) {
Calendar cal = TimeTools.findDataTime(timeStr, headers);
if (cal != null) {
@ -471,16 +508,14 @@ public class CWAParser {
}
}
/**
* @return CWA Record
*/
private CWARecord getRecord() {
CWARecord record = new CWARecord();
record.setEventId(eventId);
record.setDimension(dimension);
record.setMessageData(text);
// TimeRange tr = new TimeRange(
// startTime.getRefTimeAsCalendar(),
// endTime.getRefTimeAsCalendar());
// DataTime dataTime = new DataTime(
// startTime.getRefTimeAsCalendar(),tr);
DataTime dataTime = new DataTime(startTime.getRefTimeAsCalendar());
record.setDataTime(dataTime);
Coordinate[] coord = null;

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 com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
/**
*
@ -37,9 +37,10 @@ import org.apache.commons.logging.LogFactory;
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 1, 2010 jsanchez Initial creation
* Date Ticket# Engineer Description
* ------- ---------- ----------- --------------------------
* Feb 01, 2010 jsanchez Initial creation
* Mar 26, 2014 skorolev Updated logger.
*
* </pre>
*
@ -47,7 +48,8 @@ import org.apache.commons.logging.LogFactory;
* @version 1.0
*/
public class InternalReport {
private static Log logger = LogFactory.getLog(InternalReport.class);
private static IUFStatusHandler logger = UFStatus
.getHandler(InternalReport.class);
private static final String ISSUANCE = "^([A-Z]{3})([0-9]) +U?CWA +([0-9]{6}) *";
@ -174,9 +176,7 @@ public class InternalReport {
} else {
m = p3.matcher(s);
if (m.matches()) {
reports
.add(new InternalReport(InternalType.VICINITY,
s));
reports.add(new InternalReport(InternalType.VICINITY, s));
} else if (issuanceFound && validtoFound
&& !coordinateFound) {
reports.add(new InternalReport(InternalType.COORDS, s));

View file

@ -28,10 +28,9 @@ import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.vividsolutions.jts.geom.Coordinate;
/**
@ -42,7 +41,8 @@ import com.vividsolutions.jts.geom.Coordinate;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 2, 2010 jsanchez Initial creation
* Feb 02, 2010 jsanchez Initial creation
* Mar 26, 2014 skorolev Updated logger.
*
* </pre>
*
@ -54,7 +54,7 @@ public class TableLoader {
private static HashMap<String, Coordinate> pirepTable = new HashMap<String, Coordinate>();
/** The logger */
private Log logger = LogFactory.getLog(getClass());
private IUFStatusHandler logger = UFStatus.getHandler(TableLoader.class);
private static final String KEY = "\\w{3,3}";
@ -117,10 +117,18 @@ public class TableLoader {
}
}
/**
* @param key
* @return
*/
public Coordinate get(String key) {
return pirepTable.get(key);
}
/**
* @param key
* @return
*/
public boolean contains(String key) {
return pirepTable.containsKey(key);
}