mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-02 18:33:54 +00:00
fixed sorting and display for 0 total points; see also bug 509
This commit is contained in:
1 parent
2310819b99
commit
89cfb5be93
9 files changed
+55
-33
No files matched your search
+1
-1
@@ -18,7 +18,7 @@ public class LeaderboardPanelMock extends LeaderboardPanel {
|
||||
String leaderboardName, ErrorReporter errorReporter,
|
||||
StringMessages stringConstants) {
|
||||
super(sailingService, null, LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(
|
||||
/* racesToShow */null, /* namesOfRacesToShow */ null, /* autoExpandFirstRace */false), new CompetitorSelectionModel(
|
||||
/* racesToShow */null, /* namesOfRacesToShow */ null, null, /* autoExpandFirstRace */false), new CompetitorSelectionModel(
|
||||
/* hasMultiSelection */true), leaderboardName, null, errorReporter, stringConstants, null);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class AdminConsoleEntryPoint extends AbstractEntryPoint implements EventR
|
||||
windPanel.setSize("90%", "90%");
|
||||
tabPanel.add(windPanel, stringMessages.wind(), /* asHTML */ false);
|
||||
LeaderboardSettings defaultLeaderboardSettings = LeaderboardSettingsFactory.getInstance()
|
||||
.createNewDefaultSettings(/* racesToShow */ null, /* namesOfRacesToShow */ null, /* autoExpandFirstRace */false);
|
||||
.createNewDefaultSettings(/* racesToShow */ null, /* namesOfRacesToShow */ null, null, /* autoExpandFirstRace */false);
|
||||
final LeaderboardPanel defaultLeaderboardPanel = new LeaderboardPanel(sailingService, asyncActionsExecutor,
|
||||
defaultLeaderboardSettings,
|
||||
/* preSelectedRace */null, new CompetitorSelectionModel(/* hasMultiSelection */true),
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class LeaderboardEntryPoint extends AbstractEntryPoint {
|
||||
contentScrollPanel.setWidget(tvViewPanel);
|
||||
} else {
|
||||
LeaderboardPanel leaderboardPanel = new LeaderboardPanel(sailingService, new AsyncActionsExecutor(),
|
||||
LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, /* autoExpandFirstRace */ false),
|
||||
LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, null, /* autoExpandFirstRace */ false),
|
||||
/* preSelectedRace */ null, new CompetitorSelectionModel(/* hasMultiSelection */ true),
|
||||
new Timer(PlayModes.Replay, /* delayBetweenAutoAdvancesInMilliseconds */3000l),
|
||||
leaderboardName, leaderboardGroupName,
|
||||
|
||||
+29
-11
@@ -200,6 +200,13 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
private PlayModes oldPlayMode;
|
||||
|
||||
private final AsyncActionsExecutor asyncActionsExecutor;
|
||||
|
||||
/**
|
||||
* See also {@link #getDefaultSortColumn()}. If no other column is explicitly selected for sorting and this attribute
|
||||
* holds a non-<code>null</code> string identifying a valid race by name that is represented in this leaderboard panel
|
||||
* then sort by it. Otherwise, default sorting will default to the overall rank column.
|
||||
*/
|
||||
private String raceNameForDefaultSorting;
|
||||
|
||||
private class SettingsClickHandler implements ClickHandler {
|
||||
private final StringMessages stringMessages;
|
||||
@@ -447,11 +454,11 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
if (entry.reasonForMaxPoints.equals("NONE")) {
|
||||
if (!entry.discarded) {
|
||||
html.appendHtmlConstant("<span style=\"font-weight: bold;\">");
|
||||
html.append(entry.totalPoints);
|
||||
html.appendHtmlConstant(entry.totalPoints == 0 ? "" : ""+entry.totalPoints);
|
||||
html.appendHtmlConstant("</span>");
|
||||
} else {
|
||||
html.appendHtmlConstant(" <span style=\"opacity: 0.5;\"><del>");
|
||||
html.append(entry.netPoints);
|
||||
html.appendHtmlConstant(entry.netPoints == 0 ? "" : ""+entry.netPoints);
|
||||
html.appendHtmlConstant("</del></span>");
|
||||
}
|
||||
} else {
|
||||
@@ -791,7 +798,7 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
@Override
|
||||
public String getValue(LeaderboardRowDTO object) {
|
||||
int totalPoints = getLeaderboard().getTotalPoints(object);
|
||||
return "" + totalPoints;
|
||||
return "" + (totalPoints==0 ? "" : totalPoints);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -859,7 +866,8 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
|
||||
@Override
|
||||
public String getValue(LeaderboardRowDTO object) {
|
||||
return "" + getLeaderboard().getRank(object.competitor);
|
||||
final int rank = getLeaderboard().getRank(object.competitor);
|
||||
return "" + (rank == 0 ? "" : rank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -867,7 +875,9 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
return new Comparator<LeaderboardRowDTO>() {
|
||||
@Override
|
||||
public int compare(LeaderboardRowDTO o1, LeaderboardRowDTO o2) {
|
||||
return getLeaderboard().getRank(o1.competitor) - getLeaderboard().getRank(o2.competitor);
|
||||
final int rank1 = getLeaderboard().getRank(o1.competitor);
|
||||
final int rank2 = getLeaderboard().getRank(o2.competitor);
|
||||
return rank1 == 0 ? rank2 == 0 ? 0 : 1 : rank2 == 0 ? -1 : rank1 - rank2;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1019,10 +1029,7 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
}
|
||||
contentPanel.add(getLeaderboardTable());
|
||||
setWidget(contentPanel);
|
||||
if (settings.getNameOfRaceToSort() != null) {
|
||||
RaceColumn<?> column = getRaceColumnByRaceName(settings.getNameOfRaceToSort());
|
||||
sort(column, settings.isSortAscending());
|
||||
}
|
||||
raceNameForDefaultSorting = settings.getNameOfRaceToSort();
|
||||
}
|
||||
|
||||
private RaceInLeaderboardDTO getRaceByName(String raceName) {
|
||||
@@ -1224,7 +1231,7 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
if (comparator != null) {
|
||||
Collections.sort(getData().getList(), comparator);
|
||||
} else {
|
||||
RankColumn columnToSortFor = getRankColumn();
|
||||
SortableColumn<LeaderboardRowDTO, ?> columnToSortFor = getDefaultSortColumn();
|
||||
// if no sorting was selected, sort by ascending rank and mark
|
||||
// table header so
|
||||
sort(columnToSortFor, true);
|
||||
@@ -1240,6 +1247,17 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
}
|
||||
}
|
||||
|
||||
private SortableColumn<LeaderboardRowDTO, ?> getDefaultSortColumn() {
|
||||
SortableColumn<LeaderboardRowDTO, ?> defaultSortColumn = null;
|
||||
if (raceNameForDefaultSorting != null) {
|
||||
defaultSortColumn = getRaceColumnByRaceName(raceNameForDefaultSorting);
|
||||
}
|
||||
if (defaultSortColumn == null) {
|
||||
defaultSortColumn = getRankColumn();
|
||||
}
|
||||
return defaultSortColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the leaderboard contents in ascending order according to <code>columnToSortFor</code>'s comparator and
|
||||
* marks the table's column sort list so.
|
||||
@@ -1546,7 +1564,7 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
|
||||
|
||||
private void ensureRankColumn() {
|
||||
if (getLeaderboardTable().getColumnCount() == RANK_COLUMN_INDEX) {
|
||||
addColumn(getRankColumn());
|
||||
addColumn(getDefaultSortColumn());
|
||||
} else {
|
||||
if (!(getLeaderboardTable().getColumn(RANK_COLUMN_INDEX) instanceof RankColumn)) {
|
||||
throw new RuntimeException("The first column must always be the rank column but it was of type "
|
||||
|
||||
+6
-4
@@ -61,8 +61,9 @@ public class LeaderboardSettingsFactory {
|
||||
/* delay to live */ null, /* name of race to sort */ nameOfRaceToSort, /* ascending */ true);
|
||||
break;
|
||||
case Replay:
|
||||
settings = createNewDefaultSettings(namesOfRaceColumnsToShow, namesOfRacesToShow, /* autoExpandFirstRace */ nameOfRaceColumnToShow != null);
|
||||
break;
|
||||
settings = createNewDefaultSettings(namesOfRaceColumnsToShow, namesOfRacesToShow, nameOfRaceToSort, /* autoExpandFirstRace */
|
||||
nameOfRaceColumnToShow != null);
|
||||
break;
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
@@ -76,9 +77,10 @@ public class LeaderboardSettingsFactory {
|
||||
* @param namesOfRacesToShow
|
||||
* alternatively, races to show can also be specified by their race names; if not <code>null</code>,
|
||||
* <code>namesOfRaceColumnsToShow</code> must be <code>null
|
||||
* @param nameOfRaceToSort TODO
|
||||
*/
|
||||
public LeaderboardSettings createNewDefaultSettings(List<String> namesOfRaceColumnsToShow,
|
||||
List<String> namesOfRacesToShow, boolean autoExpandFirstRace) {
|
||||
List<String> namesOfRacesToShow, String nameOfRaceToSort, boolean autoExpandFirstRace) {
|
||||
if (namesOfRaceColumnsToShow != null && namesOfRacesToShow != null) {
|
||||
throw new IllegalArgumentException("Can specify race columns either by column or by race name, not both");
|
||||
}
|
||||
@@ -95,6 +97,6 @@ public class LeaderboardSettingsFactory {
|
||||
return new LeaderboardSettings(maneuverDetails, legDetails, raceDetails, namesOfRaceColumnsToShow,
|
||||
namesOfRacesToShow,
|
||||
autoExpandFirstRace, /* refresh interval */ null,
|
||||
/* delay to live */ null, /* sort by column */ null, /* ascending */ true);
|
||||
/* delay to live */ null, /* sort by column */ nameOfRaceToSort, /* ascending */ true);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -82,7 +82,7 @@ public class TVViewPanel extends SimplePanel implements RaceTimesInfoProviderLis
|
||||
}
|
||||
|
||||
private LeaderboardPanel createLeaderboardPanel(String leaderboardName) {
|
||||
LeaderboardSettings settings = LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, /* autoExpandFirstRace */ false);
|
||||
LeaderboardSettings settings = LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, null, /* autoExpandFirstRace */ false);
|
||||
CompetitorSelectionModel selectionModel = new CompetitorSelectionModel(/* hasMultiSelection */ true);
|
||||
Timer timer = new Timer(PlayModes.Live, /* delayBetweenAutoAdvancesInMilliseconds */3000l);
|
||||
timer.play();
|
||||
@@ -131,7 +131,7 @@ public class TVViewPanel extends SimplePanel implements RaceTimesInfoProviderLis
|
||||
namesOfRaceColumnsToShow.add(race.getRaceColumnName());
|
||||
}
|
||||
LeaderboardSettings settings = LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(
|
||||
namesOfRaceColumnsToShow, null, false);
|
||||
namesOfRaceColumnsToShow, null, null, false);
|
||||
leaderboardPanel.updateSettings(settings);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
|
||||
public EditableLeaderboardPanel(SailingServiceAsync sailingService, AsyncActionsExecutor asyncActionsExecutor, String leaderboardName, String leaderboardGroupName,
|
||||
ErrorReporter errorReporter, StringMessages stringConstants, UserAgentTypes userAgentType) {
|
||||
super(sailingService, asyncActionsExecutor, LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(
|
||||
/* racesToShow */ null, /* namesOfRacesToShow */ null, /* autoExpandFirstRace */false),
|
||||
/* racesToShow */ null, /* namesOfRacesToShow */ null, null, /* autoExpandFirstRace */false),
|
||||
new CompetitorSelectionModel(/* hasMultiSelection */true),
|
||||
leaderboardName, leaderboardGroupName, errorReporter, stringConstants, userAgentType);
|
||||
}
|
||||
|
||||
+8
-9
@@ -49,9 +49,8 @@ public class RaceBoardEntryPoint extends AbstractEntryPoint {
|
||||
String leaderboardGroupNameParamValue = Window.Location.getParameter("leaderboardGroupName");
|
||||
String viewModeParamValue = Window.Location.getParameter("viewMode");
|
||||
// set the view mode for the race board
|
||||
if(viewModeParamValue != null && !viewModeParamValue.isEmpty()) {
|
||||
if (viewModeParamValue != null && !viewModeParamValue.isEmpty()) {
|
||||
try {
|
||||
|
||||
viewMode = RaceBoardViewModes.valueOf(viewModeParamValue);
|
||||
} catch (IllegalArgumentException e) {
|
||||
viewMode = RaceBoardViewModes.ONESCREEN;
|
||||
@@ -59,12 +58,12 @@ public class RaceBoardEntryPoint extends AbstractEntryPoint {
|
||||
} else {
|
||||
viewMode = RaceBoardViewModes.ONESCREEN;
|
||||
}
|
||||
if(leaderboardNameParamValue == null || leaderboardNameParamValue.isEmpty()) {
|
||||
if (leaderboardNameParamValue == null || leaderboardNameParamValue.isEmpty()) {
|
||||
leaderboardName = DefaultLeaderboardName.DEFAULT_LEADERBOARD_NAME;
|
||||
} else {
|
||||
leaderboardName = leaderboardNameParamValue;
|
||||
}
|
||||
if(leaderboardGroupNameParamValue != null && !leaderboardGroupNameParamValue.isEmpty()) {
|
||||
if (leaderboardGroupNameParamValue != null && !leaderboardGroupNameParamValue.isEmpty()) {
|
||||
leaderboardGroupName = leaderboardGroupNameParamValue;
|
||||
}
|
||||
if (eventName == null || eventName.isEmpty() || raceName == null || raceName.isEmpty()) {
|
||||
@@ -101,7 +100,7 @@ public class RaceBoardEntryPoint extends AbstractEntryPoint {
|
||||
}
|
||||
sailingService.listEvents(listEventsCallback);
|
||||
sailingService.getLeaderboardNames(getLeaderboardNamesCallback);
|
||||
if(leaderboardGroupName != null) {
|
||||
if (leaderboardGroupName != null) {
|
||||
sailingService.getLeaderboardGroupByName(leaderboardGroupNameParamValue, getLeaderboardGroupByNameCallback);
|
||||
}
|
||||
userManagementService.getUser(getUserCallback);
|
||||
@@ -126,7 +125,7 @@ public class RaceBoardEntryPoint extends AbstractEntryPoint {
|
||||
}
|
||||
}
|
||||
selectedRace = findRace(eventName, raceName, events);
|
||||
if(selectedRace == null) {
|
||||
if (selectedRace == null) {
|
||||
createErrorPage("Could not obtain a race with name " + raceName + " for an event with name " + eventName);
|
||||
return;
|
||||
}
|
||||
@@ -151,10 +150,10 @@ public class RaceBoardEntryPoint extends AbstractEntryPoint {
|
||||
|
||||
private RaceDTO findRace(String eventName, String raceName, List<EventDTO> events) {
|
||||
for (EventDTO eventDTO : events) {
|
||||
if(eventDTO.name.equals(eventName)) {
|
||||
if (eventDTO.name.equals(eventName)) {
|
||||
for (RegattaDTO regattaDTO : eventDTO.regattas) {
|
||||
for(RaceDTO raceDTO: regattaDTO.races) {
|
||||
if(raceDTO.name.equals(raceName)) {
|
||||
for (RaceDTO raceDTO: regattaDTO.races) {
|
||||
if (raceDTO.name.equals(raceName)) {
|
||||
return raceDTO;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -101,10 +101,12 @@ public class LeaderboardDTO implements IsSerializable {
|
||||
} else if (o2 == null) {
|
||||
result = 1;
|
||||
} else {
|
||||
final int totalPoints1 = getTotalPoints(o1);
|
||||
final int totalPoints2 = getTotalPoints(o2);
|
||||
if (scoredInMedalRace(o1.competitor)) {
|
||||
if (scoredInMedalRace(o2.competitor)) {
|
||||
// both scored in medal race
|
||||
result = getTotalPoints(o1) - getTotalPoints(o2);
|
||||
result = totalPoints1 - totalPoints2;
|
||||
// in case of tie, medal race points decide:
|
||||
if (result == 0) {
|
||||
result = getMedalRaceScore(o1.competitor) - getMedalRaceScore(o2.competitor);
|
||||
@@ -118,10 +120,11 @@ public class LeaderboardDTO implements IsSerializable {
|
||||
// only o2 scored in medal race, so o2 scores better, o1 scores worse = "greater"
|
||||
result = 1;
|
||||
} else {
|
||||
// neither one scored in any medal race
|
||||
result = getTotalPoints(o1) - getTotalPoints(o2);
|
||||
// neither one scored in any medal race; 0 total points means "did not participate" and ranks worse
|
||||
result = totalPoints1 == 0 ? totalPoints2 == 0 ? 0 : 1 : totalPoints2 == 0 ? -1 : totalPoints1 - totalPoints2;
|
||||
// Now if both have equal points, count races won.
|
||||
if (result == 0) {
|
||||
// TODO bug 469: not the number of races won but the better rankings count
|
||||
result = getNumberOfRacesWon(o2.competitor) - getNumberOfRacesWon(o1.competitor);
|
||||
}
|
||||
// If number of races won is still equal, use rank in last race where at least one of the two
|
||||
|
||||
Reference in new issue
Block a user