Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected void onInitialize() {
timePeriodComboBox.setConverter(timePeriodStringConverter());

timePeriodComboBox.getItems().addAll(TimePeriod.values());
timePeriodComboBox.setValue(TimePeriod.ALL_TIME);
timePeriodComboBox.setValue(TimePeriod.LAST_MONTH);

ratingTypeComboBox.setConverter(leaderboardStringConverter());

Expand Down Expand Up @@ -472,7 +472,11 @@ public void onRatingTypeChange() {
}

private Mono<Void> loadStatistics(Leaderboard leaderboard) {
return statisticsService.getRatingHistory(player, leaderboard)
TimePeriod timePeriod = timePeriodComboBox.getValue();
OffsetDateTime since = timePeriod == TimePeriod.ALL_TIME
? null
: OffsetDateTime.of(timePeriod.getDate(), ZoneOffset.UTC);
return statisticsService.getRatingHistory(player, leaderboard, since)
.collectList()
.doOnNext(ratingHistory -> ratingData = ratingHistory)
.doOnError(throwable -> {
Expand Down
34 changes: 26 additions & 8 deletions src/main/java/com/faforever/client/stats/StatisticsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import com.faforever.client.mapstruct.LeaderboardMapper;
import com.faforever.commons.api.elide.ElideNavigator;
import com.faforever.commons.api.elide.ElideNavigatorOnCollection;
import jakarta.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import java.time.OffsetDateTime;

import static com.faforever.commons.api.elide.ElideNavigator.qBuilder;


Expand All @@ -26,18 +29,33 @@ public class StatisticsService {
private final LeaderboardMapper leaderboardMapper;

@Cacheable(value = CacheNames.RATING_HISTORY, sync = true)
public Flux<LeaderboardRatingJournal> getRatingHistory(PlayerInfo player, Leaderboard leaderboard) {
public Flux<LeaderboardRatingJournal> getRatingHistory(PlayerInfo player, Leaderboard leaderboard,
@Nullable OffsetDateTime since) {
ElideNavigatorOnCollection<com.faforever.commons.api.dto.LeaderboardRatingJournal> navigator = ElideNavigator.of(
com.faforever.commons.api.dto.LeaderboardRatingJournal.class)
.collection()
.setFilter(
qBuilder().intNum(
"gamePlayerStats.player.id")
.eq(player.getId())
.and()
.intNum(
"leaderboard.id")
.eq(leaderboard.id()))
since != null
? qBuilder().instant(
"gamePlayerStats.scoreTime")
.after(
since.toInstant(),
false)
.and()
.intNum(
"gamePlayerStats.player.id")
.eq(player.getId())
.and()
.intNum(
"leaderboard.id")
.eq(leaderboard.id())
: qBuilder().intNum(
"gamePlayerStats.player.id")
.eq(player.getId())
.and()
.intNum(
"leaderboard.id")
.eq(leaderboard.id()))
.pageSize(
fafApiAccessor.getMaxPageSize());
return fafApiAccessor.getAll(navigator).map(leaderboardMapper::map).cache();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/theme/user_info_window.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<Insets top="10.0"/>
</padding>
<children>
<ComboBox fx:id="timePeriodComboBox" onAction="#plotPlayerRatingGraph"/>
<ComboBox fx:id="timePeriodComboBox" onAction="#onRatingTypeChange"/>
<ComboBox fx:id="ratingTypeComboBox" onAction="#onRatingTypeChange"/>
</children>
</HBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setUp() throws Exception {
lenient().when(leaderboardService.getLeaderboards()).thenReturn(Flux.just(leaderboard));
lenient().when(leaderboardService.getEntriesForPlayer(eq(player)))
.thenReturn(Flux.just(Instancio.create(LeaderboardEntry.class)));
lenient().when(statisticsService.getRatingHistory(eq(player), any()))
lenient().when(statisticsService.getRatingHistory(eq(player), any(), any()))
.thenReturn(Flux.fromIterable(Instancio.ofList(LeaderboardRatingJournal.class)
.size(2)
.set(field(LeaderboardRatingJournal::meanBefore), 1500d)
Expand Down Expand Up @@ -183,6 +183,6 @@ public void testOnRatingTypeChange() {
testSetPlayerInfoBean();
instance.ratingTypeComboBox.setValue(leaderboard);
instance.onRatingTypeChange();
verify(statisticsService, times(2)).getRatingHistory(player, leaderboard);
verify(statisticsService, times(2)).getRatingHistory(eq(player), eq(leaderboard), any());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testGetStatisticsForPlayer() throws Exception {
PlayerInfo player = PlayerInfoBuilder.create().defaultValues().username("junit").get();
Flux<ElideEntity> resultFlux = Flux.just(leaderboardMapper.map(leaderboardRatingJournal));
when(fafApiAccessor.getAll(any())).thenReturn(resultFlux);
StepVerifier.create(instance.getRatingHistory(player, leaderboard)).expectNextCount(1)
StepVerifier.create(instance.getRatingHistory(player, leaderboard, null)).expectNextCount(1)
.expectComplete()
.verify();
verify(fafApiAccessor).getAll(argThat(
Expand Down