diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/RankingFlow.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/RankingFlow.java index 3514631..6ba1559 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/RankingFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/RankingFlow.java @@ -1,7 +1,9 @@ package djmil.cordacheckers.gameresult; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -35,11 +37,23 @@ public class RankingFlow implements ClientStartableFlow { try { final List gameStateResutList = getGameResultsList(); - final List board = new LinkedList(List.of( - new Rank("alice", 42, 1), - new Rank("bobik", 25, 78) - )); - + Map won = new HashMap<>(); + for (GameResultState gs : gameStateResutList) { + final var winner = gs.getWinnerName().getCommonName(); + won.put(winner, won.getOrDefault(winner, 0) +1); + } + + Map played = new HashMap<>(won); + for (GameResultState gs : gameStateResutList) { + final var looseer = gs.getLooserName().getCommonName(); + played.put(looseer, played.getOrDefault(looseer, 0) +1); + } + + List board = new LinkedList(); + for (String name : played.keySet()) { + board.add(new Rank(name, played.getOrDefault(name, 0), won.getOrDefault(name, 0))); + } + return new RankingFlowResponce(board) .toJsonEncodedString(jsonMarshallingService); } catch (Exception e) {