mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-27 06:17:27 +00:00
Changed Test to pass in fixes one by one.
This commit is contained in:
1 parent
2a37662ca5
commit
93b06f64f2
6 files changed
+85
-77
No files matched your search
+1
-3
@@ -146,12 +146,10 @@ public class AbstractPosition implements Position {
|
||||
.getDegrees());
|
||||
if (toLeft > 90) {
|
||||
distance = this.getDistance(left);
|
||||
} else {
|
||||
if (toRight > 90) {
|
||||
} else if (toRight > 90) {
|
||||
distance = this.getDistance(right);
|
||||
} else {
|
||||
distance = this.absoluteCrossTrackError(left, left.getBearingGreatCircle(right));
|
||||
}
|
||||
}
|
||||
// Right now this always returns a positiv value. It might be possible to change it so that the sign indicates
|
||||
// which side of the Line the Position is on.
|
||||
|
||||
+4
-4
@@ -116,12 +116,12 @@ public class CandidateChooser {
|
||||
}
|
||||
|
||||
private double numberOfCloseStarts(TimePoint t) {
|
||||
double numberOfSimilarStarts = -1;
|
||||
double numberOfCompetitors = -1;
|
||||
double numberOfSimilarStarts = 0;
|
||||
double numberOfCompetitors = 0;
|
||||
for (Competitor c : candidates.keySet()) {
|
||||
numberOfCompetitors++;
|
||||
for (Candidate ca : candidates.get(c)) {
|
||||
if (ca.getID() == 1 && Math.abs(ca.getTimePoint().asMillis() - t.asMillis()) < 60000) {
|
||||
if (ca.getID() == 1 && Math.abs(ca.getTimePoint().asMillis() - t.asMillis()) < 30000) {
|
||||
numberOfSimilarStarts++;
|
||||
break;
|
||||
}
|
||||
@@ -163,6 +163,6 @@ public class CandidateChooser {
|
||||
totalTime = totalTime * 3600000;
|
||||
double actualTime = c2.getTimePoint().asMillis() - c1.getTimePoint().asMillis();
|
||||
double timeDiff = Math.abs(totalTime - actualTime) / 1000;
|
||||
return 1 - (Math.log10(timeDiff+1) / 20);
|
||||
return 1-(Math.log10(timeDiff+1)/20);
|
||||
}
|
||||
}
|
||||
+13
-16
@@ -14,6 +14,7 @@ import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.tracking.DynamicGPSFixTrack;
|
||||
import com.sap.sailing.domain.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
import com.sap.sailing.domain.tracking.TrackedLeg;
|
||||
import com.sap.sailing.domain.tracking.impl.DynamicTrackImpl;
|
||||
|
||||
@@ -59,7 +60,7 @@ public class CandidateFinder {
|
||||
}
|
||||
}
|
||||
|
||||
public void newCompetitorFix(GPSFix fix, Competitor c) {
|
||||
public void newCompetitorFix(GPSFixMoving fix, Competitor c) {
|
||||
competitorTracks.get(c).addGPSFix(fix);
|
||||
distances.get(c).put(fix, new LinkedHashMap<Waypoint, Double>());
|
||||
for (Waypoint w : waypoints) {
|
||||
@@ -94,11 +95,10 @@ public class CandidateFinder {
|
||||
for (Competitor c : competitorTracks.keySet()) {
|
||||
ArrayList<GPSFix> fixesAffected = new ArrayList<>();
|
||||
TimePoint t = start;
|
||||
while (!(competitorTracks.get(c).getFirstFixAfter(t) == null)) {
|
||||
while (competitorTracks.get(c).getFirstFixAfter(t) != null) {
|
||||
GPSFix nextFix = competitorTracks.get(c).getFirstFixAfter(t);
|
||||
t = nextFix.getTimePoint();
|
||||
if (!(end == null) && !t.before(end)) {
|
||||
fixesAffected.add(competitorTracks.get(c).getFirstFixAtOrAfter(end));
|
||||
if (end!=null && !t.before(end)) {
|
||||
break;
|
||||
}
|
||||
fixesAffected.add(nextFix);
|
||||
@@ -106,18 +106,11 @@ public class CandidateFinder {
|
||||
for (GPSFix gps : fixesAffected) {
|
||||
distances.get(c).get(gps).put(w, calculateDistance(gps, w));
|
||||
}
|
||||
if (!(competitorTracks.get(c).getLastFixAtOrBefore(start) == null)) {
|
||||
fixesAffected.add(competitorTracks.get(c).getLastFixAtOrBefore(start));
|
||||
}
|
||||
if (!fixesAffected.contains(competitorTracks.get(c).getLastFixBefore(start))
|
||||
&& !(competitorTracks.get(c).getLastFixBefore(start) == null)) {
|
||||
fixesAffected.add(competitorTracks.get(c).getLastFixBefore(start));
|
||||
}
|
||||
if (fixesAffected.size() > 0) {
|
||||
System.out.println(fixesAffected.size());
|
||||
reEvaluateFixes(fixesAffected, c, w);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,6 +120,8 @@ public class CandidateFinder {
|
||||
for (GPSFix gps : fixes) {
|
||||
if (fixIsACandidate(gps, w, c) && !candidates.get(c).get(w).contains(gps)) {
|
||||
candidates.get(c).get(w).add(gps);
|
||||
if (waypoints.indexOf(w) == 0) {
|
||||
}
|
||||
Candidate newCandidate = new Candidate(w, gps.getTimePoint(), getCost(distances.get(c).get(gps).get(w),
|
||||
getLegLength(gps.getTimePoint(), w)), waypoints.indexOf(w) + 1);
|
||||
chooser.addCandidate(newCandidate, c);
|
||||
@@ -154,15 +149,15 @@ public class CandidateFinder {
|
||||
}
|
||||
|
||||
private double getCost(Double distance, Double legLength) {
|
||||
return 1/(10*Math.abs(distance/legLength)+1);
|
||||
return 1/(500*Math.abs(distance/legLength)+1);
|
||||
}
|
||||
|
||||
private boolean fixIsACandidate(GPSFix fix, Waypoint w, Competitor c) {
|
||||
GPSFix fixBefore = competitorTracks.get(c).getLastFixBefore(fix.getTimePoint());
|
||||
GPSFix fixAfter = competitorTracks.get(c).getFirstFixAfter(fix.getTimePoint());
|
||||
if (distances.get(c).containsKey(fix) && !(fixBefore == null)
|
||||
&& distances.get(c).get(fix).get(w) < distances.get(c).get(fixBefore).get(w) && !(fixAfter == null)
|
||||
&& distances.get(c).get(fix).get(w) < distances.get(c).get(fixAfter).get(w)) {
|
||||
&& distances.get(c).get(fix).get(w) <= distances.get(c).get(fixBefore).get(w) && !(fixAfter == null)
|
||||
&& distances.get(c).get(fix).get(w) <= distances.get(c).get(fixAfter).get(w)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -198,7 +193,7 @@ public class CandidateFinder {
|
||||
ArrayList<Position> positions = new ArrayList<>();
|
||||
Iterator<Mark> it = w.getMarks().iterator();
|
||||
while (it.hasNext()) {
|
||||
positions.add(markTracks.get(it.next()).getEstimatedPosition(gps.getTimePoint(), true));
|
||||
positions.add(markTracks.get(it.next()).getEstimatedPosition(gps.getTimePoint(), false));
|
||||
}
|
||||
if (p.equals(PassingInstruction.Port) || p.equals(PassingInstruction.Starboard)
|
||||
|| p.equals(PassingInstruction.Offset) || p.equals(PassingInstruction.None)) {
|
||||
@@ -206,6 +201,8 @@ public class CandidateFinder {
|
||||
}
|
||||
if (p.equals(PassingInstruction.Line)) {
|
||||
distance = gps.getPosition().getDistanceToLine(positions.get(0), positions.get(1)).getMeters();
|
||||
if(waypoints.indexOf(w)==0){
|
||||
}
|
||||
}
|
||||
if (p.equals(PassingInstruction.Gate)) {
|
||||
// Right now, both marks are observered, even though only one is actully rounded.
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ public class Edge {
|
||||
public Edge(Candidate start, Candidate end, double timeEstimation) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
penaltyForSkipped = 0.4;
|
||||
penaltyForSkipped = 0.2;
|
||||
this.timeEstimation = timeEstimation;
|
||||
}
|
||||
public String getIDs(){
|
||||
|
||||
-1
@@ -34,7 +34,6 @@ public class MarkPassingCalculator extends AbstractRaceChangeListener implements
|
||||
if(startOfTracking==null){
|
||||
startOfTracking = race.getTimePointOfOldestEvent();
|
||||
}
|
||||
System.out.println(startOfTracking);
|
||||
for (Waypoint w : race.getRace().getCourse().getWaypoints()) {
|
||||
waypoints.add(w);
|
||||
}
|
||||
|
||||
+66
-52
@@ -1,7 +1,7 @@
|
||||
package com.sap.sailing.domain.test.markpassing;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -28,6 +28,7 @@ import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
|
||||
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.impl.WindSourceImpl;
|
||||
import com.sap.sailing.domain.test.OnlineTracTracBasedTest;
|
||||
import com.sap.sailing.domain.tracking.DynamicGPSFixTrack;
|
||||
import com.sap.sailing.domain.tracking.DynamicTrackedRace;
|
||||
import com.sap.sailing.domain.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
@@ -48,36 +49,22 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
|
||||
testRace("04687b2a-9e68-11e0-85be-406186cbf87c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTornado4() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Tornado Race 4");
|
||||
testRace("5291b3ea-9934-11e0-85be-406186cbf87c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStarMedal() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Star Medal");
|
||||
testRace("d591d808-9c48-11e0-85be-406186cbf87c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test505_2() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Tornado 16");
|
||||
testRace("357c700a-9d9a-11e0-85be-406186cbf87c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test505_7() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Tornado 16");
|
||||
testRace("cb043bb4-9e92-11e0-85be-406186cbf87c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStar4() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Star 4");
|
||||
testRace("f5f531ec-99ed-11e0-85be-406186cbf87c");
|
||||
}
|
||||
|
||||
|
||||
@Test public void testTornado4() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Tornado Race 4"); testRace("5291b3ea-9934-11e0-85be-406186cbf87c"); }
|
||||
|
||||
@Test public void testStarMedal() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Star Medal"); testRace("d591d808-9c48-11e0-85be-406186cbf87c"); }
|
||||
|
||||
@Test public void test505_2() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Tornado 16"); testRace("357c700a-9d9a-11e0-85be-406186cbf87c"); }
|
||||
|
||||
@Test public void test505_7() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Tornado 16"); testRace("cb043bb4-9e92-11e0-85be-406186cbf87c"); }
|
||||
|
||||
@Test public void testStar4() throws IOException, InterruptedException, URISyntaxException {
|
||||
System.out.println("Star 4"); testRace("f5f531ec-99ed-11e0-85be-406186cbf87c"); }
|
||||
|
||||
private void testRace(String raceID) throws IOException, InterruptedException, URISyntaxException {
|
||||
setUp(raceID);
|
||||
compareMarkpasses();
|
||||
@@ -227,31 +214,57 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
|
||||
}
|
||||
}
|
||||
|
||||
// Pass in Mark Fixes
|
||||
LinkedHashMap<Mark, GPSFix> nextMarkFix = new LinkedHashMap<>();
|
||||
LinkedHashMap<Mark, DynamicGPSFixTrack<Mark, GPSFix>> markTracks = new LinkedHashMap<>();
|
||||
for (Mark m : marks) {
|
||||
try {
|
||||
getTrackedRace().getOrCreateTrack(m).lockForRead();
|
||||
for (GPSFix fix : getTrackedRace().getOrCreateTrack(m).getFixes()) {
|
||||
markPassCreator.markPositionChanged(fix, m);
|
||||
}
|
||||
markTracks.put(m, getTrackedRace().getOrCreateTrack(m));
|
||||
} finally {
|
||||
getTrackedRace().getOrCreateTrack(m).unlockAfterRead();
|
||||
}
|
||||
nextMarkFix.put(m, markTracks.get(m).getFirstRawFix());
|
||||
}
|
||||
|
||||
// Pass in Competitor Fixes
|
||||
LinkedHashMap<Competitor, GPSFixMoving> nextCompetitorFix = new LinkedHashMap<>();
|
||||
LinkedHashMap<Competitor, DynamicGPSFixTrack<Competitor, GPSFixMoving>> competitorTracks = new LinkedHashMap<>();
|
||||
for (Competitor c : getRace().getCompetitors()) {
|
||||
try {
|
||||
getTrackedRace().getTrack(c).lockForRead();
|
||||
for (GPSFixMoving fix : getTrackedRace().getTrack(c).getFixes()) {
|
||||
markPassCreator.competitorPositionChanged(fix, c);
|
||||
}
|
||||
competitorTracks.put(c, getTrackedRace().getTrack(c));
|
||||
} finally {
|
||||
getTrackedRace().getTrack(c).unlockAfterRead();
|
||||
}
|
||||
nextCompetitorFix.put(c, competitorTracks.get(c).getFirstRawFix());
|
||||
}
|
||||
for (Mark m : marks) {
|
||||
GPSFix fix = nextMarkFix.get(m);
|
||||
while (fix != null) {
|
||||
markPassCreator.markPositionChanged(fix, m);
|
||||
nextMarkFix.put(m, markTracks.get(m).getFirstFixAfter(fix.getTimePoint()));
|
||||
fix = nextMarkFix.get(m);
|
||||
}
|
||||
}
|
||||
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
done = true;
|
||||
for (Competitor c : getRace().getCompetitors()) {
|
||||
GPSFixMoving fix = nextCompetitorFix.get(c);
|
||||
if (fix != null) {
|
||||
markPassCreator.competitorPositionChanged(fix, c);
|
||||
fix = competitorTracks.get(c).getFirstFixAfter(fix.getTimePoint());
|
||||
nextCompetitorFix.put(c, fix);
|
||||
}
|
||||
}
|
||||
for (Competitor c : getRace().getCompetitors()) {
|
||||
if (!(nextCompetitorFix.get(c) == null)) {
|
||||
done = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get results
|
||||
System.out.println("Getting Results");
|
||||
for (Competitor c : getRace().getCompetitors()) {
|
||||
LinkedHashMap<Waypoint, MarkPassing> passes = new LinkedHashMap<>();
|
||||
for (Waypoint w : waypoints) {
|
||||
@@ -268,10 +281,10 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
|
||||
int correctlyNotComputed = 0;
|
||||
int correctPasses = 0;
|
||||
int incorrectPasses = 0;
|
||||
|
||||
|
||||
boolean printRight = false;
|
||||
boolean printWrong = true;
|
||||
|
||||
|
||||
for (Competitor c : getRace().getCompetitors()) {
|
||||
numberOfCompetitors++;
|
||||
System.out.println(c.getName() + "\n");
|
||||
@@ -281,27 +294,27 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
|
||||
if (printWrong) {
|
||||
System.out.println(waypoints.indexOf(w));
|
||||
System.out.println("Given is null");
|
||||
System.out.println(computedPasses.get(c).get(w)+ "\n");
|
||||
System.out.println(computedPasses.get(c).get(w) + "\n");
|
||||
}
|
||||
} else if (computedPasses.get(c).get(w) == null && !(givenPasses.get(c).get(w) == null)) {
|
||||
wronglyNotComputed++;
|
||||
if (printWrong) {
|
||||
System.out.println(waypoints.indexOf(w));
|
||||
System.out.println("Computed is null");
|
||||
System.out.println(givenPasses.get(c).get(w)+ "\n");
|
||||
System.out.println(givenPasses.get(c).get(w) + "\n");
|
||||
}
|
||||
} else if (givenPasses.get(c).get(w) == null && computedPasses.get(c).get(w) == null) {
|
||||
correctlyNotComputed++;
|
||||
if (printRight) {
|
||||
System.out.println(waypoints.indexOf(w));
|
||||
System.out.println("Both null"+ "\n");
|
||||
System.out.println("Both null" + "\n");
|
||||
}
|
||||
} else {
|
||||
long timedelta = givenPasses.get(c).get(w).getTimePoint().asMillis()
|
||||
- computedPasses.get(c).get(w).getTimePoint().asMillis();
|
||||
if ((Math.abs(timedelta) < tolerance)) {
|
||||
correctPasses++;
|
||||
if(printRight){
|
||||
if (printRight) {
|
||||
System.out.println(waypoints.indexOf(w));
|
||||
System.out.println("Calculated: " + computedPasses.get(c).get(w));
|
||||
System.out.println("Given: " + givenPasses.get(c).get(w));
|
||||
@@ -320,18 +333,19 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
|
||||
}
|
||||
}
|
||||
|
||||
int totalMarkPasses = numberOfCompetitors*waypoints.size();
|
||||
assertEquals(totalMarkPasses, incorrectPasses+correctPasses+wronglyNotComputed+correctlyNotComputed+wronglyComputed);
|
||||
int totalMarkPasses = numberOfCompetitors * waypoints.size();
|
||||
assertEquals(totalMarkPasses, incorrectPasses + correctPasses + wronglyNotComputed + correctlyNotComputed
|
||||
+ wronglyComputed);
|
||||
System.out.println("Total theoretical Passes: " + totalMarkPasses);
|
||||
double accuracy = (double) (correctPasses+correctlyNotComputed) / totalMarkPasses;
|
||||
double accuracy = (double) (correctPasses + correctlyNotComputed) / totalMarkPasses;
|
||||
System.out.println("Correct comparison: " + correctPasses);
|
||||
System.out.println("Incorrect comparison: " + incorrectPasses);
|
||||
System.out.println("Correctly Null: " + correctlyNotComputed);
|
||||
System.out.println("Should be null but arent:" + wronglyComputed);
|
||||
System.out.println("Should not be null but are: " + wronglyNotComputed);
|
||||
System.out.println("accuracy: " + accuracy);
|
||||
System.out.println("Computation time: " + (System.currentTimeMillis()-time)/1000 + " s");
|
||||
System.out.println("Computation time: " + (System.currentTimeMillis() - time) / 1000 + " s");
|
||||
assertTrue(accuracy > 0.8);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user