mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
use unique certificate IDs instead of ambiguous sail numbers
Change-Id: I20b9bc0b979bd630b6d5473dd12f410c4a409e51
This commit is contained in:
1 parent
be68c403e3
commit
78c8aaa03b
13 files changed
+132
-169
No files matched your search
+3
-3
@@ -122,15 +122,15 @@ public class ORCPerformanceCurveRankingTest extends OnlineTracTracBasedTest {
|
||||
final ORCCertificatesCollection certificates = ORCCertificatesImporter.INSTANCE.read(
|
||||
getClass().getClassLoader().getResourceAsStream("orc/worlds2019/orcWorlds2019ClassA.json"));
|
||||
assertNotNull(certificates);
|
||||
assertFalse(Util.isEmpty(certificates.getSailNumbers()));
|
||||
assertFalse(Util.isEmpty(certificates.getCertificateIds()));
|
||||
author = new LogEventAuthorImpl("Testcase", 1);
|
||||
for (final Competitor competitor : getTrackedRace().getRace().getCompetitors()) {
|
||||
final Boat boat = getTrackedRace().getRace().getBoatOfCompetitor(competitor);
|
||||
ORCCertificate certificate;
|
||||
if (boat.getSailID().equals("Air is blue")) {
|
||||
certificate = certificates.getCertificateBySailNumber("ITA5252");
|
||||
certificate = certificates.getCertificateById("ITA52521I5252");
|
||||
} else {
|
||||
certificate = certificates.getCertificateBySailNumber(boat.getSailID());
|
||||
certificate = certificates.getCertificateById(boat.getSailID());
|
||||
if (certificate == null) {
|
||||
certificate = certificates.getCertificateByBoatName(boat.getName() == null ? boat.getSailID() : boat.getName());
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,15 +22,15 @@ public class TestORCCertificateImporterJSON {
|
||||
public void testSimpleLocalJSONFileRead() throws IOException, ParseException {
|
||||
File fileGER = new File(RESOURCES + "GER2019.json");
|
||||
ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new FileInputStream(fileGER));
|
||||
ORCCertificate milan = importer.getCertificateBySailNumber(" ger 7323");
|
||||
ORCCertificate milan = importer.getCertificateById("GER166844GER7323");
|
||||
assertNotNull(milan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleOnlineJSONFileRead() throws IOException, ParseException {
|
||||
ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new URL("https://data.orc.org/public/WPub.dll?action=DownRMS&CountryId=GER&ext=json").openStream());
|
||||
ORCCertificate swan = importer.getCertificateBySailNumber(" GER 5335");
|
||||
ORCCertificate moana = importer.getCertificateBySailNumber("ger 55 49 ");
|
||||
ORCCertificate swan = importer.getCertificateById("GER140849GER5335");
|
||||
ORCCertificate moana = importer.getCertificateById("GER140772GER5549");
|
||||
assertNotNull(swan);
|
||||
assertNotNull(moana);
|
||||
assertEquals(539.1, swan .getGPHInSecondsToTheMile(), 0.0000001);
|
||||
|
||||
+3
-3
@@ -21,15 +21,15 @@ public class TestORCCertificateImporterRMS {
|
||||
public void testSimpleLocalRMSFileRead() throws IOException, ParseException {
|
||||
File fileGER = new File(RESOURCES + "GER2019.rms");
|
||||
ORCCertificatesCollection certificates = ORCCertificatesImporter.INSTANCE.read(new FileInputStream(fileGER));
|
||||
ORCCertificate milan = certificates.getCertificateBySailNumber(" ger 7323");
|
||||
ORCCertificate milan = certificates.getCertificateById("GER166844GER7323");
|
||||
assertNotNull(milan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleOnlineRMSFileRead() throws IOException, ParseException {
|
||||
ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new URL("https://data.orc.org/public/WPub.dll?action=DownRMS&CountryId=GER&ext=rms").openStream());
|
||||
ORCCertificate swan = importer.getCertificateBySailNumber(" GER 5335");
|
||||
ORCCertificate moana = importer.getCertificateBySailNumber("ger 55 49 ");
|
||||
ORCCertificate swan = importer.getCertificateById("GER140849GER5335");
|
||||
ORCCertificate moana = importer.getCertificateById("GER140772GER5549");
|
||||
assertNotNull(swan);
|
||||
assertNotNull(moana);
|
||||
assertEquals(539.1, swan .getGPHInSecondsToTheMile(), 0.0000001);
|
||||
|
||||
+40
-44
@@ -1,5 +1,6 @@
|
||||
package com.sap.sailing.domain.orc;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.File;
|
||||
@@ -32,6 +33,7 @@ import com.sap.sailing.domain.common.orc.impl.ORCPerformanceCurveLegImpl;
|
||||
import com.sap.sailing.domain.orc.impl.ORCCertificatesJsonImporter;
|
||||
import com.sap.sailing.domain.orc.impl.ORCPerformanceCurveImpl;
|
||||
import com.sap.sse.common.Duration;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.DegreeBearingImpl;
|
||||
|
||||
/**
|
||||
@@ -84,31 +86,31 @@ public class TestORCPerformanceCurve {
|
||||
|
||||
@Test
|
||||
public void testLagrangeInterpolation60() throws FunctionEvaluationException {
|
||||
ORCCertificate certificate = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
|
||||
testAllowancePerLeg(certificate, 60.0, 498.4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLagrangeInterpolation62_5() throws FunctionEvaluationException {
|
||||
ORCCertificate certificate = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
|
||||
testAllowancePerLeg(certificate, 62.5, 492.2, 425.0, 403.6, 393.1, 386.7, 382.6, 371.4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLagrangeInterpolation98_3() throws FunctionEvaluationException {
|
||||
ORCCertificate certificate = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
|
||||
testAllowancePerLeg(certificate, 98.3, 483.6, 418.7, 394.8, 377.9, 360.2, 345.0, 321.7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLagrangeInterpolation120() throws FunctionEvaluationException {
|
||||
ORCCertificate certificate = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
|
||||
testAllowancePerLeg(certificate, 120.0, 506);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLagrangeInterpolation138_7() throws FunctionEvaluationException {
|
||||
ORCCertificate certificate = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
|
||||
testAllowancePerLeg(certificate, 138.7, 588.1, 468.4, 413.8, 382.6, 355.1, 326.4, 275.4);
|
||||
}
|
||||
|
||||
@@ -123,7 +125,7 @@ public class TestORCPerformanceCurve {
|
||||
|
||||
@Test
|
||||
public void testSimpleConstructedCourse() throws FunctionEvaluationException {
|
||||
ORCCertificateImpl certificate = (ORCCertificateImpl) importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificateImpl certificate = (ORCCertificateImpl) importerLocal.getCertificateById("GER140772GER5549");
|
||||
List<ORCPerformanceCurveLeg> legs = new ArrayList<>();
|
||||
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(1.0), new DegreeBearingImpl(0)));
|
||||
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(1.0), new DegreeBearingImpl(30)));
|
||||
@@ -146,7 +148,7 @@ public class TestORCPerformanceCurve {
|
||||
@Test
|
||||
public void testPerformanceCurveInversion() throws MaxIterationsExceededException, FunctionEvaluationException {
|
||||
Double accuracy = 0.1;
|
||||
ORCCertificateImpl certificate = (ORCCertificateImpl) importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificateImpl certificate = (ORCCertificateImpl) importerLocal.getCertificateById("GER140772GER5549");
|
||||
ORCPerformanceCurveImpl performanceCurve = (ORCPerformanceCurveImpl) new ORCPerformanceCurveImpl(certificate, alturaCourse);
|
||||
testBackwardForward(accuracy, performanceCurve, 11.5);
|
||||
testBackwardForward(accuracy, performanceCurve, 17.23);
|
||||
@@ -175,12 +177,12 @@ public class TestORCPerformanceCurve {
|
||||
@Test
|
||||
public void testImpliedWind() throws MaxIterationsExceededException, FunctionEvaluationException {
|
||||
double accuracy = 0.0001;
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateBySailNumber("GER 7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateBySailNumber("GER 5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateBySailNumber("GER 5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateBySailNumber("GER 6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateBySailNumber("GER 5564");
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
|
||||
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, alturaCourse);
|
||||
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, alturaCourse);
|
||||
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, alturaCourse);
|
||||
@@ -212,12 +214,12 @@ public class TestORCPerformanceCurve {
|
||||
@Test
|
||||
public void testAllowances() throws FunctionEvaluationException {
|
||||
double accuracy = 0.00001;
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateBySailNumber("GER 7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateBySailNumber("GER 5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateBySailNumber("GER 5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateBySailNumber("GER 6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateBySailNumber("GER 5564");
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
|
||||
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, alturaCourse);
|
||||
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, alturaCourse);
|
||||
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, alturaCourse);
|
||||
@@ -232,21 +234,15 @@ public class TestORCPerformanceCurve {
|
||||
assertEquals(Duration.ONE_HOUR.times(2.0).asHours(), performanceCurveHalbtrocken.getAllowancePerCourse(new KnotSpeedImpl(7.62407)).asHours(), accuracy);
|
||||
}
|
||||
|
||||
// Tests to make sure, that the structure of the certificate files didn't change and performance curves can be build
|
||||
/**
|
||||
* Tests to make sure, that the structure of the certificate files didn't change and performance curves can be built
|
||||
*/
|
||||
@Test
|
||||
public void testOnlineImport() throws FunctionEvaluationException {
|
||||
ORCCertificate certificateMoana = importerOnline.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificateMilan = importerOnline.getCertificateBySailNumber("GER 7323");
|
||||
ORCCertificate certificateTutima = importerOnline.getCertificateBySailNumber("GER 5609");
|
||||
ORCCertificate certificateBank = importerOnline.getCertificateBySailNumber("GER 5555");
|
||||
ORCCertificate certificateHaspa = importerOnline.getCertificateBySailNumber("GER 6300");
|
||||
ORCCertificate certificateHalbtrocken = importerOnline.getCertificateBySailNumber("GER 5564");
|
||||
new ORCPerformanceCurveImpl(certificateMoana, alturaCourse);
|
||||
new ORCPerformanceCurveImpl(certificateMilan, alturaCourse);
|
||||
new ORCPerformanceCurveImpl(certificateTutima, alturaCourse);
|
||||
new ORCPerformanceCurveImpl(certificateBank, alturaCourse);
|
||||
new ORCPerformanceCurveImpl(certificateHaspa, alturaCourse);
|
||||
new ORCPerformanceCurveImpl(certificateHalbtrocken, alturaCourse);
|
||||
assertFalse(Util.isEmpty(importerOnline.getCertificateIds()));
|
||||
for (final ORCCertificate certificate : importerOnline.getCertificates()) {
|
||||
new ORCPerformanceCurveImpl(certificate, alturaCourse);
|
||||
}
|
||||
}
|
||||
|
||||
// Tests for the calculations with a more complex course which contains some special leg types. (circular random or other)
|
||||
@@ -262,12 +258,12 @@ public class TestORCPerformanceCurve {
|
||||
ORCPerformanceCurveCourse complexCourse = new ORCPerformanceCurveCourseImpl(list);
|
||||
|
||||
double accuracy = 0.0001;
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateBySailNumber("GER 7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateBySailNumber("GER 5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateBySailNumber("GER 5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateBySailNumber("GER 6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateBySailNumber("GER 5564");
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
|
||||
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, complexCourse);
|
||||
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, complexCourse);
|
||||
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, complexCourse);
|
||||
@@ -294,12 +290,12 @@ public class TestORCPerformanceCurve {
|
||||
ORCPerformanceCurveCourse complexCourse = new ORCPerformanceCurveCourseImpl(list);
|
||||
|
||||
double accuracy = 0.00001;
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateBySailNumber("GER 5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateBySailNumber("GER 7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateBySailNumber("GER 5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateBySailNumber("GER 5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateBySailNumber("GER 6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateBySailNumber("GER 5564");
|
||||
ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
|
||||
ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
|
||||
ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
|
||||
ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
|
||||
ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
|
||||
ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
|
||||
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, complexCourse);
|
||||
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, complexCourse);
|
||||
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, complexCourse);
|
||||
|
||||
+3
-19
@@ -1,7 +1,5 @@
|
||||
package com.sap.sailing.domain.orc;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.sap.sailing.domain.common.orc.ORCCertificate;
|
||||
|
||||
/**
|
||||
@@ -13,10 +11,10 @@ import com.sap.sailing.domain.common.orc.ORCCertificate;
|
||||
**/
|
||||
public interface ORCCertificatesCollection {
|
||||
/**
|
||||
* Tells the sail numbers that can be used as key in {@link #getCertificateBySailNumber(String)} and {@link #getCertificates(String[])}
|
||||
* Tells the sail numbers that can be used as key in {@link #getCertificateById(String)} and {@link #getCertificates(String[])}
|
||||
* and for which certificates are available in this object.
|
||||
*/
|
||||
Iterable<String> getSailNumbers();
|
||||
Iterable<String> getCertificateIds();
|
||||
|
||||
/**
|
||||
* Creates an {@link ORCCertificate} object to a given sail number.
|
||||
@@ -27,25 +25,11 @@ public interface ORCCertificatesCollection {
|
||||
* 'X41', ...) and a numerical identification code.
|
||||
* @return {@code null}, if there isn't any data for the given sailnumber. Otherwise an {@link ORCCertificate}.
|
||||
*/
|
||||
ORCCertificate getCertificateBySailNumber(String sailnumber);
|
||||
ORCCertificate getCertificateById(String sailnumber);
|
||||
|
||||
ORCCertificate getCertificateByBoatName(String boatName);
|
||||
|
||||
Iterable<String> getBoatNames();
|
||||
|
||||
Iterable<ORCCertificate> getCertificates();
|
||||
|
||||
/**
|
||||
* Creates an {@link Map} of {@link ORCCertificate} objects to the given sail numbers.
|
||||
* <p>
|
||||
* Same functionality as {@code getCertificate} for a single sailnumber, just for multiple elements.
|
||||
*
|
||||
* @param sailnumbers
|
||||
* represents an array of sailnumbers as specified for the boat of the {@link Competitor) in the ORC
|
||||
* files. The sailnumber commonly consists out of an alphabetical national code (e.g. 'GER', 'GBR', 'SUI', ...) or
|
||||
* an alphanumerical class code (e.g. 'F40', 'X41', ...) and a numerical identification code.
|
||||
* @return {@link Map} of {@link ORCCertificate} values and the sailnumber parameters as keys. The value equals
|
||||
* {@code null}, if there isn't any data for the given sailnumber.
|
||||
*/
|
||||
Map<String, ORCCertificate> getCertificates(String[] sailnumbers);
|
||||
}
|
||||
+1
-29
@@ -1,25 +1,10 @@
|
||||
package com.sap.sailing.domain.orc.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sap.sailing.domain.common.orc.ORCCertificate;
|
||||
import com.sap.sailing.domain.common.orc.impl.ORCCertificateImpl;
|
||||
import com.sap.sailing.domain.orc.ORCCertificatesCollection;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
public abstract class AbstractORCCertificatesCollection implements ORCCertificatesCollection {
|
||||
|
||||
/**
|
||||
* From a sail number which may contain spaces, also redundantly and repeatedly, as well
|
||||
* as dashes, slashes or other special characters, and where upper and lower case may be mixed,
|
||||
* constructs a canonicalized version such that the chances for producing a match when searching
|
||||
* for a sail number is maximized, while still minimizing the chances for a false match.
|
||||
*/
|
||||
protected String getCanonicalizedSailNumber(String sailNumber) {
|
||||
return sailNumber.replaceAll(" ", "").replaceAll("-", "").toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only the first 16 characters after removing spaces and other special characters such as parentheses and dashes
|
||||
* are compared case-insensitively.
|
||||
@@ -29,19 +14,6 @@ public abstract class AbstractORCCertificatesCollection implements ORCCertificat
|
||||
return replaced.substring(0, Math.min(replaced.length(), 16));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Map} of {@link ORCCertificateImpl} keyed by the {@link String} sailnumbers, which were given as
|
||||
* an input inside an array.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, ORCCertificate> getCertificates(String[] sailnumbers) {
|
||||
Map<String, ORCCertificate> result = new HashMap<>();
|
||||
for (String sailnumber : sailnumbers) {
|
||||
result.put(sailnumber, getCertificateBySailNumber(sailnumber));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORCCertificate getCertificateByBoatName(String boatName) {
|
||||
final String canonicalizedBoatNameToSearchFor = getCanonicalizedBoatName(boatName);
|
||||
@@ -55,7 +27,7 @@ public abstract class AbstractORCCertificatesCollection implements ORCCertificat
|
||||
|
||||
@Override
|
||||
public Iterable<ORCCertificate> getCertificates() {
|
||||
return Util.map(getSailNumbers(), sailNumber->getCertificateBySailNumber(sailNumber));
|
||||
return Util.map(getCertificateIds(), certificateId->getCertificateById(certificateId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class FormatProbingORCCertificatesImporter implements ORCCertificatesImpo
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.FINE, "Couldn't read ORC certificates from input stream as JSON: "+e.getMessage());
|
||||
}
|
||||
if (result == null || Util.isEmpty(result.getSailNumbers())) {
|
||||
if (result == null || Util.isEmpty(result.getCertificateIds())) {
|
||||
// nothing from JSON; try RMS
|
||||
try {
|
||||
result = rmsFuture.get();
|
||||
|
||||
+49
-37
@@ -37,7 +37,19 @@ import com.sap.sse.common.impl.SecondsDurationImpl;
|
||||
*
|
||||
*/
|
||||
public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollection {
|
||||
private Map<String, JSONObject> data;
|
||||
private static final String GYBE_ANGLE = "GybeAngle";
|
||||
private static final String BEAT_ANGLE = "BeatAngle";
|
||||
private static final String ALLOWANCES = "Allowances";
|
||||
private static final String ISSUE_DATE = "IssueDate";
|
||||
private static final String CDL2 = "CDL";
|
||||
private static final String GPH2 = "GPH";
|
||||
private static final String CLASS = "Class";
|
||||
private static final String YACHT_NAME = "YachtName";
|
||||
private static final String LOA = "LOA";
|
||||
private static final String SAIL_NO = "SailNo";
|
||||
private static final String CERT_NO = "CertNo";
|
||||
private static final String BIN = "BIN";
|
||||
private static final String NAT_AUTH = "NatAuth";
|
||||
private static final String RUN = "Run";
|
||||
private static final String BEAT = "Beat";
|
||||
private static final String WINDWARD_LEEWARD = "WL";
|
||||
@@ -46,18 +58,17 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
private static final String NON_SPINNAKER = "NS";
|
||||
private static final String EMPTY_CERT_NO = " ";
|
||||
|
||||
private Map<String, JSONObject> certificateJsonObjectsByCertificateId;
|
||||
|
||||
/**
|
||||
* Receives an {@link InputStream} from different possible sources (web, local file, ...) and does parse the
|
||||
* {@code .json} file.
|
||||
*/
|
||||
public ORCCertificatesCollectionJSON(Map<String, JSONObject> data) {
|
||||
this.data = new HashMap<>();
|
||||
for (final Entry<String, JSONObject> e : data.entrySet()) {
|
||||
if (this.data.put(getCanonicalizedSailNumber(e.getKey()), e.getValue()) != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Certificate sail numbers in collection not unique after canonicalization: " + e.getKey()
|
||||
+ " is canonicalized to " + getCanonicalizedSailNumber(e.getKey())
|
||||
+ " for which a certificate is already in the collection.");
|
||||
public ORCCertificatesCollectionJSON(Iterable<JSONObject> data) {
|
||||
this.certificateJsonObjectsByCertificateId = new HashMap<>();
|
||||
for (final JSONObject o : data) {
|
||||
if (this.certificateJsonObjectsByCertificateId.put(getId(o), o) != null) {
|
||||
throw new IllegalArgumentException("Certificate ID in collection not unique: " + getId(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +78,7 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
* given key, the method returns {@link null}.
|
||||
*/
|
||||
@Override
|
||||
public ORCCertificate getCertificateBySailNumber(String sailnumber) {
|
||||
public ORCCertificate getCertificateById(String certificateId) {
|
||||
String boatName = null;
|
||||
String boatclass = null;
|
||||
Distance length = null;
|
||||
@@ -79,57 +90,48 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
Map<Speed, Map<Bearing, Speed>> velocityPredictionPerTrueWindSpeedAndAngle = new HashMap<>();
|
||||
Map<Bearing, Map<Speed, Duration>> allowanceDurationsPerTrueWindAngleAndSpeed = new HashMap<>(); //per nautical mile
|
||||
Map<String, Map<Speed, Duration>> predefinedAllowanceDurationsPerTrueWindSpeed = new HashMap<>(); //per nautical mile
|
||||
String searchString = getCanonicalizedSailNumber(sailnumber);
|
||||
JSONObject object = data.get(searchString);
|
||||
JSONObject object = certificateJsonObjectsByCertificateId.get(certificateId);
|
||||
if (object == null) {
|
||||
//TODO Throw Exception for sailnumber not found. InvalidArgumentException?
|
||||
// TODO Throw Exception for sailnumber not found. InvalidArgumentException?
|
||||
return null;
|
||||
}
|
||||
String natAuth = null;
|
||||
String bin = null;
|
||||
String certNo = null;
|
||||
String sailNumber = null;
|
||||
for (Entry<Object, Object> entry : object.entrySet()) {
|
||||
switch ((String) entry.getKey()) {
|
||||
case "NatAuth":
|
||||
natAuth = entry.getValue().toString();
|
||||
case SAIL_NO:
|
||||
sailNumber = entry.getValue() == null ? null : entry.getValue().toString();
|
||||
break;
|
||||
case "BIN":
|
||||
bin = entry.getValue().toString();
|
||||
break;
|
||||
case "CertNo":
|
||||
certNo = entry.getValue() == null ? EMPTY_CERT_NO : entry.getValue().toString();
|
||||
break;
|
||||
case "LOA":
|
||||
case LOA:
|
||||
length = new MeterDistance(((Number) entry.getValue()).doubleValue());
|
||||
break;
|
||||
case "YachtName":
|
||||
case YACHT_NAME:
|
||||
boatName = entry.getValue()==null?null:entry.getValue().toString();
|
||||
break;
|
||||
case "Class":
|
||||
case CLASS:
|
||||
boatclass = (String) entry.getValue();
|
||||
break;
|
||||
case "GPH":
|
||||
case GPH2:
|
||||
gph = new SecondsDurationImpl(((Number) entry.getValue()).doubleValue());
|
||||
break;
|
||||
case "CDL":
|
||||
case CDL2:
|
||||
cdl = ((Number) entry.getValue()).doubleValue();
|
||||
break;
|
||||
case "IssueDate":
|
||||
case ISSUE_DATE:
|
||||
Date date = DatatypeConverter.parseDateTime((String) entry.getValue()).getTime();
|
||||
issueDate = new MillisecondsTimePoint(date);
|
||||
break;
|
||||
case "Allowances":
|
||||
final JSONObject allowances = (JSONObject) object.get("Allowances");
|
||||
case ALLOWANCES:
|
||||
final JSONObject allowances = (JSONObject) object.get(ALLOWANCES);
|
||||
for (final Object aKey : allowances.keySet()) {
|
||||
final JSONArray array = (JSONArray) allowances.get(aKey);
|
||||
if (((String) aKey).equals("BeatAngle")) {
|
||||
if (((String) aKey).equals(BEAT_ANGLE)) {
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
beatAngles.put(ORCCertificateImpl.ALLOWANCES_TRUE_WIND_SPEEDS[i],
|
||||
new DegreeBearingImpl(((Number) array.get(i)).doubleValue()));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (((String) aKey).equals("GybeAngle")) {
|
||||
if (((String) aKey).equals(GYBE_ANGLE)) {
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
gybeAngles.put(ORCCertificateImpl.ALLOWANCES_TRUE_WIND_SPEEDS[i],
|
||||
new DegreeBearingImpl(((Number) array.get(i)).doubleValue()));
|
||||
@@ -201,16 +203,26 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
nonSpinnakerSpeedPredictionPerTrueWindSpeed.put(tws, ORCCertificateImpl.NAUTICAL_MILE
|
||||
.inTime(predefinedAllowanceDurationsPerTrueWindSpeed.get(NON_SPINNAKER).get(tws)));
|
||||
}
|
||||
return new ORCCertificateImpl(natAuth + certNo + bin, searchString, boatName, boatclass, length, gph, cdl,
|
||||
return new ORCCertificateImpl(getId(object), sailNumber, boatName, boatclass, length, gph, cdl,
|
||||
issueDate, velocityPredictionPerTrueWindSpeedAndAngle, beatAngles, beatVMGPredictionPerTrueWindSpeed,
|
||||
beatAllowancePerTrueWindSpeed, gybeAngles, runVMGPredictionPerTrueWindSpeed,
|
||||
runAllowancePerTrueWindSpeed, windwardLeewardSpeedPredictionPerTrueWindSpeed,
|
||||
longDistanceSpeedPredictionPerTrueWindSpeed, circularRandomSpeedPredictionPerTrueWindSpeed,
|
||||
nonSpinnakerSpeedPredictionPerTrueWindSpeed);
|
||||
}
|
||||
|
||||
private String getId(JSONObject certificateAsJson) {
|
||||
return getIdFromFields(certificateAsJson.get(NAT_AUTH).toString(),
|
||||
certificateAsJson.get(CERT_NO) == null ? EMPTY_CERT_NO : certificateAsJson.get(CERT_NO).toString(),
|
||||
certificateAsJson.get(BIN).toString());
|
||||
}
|
||||
|
||||
private String getIdFromFields(final String natAuth, final String certNo, final String bin) {
|
||||
return natAuth + certNo + bin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> getSailNumbers() {
|
||||
return Collections.unmodifiableCollection(data.keySet());
|
||||
public Iterable<String> getCertificateIds() {
|
||||
return Collections.unmodifiableCollection(certificateJsonObjectsByCertificateId.keySet());
|
||||
}
|
||||
}
|
||||
+19
-19
@@ -47,6 +47,7 @@ public class ORCCertificatesCollectionRMS extends AbstractORCCertificatesCollect
|
||||
private static final String GPH = "GPH";
|
||||
private static final String LENGTH = "LOA";
|
||||
private static final String BOATNAME = "NAME";
|
||||
private static final String SAILNUMBER = "SAILNUMB";
|
||||
private static final String BOATCLASS = "TYPE";
|
||||
private static final String ISSUEDATE = "DD_MM_yyYY";
|
||||
private static final String RUN_ALLOWANCE = "D";
|
||||
@@ -59,41 +60,40 @@ public class ORCCertificatesCollectionRMS extends AbstractORCCertificatesCollect
|
||||
private static final String NON_SPINNAKER = "NSP";
|
||||
private static final String NATCERTN_FILE_ID = "NATCERTN.FILE_ID";
|
||||
|
||||
private final Map<String, Map<String, String>> certificateValuesBySailnumber;
|
||||
private final Map<String, Map<String, String>> certificateValuesByCertificateId;
|
||||
|
||||
public class ORCCertificateValues {
|
||||
private final String sailnumber;
|
||||
private final String certificateId;
|
||||
|
||||
public ORCCertificateValues(String sailnumber) {
|
||||
public ORCCertificateValues(String certificateId) {
|
||||
super();
|
||||
this.sailnumber = sailnumber;
|
||||
this.certificateId = certificateId;
|
||||
}
|
||||
|
||||
public String getValue(String columnName) {
|
||||
return certificateValuesBySailnumber.get(sailnumber).get(columnName);
|
||||
return certificateValuesByCertificateId.get(certificateId).get(columnName);
|
||||
}
|
||||
}
|
||||
|
||||
public ORCCertificatesCollectionRMS(Map<String, Map<String, String>> certificateValuesBySailnumber) throws IOException {
|
||||
this.certificateValuesBySailnumber = new HashMap<>();
|
||||
for (final Entry<String, Map<String, String>> e : certificateValuesBySailnumber.entrySet()) {
|
||||
this.certificateValuesBySailnumber.put(getCanonicalizedSailNumber(e.getKey()), e.getValue());
|
||||
public ORCCertificatesCollectionRMS(Map<String, Map<String, String>> certificateValuesByCertificateId) throws IOException {
|
||||
this.certificateValuesByCertificateId = new HashMap<>();
|
||||
for (final Entry<String, Map<String, String>> e : certificateValuesByCertificateId.entrySet()) {
|
||||
this.certificateValuesByCertificateId.put(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getSailnumbers() {
|
||||
return Collections.unmodifiableSet(certificateValuesBySailnumber.keySet());
|
||||
return Collections.unmodifiableSet(certificateValuesByCertificateId.keySet());
|
||||
}
|
||||
|
||||
private ORCCertificateValues getValuesForSailnumber(String sailnumber) {
|
||||
String searchString = getCanonicalizedSailNumber(sailnumber);
|
||||
return certificateValuesBySailnumber.containsKey(searchString) ? new ORCCertificateValues(searchString) : null;
|
||||
private ORCCertificateValues getValuesForCertificateId(String certificateId) {
|
||||
return certificateValuesByCertificateId.containsKey(certificateId) ? new ORCCertificateValues(certificateId) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORCCertificate getCertificateBySailNumber(String sailnumber) {
|
||||
String searchString = getCanonicalizedSailNumber(sailnumber);
|
||||
ORCCertificateValues certificateValues = getValuesForSailnumber(searchString);
|
||||
public ORCCertificate getCertificateById(String certificateId) {
|
||||
ORCCertificateValues certificateValues = getValuesForCertificateId(certificateId);
|
||||
final String sailNumber = certificateValues.getValue(SAILNUMBER);
|
||||
final String boatclass = certificateValues.getValue(BOATCLASS);
|
||||
final String boatName = certificateValues.getValue(BOATNAME);
|
||||
final Distance length = new MeterDistance(Double.parseDouble(certificateValues.getValue(LENGTH)));
|
||||
@@ -147,7 +147,7 @@ public class ORCCertificatesCollectionRMS extends AbstractORCCertificatesCollect
|
||||
}
|
||||
velocityPredictionsPerTrueWindSpeedAndAngle.put(tws, velocityPredictionPerTrueWindAngle);
|
||||
}
|
||||
return new ORCCertificateImpl(certificateValues.getValue(NATCERTN_FILE_ID), searchString, boatName, boatclass,
|
||||
return new ORCCertificateImpl(certificateValues.getValue(NATCERTN_FILE_ID), sailNumber, boatName, boatclass,
|
||||
length, gph, cdl, issueDate, velocityPredictionsPerTrueWindSpeedAndAngle, beatAngles, beatVMGPredictionPerTrueWindSpeed,
|
||||
beatAllowancePerTrueWindSpeed, runAngles, runVMGPredictionPerTrueWindSpeed,
|
||||
runAllowancePerTrueWindSpeed, windwardLeewardSpeedPredictionPerTrueWindSpeed,
|
||||
@@ -155,7 +155,7 @@ public class ORCCertificatesCollectionRMS extends AbstractORCCertificatesCollect
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> getSailNumbers() {
|
||||
return Collections.unmodifiableCollection(certificateValuesBySailnumber.keySet());
|
||||
public Iterable<String> getCertificateIds() {
|
||||
return Collections.unmodifiableCollection(certificateValuesByCertificateId.keySet());
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -3,8 +3,8 @@ package com.sap.sailing.domain.orc.impl;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -35,12 +35,12 @@ public class ORCCertificatesJsonImporter extends AbstractORCCertificatesImporter
|
||||
|
||||
@Override
|
||||
public ORCCertificatesCollectionJSON read(Reader reader) throws IOException, ParseException {
|
||||
Map<String, JSONObject> result = new HashMap<>();
|
||||
List<JSONObject> result = new LinkedList<>();
|
||||
JSONObject parsedJson = (JSONObject) new JSONParser().parse(reader);
|
||||
JSONArray dataArray = (JSONArray) parsedJson.get("rms");
|
||||
for (int i = 0; i < dataArray.size(); i++) {
|
||||
JSONObject object = (JSONObject) dataArray.get(i);
|
||||
result.put((String) object.get("SailNo"), object);
|
||||
result.add(object);
|
||||
}
|
||||
return new ORCCertificatesCollectionJSON(result);
|
||||
}
|
||||
|
||||
+4
-5
@@ -41,15 +41,14 @@ public class ORCCertificatesRmsImporter extends AbstractORCCertificatesImporter
|
||||
final BufferedReader br = new BufferedReader(reader);
|
||||
final LinkedHashMap<String, Integer> columnNamesAndWidths = readColumnWidthsFromFirstLine(br.readLine());
|
||||
final Iterator<String> i = columnNamesAndWidths.keySet().iterator();
|
||||
i.next(); // skip certificate ID column
|
||||
final String sailnumberColumnName = i.next();
|
||||
final Map<String, Map<String, String>> certificateValuesBySailnumber = new HashMap<>();
|
||||
final String certificateIdColumnName = i.next();
|
||||
final Map<String, Map<String, String>> certificateValuesByCertificateId = new HashMap<>();
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
final Map<String, String> parsedLine = parseLine(line, columnNamesAndWidths);
|
||||
certificateValuesBySailnumber.put(parsedLine.get(sailnumberColumnName), parsedLine);
|
||||
certificateValuesByCertificateId.put(parsedLine.get(certificateIdColumnName), parsedLine);
|
||||
}
|
||||
return new ORCCertificatesCollectionRMS(certificateValuesBySailnumber);
|
||||
return new ORCCertificatesCollectionRMS(certificateValuesByCertificateId);
|
||||
}
|
||||
|
||||
public ORCCertificatesCollectionRMS read(InputStream in) throws IOException {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class TestStoringAndLoadingRegattaORCCertificateAssignmengtEvent extends
|
||||
@Test
|
||||
public void test() throws JsonDeserializationException, ParseException {
|
||||
RaceLogORCCertificateAssignmentEvent expectedEvent = new RaceLogORCCertificateAssignmentEventImpl(MillisecondsTimePoint.now(), expectedEventTime, author,
|
||||
expectedId, expectedPassId, importer.getCertificateBySailNumber("GER 5549"), boat);
|
||||
expectedId, expectedPassId, importer.getCertificateById("GER 5549"), boat);
|
||||
|
||||
Document dbObject = mongoFactory.storeRaceLogEntry(logIdentifier, expectedEvent);
|
||||
RaceLogORCCertificateAssignmentEvent actualEvent = loadEvent(dbObject);
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public class TestStoringAndLoadingRegattaORCCertificateAssignmentEvent extends A
|
||||
@Test
|
||||
public void test() throws JsonDeserializationException, ParseException {
|
||||
RaceLogORCCertificateAssignmentEvent expectedEvent = new RaceLogORCCertificateAssignmentEventImpl(MillisecondsTimePoint.now(), expectedEventTime, author,
|
||||
expectedId, expectedPassId, importer.getCertificateBySailNumber("GER 5549"), competitor);
|
||||
expectedId, expectedPassId, importer.getCertificateById("GER 5549"), competitor);
|
||||
|
||||
Document dbObject = mongoFactory.storeRaceLogEntry(logIdentifier, expectedEvent);
|
||||
RaceLogORCCertificateAssignmentEvent actualEvent = loadEvent(dbObject);
|
||||
|
||||
Reference in new issue
Block a user