From b2f6719ca5ef9e2701d2cb52cff793edc06d9c39 Mon Sep 17 00:00:00 2001 From: Daniel Lisunkin Date: Tue, 3 Sep 2019 17:51:10 +0200 Subject: [PATCH] Finished implementation of ORCCertificateImporterRMS. --- .../orc/impl/ORCCertificateImporterRMS.java | 62 +++++++++++++++---- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificateImporterRMS.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificateImporterRMS.java index c0cc15ae928..d8ce649949c 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificateImporterRMS.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificateImporterRMS.java @@ -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. *

* - * 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 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 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> velocityPredictionsPerTrueWindSpeedAndAngle = new HashMap<>(); Map beatAngles = new HashMap<>(); Map beatVMGPredictionPerTrueWindSpeed = new HashMap<>(); @@ -173,7 +188,25 @@ public class ORCCertificateImporterRMS implements ORCCertificateImporter { Map runVMGPredictionPerTrueWindSpeed = new HashMap<>(); Map 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 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 getCertificates(String[] sailnumbers) { - // TODO Auto-generated method stub - return null; + Map result = new HashMap<>(); + + for (String sailnumber : sailnumbers) { + result.put(sailnumber, getCertificate(sailnumber)); + } + + return result; } }