From 46ab7ecf35c57a01df9b67721c8009423b05bc65 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Mon, 12 Mar 2012 01:18:20 +0000 Subject: [PATCH] Fixing calculating opp win %. --- .../gempukku/lotro/league/LeagueService.java | 25 ++++++++++++++++--- .../lotro/league/SealedLeagueDataTest.java | 6 ++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java index 7ef5b8aa4..34f5c878b 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java @@ -190,9 +190,12 @@ public class LeagueService { private List createStandingsForMatchesAndPoints(Map points, Collection matches) { Map> playerOpponents = new HashMap>(); + Map playerWins = new HashMap(); + Map playerLoss = new HashMap(); for (LeagueMatch leagueMatch : matches) { appendPlayer(playerOpponents, leagueMatch.getWinner(), leagueMatch.getLoser()); appendPlayer(playerOpponents, leagueMatch.getLoser(), leagueMatch.getWinner()); + appendMatch(playerWins, playerLoss, leagueMatch.getWinner(), leagueMatch.getLoser()); } List leagueStandings = new LinkedList(); @@ -202,9 +205,8 @@ public class LeagueService { int opponentWins = 0; int opponentGames = 0; for (String opponent : opponents) { - final LeaguePointsDAO.Points opponentPoints = points.get(opponent); - opponentWins += opponentPoints.getPoints() - opponentPoints.getGamesPlayed(); - opponentGames += opponentPoints.getGamesPlayed(); + opponentWins += playerWins.get(opponent); + opponentGames += playerWins.get(opponent) + playerLoss.get(opponent); } standing.setOpponentWin(opponentWins * 1f / opponentGames); leagueStandings.add(standing); @@ -225,6 +227,23 @@ public class LeagueService { return leagueStandings; } + private void appendMatch(Map playerWins, Map playerLoss, String winner, String loser) { + append(playerWins, winner); + append(playerLoss, loser); + if (!playerWins.containsKey(loser)) + playerWins.put(loser, 0); + if (!playerLoss.containsKey(winner)) + playerLoss.put(winner, 0); + } + + private void append(Map playerCounts, String player) { + Integer count = playerCounts.get(player); + if (count == null) + count = 0; + count++; + playerCounts.put(player, count); + } + private void appendPlayer(Map> playerOpponents, String player, String opponent) { List opponents = playerOpponents.get(player); if (opponents == null) { diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java index c30f909a1..cebc7cf9f 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java @@ -22,7 +22,7 @@ public class SealedLeagueDataTest { CollectionType collectionType = new CollectionType("test", "Test Collection"); for (int i = 20120101; i < 20120108; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); - Player player = new Player(1, "Test", "A"); + Player player = new Player(1, "Test", "A", null); data.joinLeague(collectionsManager, player, i); Mockito.verify(collectionsManager, new Times(1)).addPlayerCollection(Mockito.eq(player), Mockito.eq(collectionType), Mockito.argThat( new BaseMatcher() { @@ -57,7 +57,7 @@ public class SealedLeagueDataTest { CollectionType collectionType = new CollectionType("test", "Test Collection"); for (int i = 20120108; i < 20120115; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); - Player player = new Player(1, "Test", "A"); + Player player = new Player(1, "Test", "A", null); data.joinLeague(collectionsManager, player, i); Mockito.verify(collectionsManager, new Times(1)).addPlayerCollection(Mockito.eq(player), Mockito.eq(collectionType), Mockito.argThat( new BaseMatcher() { @@ -124,7 +124,7 @@ public class SealedLeagueDataTest { for (int i = 20120108; i < 20120115; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); Map playersInLeague = new HashMap(); - Player player = new Player(1, "Test", "A"); + Player player = new Player(1, "Test", "A", null); playersInLeague.put(player, new DefaultCardCollection()); Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(playersInLeague); int result = data.process(collectionsManager, null, 1, i);