mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-14 00:00:59 +00:00
compute distance to start line in TrackedRace
This commit is contained in:
1 parent
9cfe44389e
commit
b70db297b7
7 files changed
+82
-4
No files matched your search
+16
@@ -3,6 +3,7 @@ package com.sap.sailing.domain.swisstimingreplayadapter.test;
|
|||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -15,6 +16,7 @@ import org.junit.Ignore;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.sap.sailing.domain.base.Competitor;
|
import com.sap.sailing.domain.base.Competitor;
|
||||||
|
import com.sap.sailing.domain.common.Distance;
|
||||||
import com.sap.sailing.domain.common.impl.Util;
|
import com.sap.sailing.domain.common.impl.Util;
|
||||||
import com.sap.sailing.domain.swisstimingadapter.DomainFactory;
|
import com.sap.sailing.domain.swisstimingadapter.DomainFactory;
|
||||||
import com.sap.sailing.domain.swisstimingreplayadapter.SwissTimingReplayRace;
|
import com.sap.sailing.domain.swisstimingreplayadapter.SwissTimingReplayRace;
|
||||||
@@ -185,6 +187,20 @@ public class SwissTimingReplayAdapterServiceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartPerformanceDetection() throws Exception {
|
||||||
|
SwissTimingReplayToDomainAdapter replayListener = new SwissTimingReplayToDomainAdapter(null, DomainFactory.INSTANCE,
|
||||||
|
new DummyTrackedRegattaRegistry());
|
||||||
|
new SwissTimingReplayParserImpl().readData(getClass().getResourceAsStream("/SAW005906.20120805.replay"), replayListener);
|
||||||
|
Iterable<? extends TrackedRace> trackedRaces = replayListener.getTrackedRaces();
|
||||||
|
TrackedRace trackedRace = trackedRaces.iterator().next();
|
||||||
|
for (Competitor competitor : trackedRace.getRace().getCompetitors()) {
|
||||||
|
Distance distanceToLineAtStart = trackedRace.getDistanceToStartLine(competitor, trackedRace.getStartOfRace());
|
||||||
|
assertTrue(distanceToLineAtStart.getMeters() > 0);
|
||||||
|
assertTrue(distanceToLineAtStart.getMeters() < 8.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void printRaceData_SAW005906_20120805() throws Exception {
|
public void printRaceData_SAW005906_20120805() throws Exception {
|
||||||
|
|||||||
+2
-1
@@ -26,7 +26,8 @@ public interface SwissTimingReplayService {
|
|||||||
/**
|
/**
|
||||||
* @param link
|
* @param link
|
||||||
* the URL without the implicit "http://" prefix, as obtained, e.g., from
|
* the URL without the implicit "http://" prefix, as obtained, e.g., from
|
||||||
* {@link SwissTimingReplayRace#getLink()}.
|
* {@link SwissTimingReplayRace#getLink()}, or with an explicit protocol specification
|
||||||
|
* as in "file:///..."
|
||||||
* @param replayListener
|
* @param replayListener
|
||||||
* the listener to receive all persing events
|
* the listener to receive all persing events
|
||||||
*/
|
*/
|
||||||
|
|||||||
+6
-2
@@ -121,9 +121,13 @@ public class SwissTimingReplayServiceImpl implements SwissTimingReplayService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadRaceData(String link, SwissTimingReplayListener replayListener) {
|
public void loadRaceData(String link, SwissTimingReplayListener replayListener) {
|
||||||
URL raceDataUrl;
|
final URL raceDataUrl;
|
||||||
try {
|
try {
|
||||||
raceDataUrl = new URL("http://" + link);
|
if (link.contains("://")) {
|
||||||
|
raceDataUrl = new URL(link);
|
||||||
|
} else {
|
||||||
|
raceDataUrl = new URL("http://" + link);
|
||||||
|
}
|
||||||
InputStream urlInputStream = (InputStream) raceDataUrl.getContent();
|
InputStream urlInputStream = (InputStream) raceDataUrl.getContent();
|
||||||
ByteArrayOutputStreamWithVisibleBuffer bos = new ByteArrayOutputStreamWithVisibleBuffer();
|
ByteArrayOutputStreamWithVisibleBuffer bos = new ByteArrayOutputStreamWithVisibleBuffer();
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
|
|||||||
+6
@@ -764,4 +764,10 @@ public class MockedTrackedRace implements DynamicTrackedRace {
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Distance getDistanceToStartLine(Competitor competitor, TimePoint timePoint) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
@@ -507,4 +507,10 @@ public class MockedTrackedRaceWithStartTimeAndRanks implements TrackedRace {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Distance getDistanceToStartLine(Competitor competitor, TimePoint timePoint) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -499,4 +499,20 @@ public interface TrackedRace extends Serializable {
|
|||||||
*/
|
*/
|
||||||
void setCourseDesignChangedListener(CourseDesignChangedListener listener);
|
void setCourseDesignChangedListener(CourseDesignChangedListener listener);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells how far the given <code>competitor</code> was from the start line at the given <code>timePoint</code>.
|
||||||
|
* Using the {@link #getStartOfRace() race start time} for <code>timePoint</code>, this tells the competitor's
|
||||||
|
* distance to the line when the race was started.
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* The distance to the line is calculated by projecting the competitor's position onto the line orthogonally and
|
||||||
|
* computing the distance of the projected position and the competitor's position.
|
||||||
|
* <p
|
||||||
|
* .
|
||||||
|
*
|
||||||
|
* Should the course be empty, <code>null</code> is returned. If the course's first waypoint is not a line or gate,
|
||||||
|
* the geometric distance between the first waypoint and the competitor's position at <code>timePoint</code> is
|
||||||
|
* returned. If the competitor's position cannot be determined, <code>null</code> is returned.
|
||||||
|
*/
|
||||||
|
Distance getDistanceToStartLine(Competitor competitor, TimePoint timePoint);
|
||||||
}
|
}
|
||||||
+30
-1
@@ -2316,5 +2316,34 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
|||||||
public void setCourseDesignChangedListener(CourseDesignChangedListener listener) {
|
public void setCourseDesignChangedListener(CourseDesignChangedListener listener) {
|
||||||
this.courseDesignChangedListener = listener;
|
this.courseDesignChangedListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Distance getDistanceToStartLine(Competitor competitor, TimePoint timePoint) {
|
||||||
|
Waypoint startWaypoint = getRace().getCourse().getFirstWaypoint();
|
||||||
|
final Distance result;
|
||||||
|
if (startWaypoint == null) {
|
||||||
|
result = null;
|
||||||
|
} else {
|
||||||
|
Position competitorPosition = getTrack(competitor).getEstimatedPosition(timePoint, /* extrapolate */ false);
|
||||||
|
if (competitorPosition == null) {
|
||||||
|
result = null;
|
||||||
|
} else {
|
||||||
|
Iterable<Mark> marks = startWaypoint.getControlPoint().getMarks();
|
||||||
|
Iterator<Mark> marksIterator = marks.iterator();
|
||||||
|
Mark first = marksIterator.next();
|
||||||
|
Position firstPosition = getOrCreateTrack(first).getEstimatedPosition(timePoint, /* extrapolate */ false);
|
||||||
|
if (marksIterator.hasNext()) {
|
||||||
|
// it's a line / gate
|
||||||
|
Mark second = marksIterator.next();
|
||||||
|
Position secondPosition = getOrCreateTrack(second).getEstimatedPosition(timePoint, /* extrapolate */ false);
|
||||||
|
Position competitorProjectedOntoStartLine = competitorPosition.projectToLineThrough(firstPosition,
|
||||||
|
firstPosition.getBearingGreatCircle(secondPosition));
|
||||||
|
result = competitorPosition.getDistance(competitorProjectedOntoStartLine);
|
||||||
|
} else {
|
||||||
|
result = competitorPosition.getDistance(firstPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user