From e1cc9bd9fd2d90c9000e2ec69081a569229557b1 Mon Sep 17 00:00:00 2001 From: djmil Date: Fri, 22 Sep 2023 17:23:06 +0200 Subject: [PATCH] RankingFLow: use actual GameResultStates --- .../cordacheckers/gameresult/RankingFlow.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) 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) {