RaceColumnDTO.isLive now works both, for stripped and unstripped leaderboards; requires tracked races to have GPS and wind data to be considered "live"

This commit is contained in:
Axel Uhl committed 2012-12-03 15:46:38 +01:00
1 parent 8ebbbdfc11
commit 835460f255
2 files changed
+22 -20

No files matched your search

@@ -462,7 +462,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
for (RaceColumn raceColumn : leaderboard.getRaceColumns()) {
RaceColumnDTO raceColumnDTO = result.createEmptyRaceColumn(raceColumn.getName(), raceColumn.isMedalRace(),
leaderboard.getScoringScheme().isValidInTotalScore(leaderboard, raceColumn, timePoint));
TimePoint latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning = null;
TimePoint latestTimePointAfterQueryTimePointWhenATrackedRaceWasLive = null;
for (Fleet fleet : raceColumn.getFleets()) {
RegattaAndRaceIdentifier raceIdentifier = null;
TrackedRace trackedRace = raceColumn.getTrackedRace(fleet);
@@ -470,15 +470,15 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
if (trackedRace != null) {
raceIdentifier = new RegattaNameAndRaceName(trackedRace.getTrackedRegatta().getRegatta()
.getName(), trackedRace.getRace().getName());
if (trackedRace.hasStarted(timePoint)) {
TimePoint runningTimePointForTrackedRace = timePoint;
if (trackedRace.hasStarted(timePoint) && trackedRace.hasGPSData() && trackedRace.hasWindData()) {
TimePoint liveTimePointForTrackedRace = timePoint;
final TimePoint endOfRace = trackedRace.getEndOfRace();
if (endOfRace != null) {
runningTimePointForTrackedRace = endOfRace;
liveTimePointForTrackedRace = endOfRace;
}
if (latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning == null ||
runningTimePointForTrackedRace.after(latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning)) {
latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning = runningTimePointForTrackedRace;
if (latestTimePointAfterQueryTimePointWhenATrackedRaceWasLive == null ||
liveTimePointForTrackedRace.after(latestTimePointAfterQueryTimePointWhenATrackedRaceWasLive)) {
latestTimePointAfterQueryTimePointWhenATrackedRaceWasLive = liveTimePointForTrackedRace;
}
}
}
@@ -487,8 +487,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
result.addRace(raceColumn.getName(), raceColumn.getExplicitFactor(), fleetDTO,
raceColumn.isMedalRace(), raceIdentifier, /* StrippedRaceDTO */ null);
}
if (latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning != null) {
raceColumnDTO.setWhenLastTrackedRaceWasRunning(latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning.asDate());
if (latestTimePointAfterQueryTimePointWhenATrackedRaceWasLive != null) {
raceColumnDTO.setWhenLastTrackedRaceWasLive(latestTimePointAfterQueryTimePointWhenATrackedRaceWasLive.asDate());
}
result.setCompetitorsFromBestToWorst(raceColumnDTO, getCompetitorDTOList(leaderboard.getCompetitorsFromBestToWorst(raceColumn, timePoint)));
}
@@ -24,16 +24,17 @@ public class RaceColumnDTO extends NamedDTO implements IsSerializable {
/**
* If the column has tracked races attached, this field tells the latest time point when one of those races was
* still running. If a tracked race has started but hasn't ended yet, the query time point is used for this field if
* it is after the time point when that race started, assuming that at the query time the race was still running. If
* the race hasn't started at the query time, the race isn't considered for setting this field. If the end of the
* race is known, it is used for this field if later than any other value set for this field.
* still running. It is necessary for the race to have GPS and wind data for the time point to be recorded here. If
* a tracked race has started but hasn't ended yet, the query time point is used for this field if it is after the
* time point when that race started, assuming that at the query time the race was still running. If the race hasn't
* started at the query time, the race isn't considered for setting this field. If the end of the race is known, it
* is used for this field if later than any other value set for this field.
* <p>
*
* If no tracked race is attached to this column or none of the tracked races attached has started at the query time
* point, this field is <code>null</code>.
*/
private Date whenLastTrackedRaceWasRunning;
private Date whenLastTrackedRaceWasLive;
RaceColumnDTO() {} // for GWT serialization
@@ -145,8 +146,8 @@ public class RaceColumnDTO extends NamedDTO implements IsSerializable {
*/
public boolean isLive() {
boolean result = false;
if (getWhenLastTrackedRaceWasRunning() != null
&& getWhenLastTrackedRaceWasRunning().getTime() > System.currentTimeMillis() - IS_LIVE_GRACE_PERIOD_IN_MILLIS) {
if (getWhenLastTrackedRaceWasLive() != null
&& getWhenLastTrackedRaceWasLive().getTime() > System.currentTimeMillis() - IS_LIVE_GRACE_PERIOD_IN_MILLIS) {
result = true;
} else {
for (FleetDTO fleet : getFleets()) {
@@ -154,6 +155,7 @@ public class RaceColumnDTO extends NamedDTO implements IsSerializable {
if (trackedRaceIdentifiersPerFleet.get(fleet) != null
&& raceDTO != null
&& raceDTO.trackedRace != null
&& raceDTO.trackedRace.hasGPSData && raceDTO.trackedRace.hasWindData
&& raceDTO.endOfRace == null
&& (raceDTO.trackedRace.startOfTracking != null ? new Date()
.after(raceDTO.trackedRace.startOfTracking) : false)) {
@@ -219,11 +221,11 @@ public class RaceColumnDTO extends NamedDTO implements IsSerializable {
fleets.add(fleet);
}
private Date getWhenLastTrackedRaceWasRunning() {
return whenLastTrackedRaceWasRunning;
private Date getWhenLastTrackedRaceWasLive() {
return whenLastTrackedRaceWasLive;
}
public void setWhenLastTrackedRaceWasRunning(Date whenLastTrackedRaceWasRunning) {
this.whenLastTrackedRaceWasRunning = whenLastTrackedRaceWasRunning;
public void setWhenLastTrackedRaceWasLive(Date whenLastTrackedRaceWasLive) {
this.whenLastTrackedRaceWasLive = whenLastTrackedRaceWasLive;
}
}