mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-30 15:57:11 +00:00
added implementation and test case for TrackeRace.getCenterOfCourse
This commit is contained in:
1 parent
6edd663fdf
commit
154b0de382
8 files changed
+136
-3
No files matched your search
Executable
+77
@@ -0,0 +1,77 @@
|
||||
package com.sap.sailing.domain.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.base.impl.MarkImpl;
|
||||
import com.sap.sailing.domain.base.impl.WaypointImpl;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.DegreePosition;
|
||||
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.tracking.DynamicGPSFixTrack;
|
||||
import com.sap.sailing.domain.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sailing.domain.tracking.impl.DynamicGPSFixTrackImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.DynamicTrackedRaceImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.GPSFixImpl;
|
||||
|
||||
/**
|
||||
* Tests the calculation of the center of the course, particularly the
|
||||
* {@link TrackedRace#getCenterOfCourse(com.sap.sailing.domain.common.TimePoint)} method.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public class TrackedRaceCenterTest {
|
||||
private Mark mark1;
|
||||
private Mark mark2;
|
||||
private Waypoint wp1;
|
||||
private Waypoint wp2;
|
||||
private DynamicGPSFixTrack<Mark, GPSFix> mark1Track;
|
||||
private DynamicGPSFixTrack<Mark, GPSFix> mark2Track;
|
||||
private DynamicTrackedRaceImpl trackedRace;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
trackedRace = mock(DynamicTrackedRaceImpl.class);
|
||||
when(trackedRace.getCenterOfCourse(Matchers.any(TimePoint.class))).thenCallRealMethod();
|
||||
when(trackedRace.getApproximatePosition(Matchers.any(Waypoint.class), Matchers.any(TimePoint.class))).thenCallRealMethod();
|
||||
RaceDefinition race = mock(RaceDefinition.class);
|
||||
when(trackedRace.getRace()).thenReturn(race);
|
||||
Course course = mock(Course.class);
|
||||
when(race.getCourse()).thenReturn(course);
|
||||
mark1 = new MarkImpl("1");
|
||||
mark2 = new MarkImpl("2");
|
||||
wp1 = new WaypointImpl(mark1);
|
||||
wp2 = new WaypointImpl(mark2);
|
||||
when(course.getWaypoints()).thenReturn(Arrays.asList(new Waypoint[] { wp1, wp2 }));
|
||||
mark1Track = new DynamicGPSFixTrackImpl<Mark>(mark1, /* millisecondsOverWhichToAverage */ 10);
|
||||
mark2Track = new DynamicGPSFixTrackImpl<Mark>(mark1, /* millisecondsOverWhichToAverage */ 10);
|
||||
when(trackedRace.getOrCreateTrack(mark1)).thenReturn(mark1Track);
|
||||
when(trackedRace.getOrCreateTrack(mark2)).thenReturn(mark2Track);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleAverage() {
|
||||
MillisecondsTimePoint now = MillisecondsTimePoint.now();
|
||||
Position mark1Pos = new DegreePosition(10, 10);
|
||||
mark1Track.add(new GPSFixImpl(mark1Pos, now));
|
||||
Position mark2Pos = new DegreePosition(20, 10);
|
||||
mark2Track.add(new GPSFixImpl(mark2Pos, now));
|
||||
Position center = trackedRace.getCenterOfCourse(now);
|
||||
assertEquals(15, center.getLatDeg(), 0.00001);
|
||||
assertEquals(10, center.getLngDeg(), 0.00001);
|
||||
}
|
||||
}
|
||||
+6
@@ -1006,4 +1006,10 @@ public class MockedTrackedRace implements DynamicTrackedRace {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getCenterOfCourse(TimePoint at) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -653,4 +653,10 @@ public class MockedTrackedRaceWithStartTimeAndRanks implements TrackedRace {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getCenterOfCourse(TimePoint at) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -703,4 +703,9 @@ public interface TrackedRace extends Serializable {
|
||||
|
||||
GPSFixStore getGPSFixStore();
|
||||
|
||||
/**
|
||||
* Computes the center point of the course's marks at the given time point.
|
||||
*/
|
||||
Position getCenterOfCourse(TimePoint at);
|
||||
|
||||
}
|
||||
+25
@@ -3086,4 +3086,29 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
public GPSFixStore getGPSFixStore() {
|
||||
return gpsFixStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getCenterOfCourse(TimePoint at) {
|
||||
int count = 0;
|
||||
ScalablePosition sum = null;
|
||||
for (Waypoint waypoint : getRace().getCourse().getWaypoints()) {
|
||||
final Position waypointPosition = getApproximatePosition(waypoint, at);
|
||||
if (waypointPosition != null) {
|
||||
ScalablePosition p = new ScalablePosition(waypointPosition);
|
||||
if (sum == null) {
|
||||
sum = p;
|
||||
} else {
|
||||
sum = sum.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
final Position result;
|
||||
if (sum == null) {
|
||||
result = null;
|
||||
} else {
|
||||
result = sum.divide(count);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -1007,4 +1007,10 @@ public class MockedTrackedRace implements DynamicTrackedRace {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getCenterOfCourse(TimePoint at) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -1302,7 +1302,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
* {@link WindInfoForRaceDTO#getCombinedWindOnLegMiddle(int)}.
|
||||
*/
|
||||
private WindInfoForRaceDTO getAveragedWindInfo(TimePoint from, long millisecondsStepWidth, int numberOfFixes,
|
||||
Collection<String> windSourceTypeNames, TrackedRace trackedRace, boolean onlyUpToNewestEvent,
|
||||
Collection<String> windSourceTypeNames, final TrackedRace trackedRace, boolean onlyUpToNewestEvent,
|
||||
boolean includeCombinedWindForAllLegMiddles) {
|
||||
WindInfoForRaceDTO result = null;
|
||||
if (trackedRace != null) {
|
||||
@@ -1320,12 +1320,14 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
Util.addAll(trackedRace.getWindSources(), windSourcesToDeliver);
|
||||
final WindSource combinedWindSource = new WindSourceImpl(WindSourceType.COMBINED);
|
||||
windSourcesToDeliver.add(combinedWindSource);
|
||||
for (WindSource windSource : windSourcesToDeliver) {
|
||||
for (final WindSource windSource : windSourcesToDeliver) {
|
||||
// TODO consider parallelizing
|
||||
if (windSourceTypeNames == null || windSourceTypeNames.contains(windSource.getType().name())) {
|
||||
WindTrackInfoDTO windTrackInfoDTO = createWindTrackInfoDTO(from, millisecondsStepWidth,
|
||||
numberOfFixes, trackedRace, onlyUpToNewestEvent, newestEvent, windSource,
|
||||
new PositionAtTimeProvider() { @Override public Position getPosition(TimePoint at) { return null; }});
|
||||
new PositionAtTimeProvider() { @Override public Position getPosition(TimePoint at) {
|
||||
return windSource == combinedWindSource ? trackedRace.getCenterOfCourse(at) : null;
|
||||
}});
|
||||
windTrackInfoDTOs.put(windSource, windTrackInfoDTO);
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -605,4 +605,10 @@ public class DummyTrackedRace extends TrackedRaceWithWindEssentials {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getCenterOfCourse(TimePoint at) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user