dcac700217085f820efc0183362bd588066109ce
java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CourseChangeBasedTrackApproximationTest.java
| ... | ... | @@ -37,7 +37,7 @@ public class CourseChangeBasedTrackApproximationTest { |
| 37 | 37 | final CompetitorWithBoat competitor = TrackBasedTest.createCompetitorWithBoat("Someone"); |
| 38 | 38 | track = new DynamicGPSFixMovingTrackImpl<Competitor>(competitor, |
| 39 | 39 | /* millisecondsOverWhichToAverage */5000, /* lossless compaction */true); |
| 40 | - approximation = new CourseChangeBasedTrackApproximation(track, competitor.getBoat().getBoatClass()); |
|
| 40 | + approximation = new CourseChangeBasedTrackApproximation(track, competitor.getBoat().getBoatClass(), /* logFixes */ false); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | @Test |
java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CourseChangeBasedTrackApproximationWithTracTracDataTest.java
| ... | ... | @@ -46,9 +46,9 @@ public class CourseChangeBasedTrackApproximationWithTracTracDataTest extends Onl |
| 46 | 46 | do { |
| 47 | 47 | competitors = getTrackedRace().getRace().getCompetitors(); |
| 48 | 48 | // To pick a single competitor, e.g., for debugging, use the following line: |
| 49 | - // sampleCompetitor = (CompetitorWithBoat) Util.first(Util.filter(competitors, c->c.getName().equals("Anton"))); |
|
| 49 | + sampleCompetitor = (CompetitorWithBoat) Util.first(Util.filter(competitors, c->c.getName().equals("Dasenbrook"))); |
|
| 50 | 50 | // To pick a random competitor, use the following line: |
| 51 | - sampleCompetitor = (CompetitorWithBoat) Util.get(competitors, new Random().nextInt(Util.size(competitors))); |
|
| 51 | +// sampleCompetitor = (CompetitorWithBoat) Util.get(competitors, new Random().nextInt(Util.size(competitors))); |
|
| 52 | 52 | sampleTrack = getTrackedRace().getTrack(sampleCompetitor); |
| 53 | 53 | } while (sampleTrack.isEmpty()); |
| 54 | 54 | } |
| ... | ... | @@ -72,7 +72,7 @@ public class CourseChangeBasedTrackApproximationWithTracTracDataTest extends Onl |
| 72 | 72 | final DynamicGPSFixTrack<Competitor, GPSFixMoving> trackCopy = new DynamicGPSFixMovingTrackImpl<Competitor>( |
| 73 | 73 | sampleCompetitor, |
| 74 | 74 | /* millisecondsOverWhichToAverage */ boatClass.getApproximateManeuverDurationInMilliseconds()); |
| 75 | - final CourseChangeBasedTrackApproximation earlyInitApproximation = new CourseChangeBasedTrackApproximation(trackCopy, sampleCompetitor.getBoat().getBoatClass()); |
|
| 75 | + final CourseChangeBasedTrackApproximation earlyInitApproximation = new CourseChangeBasedTrackApproximation(trackCopy, sampleCompetitor.getBoat().getBoatClass(), /* logFixes */ true); |
|
| 76 | 76 | final TimePoint from = sampleTrack.getFirstRawFix().getTimePoint(); |
| 77 | 77 | final TimePoint to = sampleTrack.getLastRawFix().getTimePoint(); |
| 78 | 78 | sampleTrack.lockForRead(); |
| ... | ... | @@ -83,10 +83,11 @@ public class CourseChangeBasedTrackApproximationWithTracTracDataTest extends Onl |
| 83 | 83 | } finally { |
| 84 | 84 | sampleTrack.unlockAfterRead(); |
| 85 | 85 | } |
| 86 | - final CourseChangeBasedTrackApproximation lateInitApproximation = new CourseChangeBasedTrackApproximation(trackCopy, sampleCompetitor.getBoat().getBoatClass()); |
|
| 86 | + final CourseChangeBasedTrackApproximation lateInitApproximation = new CourseChangeBasedTrackApproximation(trackCopy, sampleCompetitor.getBoat().getBoatClass(), /* logFixes */ true); |
|
| 87 | 87 | assertEquals(earlyInitApproximation.getNumberOfFixesAdded(), lateInitApproximation.getNumberOfFixesAdded(), "Number of fixes added to approximators differs"); |
| 88 | 88 | final Iterable<GPSFixMoving> earlyInitResult = earlyInitApproximation.approximate(from, to); |
| 89 | 89 | final Iterable<GPSFixMoving> lateInitResult = lateInitApproximation.approximate(from, to); |
| 90 | + assertEquals(Util.size(earlyInitResult), Util.size(lateInitResult), "Different numbers of approximation points for competitor "+sampleCompetitor.getName()); |
|
| 90 | 91 | final Iterator<GPSFixMoving> earlyIter = earlyInitResult.iterator(); |
| 91 | 92 | final Iterator<GPSFixMoving> lateIter = lateInitResult.iterator(); |
| 92 | 93 | int i=0; |
| ... | ... | @@ -96,7 +97,6 @@ public class CourseChangeBasedTrackApproximationWithTracTracDataTest extends Onl |
| 96 | 97 | assertEquals(earlyFix.getTimePoint(), lateFix.getTimePoint(), "Time points of approximation fixes differ at index "+i+" for competitor "+sampleCompetitor.getName()); |
| 97 | 98 | i++; |
| 98 | 99 | } |
| 99 | - assertEquals(Util.size(earlyInitResult), Util.size(lateInitResult), "Different numbers of approximation points for competitor "+sampleCompetitor.getName()); |
|
| 100 | 100 | assertEquals(Util.asSet(earlyInitResult), Util.asSet(lateInitResult)); |
| 101 | 101 | } |
| 102 | 102 | } |
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/CourseChangeBasedTrackApproximation.java
| ... | ... | @@ -135,7 +135,10 @@ public class CourseChangeBasedTrackApproximation implements Serializable, GPSTra |
| 135 | 135 | private final double maneuverAngleInDegreesThreshold; |
| 136 | 136 | private Duration windowDuration; |
| 137 | 137 | |
| 138 | - FixWindow() { |
|
| 138 | + private final boolean logFixes; |
|
| 139 | + |
|
| 140 | + FixWindow(boolean logFixes) { |
|
| 141 | + this.logFixes = logFixes; |
|
| 139 | 142 | this.window = new LinkedList<>(); |
| 140 | 143 | this.queueOfNewFixes = new LinkedList<>(); |
| 141 | 144 | this.speedForFixesInWindow = new LinkedList<>(); |
| ... | ... | @@ -241,7 +244,17 @@ public class CourseChangeBasedTrackApproximation implements Serializable, GPSTra |
| 241 | 244 | private GPSFixMoving addOldEnoughFix(GPSFixMoving next) { |
| 242 | 245 | assert window.isEmpty() || !next.getTimePoint().before(window.peekFirst().getTimePoint()); |
| 243 | 246 | final GPSFixMoving result; |
| 247 | + final boolean validityCached = next.isValidityCached(); |
|
| 248 | + final boolean validity = validityCached ? next.isValidCached() : track.isValid(next); |
|
| 244 | 249 | final SpeedWithBearing nextSpeed = next.isEstimatedSpeedCached() ? next.getCachedEstimatedSpeed() : track.getEstimatedSpeed(next.getTimePoint()); |
| 250 | + if (logFixes) { |
|
| 251 | + // CSV logging: approxId, fixIndex, fixTimeMillis, validityCached, speedCached, COG, SOG |
|
| 252 | + System.out.println(System.identityHashCode(this) + "," + next.getTimePoint().asMillis() + "," |
|
| 253 | + + next.isValidityCached() + "," + next.isEstimatedSpeedCached() + "," |
|
| 254 | + + (nextSpeed == null ? "null" : nextSpeed.getBearing().getDegrees()) + "," |
|
| 255 | + + (nextSpeed == null ? "null" : nextSpeed.getKnots()) + "," |
|
| 256 | + + validityCached + "," + validity); |
|
| 257 | + } |
|
| 245 | 258 | if (nextSpeed != null) { |
| 246 | 259 | numberOfFixesAdded++; |
| 247 | 260 | int insertPosition = window.size(); |
| ... | ... | @@ -398,10 +411,10 @@ public class CourseChangeBasedTrackApproximation implements Serializable, GPSTra |
| 398 | 411 | } |
| 399 | 412 | } |
| 400 | 413 | |
| 401 | - public CourseChangeBasedTrackApproximation(GPSFixTrack<Competitor, GPSFixMoving> track, BoatClass boatClass) { |
|
| 414 | + public CourseChangeBasedTrackApproximation(GPSFixTrack<Competitor, GPSFixMoving> track, BoatClass boatClass, boolean logFixes) { |
|
| 402 | 415 | this.track = track; |
| 403 | 416 | this.boatClass = boatClass; |
| 404 | - this.fixWindow = new FixWindow(); |
|
| 417 | + this.fixWindow = new FixWindow(logFixes); |
|
| 405 | 418 | this.maneuverCandidates = new TreeSet<>(TimedComparator.INSTANCE); |
| 406 | 419 | track.addListener(this); |
| 407 | 420 | addAllFixesOfTrack(); |
| ... | ... | @@ -459,7 +472,7 @@ public class CourseChangeBasedTrackApproximation implements Serializable, GPSTra |
| 459 | 472 | if (fixWindow.isAtOrAfterFirst(fix.getTimePoint())) { |
| 460 | 473 | addFix(fix); |
| 461 | 474 | } else { |
| 462 | - final FixWindow outOfOrderWindow = new FixWindow(); |
|
| 475 | + final FixWindow outOfOrderWindow = new FixWindow(/* logFixes */ false); |
|
| 463 | 476 | final Duration maximumWindowLength = outOfOrderWindow.getMaximumWindowLength(); |
| 464 | 477 | // fix is an out-of-order delivery; construct a new FixWindow and analyze the track around the new fix. |
| 465 | 478 | // A time range around the fix is constructed that will be re-scanned. The time range covers at least |
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java
| ... | ... | @@ -585,7 +585,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl |
| 585 | 585 | markPassingsForCompetitor.put(competitor, new ConcurrentSkipListSet<MarkPassing>(MarkPassingByTimeComparator.INSTANCE)); |
| 586 | 586 | final DynamicGPSFixMovingTrackImpl<Competitor> track = new DynamicGPSFixMovingTrackImpl<Competitor>(competitor, millisecondsOverWhichToAverageSpeed); |
| 587 | 587 | tracks.put(competitor, track); |
| 588 | - maneuverApproximators.put(competitor, new CourseChangeBasedTrackApproximation(track, race.getBoatOfCompetitor(competitor).getBoatClass())); |
|
| 588 | + maneuverApproximators.put(competitor, new CourseChangeBasedTrackApproximation(track, race.getBoatOfCompetitor(competitor).getBoatClass(), /* logFixes */ false)); |
|
| 589 | 589 | } |
| 590 | 590 | markPassingsForWaypoint = new ConcurrentHashMap<Waypoint, NavigableSet<MarkPassing>>(); |
| 591 | 591 | for (Waypoint waypoint : race.getCourse().getWaypoints()) { |