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 37767a8b02d..87970f5af57 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 @@ -246,11 +246,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..0ddc579b7b5 --- /dev/null +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SteadyRankingForBiasedFinishLineTest.java @@ -0,0 +1,78 @@ +package com.sap.sailing.domain.test; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.net.MalformedURLException; +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; download .mtb file to local resource + 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)); + } + +} 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/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/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 ad72ac0f35a..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 @@ -241,22 +235,25 @@ 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 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); } /** 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;