Corrected data mining calculations, added REST-API-interface to disable

avg boundaries calculation
This commit is contained in:
Vladislav Chumak committed 2018-01-12 20:02:15 +01:00
1 parent 6fa6b39901
commit f52b7987a1
10 files changed
+73 -45

No files matched your search

@@ -150,8 +150,8 @@ ManeuverExitingSpeedInKnots=Maneuver exiting speed (kts)
TackBeforeManeuver=Tack before maneuver
ManeuverBoundariesRetrieverChain=Maneuver boundaries
ManeuverBoundaries=Maneuver boundaries
ManeuverBoundarySpeedDeviationRatioFromAvg=Speed deviation ratio of maneuver boundary with avg speed before maneuver
ManeuverBoundaryCogDeviationRatioFromAvg=COG deviation ratio of maneuver boundary with avg COG before maneuver
ManeuverBoundarySpeedDeviationRatioFromAvg=Speed deviation ratio of maneuver boundaries with avg speed before/after maneuver
ManeuverBoundaryCogDeviationFromAvgInDegrees=COG deviation of maneuver boundary with avg COG before maneuver in degrees
DurationToNextManeuverInSeconds=Duration from the end of current maneuver until next maneuver start in seconds
DurationFromPreviousManeuverInSeconds=Duration from the end of previous maneuver until current maneuver start in seconds
NextManeuverAtLeastOneSecondInFront=Next maneuver start is at least one second after current maneuver end
@@ -150,8 +150,8 @@ ManeuverExitingSpeedInKnots=Manöver Endgeschwindigkeit (kn)
TackBeforeManeuver=Bug vor Manöver-Eintritt
ManeuverBoundariesRetrieverChain=Manöver Grenzen
ManeuverBoundaries=Manöver Grenzen
ManeuverBoundarySpeedDeviationRatioFromAvg=Verhältnis der Geschwindigkeitabweichung an Manöver-Grenzen mit avg Geschwindigkeit vor Manöver
ManeuverBoundaryCogDeviationRatioFromAvg=Verhältnis der COG-abweichung an Manöver-Grenzen mit avg COG vor Manöver
ManeuverBoundarySpeedDeviationRatioFromAvg=Verhältnis der Geschwindigkeitabweichung an Manöver-Grenzen mit avg Geschwindigkeit vor/nach Manöver
ManeuverBoundaryCogDeviationFromAvgInDegrees=COG-abweichung an Manöver-Grenzen mit avg COG vor Manöver in Grad
DurationToNextManeuverInSeconds=Dauer vom Ende des aktuellen Manövers bis zum Anfang des nächsten Manövers in Sekunden
DurationFromPreviousManeuverInSeconds=Dauer vom Ende des letzten Manövers bis zum Anfang des aktuellen Manövers in Sekunden
NextManeuverAtLeastOneSecondInFront=Anfang des nächsten Manövers ist mindestens eine Sekunde weiter als das Ende des aktuellen Manövers
@@ -27,8 +27,8 @@ public interface HasManeuverBoundariesContext {
@Statistic(messageKey = "ManeuverBoundarySpeedDeviationRatioFromAvg", ordinal = 1, resultDecimals = 4)
Double getManeuverBoundarySpeedDeviationRatioFromAvgStatistic();
@Statistic(messageKey = "ManeuverBoundaryCogDeviationRatioFromAvg", ordinal = 2, resultDecimals = 4)
Double getManeuverBoundaryCogDeviationRatioFromAvgStatistic();
@Statistic(messageKey = "ManeuverBoundaryCogDeviationFromAvgInDegrees", ordinal = 2, resultDecimals = 4)
Double getManeuverBoundaryCogDeviationFromAvgInDegreesStatistic();
@Statistic(messageKey = "DurationToNextManeuverInSeconds", ordinal = 3, resultDecimals = 4)
Double getDurationToNextManeuverInSecondsStatistic();
@@ -39,7 +39,7 @@ public class ManeuverBoundariesRetrievalProcessor
ManeuverWithEstimationDataCalculator calculator = new ManeuverWithEstimationDataCalculatorImpl();
Iterable<Maneuver> maneuvers = trackedRace.getManeuvers(competitor, false);
Iterable<ManeuverWithEstimationData> maneuversWithEstimationData = calculator
.computeEstimationDataForManeuvers(trackedRace, competitor, maneuvers);
.computeEstimationDataForManeuvers(trackedRace, competitor, maneuvers, true);
for (ManeuverWithEstimationData maneuverWithEstimationData : maneuversWithEstimationData) {
result.add(new ManeuverBoundariesWithContext(element, maneuverWithEstimationData));
}
@@ -46,20 +46,23 @@ public class ManeuverBoundariesWithContext implements HasManeuverBoundariesConte
SpeedWithBearing averageSpeedWithBearingBeforeManeuver = maneuverWithEstimationData
.getAverageSpeedWithBearingBefore();
if (speedWithBearingBeforeManeuver != null && averageSpeedWithBearingBeforeManeuver != null) {
return averageSpeedWithBearingBeforeManeuver.getKnots() / speedWithBearingBeforeManeuver.getKnots();
if(speedWithBearingBeforeManeuver.getKnots() < averageSpeedWithBearingBeforeManeuver.getKnots()) {
return averageSpeedWithBearingBeforeManeuver.getKnots() / speedWithBearingBeforeManeuver.getKnots();
} else {
return speedWithBearingBeforeManeuver.getKnots() / averageSpeedWithBearingBeforeManeuver.getKnots();
}
}
return null;
}
@Override
public Double getManeuverBoundaryCogDeviationRatioFromAvgStatistic() {
public Double getManeuverBoundaryCogDeviationFromAvgInDegreesStatistic() {
SpeedWithBearing speedWithBearingBeforeManeuver = maneuverWithEstimationData.getManeuver()
.getManeuverCurveWithStableSpeedAndCourseBoundaries().getSpeedWithBearingBefore();
SpeedWithBearing averageSpeedWithBearingBeforeManeuver = maneuverWithEstimationData
.getAverageSpeedWithBearingBefore();
if (speedWithBearingBeforeManeuver != null && averageSpeedWithBearingBeforeManeuver != null) {
return averageSpeedWithBearingBeforeManeuver.getBearing().getDegrees()
/ speedWithBearingBeforeManeuver.getBearing().getDegrees();
return Math.abs(averageSpeedWithBearingBeforeManeuver.getBearing().getDifferenceTo(speedWithBearingBeforeManeuver.getBearing()).getDegrees());
}
return null;
}
@@ -17,6 +17,6 @@ public interface ManeuverWithEstimationDataCalculator {
* Computes estimation data for the provided maneuvers.
*/
Iterable<ManeuverWithEstimationData> computeEstimationDataForManeuvers(TrackedRace trackedRace,
Competitor competitor, Iterable<Maneuver> maneuvers);
Competitor competitor, Iterable<Maneuver> maneuvers, boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver);
}
@@ -30,7 +30,7 @@ public class ManeuverWithEstimationDataCalculatorImpl implements ManeuverWithEst
@Override
public Iterable<ManeuverWithEstimationData> computeEstimationDataForManeuvers(TrackedRace trackedRace,
Competitor competitor, Iterable<Maneuver> maneuvers) {
Competitor competitor, Iterable<Maneuver> maneuvers, boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver) {
int maneuversCount = Util.size(maneuvers);
List<ManeuverWithEstimationData> result = new ArrayList<>(maneuversCount);
if (maneuversCount > 0) {
@@ -40,13 +40,13 @@ public class ManeuverWithEstimationDataCalculatorImpl implements ManeuverWithEst
while (maneuversIterator.hasNext()) {
Maneuver nextManeuver = maneuversIterator.next();
ManeuverWithEstimationData maneuverWithEstimationData = complementManeuverWithEstimationData(
trackedRace, competitor, previousManeuver, maneuver, nextManeuver);
trackedRace, competitor, previousManeuver, maneuver, nextManeuver, avgSpeedAndCogCalculationBeforeAndAfterManeuver);
result.add(maneuverWithEstimationData);
previousManeuver = maneuver;
maneuver = nextManeuver;
}
ManeuverWithEstimationData maneuverWithEstimationData = complementManeuverWithEstimationData(trackedRace,
competitor, previousManeuver, maneuver, null);
competitor, previousManeuver, maneuver, null, avgSpeedAndCogCalculationBeforeAndAfterManeuver);
result.add(maneuverWithEstimationData);
}
@@ -54,7 +54,7 @@ public class ManeuverWithEstimationDataCalculatorImpl implements ManeuverWithEst
}
private ManeuverWithEstimationData complementManeuverWithEstimationData(TrackedRace trackedRace,
Competitor competitor, Maneuver previousManeuver, Maneuver maneuver, Maneuver nextManeuver) {
Competitor competitor, Maneuver previousManeuver, Maneuver maneuver, Maneuver nextManeuver, boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver) {
Wind wind = trackedRace.getWind(maneuver.getPosition(), maneuver.getTimePoint());
Pair<SpeedWithBearing, SpeedWithBearing> speedPair = determineHighestAndLowestSpeedWithinMainCurve(trackedRace,
@@ -62,16 +62,22 @@ public class ManeuverWithEstimationDataCalculatorImpl implements ManeuverWithEst
SpeedWithBearing highestSpeedWithinMainCurve = speedPair.getA();
SpeedWithBearing lowestSpeedWithinMainCurve = speedPair.getB();
Pair<Duration, SpeedWithBearing> durationAndAverageSpeedWithBearingBetweenManeuvers = getDurationAndAverageSpeedWithBearingBetweenManeuvers(
trackedRace, competitor, previousManeuver, maneuver);
Duration durationFromPreviousManeuverEndToManeuverStart = durationAndAverageSpeedWithBearingBetweenManeuvers
.getA();
SpeedWithBearing averageSpeedWithBearingBefore = durationAndAverageSpeedWithBearingBetweenManeuvers.getB();
durationAndAverageSpeedWithBearingBetweenManeuvers = getDurationAndAverageSpeedWithBearingBetweenManeuvers(
trackedRace, competitor, maneuver, nextManeuver);
Duration durationFromManeuverEndToNextManeuverStart = durationAndAverageSpeedWithBearingBetweenManeuvers.getA();
SpeedWithBearing averageSpeedWithBearingAfter = durationAndAverageSpeedWithBearingBetweenManeuvers.getB();
Duration durationFromPreviousManeuverEndToManeuverStart = null;
SpeedWithBearing averageSpeedWithBearingBefore = null;
Duration durationFromManeuverEndToNextManeuverStart = null;
SpeedWithBearing averageSpeedWithBearingAfter = null;
if(avgSpeedAndCogCalculationBeforeAndAfterManeuver) {
Pair<Duration, SpeedWithBearing> durationAndAverageSpeedWithBearingBetweenManeuvers = getDurationAndAverageSpeedWithBearingBetweenManeuvers(
trackedRace, competitor, previousManeuver, maneuver);
durationFromPreviousManeuverEndToManeuverStart = durationAndAverageSpeedWithBearingBetweenManeuvers
.getA();
averageSpeedWithBearingBefore = durationAndAverageSpeedWithBearingBetweenManeuvers.getB();
durationAndAverageSpeedWithBearingBetweenManeuvers = getDurationAndAverageSpeedWithBearingBetweenManeuvers(
trackedRace, competitor, maneuver, nextManeuver);
durationFromManeuverEndToNextManeuverStart = durationAndAverageSpeedWithBearingBetweenManeuvers.getA();
averageSpeedWithBearingAfter = durationAndAverageSpeedWithBearingBetweenManeuvers.getB();
}
return new ManeuverWithEstimationDataImpl(maneuver, wind, highestSpeedWithinMainCurve,
lowestSpeedWithinMainCurve, averageSpeedWithBearingBefore,
durationFromPreviousManeuverEndToManeuverStart, averageSpeedWithBearingAfter,
@@ -33,13 +33,15 @@ public class ManeuverWithEstimationDataJsonSerializer implements JsonSerializer<
private final ManeuverCurveBoundariesJsonSerializer maneuverCurveEnteringAndExitingDetailsJsonSerializer;
private final ManeuverWindJsonSerializer windJsonSerializer;
private final GPSFixJsonSerializer gpsFixSerializer;
private final boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver;
public ManeuverWithEstimationDataJsonSerializer(GPSFixJsonSerializer gpsFixSerializer,
ManeuverCurveBoundariesJsonSerializer maneuverCurveEnteringAndExitingDetailsJsonSerializer,
ManeuverWindJsonSerializer windJsonSerializer) {
ManeuverWindJsonSerializer windJsonSerializer, boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver) {
this.gpsFixSerializer = gpsFixSerializer;
this.maneuverCurveEnteringAndExitingDetailsJsonSerializer = maneuverCurveEnteringAndExitingDetailsJsonSerializer;
this.windJsonSerializer = windJsonSerializer;
this.avgSpeedAndCogCalculationBeforeAndAfterManeuver = avgSpeedAndCogCalculationBeforeAndAfterManeuver;
}
@Override
@@ -64,21 +66,23 @@ public class ManeuverWithEstimationDataJsonSerializer implements JsonSerializer<
result.put(LOWEST_SPEED_WITHIN_MAIN_CURVE_IN_KNOTS,
maneuverWithEstimationData.getLowestSpeedWithinMainCurve() == null ? null
: maneuverWithEstimationData.getLowestSpeedWithinMainCurve().getKnots());
result.put(AVERAGE_SPEED_BEFORE_IN_KNOTS, maneuverWithEstimationData.getAverageSpeedWithBearingBefore() == null
? null : maneuverWithEstimationData.getAverageSpeedWithBearingBefore().getKnots());
result.put(AVERAGE_COURSE_BEFORE_IN_DEGREES,
maneuverWithEstimationData.getAverageSpeedWithBearingBefore() == null ? null
: maneuverWithEstimationData.getAverageSpeedWithBearingBefore().getBearing().getDegrees());
result.put(DURATION_FROM_PREVIOUS_MANEUVER_IN_SECONDS,
maneuverWithEstimationData.getDurationFromPreviousManeuverEndToManeuverStart() == null ? null
: maneuverWithEstimationData.getDurationFromPreviousManeuverEndToManeuverStart().asSeconds());
result.put(AVERAGE_SPEED_AFTER_IN_KNOTS, maneuverWithEstimationData.getAverageSpeedWithBearingAfter() == null
? null : maneuverWithEstimationData.getAverageSpeedWithBearingAfter().getKnots());
result.put(AVERAGE_COURSE_AFTER_IN_DEGREES, maneuverWithEstimationData.getAverageSpeedWithBearingAfter() == null
? null : maneuverWithEstimationData.getAverageSpeedWithBearingAfter().getBearing().getDegrees());
result.put(DURATION_TO_NEXT_MANEUVER_IN_SECONDS,
maneuverWithEstimationData.getDurationFromManeuverEndToNextManeuverStart() == null ? null
: maneuverWithEstimationData.getDurationFromManeuverEndToNextManeuverStart().asSeconds());
if(avgSpeedAndCogCalculationBeforeAndAfterManeuver) {
result.put(AVERAGE_SPEED_BEFORE_IN_KNOTS, maneuverWithEstimationData.getAverageSpeedWithBearingBefore() == null
? null : maneuverWithEstimationData.getAverageSpeedWithBearingBefore().getKnots());
result.put(AVERAGE_COURSE_BEFORE_IN_DEGREES,
maneuverWithEstimationData.getAverageSpeedWithBearingBefore() == null ? null
: maneuverWithEstimationData.getAverageSpeedWithBearingBefore().getBearing().getDegrees());
result.put(DURATION_FROM_PREVIOUS_MANEUVER_IN_SECONDS,
maneuverWithEstimationData.getDurationFromPreviousManeuverEndToManeuverStart() == null ? null
: maneuverWithEstimationData.getDurationFromPreviousManeuverEndToManeuverStart().asSeconds());
result.put(AVERAGE_SPEED_AFTER_IN_KNOTS, maneuverWithEstimationData.getAverageSpeedWithBearingAfter() == null
? null : maneuverWithEstimationData.getAverageSpeedWithBearingAfter().getKnots());
result.put(AVERAGE_COURSE_AFTER_IN_DEGREES, maneuverWithEstimationData.getAverageSpeedWithBearingAfter() == null
? null : maneuverWithEstimationData.getAverageSpeedWithBearingAfter().getBearing().getDegrees());
result.put(DURATION_TO_NEXT_MANEUVER_IN_SECONDS,
maneuverWithEstimationData.getDurationFromManeuverEndToNextManeuverStart() == null ? null
: maneuverWithEstimationData.getDurationFromManeuverEndToNextManeuverStart().asSeconds());
}
return result;
}
@@ -22,11 +22,13 @@ public class ManeuversWithEstimationDataJsonSerializer extends AbstractTrackedRa
private final BoatClassJsonSerializer boatClassJsonSerializer;
private final ManeuverWithEstimationDataJsonSerializer maneuverWithEstimationDataJsonSerializer;
private final boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver;
public ManeuversWithEstimationDataJsonSerializer(BoatClassJsonSerializer boatClassJsonSerializer,
ManeuverWithEstimationDataJsonSerializer maneuverWithEstimationDataJsonSerializer) {
ManeuverWithEstimationDataJsonSerializer maneuverWithEstimationDataJsonSerializer, boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver) {
this.boatClassJsonSerializer = boatClassJsonSerializer;
this.maneuverWithEstimationDataJsonSerializer = maneuverWithEstimationDataJsonSerializer;
this.avgSpeedAndCogCalculationBeforeAndAfterManeuver = avgSpeedAndCogCalculationBeforeAndAfterManeuver;
}
@Override
@@ -55,7 +57,7 @@ public class ManeuversWithEstimationDataJsonSerializer extends AbstractTrackedRa
Iterable<ManeuverWithEstimationData> maneuversWithEstimationData = null;
try {
maneuversWithEstimationData = maneuverWithEstimationDataCalculator.computeEstimationDataForManeuvers(trackedRace, competitor,
maneuvers);
maneuvers, avgSpeedAndCogCalculationBeforeAndAfterManeuver);
} catch(Exception e) {
e.printStackTrace();
}
@@ -1029,11 +1029,24 @@ public class RegattasResource extends AbstractSailingServerResource {
return response;
}
@GET
@Produces("application/json;charset=UTF-8")
@Path("{regattaname}/races/{racename}/maneuversWithFullEstimationData")
public Response getManeuversWithFullEstimationData(@PathParam("regattaname") String regattaName,
@PathParam("racename") String raceName) {
return getManeuversWithEstimationData(regattaName, raceName, true);
}
@GET
@Produces("application/json;charset=UTF-8")
@Path("{regattaname}/races/{racename}/maneuversWithEstimationData")
public Response getManeuversWithEstimationData(@PathParam("regattaname") String regattaName,
@PathParam("racename") String raceName) {
return getManeuversWithEstimationData(regattaName, raceName, false);
}
private Response getManeuversWithEstimationData(String regattaName,
String raceName, boolean avgSpeedAndCogCalculationBeforeAndAfterManeuver) {
Response response;
Regatta regatta = findRegattaByName(regattaName);
if (regatta == null) {
@@ -1052,7 +1065,7 @@ public class RegattasResource extends AbstractSailingServerResource {
new BoatClassJsonSerializer(),
new ManeuverWithEstimationDataJsonSerializer(new GPSFixJsonSerializer(),
new ManeuverCurveBoundariesJsonSerializer(),
new ManeuverWindJsonSerializer()));
new ManeuverWindJsonSerializer(), avgSpeedAndCogCalculationBeforeAndAfterManeuver), avgSpeedAndCogCalculationBeforeAndAfterManeuver);
JSONObject jsonMarkPassings = serializer.serialize(trackedRace);
String json = jsonMarkPassings.toJSONString();
return Response.ok(json).header("Content-Type", MediaType.APPLICATION_JSON + ";charset=UTF-8").build();