From 5f057d88e9c1fad1a42cdf71471fd604cea8b6cd Mon Sep 17 00:00:00 2001 From: Vladislav Chumak Date: Thu, 5 Apr 2018 20:26:51 +0200 Subject: [PATCH] Added gpsFixesCount before and after maneuver to estimation data export --- ...tableCourseAndSpeedWithEstimationData.java | 32 +++++++---- ...eCourseAndSpeedWithEstimationDataImpl.java | 27 +++++++-- .../impl/ManeuverDetectorImpl.java | 55 +++++++++++++++---- ...SpeedWithEstimationDataJsonSerializer.java | 6 ++ 4 files changed, 92 insertions(+), 28 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationData.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationData.java index b7e6cf3028c..ba8d990852e 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationData.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationData.java @@ -17,37 +17,49 @@ public interface ManeuverCurveWithUnstableCourseAndSpeedWithEstimationData /** * Gets the average speed and course measured from the end of the previous maneuver until the start of this * maneuver. The mentioned maneuver start and end refer to - * {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). If there are no previous maneuvers, or the - * previous maneuver end is not before the start of this maneuver with a distance of at least one second, the result - * will be {@null}. + * {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). If there are no previous maneuvers, the + * result will be {@null}. */ SpeedWithBearing getAverageSpeedWithBearingBefore(); /** * Gets the duration from the end of the previous maneuver until the start of this maneuver. The mentioned maneuver * start and end refer to {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). If there are no - * previous maneuvers, or the previous maneuver end is not before the start of this maneuver with a distance of at - * least one second, the result will be {@null}. + * previous maneuvers, the result will be {@null}. */ Duration getDurationFromPreviousManeuverEndToManeuverStart(); + /** + * Gets the number of GPS-fixes recorded from the end of the previous maneuver until the start of this maneuver. The + * mentioned maneuver start and end refer to {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). + * If there are no previous maneuvers, or the previous maneuver end is not before the start of this maneuver with a + * distance of at least one second, the result will be zero. + */ + int getGpsFixesCountFromPreviousManeuverEndToManeuverStart(); + /** * Gets the average speed and course measured from the end of this maneuver until the start of the next maneuver. * Both mentioned maneuver start and end refer to - * {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). If there are no following maneuvers, or the - * the maneuver end of this maneuver is not before the start of the next maneuver with a distance of at least one - * second, the result will be {@null}. + * {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). If there are no following maneuvers, the + * result will be {@null}. */ SpeedWithBearing getAverageSpeedWithBearingAfter(); /** * Gets the duration from the end of this maneuver until the start of the next maneuver. Both mentioned maneuver * start and end refer to {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). If there are no - * following maneuvers, or the the maneuver end of this maneuver is not before the start of the next maneuver with a - * distance of at least one second, the result will be {@null}. + * following maneuvers, the result will be {@null}. */ Duration getDurationFromManeuverEndToNextManeuverStart(); + /** + * Gets the number of GPS-fixes recorded from the end of this maneuver until the start of the next maneuver. Both + * mentioned maneuver start and end refer to {@link Maneuver#getManeuverCurveWithStableSpeedAndCourseBoundaries(). + * If there are no following maneuvers, or the the maneuver end of this maneuver is not before the start of the next + * maneuver with a distance of at least one second, the result will be zero. + */ + int getGpsFixesCountFromManeuverEndToNextManeuverStart(); + /** * Gets the number of GPS-fixes contained within the maneuver curve. */ diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataImpl.java index 4039e6dce24..8c08b0fa5f7 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataImpl.java @@ -20,21 +20,26 @@ public class ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataImpl exten private final Distance distanceSailedIfNotManeuvering; private final Distance distanceSailedTowardMiddleAngleProjectionIfNotManeuvering; private final int gpsFixesCount; + private final int gpsFixesCountFromPreviousManeuverEndToManeuverStart; + private final int gpsFixesCountFromManeuverEndToNextManeuverStart; public ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataImpl(TimePoint timePointBefore, TimePoint timePointAfter, SpeedWithBearing speedWithBearingBefore, SpeedWithBearing speedWithBearingAfter, - double directionChangeInDegrees, Speed lowestSpeed, - SpeedWithBearing averageSpeedWithBearingBefore, Duration durationFromPreviousManeuverEndToManeuverStart, - SpeedWithBearing averageSpeedWithBearingAfter, Duration durationFromManeuverEndToNextManeuverStart, + double directionChangeInDegrees, Speed lowestSpeed, SpeedWithBearing averageSpeedWithBearingBefore, + Duration durationFromPreviousManeuverEndToManeuverStart, + int gpsFixesCountFromPreviousManeuverEndToManeuverStart, SpeedWithBearing averageSpeedWithBearingAfter, + Duration durationFromManeuverEndToNextManeuverStart, int gpsFixesCountFromManeuverEndToNextManeuverStart, Distance distanceSailedWithinManeuver, Distance distanceSailedWithinManeuverTowardMiddleAngleProjection, - Distance distanceSailedIfNotManeuvering, - Distance distanceSailedTowardMiddleAngleProjectionIfNotManeuvering, int gpsFixesCount) { + Distance distanceSailedIfNotManeuvering, Distance distanceSailedTowardMiddleAngleProjectionIfNotManeuvering, + int gpsFixesCount) { super(timePointBefore, timePointAfter, speedWithBearingBefore, speedWithBearingAfter, directionChangeInDegrees, lowestSpeed); this.averageSpeedWithBearingBefore = averageSpeedWithBearingBefore; this.durationFromPreviousManeuverEndToManeuverStart = durationFromPreviousManeuverEndToManeuverStart; + this.gpsFixesCountFromPreviousManeuverEndToManeuverStart = gpsFixesCountFromPreviousManeuverEndToManeuverStart; this.averageSpeedWithBearingAfter = averageSpeedWithBearingAfter; this.durationFromManeuverEndToNextManeuverStart = durationFromManeuverEndToNextManeuverStart; + this.gpsFixesCountFromManeuverEndToNextManeuverStart = gpsFixesCountFromManeuverEndToNextManeuverStart; this.distanceSailedWithinManeuver = distanceSailedWithinManeuver; this.distanceSailedWithinManeuverTowardMiddleAngleProjection = distanceSailedWithinManeuverTowardMiddleAngleProjection; this.distanceSailedIfNotManeuvering = distanceSailedIfNotManeuvering; @@ -81,10 +86,20 @@ public class ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataImpl exten public Distance getDistanceSailedTowardMiddleAngleProjectionIfNotManeuvering() { return distanceSailedTowardMiddleAngleProjectionIfNotManeuvering; } - + @Override public int getGpsFixesCount() { return gpsFixesCount; } + @Override + public int getGpsFixesCountFromPreviousManeuverEndToManeuverStart() { + return gpsFixesCountFromPreviousManeuverEndToManeuverStart; + } + + @Override + public int getGpsFixesCountFromManeuverEndToNextManeuverStart() { + return gpsFixesCountFromManeuverEndToNextManeuverStart; + } + } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverDetectorImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverDetectorImpl.java index 1cfcb51ef58..b1b9a4a2293 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverDetectorImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverdetection/impl/ManeuverDetectorImpl.java @@ -277,16 +277,42 @@ public class ManeuverDetectorImpl implements ManeuverDetector { } int gpsFixCountWithinMainCurve = 0; int gpsFixCountWithinWholeCurve = 0; + int gpsFixesCountFromPreviousManeuver = 0; + int gpsFixesCountToNextManeuver = 0; try { track.lockForRead(); for (GPSFixMoving fix : track.getFixes( - maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries().getTimePointBefore(), true, - maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries().getTimePointAfter(), true)) { - if (!fix.getTimePoint().before(maneuverCurve.getMainCurveBoundaries().getTimePointBefore()) - && !fix.getTimePoint().after(maneuverCurve.getMainCurveBoundaries().getTimePointAfter())) { - ++gpsFixCountWithinMainCurve; + previousManeuverCurve != null && previousManeuverCurve + .getManeuverCurveWithStableSpeedAndCourseBoundaries().getTimePointAfter() + .before(maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries() + .getTimePointBefore()) + ? previousManeuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries() + .getTimePointAfter() + : maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries() + .getTimePointBefore(), + true, + nextManeuverCurve != null && nextManeuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries() + .getTimePointBefore() + .after(maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries() + .getTimePointAfter()) + ? nextManeuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries() + .getTimePointBefore() + : maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries() + .getTimePointAfter(), + true)) { + if (fix.getTimePoint().before( + maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries().getTimePointBefore())) { + ++gpsFixesCountFromPreviousManeuver; + } else if (fix.getTimePoint().after( + maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries().getTimePointAfter())) { + ++gpsFixesCountToNextManeuver; + } else { + if (!fix.getTimePoint().before(maneuverCurve.getMainCurveBoundaries().getTimePointBefore()) + && !fix.getTimePoint().after(maneuverCurve.getMainCurveBoundaries().getTimePointAfter())) { + ++gpsFixCountWithinMainCurve; + } + ++gpsFixCountWithinWholeCurve; } - ++gpsFixCountWithinWholeCurve; } } finally { track.unlockAfterRead(); @@ -338,8 +364,9 @@ public class ManeuverDetectorImpl implements ManeuverDetector { maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries().getDirectionChangeInDegrees(), maneuverCurve.getManeuverCurveWithStableSpeedAndCourseBoundaries().getLowestSpeed(), durationAndAvgSpeedWithBearingBefore.getB(), durationAndAvgSpeedWithBearingBefore.getA(), - durationAndAvgSpeedWithBearingAfter.getB(), durationAndAvgSpeedWithBearingAfter.getA(), - distanceSailedWithinManeuver, projectedManeuverLoss.getDistanceSailed(), distanceSailedIfNotManeuvering, + gpsFixesCountFromPreviousManeuver, durationAndAvgSpeedWithBearingAfter.getB(), + durationAndAvgSpeedWithBearingAfter.getA(), gpsFixesCountToNextManeuver, distanceSailedWithinManeuver, + projectedManeuverLoss.getDistanceSailed(), distanceSailedIfNotManeuvering, projectedManeuverLoss.getDistanceSailedIfNotManeuvering(), gpsFixCountWithinWholeCurve); TimePoint maneuverTimePoint = maneuverCurve.getMainCurveBoundaries().getTimePoint(); Position maneuverPosition = track.getEstimatedPosition(maneuverTimePoint, /* extrapolate */false); @@ -511,9 +538,12 @@ public class ManeuverDetectorImpl implements ManeuverDetector { * to, or else the list of maneuver spots with corresponding maneuvers detected. */ protected List detectManeuvers(TimePoint earliestManeuverStart, TimePoint latestManeuverEnd) { - return detectManeuvers(trackedRace.approximate(competitor, - trackedRace.getRace().getBoatOfCompetitor(competitor).getBoatClass().getMaximumDistanceForCourseApproximation(), - earliestManeuverStart, latestManeuverEnd), earliestManeuverStart, latestManeuverEnd); + return detectManeuvers( + trackedRace.approximate(competitor, + trackedRace.getRace().getBoatOfCompetitor(competitor).getBoatClass() + .getMaximumDistanceForCourseApproximation(), + earliestManeuverStart, latestManeuverEnd), + earliestManeuverStart, latestManeuverEnd); } /** @@ -592,7 +622,8 @@ public class ManeuverDetectorImpl implements ManeuverDetector { if (lastCourseChangeDirection != newCourseChangeDirection) { return false; } - Distance threeHullLengths = trackedRace.getRace().getBoatOfCompetitor(competitor).getBoatClass().getHullLength().scale(3); + Distance threeHullLengths = trackedRace.getRace().getBoatOfCompetitor(competitor).getBoatClass().getHullLength() + .scale(3); if (currentFix.getTimePoint().asMillis() - previousFix.getTimePoint().asMillis() > getApproximateManeuverDuration().asMillis() && currentFix.getPosition().getDistance(previousFix.getPosition()).compareTo(threeHullLengths) > 0) { diff --git a/java/com.sap.sailing.server.gateway.serialization/src/com/sap/sailing/server/gateway/serialization/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataJsonSerializer.java b/java/com.sap.sailing.server.gateway.serialization/src/com/sap/sailing/server/gateway/serialization/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataJsonSerializer.java index 5458c97cf77..a012d907031 100644 --- a/java/com.sap.sailing.server.gateway.serialization/src/com/sap/sailing/server/gateway/serialization/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataJsonSerializer.java +++ b/java/com.sap.sailing.server.gateway.serialization/src/com/sap/sailing/server/gateway/serialization/impl/ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataJsonSerializer.java @@ -19,6 +19,8 @@ public class ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataJsonSerial public final static String AVERAGE_COURSE_AFTER_IN_DEGREES = "averageCourseAfterInDegrees"; public final static String DURATION_FROM_PREVIOUS_MANEUVER_IN_SECONDS = "durationFromPreviousManeuverInSeconds"; public final static String DURATION_TO_NEXT_MANEUVER_IN_SECONDS = "durationToNextManeuverInSeconds"; + public final static String GPS_FIXES_COUNT_FROM_PREVIOUS_MANEUVER_IN_SECONDS = "gpsFixesCountFromPreviousManeuver"; + public final static String GPS_FIXES_COUNT_TO_NEXT_MANEUVER_IN_SECONDS = "gpsFixesCountToNextManeuver"; public static final String GPS_FIXES_COUNT = "gpsFixesCount"; @Override @@ -41,6 +43,10 @@ public class ManeuverCurveWithUnstableCourseAndSpeedWithEstimationDataJsonSerial curve.getDurationFromManeuverEndToNextManeuverStart() == null ? null : curve.getDurationFromManeuverEndToNextManeuverStart().asSeconds()); result.put(GPS_FIXES_COUNT, curve.getGpsFixesCount()); + result.put(GPS_FIXES_COUNT_FROM_PREVIOUS_MANEUVER_IN_SECONDS, + curve.getGpsFixesCountFromPreviousManeuverEndToManeuverStart()); + result.put(GPS_FIXES_COUNT_TO_NEXT_MANEUVER_IN_SECONDS, + curve.getGpsFixesCountFromManeuverEndToNextManeuverStart()); } return result; }