From e70880d9ad2807f0c54a7af309f611185d677a61 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Sun, 21 Apr 2019 20:55:02 +0200 Subject: [PATCH 1/4] bug 5004: rank by windward distance from leg start instead of windward distance to go; this intends to create more stability for situations where a line at the end of a leg has a significant bias which so far has led to the windward distance to go getting minimized while the competitor's projection is between the two marks of the biased line --- .../impl/AbstractRaceRankComparator.java | 3 ++ .../tracking/impl/RaceRankComparator.java | 48 +++++++++++++++++-- .../impl/TrackedLegOfCompetitorImpl.java | 12 ++--- .../mongodb/test/MongoClientURITest.java | 2 +- .../sap/sse/mongodb/MongoDBConfiguration.java | 32 +++++++------ 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/AbstractRaceRankComparator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/AbstractRaceRankComparator.java index ed83da1f4b6..50762cf20e8 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/AbstractRaceRankComparator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/AbstractRaceRankComparator.java @@ -166,5 +166,8 @@ public abstract class AbstractRaceRankComparator> implem return result; } + /** + * A distance to use for competitor comparison. Less means better rank. Negative distances are allowed. + */ protected abstract C getComparisonValueForSameLeg(Competitor competitor); } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java index 219b3b0bf2d..c171f7d2a31 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java @@ -8,12 +8,18 @@ import java.util.SortedSet; import com.sap.sailing.domain.base.Competitor; import com.sap.sailing.domain.base.Course; +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.tracking.MarkPassing; +import com.sap.sailing.domain.tracking.TrackedLeg; import com.sap.sailing.domain.tracking.TrackedLegOfCompetitor; import com.sap.sailing.domain.tracking.TrackedRace; import com.sap.sailing.domain.tracking.WindLegTypeAndLegBearingCache; import com.sap.sailing.domain.tracking.WindPositionMode; import com.sap.sse.common.Distance; import com.sap.sse.common.TimePoint; +import com.sap.sse.common.Util; /** * Compares two competitors by their ranking in the overall race for a given time point. Competitors who haven't started @@ -38,25 +44,57 @@ import com.sap.sse.common.TimePoint; * */ public class RaceRankComparator extends AbstractRaceRankComparator { - private final Map windwardDistanceToGoInLegCache; + private final Map negatedWindwardDistanceFromStartOfLeg; private final WindLegTypeAndLegBearingCache cache; + /** + * The position of the leg's {@link Leg#getFrom() start} at the time the first competitor + * passed it. This way we can cope with the waypoint's mark(s) being moved after all + * competitors rounded it the last time, and we get a constant reference point regardless + * of which competitor we're computing the distance from this point for.

+ * + * Starts out as {@code null} and will be calculated until not {@code null} anymore. + */ + private Position startOfLeg; + public RaceRankComparator(TrackedRace trackedRace, TimePoint timePoint, WindLegTypeAndLegBearingCache cache) { super(trackedRace, timePoint, /* lessIsBetter */ true); this.cache = cache; - this.windwardDistanceToGoInLegCache = new HashMap(); + this.negatedWindwardDistanceFromStartOfLeg = new HashMap(); } @Override protected Distance getComparisonValueForSameLeg(Competitor competitor) { - Distance result = windwardDistanceToGoInLegCache.get(competitor); + Distance result = negatedWindwardDistanceFromStartOfLeg.get(competitor); if (result == null) { final TrackedLegOfCompetitor trackedLegOfCompetitor = getTrackedRace().getTrackedLeg(competitor, getTimePoint()); if (trackedLegOfCompetitor != null) { - result = trackedLegOfCompetitor.getWindwardDistanceToGo(getTimePoint(), WindPositionMode.LEG_MIDDLE, cache); - windwardDistanceToGoInLegCache.put(competitor, result); + final Position startOfLegPosition = getStartOfLeg(trackedLegOfCompetitor.getTrackedLeg()); + if (startOfLegPosition != null) { + Position estimatedCompetitorPosition = getTrackedRace().getTrack(competitor).getEstimatedPosition(getTimePoint(), false); + if (estimatedCompetitorPosition != null) { + // use the negative windward distance from the leg start + result = trackedLegOfCompetitor.getTrackedLeg().getAbsoluteWindwardDistance( + startOfLegPosition, estimatedCompetitorPosition, + getTimePoint(), WindPositionMode.LEG_MIDDLE, cache).scale(-1); + negatedWindwardDistanceFromStartOfLeg.put(competitor, result); + } + } } } return result; } + + private Position getStartOfLeg(TrackedLeg trackedLeg) { + if (startOfLeg == null) { + final Waypoint legStartWaypoint = trackedLeg.getLeg().getFrom(); + final Iterable markPassingsForLegStart = getTrackedRace().getMarkPassingsInOrder(legStartWaypoint); + if (!Util.isEmpty(markPassingsForLegStart)) { + final MarkPassing firstMarkPassingForLegStart = markPassingsForLegStart.iterator().next(); + final TimePoint timePointOfFirstMarkPassingForLegStart = firstMarkPassingForLegStart.getTimePoint(); + startOfLeg = getTrackedRace().getApproximatePosition(legStartWaypoint, timePointOfFirstMarkPassingForLegStart); + } + } + return startOfLeg; + } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java index ad72ac0f35a..5e73bb20ea2 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java @@ -241,12 +241,12 @@ public class TrackedLegOfCompetitorImpl implements TrackedLegOfCompetitor { } /** - * If the current {@link #getLeg() leg} is +/- {@link LegType#UPWIND_DOWNWIND_TOLERANCE_IN_DEG} degrees collinear with the - * wind's bearing, the competitor's position is projected onto the line crossing mark in the wind's - * bearing, and the distance from the projection to the mark is returned. Otherwise, it is assumed that - * the leg is neither an upwind nor a downwind leg, and hence the true distance to mark is returned. A - * cache for wind and leg type / bearing can be passed to avoid their redundant calculation during a single - * round-trip. + * If the current {@link #getLeg() leg} is +/- {@link LegType#UPWIND_DOWNWIND_TOLERANCE_IN_DEG} degrees collinear + * with the wind's bearing, the competitor's position is projected onto the line crossing mark in the + * wind's bearing, and the distance from the projection to the mark is returned. Otherwise, it is + * assumed that the leg is neither an upwind nor a downwind leg, and hence the along-track distance to + * mark is returned. A cache for wind and leg type / bearing can be passed to avoid their redundant + * calculation during a single round-trip. *

* * If no wind information is available, again the true geometrical distance to mark is returned. diff --git a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/MongoClientURITest.java b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/MongoClientURITest.java index a29347972e2..39385c06732 100755 --- a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/MongoClientURITest.java +++ b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/MongoClientURITest.java @@ -19,7 +19,7 @@ public class MongoClientURITest { } @Test - public void testSpecifigConnectionOptions() { + public void testSpecificConnectionOptions() { MongoDBConfiguration config = new MongoDBConfiguration("mongodb://humba:12345/mydb?replicaset=rs0&readpreference=primary"); assertEquals("humba", config.getHostname()); assertEquals(12345, config.getPort()); diff --git a/java/com.sap.sse.mongodb/src/com/sap/sse/mongodb/MongoDBConfiguration.java b/java/com.sap.sse.mongodb/src/com/sap/sse/mongodb/MongoDBConfiguration.java index 6c385c9e281..3d8c8cda1e2 100644 --- a/java/com.sap.sse.mongodb/src/com/sap/sse/mongodb/MongoDBConfiguration.java +++ b/java/com.sap.sse.mongodb/src/com/sap/sse/mongodb/MongoDBConfiguration.java @@ -60,23 +60,27 @@ public class MongoDBConfiguration { } public static MongoDBConfiguration getDefaultTestConfiguration() { - String defaultHostName = "127.0.0.1"; - if (System.getProperty(MONGO_HOSTNAME) != null) { - defaultHostName = System.getProperty(MONGO_HOSTNAME); - } else { - if (System.getenv("MONGODB_HOST") != null) { - defaultHostName = System.getenv("MONGODB_HOST"); - } - } - String defaultDatabaseName = System.getProperty(MONGO_DB_NAME, DEFAULT_TEST_DB_NAME); final MongoDBConfiguration result; - if (System.getProperty(MONGO_PORT) != null) { - result = new MongoDBConfiguration(defaultHostName, Integer.valueOf(System.getProperty(MONGO_PORT).trim()), defaultDatabaseName); + if (System.getProperty(MONGO_URI) != null) { + result = new MongoDBConfiguration(new MongoClientURI(System.getProperty(MONGO_URI))); } else { - if (System.getenv("MONGODB_PORT") != null) { - result = new MongoDBConfiguration(defaultHostName, Integer.valueOf(System.getenv("MONGODB_PORT").trim()), defaultDatabaseName); + String defaultHostName = "127.0.0.1"; + if (System.getProperty(MONGO_HOSTNAME) != null) { + defaultHostName = System.getProperty(MONGO_HOSTNAME); } else { - result = new MongoDBConfiguration(defaultHostName, defaultDatabaseName); + if (System.getenv("MONGODB_HOST") != null) { + defaultHostName = System.getenv("MONGODB_HOST"); + } + } + String defaultDatabaseName = System.getProperty(MONGO_DB_NAME, DEFAULT_TEST_DB_NAME); + if (System.getProperty(MONGO_PORT) != null) { + result = new MongoDBConfiguration(defaultHostName, Integer.valueOf(System.getProperty(MONGO_PORT).trim()), defaultDatabaseName); + } else { + if (System.getenv("MONGODB_PORT") != null) { + result = new MongoDBConfiguration(defaultHostName, Integer.valueOf(System.getenv("MONGODB_PORT").trim()), defaultDatabaseName); + } else { + result = new MongoDBConfiguration(defaultHostName, defaultDatabaseName); + } } } return result; From c83047c2a795e849d8daacc707c8fbd8856ccf85 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Sun, 21 Apr 2019 22:30:16 +0200 Subject: [PATCH 2/4] bug5004: changed TrackedLegOfCompetitor.getWindwardDistanceToGo so it can turn negative; with this, more consistency is achieved between ranking and windward distance to go column in the leaderboard --- .../sailing/domain/tracking/TrackedLeg.java | 7 +++ .../tracking/TrackedLegOfCompetitor.java | 4 +- .../tracking/impl/RaceRankComparator.java | 48 ++----------------- .../domain/tracking/impl/TrackedLegImpl.java | 3 +- .../impl/TrackedLegOfCompetitorImpl.java | 41 ++++++++-------- 5 files changed, 36 insertions(+), 67 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLeg.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLeg.java index abd27937eb6..380767c32f4 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLeg.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLeg.java @@ -117,6 +117,13 @@ public interface TrackedLeg extends Serializable { */ Distance getAbsoluteWindwardDistance(Position pos1, Position pos2, TimePoint at, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache); + /** + * Same as {@link #getWindwardDistance(Position, Position, TimePoint, WindPositionMode)}, only that a cache + * for leg types, wind data and leg bearings can be passed to save the effort of redundant calculations of these + * values. + */ + Distance getWindwardDistance(final Position pos1, final Position pos2, TimePoint at, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache); + /** * Same as {@link #getAbsoluteWindwardDistance(Position, Position, TimePoint, WindPositionMode)}, but this method considers the leg's * direction and will return a negative distance if pos1 is already "ahead" of pos2 in the diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLegOfCompetitor.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLegOfCompetitor.java index 72eb01858a6..4fba5147b45 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLegOfCompetitor.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedLegOfCompetitor.java @@ -62,7 +62,9 @@ public interface TrackedLegOfCompetitor extends Serializable { * direction. If the competitor already finished this leg, a zero, non-null distance will result. * If the competitor hasn't started the leg yet, the full leg distance is returned. For reaching legs or when * no wind information is available, the projection onto the leg's direction will be used instead of wind - * projection. + * projection. When for the {@code timePoint} given the competitor hasn't finished the leg yet but has + * already passed the approximate windward / along course position of the leg's end, a negative distance + * will result. */ Distance getWindwardDistanceToGo(TimePoint timePoint, WindPositionMode windPositionMode); diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java index c171f7d2a31..219b3b0bf2d 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java @@ -8,18 +8,12 @@ import java.util.SortedSet; import com.sap.sailing.domain.base.Competitor; import com.sap.sailing.domain.base.Course; -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.tracking.MarkPassing; -import com.sap.sailing.domain.tracking.TrackedLeg; import com.sap.sailing.domain.tracking.TrackedLegOfCompetitor; import com.sap.sailing.domain.tracking.TrackedRace; import com.sap.sailing.domain.tracking.WindLegTypeAndLegBearingCache; import com.sap.sailing.domain.tracking.WindPositionMode; import com.sap.sse.common.Distance; import com.sap.sse.common.TimePoint; -import com.sap.sse.common.Util; /** * Compares two competitors by their ranking in the overall race for a given time point. Competitors who haven't started @@ -44,57 +38,25 @@ import com.sap.sse.common.Util; * */ public class RaceRankComparator extends AbstractRaceRankComparator { - private final Map negatedWindwardDistanceFromStartOfLeg; + private final Map windwardDistanceToGoInLegCache; private final WindLegTypeAndLegBearingCache cache; - /** - * The position of the leg's {@link Leg#getFrom() start} at the time the first competitor - * passed it. This way we can cope with the waypoint's mark(s) being moved after all - * competitors rounded it the last time, and we get a constant reference point regardless - * of which competitor we're computing the distance from this point for.

- * - * Starts out as {@code null} and will be calculated until not {@code null} anymore. - */ - private Position startOfLeg; - public RaceRankComparator(TrackedRace trackedRace, TimePoint timePoint, WindLegTypeAndLegBearingCache cache) { super(trackedRace, timePoint, /* lessIsBetter */ true); this.cache = cache; - this.negatedWindwardDistanceFromStartOfLeg = new HashMap(); + this.windwardDistanceToGoInLegCache = new HashMap(); } @Override protected Distance getComparisonValueForSameLeg(Competitor competitor) { - Distance result = negatedWindwardDistanceFromStartOfLeg.get(competitor); + Distance result = windwardDistanceToGoInLegCache.get(competitor); if (result == null) { final TrackedLegOfCompetitor trackedLegOfCompetitor = getTrackedRace().getTrackedLeg(competitor, getTimePoint()); if (trackedLegOfCompetitor != null) { - final Position startOfLegPosition = getStartOfLeg(trackedLegOfCompetitor.getTrackedLeg()); - if (startOfLegPosition != null) { - Position estimatedCompetitorPosition = getTrackedRace().getTrack(competitor).getEstimatedPosition(getTimePoint(), false); - if (estimatedCompetitorPosition != null) { - // use the negative windward distance from the leg start - result = trackedLegOfCompetitor.getTrackedLeg().getAbsoluteWindwardDistance( - startOfLegPosition, estimatedCompetitorPosition, - getTimePoint(), WindPositionMode.LEG_MIDDLE, cache).scale(-1); - negatedWindwardDistanceFromStartOfLeg.put(competitor, result); - } - } + result = trackedLegOfCompetitor.getWindwardDistanceToGo(getTimePoint(), WindPositionMode.LEG_MIDDLE, cache); + windwardDistanceToGoInLegCache.put(competitor, result); } } return result; } - - private Position getStartOfLeg(TrackedLeg trackedLeg) { - if (startOfLeg == null) { - final Waypoint legStartWaypoint = trackedLeg.getLeg().getFrom(); - final Iterable markPassingsForLegStart = getTrackedRace().getMarkPassingsInOrder(legStartWaypoint); - if (!Util.isEmpty(markPassingsForLegStart)) { - final MarkPassing firstMarkPassingForLegStart = markPassingsForLegStart.iterator().next(); - final TimePoint timePointOfFirstMarkPassingForLegStart = firstMarkPassingForLegStart.getTimePoint(); - startOfLeg = getTrackedRace().getApproximatePosition(legStartWaypoint, timePointOfFirstMarkPassingForLegStart); - } - } - return startOfLeg; - } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegImpl.java index ef84b1e6943..abf9c52d2ec 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegImpl.java @@ -481,7 +481,8 @@ public class TrackedLegImpl implements TrackedLeg { return getAbsoluteWindwardDistance(fromPos, toPos, middle, WindPositionMode.LEG_MIDDLE, cache); } - Distance getWindwardDistance(final Position pos1, final Position pos2, TimePoint at, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache) { + @Override + public Distance getWindwardDistance(final Position pos1, final Position pos2, TimePoint at, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache) { Distance result; if (pos1 == null || pos2 == null) { result = null; diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java index 5e73bb20ea2..0acfc6d5cb8 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java @@ -9,7 +9,6 @@ import java.util.function.BiFunction; import com.sap.sailing.domain.base.Boat; import com.sap.sailing.domain.base.Competitor; import com.sap.sailing.domain.base.Leg; -import com.sap.sailing.domain.base.Mark; import com.sap.sailing.domain.base.Waypoint; import com.sap.sailing.domain.common.LegType; import com.sap.sailing.domain.common.ManeuverType; @@ -221,18 +220,13 @@ public class TrackedLegOfCompetitorImpl implements TrackedLegOfCompetitor { @Override public Distance getWindwardDistanceToGo(TimePoint timePoint, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache) { + final Distance result; if (hasFinishedLeg(timePoint)) { - return Distance.NULL; + result = Distance.NULL; } else { - Distance result = null; - for (Mark mark : getLeg().getTo().getMarks()) { - Distance d = getWindwardDistanceTo(mark, timePoint, windPositionMode, cache); - if (result == null || d != null && d.compareTo(result) < 0) { - result = d; - } - } - return result; + result = getWindwardDistanceTo(getLeg().getTo(), timePoint, windPositionMode, cache); } + return result; } @Override @@ -242,21 +236,24 @@ public class TrackedLegOfCompetitorImpl implements TrackedLegOfCompetitor { /** * If the current {@link #getLeg() leg} is +/- {@link LegType#UPWIND_DOWNWIND_TOLERANCE_IN_DEG} degrees collinear - * with the wind's bearing, the competitor's position is projected onto the line crossing mark in the - * wind's bearing, and the distance from the projection to the mark is returned. Otherwise, it is - * assumed that the leg is neither an upwind nor a downwind leg, and hence the along-track distance to - * mark is returned. A cache for wind and leg type / bearing can be passed to avoid their redundant - * calculation during a single round-trip. + * with the wind's bearing, the competitor's position is projected onto the line crossing waypoint (its + * approximate position) in the wind's bearing, and the distance from the projection to the waypoint is + * returned. Otherwise, it is assumed that the leg is neither an upwind nor a downwind leg, and hence the + * along-track distance to waypoint is returned. A cache for wind and leg type / bearing can be passed to + * avoid their redundant calculation during a single round-trip. *

* - * If no wind information is available, again the true geometrical distance to mark is returned. + * If no wind information is available, again the along-track distance to waypoint is returned. *

* - * If the competitor's position or the mark's position cannot be determined, null is returned. + * If the competitor's position or the waypoint's position cannot be determined, null is returned. * null is also returned if the leg's bearing cannot be determined because for at least one of its two - * waypoints no mark has a known position. + * waypoints no mark has a known position.

+ * + * The distance returned may turn negative if the competitor sailed past the approximate windward position of the + * leg's {@link Leg#getTo() end waypoint} but hasn't finished the leg yet. */ - private Distance getWindwardDistanceTo(Mark mark, TimePoint at, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache) { + private Distance getWindwardDistanceTo(Waypoint waypoint, TimePoint at, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache) { Position estimatedPosition = getTrackedRace().getTrack(getCompetitor()).getEstimatedPosition(at, false); if (!hasStartedLeg(at) || estimatedPosition == null) { // covers the case with no fixes for this leg yet, also if the mark passing has already been received @@ -266,11 +263,11 @@ public class TrackedLegOfCompetitorImpl implements TrackedLegOfCompetitor { if (estimatedPosition == null) { // may happen if mark positions haven't been received yet return null; } - final Position estimatedMarkPosition = getTrackedRace().getOrCreateTrack(mark).getEstimatedPosition(at, false); - if (estimatedMarkPosition == null) { + final Position approximateWaypointPosition = getTrackedRace().getApproximatePosition(waypoint, at); + if (approximateWaypointPosition == null) { return null; } - return getTrackedLeg().getAbsoluteWindwardDistance(estimatedPosition, estimatedMarkPosition, at, windPositionMode, cache); + return getTrackedLeg().getWindwardDistance(estimatedPosition, approximateWaypointPosition, at, windPositionMode, cache); } /** From e35b69d4c023aa5ade7366d8dd955abadcaa53e6 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Sun, 21 Apr 2019 23:14:10 +0200 Subject: [PATCH 3/4] failing test case for bug5004 --- .../domain/test/OnlineTracTracBasedTest.java | 7 +- .../SteadyRankingForBiasedFinishLineTest.java | 79 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java index f58f35d64a6..c61d4b0b149 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java @@ -244,11 +244,16 @@ public abstract class OnlineTracTracBasedTest extends AbstractTracTracLiveTest i protected void setUpWithoutLaunchingController(String regattaName, String raceId, final URI liveUri, final URI storedUri) throws MalformedURLException, FileNotFoundException, URISyntaxException, SubscriberInitializationException, CreateModelException { - final URL paramUrl = new URL("http://" + TracTracConnectionConstants.HOST_NAME + "/events/"+regattaName+"/"+raceId+".txt"); + final URL paramUrl = getParamUrl(regattaName, raceId); setUpWithoutLaunchingController(paramUrl, liveUri, storedUri); } + protected URL getParamUrl(String regattaName, String raceId) throws MalformedURLException { + return new URL("http://" + TracTracConnectionConstants.HOST_NAME + "/events/"+regattaName+"/"+raceId+".txt"); + } + + protected void setUpWithoutLaunchingController(final URL paramUrl, final URI liveUri, final URI storedUri) throws FileNotFoundException, MalformedURLException, URISyntaxException, SubscriberInitializationException, CreateModelException { super.setUp(paramUrl, liveUri, storedUri); diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java new file mode 100644 index 00000000000..275c3b79425 --- /dev/null +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java @@ -0,0 +1,79 @@ +package com.sap.sailing.domain.test; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.text.ParseException; + +import org.junit.Before; +import org.junit.Test; + +import com.sap.sailing.domain.base.Competitor; +import com.sap.sailing.domain.common.WindSourceType; +import com.sap.sailing.domain.common.impl.DegreePosition; +import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl; +import com.sap.sailing.domain.common.impl.WindImpl; +import com.sap.sailing.domain.common.impl.WindSourceImpl; +import com.sap.sailing.domain.tractracadapter.ReceiverType; +import com.sap.sse.common.impl.DegreeBearingImpl; +import com.sap.sse.common.impl.MillisecondsTimePoint; +import com.tractrac.model.lib.api.event.CreateModelException; +import com.tractrac.subscription.lib.api.SubscriberInitializationException; + +/** + * See bug 5004 + * + * @author Axel Uhl (d043530) + * + */ +public class SteadyRankingForBiasedFinishLineTest extends OnlineTracTracBasedTest { + final static MillisecondsTimePoint TIME_14_30_00 = new MillisecondsTimePoint(1555849800000l); + final static MillisecondsTimePoint TIME_14_30_12 = new MillisecondsTimePoint(1555849812000l); + + public SteadyRankingForBiasedFinishLineTest() throws MalformedURLException, URISyntaxException { + } + + @Override + protected String getExpectedEventName() { + return "Sailing World Cup Genoa 2019"; + } + + @Override + protected URL getParamUrl(String regattaName, String raceId) throws MalformedURLException { + // TODO adjust once TracTrac has migrated this to the regular back-end + return new URL("http://aws.tractrac.com/events/"+regattaName+"/clientparams.php?event="+regattaName+"&race="+raceId); + } + + @Before + public void setUp() throws MalformedURLException, IOException, InterruptedException, URISyntaxException, ParseException, SubscriberInitializationException, CreateModelException { + super.setUp(); + super.setUp("event_20190412_SailingWor", + /* raceId */ "0fb18f50-45d7-0137-24dd-021d89ada30e", + /* liveUri */ null, /* storedUri */ null, + new ReceiverType[] { ReceiverType.MARKPASSINGS, ReceiverType.RACECOURSE, ReceiverType.RAWPOSITIONS, ReceiverType.MARKPOSITIONS, ReceiverType.RACECOURSE, + ReceiverType.RACESTARTFINISH }); + getTrackedRace().recordWind(new WindImpl(/* position */ new DegreePosition(44.37670797575265, 8.925960855558515), TIME_14_30_00, + new KnotSpeedWithBearingImpl(7.5, new DegreeBearingImpl(246).reverse())), new WindSourceImpl(WindSourceType.WEB)); + } + + @Test + public void testVadnaiLead() { + Competitor vadnai = getCompetitorByName("Benjamin Vadnai"); + Competitor lewis = getCompetitorByName("Andrew Lewis"); + Competitor lynch = getCompetitorByName("Finn Lynch"); + Competitor blanco = getCompetitorByName("JoaquĆ­n Blanco"); + assertEquals(1, getTrackedRace().getRank(vadnai, TIME_14_30_00)); + assertEquals(2, getTrackedRace().getRank(lewis, TIME_14_30_00)); + assertEquals(3, getTrackedRace().getRank(lynch, TIME_14_30_00)); + assertEquals(4, getTrackedRace().getRank(blanco, TIME_14_30_00)); + assertEquals(1, getTrackedRace().getRank(vadnai, TIME_14_30_12)); + assertEquals(2, getTrackedRace().getRank(lewis, TIME_14_30_12)); + assertEquals(3, getTrackedRace().getRank(lynch, TIME_14_30_12)); + assertEquals(4, getTrackedRace().getRank(blanco, TIME_14_30_12)); + } + +} From 506acf710973a0b03ae861231cbcf34adadbf509 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Sun, 21 Apr 2019 23:16:17 +0200 Subject: [PATCH 4/4] consolidated imports, improved TODO --- .../domain/test/SteadyRankingForBiasedFinishLineTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java index 275c3b79425..0ddc579b7b5 100644 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import java.net.MalformedURLException; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.text.ParseException; @@ -44,7 +43,7 @@ public class SteadyRankingForBiasedFinishLineTest extends OnlineTracTracBasedTes @Override protected URL getParamUrl(String regattaName, String raceId) throws MalformedURLException { - // TODO adjust once TracTrac has migrated this to the regular back-end + // TODO adjust once TracTrac has migrated this to the regular back-end; download .mtb file to local resource return new URL("http://aws.tractrac.com/events/"+regattaName+"/clientparams.php?event="+regattaName+"&race="+raceId); }