mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
adjusted Expedition wind importer so it can read Phoenix data; added test case
Change-Id: Ide5c060899877b14428de2a9e833e6ddb330f037
This commit is contained in:
1 parent
06dd58c820
commit
d5ce190c58
4 files changed
+44
-27
No files matched your search
+2
-2
@@ -21,8 +21,8 @@ import com.sap.sailing.domain.trackimport.GPSFixImporter;
|
||||
import com.sap.sailing.server.trackfiles.impl.ExpeditionExtendedDataImporterImpl;
|
||||
|
||||
public class ExpeditionGPSFixImporter implements GPSFixImporter {
|
||||
private static final String LAT_COLUMN_HEADING = ExpeditionExtendedDataImporterImpl.GENERATED_LAT_HEADER;
|
||||
private static final String LON_COLUMN_HEADING = ExpeditionExtendedDataImporterImpl.GENERATED_LON_HEADER;
|
||||
private static final String LAT_COLUMN_HEADING = ExpeditionExtendedDataImporterImpl.COL_NAME_LAT;
|
||||
private static final String LON_COLUMN_HEADING = ExpeditionExtendedDataImporterImpl.COL_NAME_LON;
|
||||
private static final String COG_COLUMN_HEADING = "Ext_COG";
|
||||
private static final String SOG_COLUMN_HEADING = "Ext_SOG";
|
||||
@Override
|
||||
|
||||
+11
-1
@@ -2,6 +2,7 @@ package com.sap.sailing.server.gateway.expeditionimport;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.number.IsCloseTo.closeTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -14,7 +15,16 @@ public class TestWindLogParser {
|
||||
|
||||
private static final double DOUBLE_TOLERANCE = 1e-7;
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void testPhoenixRows() throws Exception {
|
||||
assertEquals(51., Double.valueOf("051"), 0.000001);
|
||||
Iterable<Wind> windImport = WindLogParser.importWind(getClass().getResourceAsStream("PhoenixRowWithWind.csv"));
|
||||
assertThat(Util.size(windImport), is(1));
|
||||
Wind wind = windImport.iterator().next();
|
||||
assertWind(wind, 10.5, 51, 41.521689, -71.338883);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteRow() throws Exception {
|
||||
Iterable<Wind> windImport = WindLogParser.importWind(getClass().getResourceAsStream("CompleteRow.csv"));
|
||||
assertThat(Util.size(windImport), is(1));
|
||||
|
||||
+26
-19
@@ -74,16 +74,14 @@ public class WindLogParser {
|
||||
}
|
||||
|
||||
private static final String COL_NAME_TRUE_WIND_SPEED = "Tws";
|
||||
private static final String COL_NAME_TRUE_WIND_SPEED2 = "TW_speed";
|
||||
private static final String COL_NAME_TRUE_WIND_DIRECTION = "Twd";
|
||||
private static final String COL_NAME_LAT = "Lat";
|
||||
private static final String COL_NAME_LONG = "Lon";
|
||||
private static final String COL_NAME_TRUE_WIND_DIRECTION2 = "TW_Dirn";
|
||||
private static final String COL_NAME_LAT = ExpeditionExtendedDataImporterImpl.COL_NAME_LAT;
|
||||
private static final String COL_NAME_LON = ExpeditionExtendedDataImporterImpl.COL_NAME_LON;
|
||||
|
||||
/**
|
||||
* See ExpeditionMessage, UDPExpeditionReceiver
|
||||
*
|
||||
* @param windStream
|
||||
* @return
|
||||
* @throws IOException
|
||||
* Reads an Expedition log file passed as the {@code windStream} input stream.
|
||||
*/
|
||||
public static Iterable<Wind> importWind(InputStream windStream) throws IOException {
|
||||
BufferedReader csvReader = new BufferedReader(new InputStreamReader(windStream));
|
||||
@@ -93,18 +91,27 @@ public class WindLogParser {
|
||||
WindBuffer windBuffer = new WindBuffer();
|
||||
final AtomicInteger lineNr = new AtomicInteger(1);
|
||||
csvReader.lines().forEach(line->{
|
||||
ExpeditionExtendedDataImporterImpl.parseLine(lineNr.incrementAndGet(), "Expedition Wind Import",
|
||||
line, headers, (timePoint, columnValues, headerDefinitions)->{
|
||||
windBuffer.updateTime(timePoint);
|
||||
windBuffer.updateWindData(columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_SPEED)],
|
||||
columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_DIRECTION)]);
|
||||
windBuffer.updatePosition(columnValues[headerDefinitions.get(COL_NAME_LAT)],
|
||||
columnValues[headerDefinitions.get(COL_NAME_LONG)]);
|
||||
Wind wind = windBuffer.createWindIfReady();
|
||||
if (wind != null) {
|
||||
result.add(wind);
|
||||
}
|
||||
});
|
||||
if (!line.trim().isEmpty()) {
|
||||
ExpeditionExtendedDataImporterImpl.parseLine(lineNr.incrementAndGet(), "Expedition Wind Import",
|
||||
line, headers, (timePoint, columnValues, headerDefinitions)->{
|
||||
windBuffer.updateTime(timePoint);
|
||||
final String trueWindSpeedData = headerDefinitions.containsKey(COL_NAME_TRUE_WIND_SPEED) &&
|
||||
columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_SPEED)] != null ? columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_SPEED)]
|
||||
: headerDefinitions.containsKey(COL_NAME_TRUE_WIND_SPEED2) ? columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_SPEED2)]
|
||||
: null;
|
||||
final String trueWindDirectionData = headerDefinitions.containsKey(COL_NAME_TRUE_WIND_DIRECTION) &&
|
||||
columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_DIRECTION)] != null ? columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_DIRECTION)]
|
||||
: headerDefinitions.containsKey(COL_NAME_TRUE_WIND_DIRECTION2) ? columnValues[headerDefinitions.get(COL_NAME_TRUE_WIND_DIRECTION2)]
|
||||
: null;
|
||||
windBuffer.updateWindData(trueWindSpeedData, trueWindDirectionData);
|
||||
windBuffer.updatePosition(columnValues[headerDefinitions.get(COL_NAME_LAT)],
|
||||
columnValues[headerDefinitions.get(COL_NAME_LON)]);
|
||||
Wind wind = windBuffer.createWindIfReady();
|
||||
if (wind != null) {
|
||||
result.add(wind);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
+5
-5
@@ -45,8 +45,8 @@ public class ExpeditionExtendedDataImporterImpl extends AbstractDoubleVectorFixI
|
||||
public static final String EXPEDITION_EXTENDED_TYPE = "EXPEDITION_EXTENDED";
|
||||
private static final Logger logger = Logger.getLogger(ExpeditionExtendedDataImporterImpl.class.getName());
|
||||
private static final String ORIGINAL_POSITION_HEADER = "Pos[ddd.dd]";
|
||||
public static final String GENERATED_LAT_HEADER = "Lat";
|
||||
public static final String GENERATED_LON_HEADER = "Lon";
|
||||
public static final String COL_NAME_LAT = "Lat";
|
||||
public static final String COL_NAME_LON = "Lon";
|
||||
private static final String DATE_COLUMN_1 = "dd/mm/yy";
|
||||
private static final String DATE_COLUMN_1_PATTERN = "dd/MM/yy";
|
||||
private static final String DATE_COLUMN_2 = "mm/dd/yy";
|
||||
@@ -120,7 +120,7 @@ public class ExpeditionExtendedDataImporterImpl extends AbstractDoubleVectorFixI
|
||||
|
||||
/**
|
||||
* When the header contains one or more occurrences of {@link #ORIGINAL_POSITION_HEADER}, it is substituted
|
||||
* by the two header columns {@link #GENERATED_LAT_HEADER} and {@link #GENERATED_LON_HEADER} because that's
|
||||
* by the two header columns {@link #COL_NAME_LAT} and {@link #COL_NAME_LON} because that's
|
||||
* how positions are stored in Expedition files: as two comma-separated values, one for latitude, another
|
||||
* for longitude, although there is only one header field.
|
||||
*/
|
||||
@@ -131,8 +131,8 @@ public class ExpeditionExtendedDataImporterImpl extends AbstractDoubleVectorFixI
|
||||
for (int columnInHeader = 0; columnInHeader < headerTokens.length; columnInHeader++) {
|
||||
String header = headerTokens[columnInHeader];
|
||||
if (header.equals(ORIGINAL_POSITION_HEADER)) {
|
||||
colIndicesInFile.put(GENERATED_LAT_HEADER, columnInResultingHeader++);
|
||||
colIndicesInFile.put(GENERATED_LON_HEADER, columnInResultingHeader++);
|
||||
colIndicesInFile.put(COL_NAME_LAT, columnInResultingHeader++);
|
||||
colIndicesInFile.put(COL_NAME_LON, columnInResultingHeader++);
|
||||
} else {
|
||||
colIndicesInFile.put(header, columnInResultingHeader++);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user