Added PROGRESS state for regattas and improved the calculation of the

regatta state based on the event state and race states
This commit is contained in:
Steffen Schaefer committed 2015-07-20 15:44:43 +02:00
1 parent ed5df9a27b
commit 8f247fdcd8
7 files changed
+92 -42

No files matched your search

@@ -25,8 +25,6 @@ import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.domain.leaderboard.RegattaLeaderboard;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.gwt.ui.shared.eventlist.EventListEventDTO;
import com.sap.sailing.gwt.ui.shared.eventview.HasRegattaMetadata.RegattaState;
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
import com.sap.sailing.gwt.ui.shared.general.EventMetadataDTO;
import com.sap.sailing.gwt.ui.shared.general.EventReferenceDTO;
import com.sap.sailing.gwt.ui.shared.general.EventState;
@@ -82,22 +80,6 @@ public final class HomeServiceUtil {
return true;
}
public static RegattaState calculateRegattaState(RegattaMetadataDTO regatta) {
Date now = new Date();
Date startDate = regatta.getStartDate();
Date endDate = regatta.getEndDate();
if(startDate != null && now.compareTo(startDate) < 0) {
return RegattaState.UPCOMING;
}
if(endDate != null && now.compareTo(endDate) > 0) {
return RegattaState.FINISHED;
}
if(startDate != null && now.compareTo(startDate) >= 0 && endDate != null && now.compareTo(endDate) <= 0) {
return RegattaState.RUNNING;
}
return RegattaState.UNKNOWN;
}
public static EventState calculateEventState(EventBase event) {
return calculateEventState(event.isPublic(), event.getStartDate().asDate(), event.getEndDate().asDate());
}
@@ -43,7 +43,7 @@ public final class EventActionUtil {
}
LeaderboardGroup leaderboardGroup = Util.get(event.getLeaderboardGroups(), 0);
Leaderboard overallLeaderboard = leaderboardGroup.getOverallLeaderboard();
return new LeaderboardContext(service, event, leaderboardGroup, overallLeaderboard);
return new LeaderboardContext(context, event, leaderboardGroup, overallLeaderboard);
}
public static LeaderboardContext getLeaderboardContext(DispatchContext context, UUID eventId, String leaderboardId) {
@@ -52,7 +52,7 @@ public final class EventActionUtil {
for(LeaderboardGroup leaderboardGroup : event.getLeaderboardGroups()) {
for(Leaderboard leaderboard : leaderboardGroup.getLeaderboards()) {
if(leaderboard.getName().equals(leaderboardId)) {
return new LeaderboardContext(service, event, leaderboardGroup, leaderboard);
return new LeaderboardContext(context, event, leaderboardGroup, leaderboard);
}
}
}
@@ -109,10 +109,9 @@ public final class EventActionUtil {
}
public static void forLeaderboardsOfEvent(DispatchContext context, Event event, LeaderboardCallback callback) {
RacingEventService service = context.getRacingEventService();
for (LeaderboardGroup leaderboardGroup : event.getLeaderboardGroups()) {
for (Leaderboard leaderboard : leaderboardGroup.getLeaderboards()) {
callback.doForLeaderboard(new LeaderboardContext(service, event, leaderboardGroup, leaderboard));
callback.doForLeaderboard(new LeaderboardContext(context, event, leaderboardGroup, leaderboard));
}
}
}
@@ -121,12 +120,12 @@ public final class EventActionUtil {
forLeaderboardsOfEvent(context, eventId, new LeaderboardCallback() {
@Override
public void doForLeaderboard(LeaderboardContext leaderboardContext) {
leaderboardContext.forRaces(context, callback);
leaderboardContext.forRaces(callback);
}
});
}
public static void forRacesOfRegatta(DispatchContext context, UUID eventId, String regattaName, RaceCallback callback) {
getLeaderboardContext(context, eventId, regattaName).forRaces(context, callback);
getLeaderboardContext(context, eventId, regattaName).forRaces(callback);
}
}
@@ -30,7 +30,7 @@ public class GetRegattaListViewAction implements Action<ResultWithTTL<SortedSetR
EventActionUtil.forLeaderboardsOfEvent(context, eventId, new LeaderboardCallback() {
@Override
public void doForLeaderboard(LeaderboardContext leaderboardContext) {
result.add(leaderboardContext.getRegattaWithProgress(context));
result.add(leaderboardContext.getRegattaWithProgress());
}
});
return new ResultWithTTL<>(EventActionUtil.getEventStateDependentTTL(context, eventId, 3 * 60 * 1000), new SortedSetResult<>(result));
@@ -26,6 +26,6 @@ public class GetRegattaWithProgressAction implements Action<ResultWithTTL<Regatt
@GwtIncompatible
public ResultWithTTL<RegattaWithProgressDTO> execute(DispatchContext context) {
return new ResultWithTTL<>(EventActionUtil.getEventStateDependentTTL(context, eventId, 5 * 60 * 1000),
EventActionUtil.getLeaderboardContext(context, eventId, regattaId).getRegattaWithProgress(context));
EventActionUtil.getLeaderboardContext(context, eventId, regattaId).getRegattaWithProgress());
}
}
@@ -2,7 +2,6 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -12,11 +11,9 @@ import com.sap.sailing.domain.base.Fleet;
import com.sap.sailing.domain.base.RaceColumn;
import com.sap.sailing.domain.base.Regatta;
import com.sap.sailing.domain.common.dto.CompetitorDTO;
import com.sap.sailing.domain.common.dto.FleetDTO;
import com.sap.sailing.domain.common.dto.LeaderboardDTO;
import com.sap.sailing.domain.common.dto.LeaderboardEntryDTO;
import com.sap.sailing.domain.common.dto.LeaderboardRowDTO;
import com.sap.sailing.domain.common.dto.RaceColumnDTO;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.domain.leaderboard.RegattaLeaderboard;
@@ -26,38 +23,41 @@ import com.sap.sailing.gwt.ui.shared.dispatch.DispatchException;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.RaceCallback;
import com.sap.sailing.gwt.ui.shared.dispatch.regatta.RegattaWithProgressDTO;
import com.sap.sailing.gwt.ui.shared.eventview.HasRegattaMetadata.RegattaState;
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
import com.sap.sailing.gwt.ui.shared.general.EventState;
import com.sap.sailing.server.RacingEventService;
import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.common.impl.MillisecondsTimePoint;
public class LeaderboardContext {
private static final Logger logger = Logger.getLogger(LeaderboardContext.class.getName());
private final TimePoint now = MillisecondsTimePoint.now();
private final Event event;
private final LeaderboardGroup leaderboardGroup;
private final Leaderboard leaderboard;
private final RacingEventService service;
public LeaderboardContext(RacingEventService service, Event event, LeaderboardGroup leaderboardGroup, Leaderboard leaderboard) {
this.service = service;
public LeaderboardContext(DispatchContext dispatchContext, Event event, LeaderboardGroup leaderboardGroup, Leaderboard leaderboard) {
this.service = dispatchContext.getRacingEventService();
this.event = event;
this.leaderboardGroup = leaderboardGroup;
this.leaderboard = leaderboard;
}
public void forRaces(DispatchContext context, RaceCallback callback) {
public void forRaces(RaceCallback callback) {
for(RaceColumn raceColumn : leaderboard.getRaceColumns()) {
for(Fleet fleet : raceColumn.getFleets()) {
callback.doForRace(new RaceContext(service, event, leaderboard, raceColumn, fleet, context.getRacingEventService()));
callback.doForRace(new RaceContext(service, event, leaderboard, raceColumn, fleet, service));
}
}
}
public RegattaWithProgressDTO getRegattaWithProgress(DispatchContext context) {
public RegattaWithProgressDTO getRegattaWithProgress() {
RegattaProgressCalculator regattaProgressCalculator = new RegattaProgressCalculator();
forRaces(context, regattaProgressCalculator);
forRaces(regattaProgressCalculator);
RegattaWithProgressDTO regattaDTO = new RegattaWithProgressDTO(regattaProgressCalculator.getResult());
fillRegattaFields(regattaDTO);
return regattaDTO;
@@ -73,7 +73,7 @@ public class LeaderboardContext {
result.setScoreCorrectionText(leaderboardDTO.getComment());
result.setLastScoreUpdate(leaderboardDTO.getTimePointOfLastCorrectionsValidity());
boolean isLive = hasLiveRace(leaderboardDTO);
boolean isLive = hasLiveRace();
result.setLive(isLive);
int rank = 0;
@@ -99,9 +99,42 @@ public class LeaderboardContext {
}
}
private boolean hasLiveRace(LeaderboardDTO leaderboard) {
List<Pair<RaceColumnDTO, FleetDTO>> liveRaces = leaderboard.getLiveRaces(HomeServiceUtil.getLiveTimePointInMillis());
return !liveRaces.isEmpty();
private boolean hasLiveRace() {
OverallRacesStateCalculator racesStateCalculator = new OverallRacesStateCalculator();
forRaces(racesStateCalculator);
return racesStateCalculator.hasLiveRace();
}
public RegattaState calculateRegattaState() {
EventState eventState = HomeServiceUtil.calculateEventState(event);
if(eventState == EventState.FINISHED) {
return RegattaState.FINISHED;
}
if(eventState == EventState.UPCOMING || eventState == EventState.PLANNED) {
return RegattaState.UPCOMING;
}
TimePoint startDate = getStartTimePoint();
TimePoint endDate = getEndTimePoint();
if(startDate != null && now.compareTo(startDate) < 0) {
return RegattaState.UPCOMING;
}
if(endDate != null && now.compareTo(endDate) > 0) {
return RegattaState.FINISHED;
}
OverallRacesStateCalculator racesStateCalculator = new OverallRacesStateCalculator();
forRaces(racesStateCalculator);
if(racesStateCalculator.hasLiveRace()) {
return RegattaState.RUNNING;
}
if(!racesStateCalculator.hasUnfinishedRace()) {
return RegattaState.FINISHED;
}
if(racesStateCalculator.hasAbandonedOrPostponedRace() || racesStateCalculator.hasFinishedRace()) {
return RegattaState.PROGRESS;
}
return RegattaState.UPCOMING;
}
private Date getStartDateWithEventFallback() {
@@ -176,7 +209,7 @@ public class LeaderboardContext {
regattaDTO.setStartDate(getStartDateWithEventFallback());
regattaDTO.setEndDate(getEndDateWithEventFallback());
}
regattaDTO.setState(HomeServiceUtil.calculateRegattaState(regattaDTO));
regattaDTO.setState(calculateRegattaState());
regattaDTO.setDefaultCourseAreaName(HomeServiceUtil.getCourseAreaNameForRegattaIdThereIsMoreThanOne(event, leaderboard));
}
@@ -0,0 +1,36 @@
package com.sap.sailing.gwt.ui.shared.dispatch.event;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.RaceCallback;
import com.sap.sailing.gwt.ui.shared.race.RaceMetadataDTO.RaceViewState;
public class OverallRacesStateCalculator implements RaceCallback {
private boolean hasLiveRace = false;
private boolean hasFinishedRace = false;
private boolean hasAbandonedOrPostponedRace = false;
private boolean hasUnfinishedRace = false;
@Override
public void doForRace(RaceContext context) {
RaceViewState raceViewState = context.getLiveRaceViewState();
hasLiveRace |= raceViewState == RaceViewState.RUNNING;
hasFinishedRace |= raceViewState == RaceViewState.FINISHED;
hasAbandonedOrPostponedRace |= raceViewState == RaceViewState.POSTPONED || raceViewState == RaceViewState.ABANDONED;
hasUnfinishedRace |= raceViewState != RaceViewState.FINISHED;
}
public boolean hasLiveRace() {
return hasLiveRace;
}
public boolean hasFinishedRace() {
return hasFinishedRace;
}
public boolean hasUnfinishedRace() {
return hasUnfinishedRace;
}
public boolean hasAbandonedOrPostponedRace() {
return hasAbandonedOrPostponedRace;
}
}
@@ -7,7 +7,7 @@ import com.sap.sailing.gwt.ui.shared.general.LabelType;
public interface HasRegattaMetadata {
public enum RegattaState {
UPCOMING(LabelType.UPCOMING), RUNNING(LabelType.LIVE), FINISHED(LabelType.FINISHED), UNKNOWN(LabelType.NONE);
UPCOMING(LabelType.UPCOMING), PROGRESS(LabelType.PROGRESS), RUNNING(LabelType.LIVE), FINISHED(LabelType.FINISHED), UNKNOWN(LabelType.NONE);
private final LabelType stateMarker;