bug6048: implemented new statistic for duration since start to first tack

This commit is contained in:
Axel Uhl
2024-08-22 23:48:03 +02:00
parent 0c4c8e763d
commit 2ffb3e7b5f
5 changed files with 33 additions and 2 deletions
@@ -272,4 +272,5 @@ CompetitorSailingDomainRetrieverChain=Competitors in Leaderboards
SmoothedSpeed=Smoothed Speed
RatioDistanceLongVsShortTack=Ratio distance long tack / short tack
RatioDurationLongVsShortTack=Ratio duration long tack / short tack
Discarded=Discarded
Discarded=Discarded
DurationFromRaceStartToFirstTack=Duration from race start to first tack
@@ -270,4 +270,5 @@ CompetitorSailingDomainRetrieverChain=Teilnehmer in Ranglisten
SmoothedSpeed=Geglättete Geschwindigkeit
RatioDistanceLongVsShortTack=Verhältnis gesegelte Distanz auf Streck- zu Holebug
RatioDurationLongVsShortTack=Verhältnis gesegelte Dauer auf Streck- zu Holebug
Discarded=Gestrichen
Discarded=Gestrichen
DurationFromRaceStartToFirstTack=Dauer vom Start der Wettfahrt bis zur ersten Wende
@@ -143,6 +143,13 @@ public interface HasRaceOfCompetitorContext {
@Statistic(messageKey="RaceDuration")
Duration getDuration();
/**
* The time between the start of the race and the {@link #getCompetitor() competitor}'s first tack;
* {@code null} if no tack is found for the competitor in the race.
*/
@Statistic(messageKey="DurationFromRaceStartToFirstTack")
Duration getDurationFromStartToFirstTack();
@Statistic(messageKey="DistanceToStarboardSideAtStartOfRace", resultDecimals=2)
public Double getRelativeDistanceToStarboardSideAtStartOfRace();
@@ -36,6 +36,7 @@ import com.sap.sailing.domain.tracking.TrackedLeg;
import com.sap.sailing.domain.tracking.TrackedLegOfCompetitor;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.WindPositionMode;
import com.sap.sailing.domain.tracking.impl.TimedComparator;
import com.sap.sse.common.Bearing;
import com.sap.sse.common.Distance;
import com.sap.sse.common.Duration;
@@ -399,6 +400,26 @@ public class RaceOfCompetitorWithContext implements HasRaceOfCompetitorContext {
return duration;
}
@Override
public Duration getDurationFromStartToFirstTack() {
final TrackedRace race = getTrackedRace();
final Duration result;
if (race.getStartOfRace() == null) {
result = null;
} else {
final Iterable<Maneuver> maneuvers = race.getManeuvers(competitor, /* wait for latest */ false);
final List<Maneuver> tacks = Util.asList(Util.filter(maneuvers,
m->m.getType() == ManeuverType.TACK && !m.getTimePoint().before(race.getStartOfRace())));
if (tacks.isEmpty()) {
result = null;
} else {
tacks.sort(TimedComparator.INSTANCE);
result = race.getStartOfRace().until(tacks.get(0).getTimePoint());
}
}
return result;
}
@Override
public Double getRelativeDistanceToStarboardSideAtStartOfRace() {
TrackedRace trackedRace = getTrackedRace();