Adjusted loading of statistics for different event type

This commit is contained in:
Benjamin Barth committed 2015-09-21 13:24:46 +02:00
1 parent 70693dc276
commit 3e93e89b97
9 files changed
+79 -162

No files matched your search

@@ -76,7 +76,7 @@ public class MultiregattaOverviewTabView extends Composite implements Multiregat
refreshManager.add(liveRacesListUi.getRefreshable(), new GetLiveRacesForEventAction(currentPresenter.getCtx().getEventDTO().getId()));
refreshManager.add(regattaFilterList, new GetRegattaListViewAction(currentPresenter.getCtx().getEventDTO().getId()));
refreshManager.add(statisticsBoxUi, new GetEventStatisticsAction(currentPresenter.getCtx().getEventDTO().getId(), true));
refreshManager.add(statisticsBoxUi, new GetEventStatisticsAction(currentPresenter.getCtx().getEventDTO().getId()));
contentArea.setWidget(this);
}
@@ -19,9 +19,9 @@ import com.sap.sailing.gwt.home.desktop.partials.multiregattalist.MultiRegattaLi
import com.sap.sailing.gwt.home.desktop.partials.standings.StandingsList;
import com.sap.sailing.gwt.home.desktop.partials.statistics.StatisticsBox;
import com.sap.sailing.gwt.home.shared.ExperimentalFeatures;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetEventStatisticsAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetLiveRacesForRegattaAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetMiniLeaderbordAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRegattaStatisticsAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRegattaWithProgressAction;
import com.sap.sailing.gwt.ui.shared.dispatch.regatta.RegattaWithProgressDTO;
import com.sap.sailing.gwt.ui.shared.eventview.EventViewDTO.EventType;
@@ -83,7 +83,7 @@ public class RegattaOverviewTabView extends Composite implements RegattaTabView<
refreshManager.add(liveRacesListUi.getRefreshable(), new GetLiveRacesForRegattaAction(currentPresenter.getCtx().getEventDTO()
.getId(), currentPresenter.getCtx().getRegattaId()));
refreshManager.add(standingsUi, new GetMiniLeaderbordAction(myPlace.getCtx().getEventDTO().getId(), myPlace.getRegattaId(), 5));
refreshManager.add(statisticsBoxUi, new GetEventStatisticsAction(myPlace.getCtx().getEventDTO().getId(), true));
refreshManager.add(statisticsBoxUi, new GetRegattaStatisticsAction(myPlace.getCtx().getEventDTO().getId(), myPlace.getRegattaId()));
contentArea.setWidget(this);
}
@@ -20,6 +20,7 @@ import com.sap.sailing.gwt.ui.shared.dispatch.event.GetEventOverviewStageAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetEventStatisticsAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetLiveRacesForRegattaAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetMiniLeaderbordAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRegattaStatisticsAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRegattaWithProgressAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRegattasAndLiveRacesForEventAction;
import com.sap.sailing.gwt.ui.shared.general.EventState;
@@ -108,7 +109,8 @@ public class EventViewImpl extends AbstractEventView<EventView.Presenter> implem
private void setupStatisticsBox(Panel container) {
statisticsBoxUi = new StatisticsBox(isMultiRegattaEvent());
refreshManager.add(statisticsBoxUi, new GetEventStatisticsAction(getEventId()));
refreshManager.add(statisticsBoxUi, isMultiRegattaEvent() ? new GetEventStatisticsAction(getEventId())
: new GetRegattaStatisticsAction(getEventId(), getRegattaId()));
container.add(statisticsBoxUi);
}
@@ -12,9 +12,9 @@ import com.sap.sailing.gwt.home.mobile.partials.statisticsBox.StatisticsBox;
import com.sap.sailing.gwt.home.mobile.places.QuickfinderPresenter;
import com.sap.sailing.gwt.home.mobile.places.event.AbstractEventView;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetEventStatisticsAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetLiveRacesForRegattaAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetMiniLeaderbordAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRegattaStatisticsAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRegattaWithProgressAction;
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
@@ -57,8 +57,7 @@ public class RegattaViewImpl extends AbstractEventView<RegattaView.Presenter> im
private void initStatisticsUi(Panel container) {
statisticsUi = new StatisticsBox(false);
// FIXME only show statistics of the regatta
refreshManager.add(statisticsUi, new GetEventStatisticsAction(getEventId(), true));
refreshManager.add(statisticsUi, new GetRegattaStatisticsAction(getEventId(), getRegattaId()));
container.add(statisticsUi);
}
@@ -16,8 +16,8 @@ import com.sap.sailing.gwt.home.mobile.partials.seriesheader.SeriesHeader;
import com.sap.sailing.gwt.home.mobile.partials.statisticsBox.StatisticsBox;
import com.sap.sailing.gwt.home.mobile.places.QuickfinderPresenter;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetEventStatisticsAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetMiniOverallLeaderbordAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetSeriesStatisticsAction;
import com.sap.sailing.gwt.ui.shared.fakeseries.EventSeriesViewDTO;
import com.sap.sailing.gwt.ui.shared.general.EventMetadataDTO;
import com.sap.sailing.gwt.ui.shared.general.EventState;
@@ -75,6 +75,6 @@ public class SeriesViewImpl extends Composite implements SeriesView {
private void setupStatisticsBox(EventSeriesViewDTO series) {
statisticsBoxUi = new StatisticsBox(true);
refreshManager.add(statisticsBoxUi, new GetEventStatisticsAction(series.getId(), false));
refreshManager.add(statisticsBoxUi, new GetSeriesStatisticsAction(series.getId()));
}
}
@@ -106,6 +106,9 @@ public final class EventActionUtil {
public static void forLeaderboardsOfEvent(DispatchContext context, UUID eventId, LeaderboardCallback callback) {
RacingEventService service = context.getRacingEventService();
Event event = service.getEvent(eventId);
if (event == null) {
throw new RuntimeException("Event not found");
}
forLeaderboardsOfEvent(context, event, callback);
}
@@ -1,175 +1,28 @@
package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.Mark;
import com.sap.sailing.domain.common.Distance;
import com.sap.sailing.domain.common.Speed;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.WindSourceType;
import com.sap.sailing.domain.common.tracking.GPSFix;
import com.sap.sailing.domain.common.tracking.GPSFixMoving;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.domain.tracking.GPSFixTrack;
import com.sap.sailing.domain.tracking.MarkPassing;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.WindTrack;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sse.common.Duration;
import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.common.Util.Triple;
import com.sap.sse.common.impl.MillisecondsTimePoint;
public class GetEventStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>> {
private static final Logger logger = Logger.getLogger(GetEventStatisticsAction.class.getName());
private static boolean CALCULATE_MAX_SPEED = false;
private static boolean CALCULATE_SAILED_MILES = true;
private UUID eventId;
private boolean onlyCurrentEvent;
@SuppressWarnings("unused")
private GetEventStatisticsAction() {
protected GetEventStatisticsAction() {
}
public GetEventStatisticsAction(UUID eventId) {
this(eventId, true);
}
public GetEventStatisticsAction(UUID eventId, boolean onlyCurrentEvent) {
this.eventId = eventId;
this.onlyCurrentEvent = onlyCurrentEvent;
}
@Override
@GwtIncompatible
public ResultWithTTL<EventStatisticsDTO> execute(DispatchContext context) {
Event event = context.getRacingEventService().getEvent(eventId);
if (event == null) {
throw new RuntimeException("Event not found");
}
int competitors = 0;
int races = 0;
int trackedRaces = 0;
int regattas = 0;
long numberOfGPSFixes = 0;
long numberOfWindFixes = 0;
Distance totalDistanceTraveled = Distance.NULL;
Triple<Competitor, Speed, TimePoint> maxSpeed = null;
final TimePoint now = MillisecondsTimePoint.now();
final Set<Leaderboard> leaderboards = new HashSet<>();
final boolean filterLeaderboards = onlyCurrentEvent && HomeServiceUtil.isFakeSeries(event);
for (LeaderboardGroup lg : event.getLeaderboardGroups()) {
for (Leaderboard leaderboard : lg.getLeaderboards()) {
if(!filterLeaderboards || HomeServiceUtil.isPartOfEvent(event, leaderboard)) {
leaderboards.add(leaderboard);
}
}
}
for (Leaderboard leaderboard : leaderboards) {
competitors += HomeServiceUtil.calculateCompetitorsCount(leaderboard);
races += HomeServiceUtil.calculateRaceColumnCount(leaderboard);
trackedRaces += HomeServiceUtil.calculateTrackedRaceCount(leaderboard);
regattas++;
String disableStats = System.getenv("DISABLE_STATS");
if (disableStats == null || "false".equals(disableStats)) {
try {
for (TrackedRace trackedRace : leaderboard.getTrackedRaces()) {
for (Competitor competitor : trackedRace.getRace().getCompetitors()) {
GPSFixTrack<Competitor, GPSFixMoving> competitorTrack = trackedRace.getTrack(competitor);
competitorTrack.lockForRead();
try {
numberOfGPSFixes += Util.size(competitorTrack.getRawFixes());
} finally {
competitorTrack.unlockAfterRead();
}
if (trackedRace.hasStarted(now)) {
final NavigableSet<MarkPassing> competitorMarkPassings = trackedRace
.getMarkPassings(competitor);
MarkPassing lastMarkPassingBeforeNow = null;
trackedRace.lockForRead(competitorMarkPassings);
try {
MarkPassing next = null;
Iterator<MarkPassing> i = competitorMarkPassings.descendingIterator();
while (i.hasNext() && (next = i.next()).getTimePoint().after(now))
;
if (next != null) {
lastMarkPassingBeforeNow = next;
}
} finally {
trackedRace.unlockAfterRead(competitorMarkPassings);
}
if (lastMarkPassingBeforeNow != null) {
// competitor has started and has at least one mark passing before now; compute
// distance traveled up to that mark passing, increasing likelihood of cache hits as compared to
// using "now" as the query time point
if (CALCULATE_SAILED_MILES) {
totalDistanceTraveled = totalDistanceTraveled.add(competitorTrack
.getDistanceTraveled(trackedRace.getStartOfRace(),
lastMarkPassingBeforeNow.getTimePoint()));
}
if (CALCULATE_MAX_SPEED) {
Pair<GPSFixMoving, Speed> competitorMaxSpeed = competitorTrack
.getMaximumSpeedOverGround(trackedRace.getStartOfRace(),
lastMarkPassingBeforeNow.getTimePoint());
if (competitorMaxSpeed != null
&& (maxSpeed == null || competitorMaxSpeed.getB().compareTo(
maxSpeed.getB()) > 0)
// only accept "reasonable" max speeds
&& competitorMaxSpeed.getB().compareTo(
GPSFixTrack.DEFAULT_MAX_SPEED_FOR_SMOOTHING) <= 0) {
maxSpeed = new Triple<>(competitor, competitorMaxSpeed.getB(),
competitorMaxSpeed.getA().getTimePoint());
}
}
}
}
}
for (Mark mark : trackedRace.getMarks()) {
GPSFixTrack<Mark, GPSFix> markTrack = trackedRace.getOrCreateTrack(mark);
markTrack.lockForRead();
try {
numberOfGPSFixes += Util.size(markTrack.getRawFixes());
} finally {
markTrack.unlockAfterRead();
}
}
for (WindSource windSource : trackedRace.getWindSources()) {
// don't count the "virtual" wind sources
if (windSource.canBeStored() || windSource.getType() == WindSourceType.RACECOMMITTEE) {
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
windTrack.lockForRead();
try {
numberOfWindFixes += Util.size(windTrack.getRawFixes());
} finally {
windTrack.unlockAfterRead();
}
}
}
}
} catch (Exception e) {
logger.log(Level.WARNING, "Exception during calculation of event statistics", e);
}
}
}
if (totalDistanceTraveled == Distance.NULL) {
totalDistanceTraveled = null;
}
return new ResultWithTTL<EventStatisticsDTO>(Duration.ONE_MINUTE.times(5), new EventStatisticsDTO(regattas,
competitors, races, trackedRaces, numberOfGPSFixes, numberOfWindFixes, maxSpeed, totalDistanceTraveled));
public ResultWithTTL<EventStatisticsDTO> execute(DispatchContext context) throws Exception {
StatisticsCalculator statisticsCalculator = new StatisticsCalculator();
EventActionUtil.forLeaderboardsOfEvent(context, eventId, statisticsCalculator);
return statisticsCalculator.getResult();
}
}
@@ -0,0 +1,31 @@
package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
public class GetRegattaStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>>{
private UUID eventId;
private String regattaId;
protected GetRegattaStatisticsAction() {
}
public GetRegattaStatisticsAction(UUID eventId, String regattaId) {
this.eventId = eventId;
this.regattaId = regattaId;
}
@Override
@GwtIncompatible
public ResultWithTTL<EventStatisticsDTO> execute(DispatchContext context) throws Exception {
StatisticsCalculator statisticsCalculator = new StatisticsCalculator();
statisticsCalculator.doForLeaderboard(EventActionUtil.getLeaderboardContext(context, eventId, regattaId));
return statisticsCalculator.getResult();
}
}
@@ -0,0 +1,29 @@
package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
public class GetSeriesStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>>{
private UUID seriesId;
protected GetSeriesStatisticsAction() {
}
public GetSeriesStatisticsAction(UUID seriesId) {
this.seriesId = seriesId;
}
@Override
@GwtIncompatible
public ResultWithTTL<EventStatisticsDTO> execute(DispatchContext context) throws Exception {
StatisticsCalculator statisticsCalculator = new StatisticsCalculator();
EventActionUtil.forLeaderboardsOfEvent(context, seriesId, statisticsCalculator);
return statisticsCalculator.getResult();
}
}