Finished implementation of ORCCertificateImporterRMS.

This commit is contained in:
Daniel Lisunkin committed 2019-09-03 17:51:10 +02:00
1 parent 86e69b66af
commit b2f6719ca5
1 file changed
+50 -12
@@ -8,6 +8,7 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -18,6 +19,7 @@ import java.util.regex.Pattern;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;
import com.sap.sse.common.impl.DegreeBearingImpl;
import com.sap.sailing.domain.common.impl.MeterDistance;
import com.sap.sailing.domain.common.orc.ORCCertificate;
import com.sap.sailing.domain.common.orc.impl.ORCCertificateImpl;
@@ -38,9 +40,10 @@ import com.sap.sse.common.impl.SecondsDurationImpl;
* simply split by space characters.
* <p>
*
* The result of successfully parsing a {@code .rms} file is a map keyed by the so-called national certificate file ID,
* with values being equal-sized maps from the column names to the {@link String} values. Additionally, the column names
* corresponding to the array indices can be queried.
* The result of successfully parsing a {@code .rms} file is a map keyed by the sailnumber, with values being
* equal-sized maps from the column names to the {@link String} values. Additionally, the column names corresponding to
* the array indices can be queried. A further step involves the creation of {@link ORCCertificate}s from the values of
* the map.
*
* @author Axel Uhl (d043530)
* @author Daniel Lisunkin (i505543)
@@ -48,6 +51,17 @@ import com.sap.sse.common.impl.SecondsDurationImpl;
*/
public class ORCCertificateImporterRMS implements ORCCertificateImporter {
//Codes used in the RMS document as column names for different information
private static final String TWA_COURSES = "R";
private static final String CDL = "CDL";
private static final String GPH = "GPH";
private static final String LENGTH = "LOA";
private static final String BOATCLASS = "TYPE";
private static final String RUN_ALLOWANCE = "D";
private static final String RUN_ANGLE = "DA";
private static final String BEAT_ALLOWANCE = "UP";
private static final String BEAT_ANGLE = "UA";
private static final String NAME_OF_LAST_LEFT_ALIGNED_COLUMN_HEADER = "HH:MM:SS";
private final LinkedHashMap<String, Integer> columnNamesAndWidths;
@@ -90,8 +104,9 @@ public class ORCCertificateImporterRMS implements ORCCertificateImporter {
InputStreamReader reader = new InputStreamReader(new BufferedInputStream(bomInputStream), charsetName);
BufferedReader br = new BufferedReader(reader);
columnNamesAndWidths = readColumnWidthsFromFirstLine(br.readLine());
final String fileIdColumnName = columnNamesAndWidths.keySet().iterator().next();
final String sailnumberColumnName = columnNamesAndWidths.keySet().iterator().next();
Iterator<String> iterator = columnNamesAndWidths.keySet().iterator();
final String fileIdColumnName = iterator.next();
final String sailnumberColumnName = iterator.next();
certificateValuesBySailnumber = new HashMap<>();
String line;
@@ -161,10 +176,10 @@ public class ORCCertificateImporterRMS implements ORCCertificateImporter {
public ORCCertificate getCertificate(String sailnumber) {
String searchString = sailnumber.replaceAll(" ", "").toUpperCase();
ORCCertificateValues certificateValues = getValuesForSailnumber(searchString);
String boatclass = certificateValues.getValue("TYPE");
Distance length = new MeterDistance(Double.parseDouble(certificateValues.getValue("LOA")));
Duration gph = new SecondsDurationImpl(Double.parseDouble(certificateValues.getValue("GPH")));
Double cdl = Double.parseDouble(certificateValues.getValue("CDL"));
String boatclass = certificateValues.getValue(BOATCLASS);
Distance length = new MeterDistance(Double.parseDouble(certificateValues.getValue(LENGTH)));
Duration gph = new SecondsDurationImpl(Double.parseDouble(certificateValues.getValue(GPH)));
Double cdl = Double.parseDouble(certificateValues.getValue(CDL));
Map<Speed, Map<Bearing, Speed>> velocityPredictionsPerTrueWindSpeedAndAngle = new HashMap<>();
Map<Speed, Bearing> beatAngles = new HashMap<>();
Map<Speed, Speed> beatVMGPredictionPerTrueWindSpeed = new HashMap<>();
@@ -173,7 +188,25 @@ public class ORCCertificateImporterRMS implements ORCCertificateImporter {
Map<Speed, Speed> runVMGPredictionPerTrueWindSpeed = new HashMap<>();
Map<Speed, Duration> runAllowancePerTrueWindSpeed = new HashMap<>();
for (Speed tws : ORCCertificateImpl.ALLOWANCES_TRUE_WIND_SPEEDS) {
String windSpeed = Integer.toString((int) tws.getKnots());
String beatAngleKey = BEAT_ANGLE + windSpeed;
String beatAllowanceKey = BEAT_ALLOWANCE + windSpeed;
String runAngleKey = RUN_ANGLE + windSpeed;
String runAllowanceKey = RUN_ALLOWANCE + windSpeed;
beatAngles.put(tws, new DegreeBearingImpl(Double.parseDouble(certificateValues.getValue(beatAngleKey))));
beatAllowancePerTrueWindSpeed.put(tws, new SecondsDurationImpl(Double.parseDouble(certificateValues.getValue(beatAllowanceKey))));
beatVMGPredictionPerTrueWindSpeed.put(tws, ORCCertificateImpl.NAUTICAL_MILE.inTime(beatAllowancePerTrueWindSpeed.get(tws)));
runAngles.put(tws, new DegreeBearingImpl(Double.parseDouble(certificateValues.getValue(runAngleKey))));
runAllowancePerTrueWindSpeed.put(tws, new SecondsDurationImpl(Double.parseDouble(certificateValues.getValue(runAllowanceKey))));
runVMGPredictionPerTrueWindSpeed.put(tws, ORCCertificateImpl.NAUTICAL_MILE.inTime(runAllowancePerTrueWindSpeed.get(tws)));
Map<Bearing, Speed> velocityPredictionPerTrueWindAngle = new HashMap<>();
for (Bearing twa : ORCCertificateImpl.ALLOWANCES_TRUE_WIND_ANGLES ) {
String twaCoursesKey = TWA_COURSES + Integer.toString((int) twa.getDegrees()) + windSpeed;
velocityPredictionPerTrueWindAngle.put(twa, ORCCertificateImpl.NAUTICAL_MILE.inTime(new SecondsDurationImpl(Double.parseDouble(certificateValues.getValue(twaCoursesKey)))));
}
velocityPredictionsPerTrueWindSpeedAndAngle.put(tws, velocityPredictionPerTrueWindAngle);
}
return new ORCCertificateImpl(searchString, boatclass, length, gph, cdl,
velocityPredictionsPerTrueWindSpeedAndAngle, beatAngles, beatVMGPredictionPerTrueWindSpeed,
@@ -183,7 +216,12 @@ public class ORCCertificateImporterRMS implements ORCCertificateImporter {
@Override
public Map<String, ORCCertificate> getCertificates(String[] sailnumbers) {
// TODO Auto-generated method stub
return null;
Map<String, ORCCertificate> result = new HashMap<>();
for (String sailnumber : sailnumbers) {
result.put(sailnumber, getCertificate(sailnumber));
}
return result;
}
}