Implemented a way to control the time when the autoplayer switches between leaderboard and a live race

This commit is contained in:
fmittag committed 2015-12-15 14:50:20 +01:00
1 parent da2189ce65
commit 602c2cc829
5 files changed
+33 -18

No files matched your search

@@ -53,13 +53,14 @@ import com.sap.sse.security.ui.client.UserService;
public class AutoPlayController implements RaceTimesInfoProviderListener {
private static final int REFRESH_INTERVAL_IN_MILLIS_LEADERBOARD = 10000;
private static final long REFRESH_INTERVAL_IN_MILLIS_RACEBOARD = 1000;
private static final long WAIT_TIME_AFTER_END_OF_RACE_MIILIS = 60 * 1000; // 1 min
private final SailingServiceAsync sailingService;
private final MediaServiceAsync mediaService;
private final UserService userService;
private final ErrorReporter errorReporter;
private final UserAgentDetails userAgent;
private final AsyncActionsExecutor asyncActionsExecutor;
/**
* We use two timers: one for the leaderboard, one for the race board. This way, we can stop one while the other continues.
* This way, the other component stops its auto-updates.
@@ -343,13 +344,12 @@ public class AutoPlayController implements RaceTimesInfoProviderListener {
RaceTimesInfoDTO currentRaceTimes = raceTimesInfo.get(currentLiveRace);
Date endOfRace = currentRaceTimes.endOfRace;
long waitTimeAfterEndOfRace = 60 * 1000; // 1 min
if (endOfRace != null && raceboardTimer.getTime().getTime() > endOfRace.getTime() + waitTimeAfterEndOfRace
if (endOfRace != null && raceboardTimer.getTime().getTime() > endOfRace.getTime() + WAIT_TIME_AFTER_END_OF_RACE_MIILIS
&& raceboardTimer.getPlayMode() == PlayModes.Live) {
updatePlayMode(AutoPlayModes.Leaderboard);
}
} else {
currentLiveRace = checkForLiveRace();
currentLiveRace = checkForLiveRace(raceboardTimer.getLiveTimePointInMillis());
if (currentLiveRace != null) {
updatePlayMode(AutoPlayModes.Raceboard);
} else {
@@ -358,16 +358,22 @@ public class AutoPlayController implements RaceTimesInfoProviderListener {
}
}
private RegattaAndRaceIdentifier checkForLiveRace() {
private RegattaAndRaceIdentifier checkForLiveRace(long serverTimePointAsMillis) {
RegattaAndRaceIdentifier result = null;
Map<RegattaAndRaceIdentifier, RaceTimesInfoDTO> raceTimesInfos = raceTimesInfoProvider.getRaceTimesInfos();
for (RaceColumnDTO race : leaderboard.getRaceList()) {
for (FleetDTO fleet : race.getFleets()) {
RegattaAndRaceIdentifier raceIdentifier = race.getRaceIdentifier(fleet);
if (raceIdentifier != null) {
if(raceIdentifier != null) {
RaceTimesInfoDTO raceTimes = raceTimesInfos.get(raceIdentifier);
if (raceTimes != null && raceTimes.startOfTracking != null && raceTimes.endOfRace == null) {
return raceIdentifier;
if (raceTimes != null && raceTimes.startOfTracking != null && raceTimes.getStartOfRace() != null && raceTimes.endOfRace == null) {
long startTimeInMs = raceTimes.getStartOfRace().getTime();
long timeToSwitchBeforeRaceStartInMs = autoPlayerConfiguration.getTimeToSwitchBeforeRaceStartInSeconds() * 1000;
long delayToLiveInMs = raceTimes.delayToLiveInMs;
// the switch to the live race should happen at a defined timepoint before the race start (default is 3 min)
if (serverTimePointAsMillis - delayToLiveInMs > startTimeInMs - timeToSwitchBeforeRaceStartInMs) {
return raceIdentifier;
}
}
}
}
@@ -5,15 +5,18 @@ public class AutoPlayerConfiguration {
public final static String PARAM_EVENTID = "eventId";
public final static String PARAM_FULLSCREEN = "fullscreen";
public final static String PARAM_LEADEROARD_NAME = "leaderboardName";
public final static String PARAM_TIME_TO_SWITCH_BEFORE_RACE_START = "timeToSwitchBeforeRaceStart";
private String eventUidAsString;
private String leaderboardName;
private boolean fullscreenMode;
private long timeToSwitchBeforeRaceStartInSeconds;
public AutoPlayerConfiguration(String eventUidAsString, String leaderboardName, boolean fullscreenMode) {
public AutoPlayerConfiguration(String eventUidAsString, String leaderboardName, boolean fullscreenMode, long timeToSwitchBeforeRaceStartInSeconds) {
this.eventUidAsString = eventUidAsString;
this.leaderboardName = leaderboardName;
this.fullscreenMode = fullscreenMode;
this.timeToSwitchBeforeRaceStartInSeconds = timeToSwitchBeforeRaceStartInSeconds;
}
public String getEventUidAsString() {
@@ -27,4 +30,8 @@ public class AutoPlayerConfiguration {
public boolean isFullscreenMode() {
return fullscreenMode;
}
public long getTimeToSwitchBeforeRaceStartInSeconds() {
return timeToSwitchBeforeRaceStartInSeconds;
}
}
@@ -19,8 +19,9 @@ public class PlayerPlace extends AbstractBasePlace {
String eventUuidAsString = getParameter(AutoPlayerConfiguration.PARAM_EVENTID);
String leaderboardName= getParameter(AutoPlayerConfiguration.PARAM_LEADEROARD_NAME);
Boolean fullscreen = Boolean.valueOf(getParameter(AutoPlayerConfiguration.PARAM_FULLSCREEN));
Integer timeToSwitchBeforeRaceStartInSeconds = Integer.valueOf(getParameter(AutoPlayerConfiguration.PARAM_TIME_TO_SWITCH_BEFORE_RACE_START));
this.playerConfiguration = new AutoPlayerConfiguration(eventUuidAsString, leaderboardName, fullscreen);
this.playerConfiguration = new AutoPlayerConfiguration(eventUuidAsString, leaderboardName, fullscreen, timeToSwitchBeforeRaceStartInSeconds);
this.leaderboardPerspectiveSettings = null;
this.raceboardPerspectiveSettings = null;
}
@@ -29,7 +30,8 @@ public class PlayerPlace extends AbstractBasePlace {
Pair<RaceBoardPerspectiveSettings, CompositeSettings> raceboardPerspectiveSettings) {
super(AutoPlayerConfiguration.PARAM_EVENTID, playerConfiguration.getEventUidAsString(),
AutoPlayerConfiguration.PARAM_FULLSCREEN, String.valueOf(playerConfiguration.isFullscreenMode()),
AutoPlayerConfiguration.PARAM_LEADEROARD_NAME, playerConfiguration.getLeaderboardName());
AutoPlayerConfiguration.PARAM_LEADEROARD_NAME, playerConfiguration.getLeaderboardName(),
AutoPlayerConfiguration.PARAM_TIME_TO_SWITCH_BEFORE_RACE_START, String.valueOf(playerConfiguration.getTimeToSwitchBeforeRaceStartInSeconds()));
this.playerConfiguration = playerConfiguration;
this.leaderboardPerspectiveSettings = leaderboardPerspectiveSettings;
this.raceboardPerspectiveSettings = raceboardPerspectiveSettings;
@@ -20,8 +20,8 @@ import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.EventBus;
import com.sap.sailing.domain.common.DetailType;
@@ -31,8 +31,8 @@ import com.sap.sailing.gwt.autoplay.client.app.PlaceNavigator;
import com.sap.sailing.gwt.autoplay.client.place.player.AutoPlayerConfiguration;
import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeader;
import com.sap.sailing.gwt.common.client.SharedResources;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.common.client.i18n.TextMessages;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.ui.client.shared.charts.AbstractCompetitorRaceChart;
import com.sap.sailing.gwt.ui.client.shared.charts.ChartSettings;
import com.sap.sailing.gwt.ui.client.shared.charts.MultiCompetitorRaceChartSettings;
@@ -71,7 +71,7 @@ public class DesktopStartView extends Composite implements StartView {
@UiField FlowPanel raceboardPerspectiveSettingsPanel;
@UiField CheckBox autoSwitchToRaceboard;
@UiField TextBox timeToRaceStartInSeconds;
@UiField IntegerBox timeToRaceStartInSeconds;
private final PlaceNavigator navigator;
private final EventBus eventBus;
@@ -80,7 +80,7 @@ public class DesktopStartView extends Composite implements StartView {
private ProxyLeaderboardPerspective leaderboardPerspective;
private ProxyRaceBoardPerspective raceboardPerspective;
private final int defaultTimeToStartTimeInSeconds = 180;
private final int defaultTimeToRaceStartTimeInSeconds = 180;
private final Map<Perspective<?>, CompositeSettings> perspectiveSettings;
public DesktopStartView(PlaceNavigator navigator, EventBus eventBus) {
@@ -117,7 +117,7 @@ public class DesktopStartView extends Composite implements StartView {
startInFullscreenModeBox.setValue(true);
autoSwitchToRaceboard.setValue(true);
timeToRaceStartInSeconds.setValue(String.valueOf(defaultTimeToStartTimeInSeconds));
timeToRaceStartInSeconds.setValue(defaultTimeToRaceStartTimeInSeconds);
leaderboardSelectionUi.getStyle().setVisibility(Visibility.HIDDEN);
screenConfigurationUi.getStyle().setVisibility(Visibility.HIDDEN);
@@ -243,7 +243,7 @@ public class DesktopStartView extends Composite implements StartView {
if(selectedEvent != null && selectedLeaderboardName != null) {
navigator.goToPlayer(new AutoPlayerConfiguration(selectedEvent.id.toString(), selectedLeaderboardName,
startInFullscreenModeBox.getValue()), leaderboardPerspectiveSettings, raceboardPerspectiveSettings);
startInFullscreenModeBox.getValue(), timeToRaceStartInSeconds.getValue()), leaderboardPerspectiveSettings, raceboardPerspectiveSettings);
}
}
@@ -73,7 +73,7 @@
<span>...when to start is less than (in s):</span>
</div>
<div class="{res.mediaCss.small12} {res.mediaCss.medium6} {res.mediaCss.large9} {res.mediaCss.columns}">
<g:TextBox ui:field="timeToRaceStartInSeconds" />
<g:IntegerBox ui:field="timeToRaceStartInSeconds" />
</div>
</div>
<div class="{res.mediaCss.grid} {style.row} {style.headline}">