Skip to content

Commit

Permalink
Merge pull request #87 from Picard4/Group-14-Palmar
Browse files Browse the repository at this point in the history
Patched the LeaderboardFragment child classes
  • Loading branch information
Picard4 authored Apr 29, 2024
2 parents 0361d96 + a12db36 commit 2ccf5e7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ protected List<Ranking> calculateLatestAverageRankingsData(List<LeaderboardPager
continue;

if (!statsMap.containsKey(trackUser.nickname)) {
statsMap.put(trackUser.nickname, new SummedStatTrackUser(trackUser));
SummedStatTrackUser nextSummedStatTrackUser = new SummedStatTrackUser(trackUser);
nextSummedStatTrackUser.setScoreSum(new Speed(nextSummedStatTrackUser.getPlaceHolderTrackUser().trackStatistics.getAverageMovingSpeed().speed_mps()));
statsMap.put(trackUser.nickname, nextSummedStatTrackUser);
}
else {
SummedStatTrackUser existingRecord = statsMap.get(trackUser.nickname);
existingRecord.getPlaceHolderTrackUser().trackStatistics.setMaxSpeed(
new Speed(existingRecord.getPlaceHolderTrackUser().trackStatistics.getAverageMovingSpeed().speed_mps()
+ trackUser.trackStatistics.getAverageMovingSpeed().speed_mps())
Speed oldSpeed = (Speed)existingRecord.getScoreSum();
existingRecord.setScoreSum(
new Speed(oldSpeed.speed_mps() + trackUser.trackStatistics.getAverageMovingSpeed().speed_mps())
);
existingRecord.incrementSumFactorCount();
}
Expand Down Expand Up @@ -100,7 +102,8 @@ private String getAverageMovingSpeedDisplay(Speed averageMovingSpeed) {
}

private Speed getAverageSpeedFromSummedStatTrackUser(SummedStatTrackUser summedStatTrackUser) {
return new Speed(summedStatTrackUser.getPlaceHolderTrackUser().trackStatistics.getAverageMovingSpeed().speed_mps() / summedStatTrackUser.getSumFactorCount());
Speed averageSpeed = (Speed)summedStatTrackUser.getScoreSum();
return new Speed(averageSpeed.speed_mps() / summedStatTrackUser.getSumFactorCount());
}

private class SortByAverageAverageMovingSpeed implements Comparator<SummedStatTrackUser> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ protected List<Ranking> calculateLatestAverageRankingsData(List<LeaderboardPager
continue;

if (!statsMap.containsKey(trackUser.nickname)) {
statsMap.put(trackUser.nickname, new SummedStatTrackUser(trackUser));
SummedStatTrackUser nextSummedStatTrackUser = new SummedStatTrackUser(trackUser);
nextSummedStatTrackUser.setScoreSum(new Distance(nextSummedStatTrackUser.getPlaceHolderTrackUser().trackStatistics.getTotalDistance().distance_m()));
statsMap.put(trackUser.nickname, nextSummedStatTrackUser);
}
else {
SummedStatTrackUser existingRecord = statsMap.get(trackUser.nickname);
existingRecord.getPlaceHolderTrackUser().trackStatistics.setTotalDistance(
new Distance(existingRecord.getPlaceHolderTrackUser().trackStatistics.getTotalDistance().distance_m()
+ trackUser.trackStatistics.getTotalDistance().distance_m())
Distance oldDistance = (Distance)existingRecord.getScoreSum();
existingRecord.setScoreSum(
new Distance(oldDistance.distance_m() + trackUser.trackStatistics.getTotalDistance().distance_m())
);
existingRecord.incrementSumFactorCount();
}
Expand Down Expand Up @@ -76,7 +78,8 @@ private String getDistanceDisplay(Distance distance) {
}

private Distance getAverageDistanceFromSummedStatTrackUser(SummedStatTrackUser summedStatTrackUser) {
return new Distance(summedStatTrackUser.getPlaceHolderTrackUser().trackStatistics.getTotalDistance().distance_m() / summedStatTrackUser.getSumFactorCount());
Distance distance = (Distance)summedStatTrackUser.getScoreSum();
return new Distance(distance.distance_m() / summedStatTrackUser.getSumFactorCount());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ protected class SummedStatTrackUser {
private LeaderboardPagerAdapter.PlaceHolderTrackUser placeHolderTrackUser;
private int sumFactorCount;

private Object scoreSum;

public SummedStatTrackUser(LeaderboardPagerAdapter.PlaceHolderTrackUser placeHolderTrackUser) {
this.placeHolderTrackUser = placeHolderTrackUser;
sumFactorCount = 1;
}

public SummedStatTrackUser(LeaderboardPagerAdapter.PlaceHolderTrackUser placeHolderTrackUser, Object scoreSum) {
this(placeHolderTrackUser);
setScoreSum(scoreSum);
}

public LeaderboardPagerAdapter.PlaceHolderTrackUser getPlaceHolderTrackUser() {
return placeHolderTrackUser;
}
Expand All @@ -118,5 +125,13 @@ public int getSumFactorCount() {
public void incrementSumFactorCount() {
sumFactorCount++;
}

public Object getScoreSum() {
return scoreSum;
}

public void setScoreSum(Object scoreSum) {
this.scoreSum = scoreSum;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ protected List<Ranking> calculateLatestAverageRankingsData(List<LeaderboardPager
if (!trackUser.socialAllow)
continue;

statsMap.computeIfAbsent(trackUser.nickname, k -> 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();
}
Expand All @@ -36,7 +35,8 @@ protected List<Ranking> calculateLatestAverageRankingsData(List<LeaderboardPager
int consecutiveTies = 0;
String lastScore = "";
for (SummedStatTrackUser summedStatTrackUser : latestSummedLeaderboardData) {
Duration averageMovingTime = summedStatTrackUser.getPlaceHolderTrackUser().trackStatistics.getMovingTime().dividedBy(summedStatTrackUser.getSumFactorCount());
Duration totalMovingTime = (Duration)summedStatTrackUser.getScoreSum();
Duration averageMovingTime = totalMovingTime.dividedBy(summedStatTrackUser.getSumFactorCount());
Ranking nextRanking = new Ranking(
++rank,
summedStatTrackUser.getPlaceHolderTrackUser().nickname,
Expand All @@ -58,8 +58,9 @@ protected List<Ranking> calculateLatestAverageRankingsData(List<LeaderboardPager
private class SortByAverageMovingTime implements Comparator<SummedStatTrackUser> {
@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);
}
}

Expand Down

0 comments on commit 2ccf5e7

Please sign in to comment.