RankingFLow: use actual GameResultStates
This commit is contained in:
parent
5f59260120
commit
e1cc9bd9fd
@ -1,7 +1,9 @@
|
|||||||
package djmil.cordacheckers.gameresult;
|
package djmil.cordacheckers.gameresult;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -35,11 +37,23 @@ public class RankingFlow implements ClientStartableFlow {
|
|||||||
try {
|
try {
|
||||||
final List<GameResultState> gameStateResutList = getGameResultsList();
|
final List<GameResultState> gameStateResutList = getGameResultsList();
|
||||||
|
|
||||||
final List<Rank> board = new LinkedList<Rank>(List.of(
|
Map<String, Integer> won = new HashMap<>();
|
||||||
new Rank("alice", 42, 1),
|
for (GameResultState gs : gameStateResutList) {
|
||||||
new Rank("bobik", 25, 78)
|
final var winner = gs.getWinnerName().getCommonName();
|
||||||
));
|
won.put(winner, won.getOrDefault(winner, 0) +1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Integer> played = new HashMap<>(won);
|
||||||
|
for (GameResultState gs : gameStateResutList) {
|
||||||
|
final var looseer = gs.getLooserName().getCommonName();
|
||||||
|
played.put(looseer, played.getOrDefault(looseer, 0) +1);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Rank> board = new LinkedList<Rank>();
|
||||||
|
for (String name : played.keySet()) {
|
||||||
|
board.add(new Rank(name, played.getOrDefault(name, 0), won.getOrDefault(name, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
return new RankingFlowResponce(board)
|
return new RankingFlowResponce(board)
|
||||||
.toJsonEncodedString(jsonMarshallingService);
|
.toJsonEncodedString(jsonMarshallingService);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user