From e8cbec829ffa2c9675b58c70295250a51d572357 Mon Sep 17 00:00:00 2001 From: Palmarino DiMarco Date: Sun, 28 Apr 2024 20:55:05 -0400 Subject: [PATCH 1/2] Changed the average for leaderboard so that the number is summed separately from the rest of the data. --- .../AverageMovingSpeedLeaderboardFragment.java | 13 ++++++++----- .../leaderboardFragment/LeaderboardFragment.java | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java index 52250470e..fb3ee944c 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java +++ b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java @@ -20,13 +20,15 @@ protected List calculateLatestAverageRankingsData(List { diff --git a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/LeaderboardFragment.java b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/LeaderboardFragment.java index 316b27d12..aab2b71f1 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/LeaderboardFragment.java +++ b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/LeaderboardFragment.java @@ -102,6 +102,8 @@ protected class SummedStatTrackUser { private LeaderboardPagerAdapter.PlaceHolderTrackUser placeHolderTrackUser; private int sumFactorCount; + private Object scoreSum; + public SummedStatTrackUser(LeaderboardPagerAdapter.PlaceHolderTrackUser placeHolderTrackUser) { this.placeHolderTrackUser = placeHolderTrackUser; sumFactorCount = 1; @@ -118,5 +120,13 @@ public int getSumFactorCount() { public void incrementSumFactorCount() { sumFactorCount++; } + + public Object getScoreSum() { + return scoreSum; + } + + public void setScoreSum(Object scoreSum) { + this.scoreSum = scoreSum; + } } } \ No newline at end of file From a12db3676eb7a11436c18e6a91fdeb4dc1b494c5 Mon Sep 17 00:00:00 2001 From: Palmarino DiMarco Date: Sun, 28 Apr 2024 21:24:09 -0400 Subject: [PATCH 2/2] Patched all the LeaderboardFragment child classes so that they do not change the sent records --- .../AverageMovingSpeedLeaderboardFragment.java | 2 +- .../DistanceLeaderboardFragment.java | 13 ++++++++----- .../LeaderboardFragment.java | 5 +++++ .../MovingTimeLeaderboardFragment.java | 17 +++++++++-------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java index fb3ee944c..71bba0269 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java +++ b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/leaderboardFragment/AverageMovingSpeedLeaderboardFragment.java @@ -21,7 +21,7 @@ protected List calculateLatestAverageRankingsData(List calculateLatestAverageRankingsData(List calculateLatestAverageRankingsData(List new SummedStatTrackUser(trackUser)); + statsMap.computeIfAbsent(trackUser.nickname, k -> new SummedStatTrackUser(trackUser, trackUser.trackStatistics.getMovingTime().abs())); SummedStatTrackUser existingRecord = statsMap.get(trackUser.nickname); - existingRecord.getPlaceHolderTrackUser().trackStatistics.setMovingTime( - existingRecord.getPlaceHolderTrackUser().trackStatistics.getMovingTime().plus( - trackUser.trackStatistics.getMovingTime() - ) + Duration oldDuration = (Duration)existingRecord.getScoreSum(); + existingRecord.setScoreSum( + oldDuration.plus(trackUser.trackStatistics.getMovingTime()) ); existingRecord.incrementSumFactorCount(); } @@ -36,7 +35,8 @@ protected List calculateLatestAverageRankingsData(List calculateLatestAverageRankingsData(List { @Override public int compare(SummedStatTrackUser user1, SummedStatTrackUser user2) { - return user2.getPlaceHolderTrackUser().trackStatistics.getMovingTime().compareTo( - user1.getPlaceHolderTrackUser().trackStatistics.getMovingTime()); + Duration user1MovingTime = (Duration) user1.getScoreSum(); + Duration user2MovingTime = (Duration) user2.getScoreSum(); + return user2MovingTime.compareTo(user1MovingTime); } }