Skip to content

Commit cc9b6f8

Browse files
author
TheRestOfMe
committed
Address issues from osh-addons PR #190
1 parent 16042ba commit cc9b6f8

3 files changed

Lines changed: 16 additions & 20 deletions

File tree

sensors/hydro/sensorhub-driver-ndbc/src/main/java/org/sensorhub/impl/sensor/ndbc/BuoyDataReader.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ public class BuoyDataReader
3737
{
3838
static final String MISSING = "MM";
3939
static final Logger logger = LoggerFactory.getLogger(BuoyDataReader.class);
40+
static final String expectedFields = "#STN LAT LON YYYY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES PTDY ATMP WTMP DEWP VIS TIDE";
41+
static final String expectedUnits = "#text deg deg yr mo day hr mn degT m/s m/s m sec sec degT hPa hPa degC degC degC nmi ft";
4042

4143
public static List<BuoyDataRecord> read(String url) throws IOException {
4244
List<BuoyDataRecord> recs = new ArrayList<>();
4345
URL dataUrl = new URL(url);
4446

4547
try (BufferedReader reader = new BufferedReader(new InputStreamReader(dataUrl.openStream()))) {
46-
// Skip Header lines
47-
String header = reader.readLine();
48-
boolean headerOk = checkHeader(header);
49-
if(!headerOk) {
50-
throw new IOException("Unexpected header format: " + header);
48+
String fields = reader.readLine();
49+
boolean fieldsOk = checkFields(fields);
50+
if(!fieldsOk) {
51+
logger.warn("Fields in header do not match expected fields:\n\t{}", fields);
5152
}
5253
String units = reader.readLine();
5354
boolean unitsOk = checkUnits(units);
5455
if(!unitsOk) {
55-
throw new IOException("Unexpected units format: " + units);
56+
logger.warn("Units in header do not match expected units:\n\t{}", units);
5657
}
5758
while(true) {
5859
String inline = reader.readLine();
@@ -61,8 +62,6 @@ public static List<BuoyDataRecord> read(String url) throws IOException {
6162
if(inline.isBlank()) continue;
6263

6364
String [] values = inline.split("\\s+");
64-
// #STN LAT LON YYYY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES PTDY ATMP WTMP DEWP VIS TIDE
65-
// #text deg deg yr mo day hr mn degT m/s m/s m sec sec degT hPa hPa degC degC degC nmi ft
6665
BuoyDataRecord rec = new BuoyDataRecord();
6766
rec.id = values[0];
6867
rec.lat = parseDouble(values[1]);
@@ -103,18 +102,14 @@ public static List<BuoyDataRecord> read(String url) throws IOException {
103102
}
104103
}
105104

106-
// #STN LAT LON YYYY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES PTDY ATMP WTMP DEWP VIS TIDE
107-
public static boolean checkHeader(String header) {
108-
// TODO check fields are as expected
109-
String [] fields = header.split("\\s+");
110-
return (fields.length == 22);
105+
public static boolean checkFields(String fields) {
106+
fields = fields.trim();
107+
return fields.equalsIgnoreCase(expectedFields);
111108
}
112109

113-
// #text deg deg yr mo day hr mn degT m/s m/s m sec sec degT hPa hPa degC degC degC nmi ft
114110
public static boolean checkUnits(String units) {
115-
String [] fields = units.split("\\s+");
116-
// TODO check units are as expected
117-
return (fields.length == 22);
111+
units = units.trim();
112+
return units.equalsIgnoreCase(expectedUnits);
118113
}
119114

120115
// Default URL is https://www.ndbc.noaa.gov/data/latest_obs/latest_obs.txt
@@ -138,7 +133,7 @@ public static Double parseDouble(String s) {
138133
try {
139134
return Double.parseDouble(s);
140135
} catch (NumberFormatException e) {
141-
logger.error("", e);
136+
logger.error(e.getMessage(), e);
142137
return null;
143138
}
144139
}
@@ -153,7 +148,7 @@ public static Integer parseInt(String s) {
153148
try {
154149
return Integer.parseInt(s);
155150
} catch (NumberFormatException e) {
156-
logger.error("", e);
151+
logger.error(e.getMessage(), e);
157152
return null;
158153
}
159154
}

sensors/hydro/sensorhub-driver-ndbc/src/main/java/org/sensorhub/impl/sensor/ndbc/BuoyEnums.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @author Tony Cook
2121
*/
2222

23+
@Deprecated // This is a legacy enum from original driver. Marking deprecated but may bring it back in future driver development
2324
public class BuoyEnums {
2425

2526
public enum ObsParam

sensors/hydro/sensorhub-driver-ndbc/src/main/java/org/sensorhub/impl/sensor/ndbc/BuoyOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected void init() {
113113
.description("Pressure Tendency is the direction (plus or minus) and the amount of"
114114
+ "pressure change (hPa)for a three hour period ending at the time of observation")
115115
.definition("https://mmisw.org/ont/mx_testing/mxparms1/pressure_tendency")
116-
// .uomCode() hPa/3 hours- not sure how to encode
116+
.uomCode("hPa/(3.h)") // hectoPascals/3 hours
117117
.build())
118118
.addField("airTemperature", geoFac.createQuantity()
119119
.description("Air temperature (Celsius) at sensor height")

0 commit comments

Comments
 (0)