added flag used by non-stripped leaderboard to indicate a column's live mode in case no RaceDTOs and TrackedRaceDTOs are attached

This commit is contained in:
Axel Uhl committed 2012-12-03 15:19:56 +01:00
1 parent 13706456f7
commit f0bacfdb27
4 files changed
+65 -13

No files matched your search

@@ -63,10 +63,12 @@ public interface TrackedRace extends Serializable {
* Determine the race end time is tricky. Boats may sink, stop, not finish, although they started the race. We therefore
* cannot wait for all boats to reach the finish line.
* The following rules are used to calculate the endOfRace:
* 1. Returns <code>Null</code> if no boat passed the finish line
* 2. Returns time of the last mark passing recorded for the finish line
* 3. TODO: Returns the time of the first passing of the finish line + the target window (defined in the competition rules)
* if a target window has been defined for the race
* <ol>
* <li>Returns <code>null</code> if no boat passed the finish line</li>
* <li>Returns time of the last mark passing recorded for the finish line</li>
* <li>TODO: Returns the time of the first passing of the finish line + the target window (defined in the competition rules)
* if a target window has been defined for the race</li>
* </ol>
*/
TimePoint getEndOfRace();
@@ -462,6 +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;
for (Fleet fleet : raceColumn.getFleets()) {
RegattaAndRaceIdentifier raceIdentifier = null;
TrackedRace trackedRace = raceColumn.getTrackedRace(fleet);
@@ -469,12 +470,26 @@ 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;
final TimePoint endOfRace = trackedRace.getEndOfRace();
if (endOfRace != null) {
runningTimePointForTrackedRace = endOfRace;
}
if (latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning == null ||
runningTimePointForTrackedRace.after(latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning)) {
latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning = runningTimePointForTrackedRace;
}
}
}
// Note: the RaceColumnDTO won't be created by the following addRace call because it has been created
// above by the result.createEmptyRaceColumn call
result.addRace(raceColumn.getName(), raceColumn.getExplicitFactor(), fleetDTO,
raceColumn.isMedalRace(), raceIdentifier, /* StrippedRaceDTO */ null);
}
if (latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning != null) {
raceColumnDTO.setWhenLastTrackedRaceWasRunning(latestTimePointAfterQueryTimePointWhenATrackedRaceWasRunning.asDate());
}
result.setCompetitorsFromBestToWorst(raceColumnDTO, getCompetitorDTOList(leaderboard.getCompetitorsFromBestToWorst(raceColumn, timePoint)));
}
result.setDelayToLiveInMillisForLatestRace(leaderboard.getDelayToLiveInMillis());
@@ -137,7 +137,10 @@ public abstract class AbstractLeaderboardDTO implements IsSerializable {
* ensures that a fleet named <code>fleetName</code> is present. If it's not present yet, it's added to the race
* column's fleet name list. The <code>trackedRaceIdentifier</code> and <code>race</code> are associated with the
* column for the fleet identified by <code>fleetName</code>.
* @param explicitFactor TODO
*
* @param explicitFactor
* factor by which to multiply the race column's points for the overall score; if <code>null</code>, the
* default will be determined by whether or not the column is marked as medal race
* @param fleetDTO
* must not be null
*/
@@ -13,12 +13,27 @@ import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.RegattaAndRaceIdentifier;
public class RaceColumnDTO extends NamedDTO implements IsSerializable {
private static final long IS_LIVE_GRACE_PERIOD_IN_MILLIS = 5 * 60 * 1000; // five minutes
private boolean medalRace;
private List<FleetDTO> fleets;
private Map<FleetDTO, RegattaAndRaceIdentifier> trackedRaceIdentifiersPerFleet;
private Map<FleetDTO, RaceDTO> racesPerFleet;
private Boolean isValidInTotalScore;
private Double explicitFactor;
/**
* 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.
* <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;
RaceColumnDTO() {} // for GWT serialization
@@ -129,16 +144,25 @@ public class RaceColumnDTO extends NamedDTO implements IsSerializable {
* @return <code>true</code> if the startOfTracking is after the current date and there's no end of the race
*/
public boolean isLive() {
for (FleetDTO fleet : getFleets()) {
final RaceDTO raceDTO = racesPerFleet.get(fleet);
if (trackedRaceIdentifiersPerFleet.get(fleet) != null
&& raceDTO != null && raceDTO.trackedRace != null
&& raceDTO.endOfRace == null
&& (raceDTO.trackedRace.startOfTracking != null ? new Date().after(raceDTO.trackedRace.startOfTracking) : false)) {
return true;
boolean result = false;
if (getWhenLastTrackedRaceWasRunning() != null
&& getWhenLastTrackedRaceWasRunning().getTime() > System.currentTimeMillis() - IS_LIVE_GRACE_PERIOD_IN_MILLIS) {
result = true;
} else {
for (FleetDTO fleet : getFleets()) {
final RaceDTO raceDTO = racesPerFleet.get(fleet);
if (trackedRaceIdentifiersPerFleet.get(fleet) != null
&& raceDTO != null
&& raceDTO.trackedRace != null
&& raceDTO.endOfRace == null
&& (raceDTO.trackedRace.startOfTracking != null ? new Date()
.after(raceDTO.trackedRace.startOfTracking) : false)) {
result = true;
break;
}
}
}
return false;
return result;
}
@Override
@@ -194,4 +218,12 @@ public class RaceColumnDTO extends NamedDTO implements IsSerializable {
public void addFleet(FleetDTO fleet) {
fleets.add(fleet);
}
private Date getWhenLastTrackedRaceWasRunning() {
return whenLastTrackedRaceWasRunning;
}
public void setWhenLastTrackedRaceWasRunning(Date whenLastTrackedRaceWasRunning) {
this.whenLastTrackedRaceWasRunning = whenLastTrackedRaceWasRunning;
}
}