Skip to content

Commit

Permalink
Fix #237 : Propose to sell players also when recent efficiency focused
Browse files Browse the repository at this point in the history
  • Loading branch information
axel3rd committed Aug 4, 2022
1 parent db6d891 commit 4484a18
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ static void processGames(League league, ApiClients apiClients, Config config) {
ChampionshipTypeWrapper.toStats(league.getChampionship()), config, false, false);

Integer currentPlayersBuy = team.getBids().stream().map(Player::getPricePaid).collect(Collectors.summingInt(Integer::intValue));
writeTransactionsProposal(playersTeam, playersAvailable, team.getBudget() - currentPlayersBuy, apiClients.getOutPlayers(),
ChampionshipTypeWrapper.toOut(league.getChampionship()), config);
writeTransactionsProposal(cd.getDay(), playersTeam, playersAvailable, team.getBudget() - currentPlayersBuy,
apiClients.getOutPlayers(), ChampionshipTypeWrapper.toOut(league.getChampionship()), config);
}
}
} catch (NoMoreGamesException e) {
Expand Down Expand Up @@ -303,7 +303,7 @@ private static void updateTeamWithRetry(MpgClient mpgClient, Division division,
}
}

private static void writeTransactionsProposal(List<Player> playersTeam, List<Player> playersAvailable, int budget,
private static void writeTransactionsProposal(int currentDay, List<Player> playersTeam, List<Player> playersAvailable, int budget,
InjuredSuspendedWrapperClient outPlayersClient, ChampionshipOutType championship, Config config) {

// Players with bad efficiency
Expand All @@ -319,7 +319,7 @@ private static void writeTransactionsProposal(List<Player> playersTeam, List<Pla
}

int cash = budget;
if (!config.isEfficiencyRecentFocus() && !players2Sell.isEmpty()) {
if (currentDay > 2 && !players2Sell.isEmpty()) {
LOG.info("Players to sell (initial cash: {}):", budget);
AsciiTable at = getTable(TABLE_POSITION, TABLE_PLAYER_NAME, TABLE_EFFICIENCY, TABLE_QUOTE);
for (Player player : players2Sell) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/blondin/mpg/stats/model/CurrentDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class CurrentDay {
@JsonProperty("lD")
private int lastDayReached;

public int getDay() {
return day;
}

public int getDayReached() {
return lastDayReached;
}
Expand Down
38 changes: 37 additions & 1 deletion src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.blondin.mpg.config.Config;
import org.blondin.mpg.out.InjuredSuspendedWrapperClient;
import org.blondin.mpg.root.MpgClient;
import org.blondin.mpg.root.model.Position;
import org.blondin.mpg.stats.MpgStatsClient;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -259,6 +260,39 @@ public void testCaptainAndBoostPlayerBonus() throws Exception {
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Picouleau Mathis)"));
}

@Test
public void testTransactionProposalSelling() throws Exception {
prepareMainFrenchLigue2Mocks("MLEFEX6G-20211019", "2021", "20211019", "20211019");
stubFor(get("/division/mpg_division_MLEFEX6G_3_1")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20211019.json")));
stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20211019.json")));
stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20211019.json")));
// Not the same date, UT added after
stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players").willReturn(
aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20211122.json")));
stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_12_5_2")
.withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20211019-Request.json")))
.willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json")
.withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_12_5_2")));

Config config = spy(getConfig());
doReturn(true).when(config).isTeampUpdate();
doReturn(false).when(config).isTacticalSubstitutes();
doReturn(true).when(config).isTransactionsProposal();
doReturn(4f).when(config).getEfficiencySell(Position.D);
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Boissier Remy"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Picouleau Mathis)"));

Assert.assertTrue(getLogOut(), getLogOut().contains("Players to sell (initial cash: "));
Assert.assertTrue(getLogOut(), getLogOut().contains("| D | Arcus Carlens | 3.44 | 22 |"));
// GoalKeeper second from same team => should not be sold
Assert.assertFalse(getLogOut(), getLogOut().contains("| G | Jeannin Mehdi | 0.00 | 7 |"));
}

@Test
public void testCaptainNotOnMainPitch() throws Exception {
prepareMainFrenchLigue1Mocks("MLAX7HMK-status-4", "2021", "20210812", "20210812");
Expand Down Expand Up @@ -438,8 +472,10 @@ public void testProcessFromEmptyCoach() throws Exception {
Assert.assertTrue(getLogOut(), getLogOut().contains("Ligue 2 Fous"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Ba"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Transactions proposal"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Prevot Maxence (mpg_championship_player_220359) | 4.00 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Transactions proposal"));
// currentGameWeek is 2 => selling players should not be displayed
Assert.assertFalse(getLogOut(), getLogOut().contains("Players to sell (initial cash"));
}

private void executeMainProcess(Config config) {
Expand Down

0 comments on commit 4484a18

Please sign in to comment.