mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-05 03:43:52 +00:00
Added isLive functionality on server side
This commit is contained in:
1 parent
48abc14d62
commit
dfedfb5ecb
2 files changed
+64
No files matched your search
@@ -87,6 +87,29 @@ public interface TrackedRace extends Serializable {
|
||||
* Shorthand for <code>{@link #getStart()}.{@link TimePoint#compareTo(TimePoint) compareTo(at)} <= 0</code>
|
||||
*/
|
||||
boolean hasStarted(TimePoint at);
|
||||
|
||||
/**
|
||||
* A race is considered "live" if it
|
||||
* {@link TrackedRaceDTO#hasGPSData has GPS data} and {@link TrackedRaceDTO#hasWindData wind data} and if the
|
||||
* <code>at</code> time point is between the start and the end of the race.
|
||||
* <p>
|
||||
*
|
||||
* The pre-start phase of a race is interesting also in live mode. Therefore, if a {@link TrackedRace#getStartOfRace start
|
||||
* time} is available for the race, the {@link TimingConstants#PRE_START_PHASE_DURATION_IN_MILLIS} is subtracted
|
||||
* from the actual start time so that the pre-start phase also counts as live. If no start time is known for the
|
||||
* race, but a {@link TrackedRace#getStartOfTracking start of tracking time} is known, it is used as the start of
|
||||
* the "live" interval.
|
||||
* <p>
|
||||
*
|
||||
* If an {@link TrackedRace#getEndOfRace end time} is already known for the race,
|
||||
* {@link TimingConstants#IS_LIVE_GRACE_PERIOD_IN_MILLIS} is added to that and the result is taken to be the end of
|
||||
* the "live" period. If no end time is known but a {@link TrackedRace#getTimePointOfNewestEvent} is set, again the
|
||||
* {@link TimingConstants#IS_LIVE_GRACE_PERIOD_IN_MILLIS} is added to that to mark the end of the "live" interval.
|
||||
* <p>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean isLive(TimePoint at);
|
||||
|
||||
/**
|
||||
* Clients can safely iterate over the iterable returned because it's a non-live copy of the tracked legs of this
|
||||
|
||||
+41
@@ -58,6 +58,7 @@ import com.sap.sailing.domain.common.RegattaAndRaceIdentifier;
|
||||
import com.sap.sailing.domain.common.RegattaNameAndRaceName;
|
||||
import com.sap.sailing.domain.common.Tack;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.TimingConstants;
|
||||
import com.sap.sailing.domain.common.TrackedRaceStatusEnum;
|
||||
import com.sap.sailing.domain.common.WindSource;
|
||||
import com.sap.sailing.domain.common.WindSourceType;
|
||||
@@ -629,6 +630,46 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
public boolean hasStarted(TimePoint at) {
|
||||
return getStartOfRace() != null && getStartOfRace().compareTo(at) <= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLive(TimePoint at) {
|
||||
final Date startOfLivePeriod;
|
||||
final Date endOfLivePeriod;
|
||||
if (!hasGPSData() || !hasWindData()) {
|
||||
startOfLivePeriod = null;
|
||||
endOfLivePeriod = null;
|
||||
} else {
|
||||
if (getStartOfRace() == null) {
|
||||
startOfLivePeriod = getStartOfTracking().asDate();
|
||||
} else {
|
||||
startOfLivePeriod = new Date(getStartOfRace().asMillis() - TimingConstants.PRE_START_PHASE_DURATION_IN_MILLIS);
|
||||
}
|
||||
if (getEndOfRace() == null) {
|
||||
if (getTimePointOfNewestEvent() != null) {
|
||||
endOfLivePeriod = new Date(getTimePointOfNewestEvent().asMillis()
|
||||
+ TimingConstants.IS_LIVE_GRACE_PERIOD_IN_MILLIS);
|
||||
} else {
|
||||
endOfLivePeriod = null;
|
||||
}
|
||||
} else {
|
||||
endOfLivePeriod = new Date(getEndOfRace().asMillis() + TimingConstants.IS_LIVE_GRACE_PERIOD_IN_MILLIS);
|
||||
}
|
||||
}
|
||||
|
||||
// if an empty timepoint is given then take the start of the race
|
||||
if (at.asMillis() == 0) {
|
||||
at = new MillisecondsTimePoint(startOfLivePeriod.getTime()+1);
|
||||
}
|
||||
|
||||
// whenLastTrackedRaceWasLive is null if there is no tracked race for fleet, or the tracked race hasn't started yet at the server time
|
||||
// when this DTO was assembled, or there were no GPS or wind data
|
||||
final boolean result =
|
||||
startOfLivePeriod != null &&
|
||||
endOfLivePeriod != null &&
|
||||
startOfLivePeriod.getTime() <= at.asMillis() &&
|
||||
at.asMillis() <= endOfLivePeriod.getTime();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceDefinition getRace() {
|
||||
|
||||
Reference in new issue
Block a user