mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-16 07:10:48 +00:00
added test case for ORC PCS ranking metric; still failing (maybe wrong certificates?)
Change-Id: I965ae4582c97adad16f3e05b5a7d048c5396ea9a
This commit is contained in:
1 parent
5875406ce5
commit
cffe615bfb
22 files changed
+365
-152
No files matched your search
+8
-3
@@ -13,7 +13,7 @@ import com.sap.sailing.domain.common.orc.ORCCertificate;
|
||||
**/
|
||||
public interface ORCCertificatesCollection {
|
||||
/**
|
||||
* Tells the sail numbers that can be used as key in {@link #getCertificate(String)} and {@link #getCertificates(String[])}
|
||||
* Tells the sail numbers that can be used as key in {@link #getCertificateBySailNumber(String)} and {@link #getCertificates(String[])}
|
||||
* and for which certificates are available in this object.
|
||||
*/
|
||||
Iterable<String> getSailNumbers();
|
||||
@@ -27,7 +27,13 @@ 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 getCertificate(String sailnumber);
|
||||
ORCCertificate getCertificateBySailNumber(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.
|
||||
@@ -42,5 +48,4 @@ public interface ORCCertificatesCollection {
|
||||
* {@code null}, if there isn't any data for the given sailnumber.
|
||||
*/
|
||||
Map<String, ORCCertificate> getCertificates(String[] sailnumbers);
|
||||
|
||||
}
|
||||
+56
-1
@@ -1,6 +1,12 @@
|
||||
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 {
|
||||
|
||||
@@ -11,6 +17,55 @@ public abstract class AbstractORCCertificatesCollection implements ORCCertificat
|
||||
* for a sail number is maximized, while still minimizing the chances for a false match.
|
||||
*/
|
||||
protected String getCanonicalizedSailNumber(String sailNumber) {
|
||||
return sailNumber.replaceAll(" ", "").toUpperCase();
|
||||
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.
|
||||
*/
|
||||
protected String getCanonicalizedBoatName(String boatName) {
|
||||
final String replaced = boatName.toUpperCase().replaceAll("[^A-Z0-9]", "");
|
||||
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);
|
||||
for (final ORCCertificate certificate : getCertificates()) {
|
||||
if (canonicalizedBoatNameToSearchFor.equals(getCanonicalizedBoatName(certificate.getBoatName()))) {
|
||||
return certificate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ORCCertificate> getCertificates() {
|
||||
return Util.map(getSailNumbers(), sailNumber->getCertificateBySailNumber(sailNumber));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> getBoatNames() {
|
||||
return Util.map(getCertificates(), c->getCanonicalizedBoatName(c.getBoatName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Util.joinStrings(", ", Util.map(getCertificates(), c->c.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
+17
-23
@@ -47,7 +47,12 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
public ORCCertificatesCollectionJSON(Map<String, JSONObject> data) {
|
||||
this.data = new HashMap<>();
|
||||
for (final Entry<String, JSONObject> e : data.entrySet()) {
|
||||
this.data.put(getCanonicalizedSailNumber(e.getKey()), e.getValue());
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +61,8 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
* given key, the method returns {@link null}.
|
||||
*/
|
||||
@Override
|
||||
public ORCCertificate getCertificate(String sailnumber) {
|
||||
public ORCCertificate getCertificateBySailNumber(String sailnumber) {
|
||||
String boatName = null;
|
||||
String boatclass = null;
|
||||
Distance length = null;
|
||||
Duration gph = null;
|
||||
@@ -77,6 +83,9 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
case "LOA":
|
||||
length = new MeterDistance(((Number) entry.getValue()).doubleValue());
|
||||
break;
|
||||
case "YachtName":
|
||||
boatName = entry.getValue().toString();
|
||||
break;
|
||||
case "Class":
|
||||
boatclass = (String) entry.getValue();
|
||||
break;
|
||||
@@ -168,27 +177,12 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
|
||||
nonSpinnakerSpeedPredictionPerTrueWindSpeed.put(tws, ORCCertificateImpl.NAUTICAL_MILE
|
||||
.inTime(predefinedAllowanceDurationsPerTrueWindSpeed.get(NON_SPINNAKER).get(tws)));
|
||||
}
|
||||
return new ORCCertificateImpl(searchString, boatclass, length, gph, cdl,
|
||||
velocityPredictionPerTrueWindSpeedAndAngle, beatAngles, beatVMGPredictionPerTrueWindSpeed,
|
||||
beatAllowancePerTrueWindSpeed, gybeAngles, runVMGPredictionPerTrueWindSpeed,
|
||||
runAllowancePerTrueWindSpeed, windwardLeewardSpeedPredictionPerTrueWindSpeed,
|
||||
longDistanceSpeedPredictionPerTrueWindSpeed, circularRandomSpeedPredictionPerTrueWindSpeed,
|
||||
nonSpinnakerSpeedPredictionPerTrueWindSpeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, getCertificate(sailnumber));
|
||||
}
|
||||
|
||||
return result;
|
||||
return new ORCCertificateImpl(searchString, boatName, boatclass, length, gph,
|
||||
cdl, velocityPredictionPerTrueWindSpeedAndAngle, beatAngles,
|
||||
beatVMGPredictionPerTrueWindSpeed, beatAllowancePerTrueWindSpeed, gybeAngles,
|
||||
runVMGPredictionPerTrueWindSpeed, runAllowancePerTrueWindSpeed,
|
||||
windwardLeewardSpeedPredictionPerTrueWindSpeed, longDistanceSpeedPredictionPerTrueWindSpeed,
|
||||
circularRandomSpeedPredictionPerTrueWindSpeed, nonSpinnakerSpeedPredictionPerTrueWindSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-17
@@ -44,6 +44,7 @@ public class ORCCertificatesCollectionRMS extends AbstractORCCertificatesCollect
|
||||
private static final String GPH = "GPH";
|
||||
private static final String LENGTH = "LOA";
|
||||
private static final String BOATCLASS = "TYPE";
|
||||
private static final String BOATNAME = "NAME";
|
||||
private static final String RUN_ALLOWANCE = "D";
|
||||
private static final String RUN_ANGLE = "DA";
|
||||
private static final String BEAT_ALLOWANCE = "UP";
|
||||
@@ -79,16 +80,17 @@ public class ORCCertificatesCollectionRMS extends AbstractORCCertificatesCollect
|
||||
return Collections.unmodifiableSet(certificateValuesBySailnumber.keySet());
|
||||
}
|
||||
|
||||
public ORCCertificateValues getValuesForSailnumber(String sailnumber) {
|
||||
private ORCCertificateValues getValuesForSailnumber(String sailnumber) {
|
||||
String searchString = getCanonicalizedSailNumber(sailnumber);
|
||||
return certificateValuesBySailnumber.containsKey(searchString) ? new ORCCertificateValues(searchString) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORCCertificate getCertificate(String sailnumber) {
|
||||
public ORCCertificate getCertificateBySailNumber(String sailnumber) {
|
||||
String searchString = getCanonicalizedSailNumber(sailnumber);
|
||||
ORCCertificateValues certificateValues = getValuesForSailnumber(searchString);
|
||||
final String boatclass = certificateValues.getValue(BOATCLASS);
|
||||
final String boatName = certificateValues.getValue(BOATNAME);
|
||||
final Distance length = new MeterDistance(Double.parseDouble(certificateValues.getValue(LENGTH)));
|
||||
final Duration gph = new SecondsDurationImpl(Double.parseDouble(certificateValues.getValue(GPH)));
|
||||
final Double cdl = Double.parseDouble(certificateValues.getValue(CDL));
|
||||
@@ -135,21 +137,12 @@ public class ORCCertificatesCollectionRMS extends AbstractORCCertificatesCollect
|
||||
}
|
||||
velocityPredictionsPerTrueWindSpeedAndAngle.put(tws, velocityPredictionPerTrueWindAngle);
|
||||
}
|
||||
return new ORCCertificateImpl(searchString, boatclass, length, gph, cdl,
|
||||
velocityPredictionsPerTrueWindSpeedAndAngle, beatAngles, beatVMGPredictionPerTrueWindSpeed,
|
||||
beatAllowancePerTrueWindSpeed, runAngles, runVMGPredictionPerTrueWindSpeed,
|
||||
runAllowancePerTrueWindSpeed, windwardLeewardSpeedPredictionPerTrueWindSpeed,
|
||||
longDistanceSpeedPredictionPerTrueWindSpeed, circularRandomSpeedPredictionPerTrueWindSpeed,
|
||||
nonSpinnakerSpeedPredictionPerTrueWindSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ORCCertificate> getCertificates(String[] sailnumbers) {
|
||||
Map<String, ORCCertificate> result = new HashMap<>();
|
||||
for (String sailnumber : sailnumbers) {
|
||||
result.put(sailnumber, getCertificate(sailnumber));
|
||||
}
|
||||
return result;
|
||||
return new ORCCertificateImpl(searchString, boatName, boatclass, length, gph,
|
||||
cdl, velocityPredictionsPerTrueWindSpeedAndAngle, beatAngles,
|
||||
beatVMGPredictionPerTrueWindSpeed, beatAllowancePerTrueWindSpeed, runAngles,
|
||||
runVMGPredictionPerTrueWindSpeed, runAllowancePerTrueWindSpeed,
|
||||
windwardLeewardSpeedPredictionPerTrueWindSpeed, longDistanceSpeedPredictionPerTrueWindSpeed,
|
||||
circularRandomSpeedPredictionPerTrueWindSpeed, nonSpinnakerSpeedPredictionPerTrueWindSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+20
@@ -32,7 +32,9 @@ import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEventVisitor;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.impl.BaseRegattaLogEventVisitor;
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.CourseListener;
|
||||
import com.sap.sailing.domain.base.Leg;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.orc.ORCCertificate;
|
||||
import com.sap.sailing.domain.common.orc.ORCPerformanceCurveCourse;
|
||||
@@ -129,6 +131,17 @@ public class ORCPerformanceCurveRankingMetric extends AbstractRankingMetric {
|
||||
updateScratchBoatFromLogs();
|
||||
}
|
||||
});
|
||||
trackedRace.getRace().getCourse().addCourseListener(new CourseListener() {
|
||||
@Override
|
||||
public void waypointRemoved(int zeroBasedIndex, Waypoint waypointThatGotRemoved) {
|
||||
updateCourseFromRaceLogs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waypointAdded(int zeroBasedIndex, Waypoint waypointThatGotAdded) {
|
||||
updateCourseFromRaceLogs();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,8 +185,15 @@ public class ORCPerformanceCurveRankingMetric extends AbstractRankingMetric {
|
||||
public void visit(RaceLogRevokeEvent event) {
|
||||
if (event.getRevokedEventType().equals(RaceLogORCLegDataEventImpl.class.getName())) {
|
||||
updateCourseFromRaceLogs();
|
||||
} else if (event.getRevokedEventType().equals(RaceLogORCLegDataEventImpl.class.getName())) {
|
||||
updateScratchBoatFromLogs();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RaceLogORCScratchBoatEvent event) {
|
||||
updateScratchBoatFromLogs();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user