Skip to content

Commit

Permalink
Fix #232 : Use "long auctions" when "auctions" is not present or n <= 5
Browse files Browse the repository at this point in the history
  • Loading branch information
axel3rd committed Jul 24, 2022
1 parent 2e0faa9 commit fb64148
Show file tree
Hide file tree
Showing 13 changed files with 94,517 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Automate and optimize your [MPG](http://mpg.football/) weekly league actions, us
* Displaying your teams, line by line, ordered by players efficiency (with injured players)
* Updating your team
* Proposing some players to buy, better than the one you have (if option `transactions.proposal` is enabled and *MPG* expert mode is bought)
* When league not started (aka: *mercato*), the best players to buy with good turn 1 auction (since v1.9) for your incoming team
* When league not started (aka: *mercato*), the best players to buy with good turn 1 auction (since v1.9) for your incoming team (since v1.10 long auction is used if season not started or current auction not representative)

**NB:** Your tactical organization and selected bonus are not updated and let as configured (but selected if some will be lost or no captain).

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.blondin</groupId>
<artifactId>mpg-coach-bot</artifactId>
<packaging>jar</packaging>
<version>1.9.1-SNAPSHOT</version>
<version>1.10-SNAPSHOT</version>
<name>MPG Coach Bot</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,14 @@ private static List<Player> completeAuctionAndcalculateEfficiency(List<Player> p
for (Player player : players) {
try {
org.blondin.mpg.stats.model.Player p = stats.getStats(championship).getPlayer(player.getName());
if (p.getAuction() != null) {
if (p.getAuction() != null && p.getAuction().getNumber() > 5) {
// Feature in API only since 2021-11
player.setAuction(p.getAuction().getAverage());
}
if (player.getAuction() == 0 && p.getAuctionLong() != null) {
// Feature in API only since 2022-07
player.setAuction(p.getAuctionLong().getAverage());
}
player.setEfficiency(p.getEfficiency());
} catch (PlayerNotFoundException e) {
if (failIfPlayerNotFound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class InjuredSuspendedMaLigue2Client extends AbstractClient {
* Team name "maligue2 -> MPG" wrapper
*/
TEAM_NAME_WRAPPER.put("QRM", "Quevilly Rouen");
TEAM_NAME_WRAPPER.put("AS Saint-Etienne", "St Etienne");
}

private List<Player> cache = null;
Expand Down Expand Up @@ -60,12 +61,14 @@ static String getMpgTeamName(String name) {
public Player getPlayer(String playerName, String teamName) {
// For composed lastName (highest priority than firstName composed), we replace space by '-'
String lastName = playerName;
int spaceIndex = lastName.lastIndexOf(' ');
if (spaceIndex > 0) {
lastName = lastName.substring(0, spaceIndex);
if (!playerName.startsWith("De ")) {
int spaceIndex = lastName.lastIndexOf(' ');
if (spaceIndex > 0) {
lastName = lastName.substring(0, spaceIndex);
}
lastName = lastName.replace(' ', '-');
lastName = lastName.replace("Saint-", "St-");
}
lastName = lastName.replace(' ', '-');
lastName = lastName.replace("Saint-", "St-");
for (Player player : getPlayers()) {
if (lastName.equalsIgnoreCase(player.getFullNameWithPosition())) {
if (StringUtils.isNotBlank(teamName) && !player.getTeam().contains(teamName)) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/blondin/mpg/stats/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Player {
private int price;
@JsonProperty("a")
private Auction auction;
@JsonProperty("la")
private Auction auctionLong;

private double efficiency;

Expand Down Expand Up @@ -56,6 +58,10 @@ public Auction getAuction() {
return auction;
}

public Auction getAuctionLong() {
return auctionLong;
}

public Stats getStats() {
if (stats == null) {
stats = new Stats();
Expand Down
14 changes: 12 additions & 2 deletions src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public void testRealWithBadCredentials() throws Exception {
}
}

@Test
public void testMpgStatsLongAuctions() throws Exception {
prepareMainFrenchLigue2Mocks("20220724", "2022", "20220724", "20220724");

Config config = spy(getConfig());
executeMainProcess(config);

Assert.assertFalse(getLogOut(), getLogOut().contains("| M | Weissbeck Gaétan | 38.01 | 29 | 0 | |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| M | Weissbeck Gaétan | 38.01 | 29 | 41 | |"));
}

@Test
public void testMpgStatsApiV2() throws Exception {
prepareMainFrenchLigue1Mocks("20220327", "2022", "20220327", "20220327");
Expand Down Expand Up @@ -148,8 +159,7 @@ public void testKeepAtLeastOneGoalkeeperEvenIfAbsent() throws Exception {
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains("All goalkeeper(s) are injured/absent, so maintained on the pitch"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Braat Quentin | 4.81 | 19 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Maronne Yanis | 0.00 | 3 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Maronne Yanis | 0.00 | 3 |"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,61 @@

public class InjuredSuspendedMaLigue2ClientTest extends AbstractMockTestClient {

@Test
public void testCheckTeams2022L2() throws Exception {
List<String> mpgTeams = Arrays.asList("Amiens", "Annecy", "Bastia", "Bordeaux", "Caen", "Dijon", "Grenoble", "Guingamp", "Laval", "Le Havre",
"Metz", "Nîmes", "Niort", "Paris FC", "Pau", "Quevilly Rouen", "Rodez", "St Etienne", "Sochaux", "Valenciennes");
Document doc = Jsoup.parse(FileUtils.readFileToString(new File(TESTFILES_BASE, "maligue2.joueurs-blesses-et-suspendus.20220724.html"),
Charset.forName("UTF-8")));
List<String> maLigue2Teams = new ArrayList<>();
for (Element item : doc.select("tr")) {
if (item.selectFirst("th.column-1") != null && "Club".equals(item.selectFirst("th.column-1").text())) {
continue;
}
maLigue2Teams.add(InjuredSuspendedMaLigue2Client.getMpgTeamName(item.selectFirst("td.column-1").text()));
}
for (String mpgTeam : mpgTeams) {
boolean contains = false;
for (String maLigue2Team : maLigue2Teams) {
if (maLigue2Team.contains(mpgTeam)) {
contains = true;
}
}
Assert.assertTrue(mpgTeam, contains);
}
}

@Test
public void testReasons2022() throws Exception {
InjuredSuspendedMaLigue2Client client = spy(InjuredSuspendedMaLigue2Client.build(null));
doReturn(
FileUtils.readFileToString(new File(TESTFILES_BASE, "maligue2.joueurs-blesses-et-suspendus.20220724.html"), Charset.forName("UTF-8")))
.when(client).getHtmlContent();

Assert.assertNotNull("Annecy Spano Blesse", client.getPlayer("Spano", "Annecy"));
Assert.assertEquals("Annecy Spano Blesse", OutType.INJURY_RED, client.getPlayer("Spano", "Annecy").getOutType());
Assert.assertNotNull("Caen Abdi Suspendu", client.getPlayer("Abdi", "Caen"));
Assert.assertEquals("Caen Abdi Suspendu", OutType.SUSPENDED, client.getPlayer("Abdi", "Caen").getOutType());
Assert.assertNotNull("Caen Ntim Suspendu", client.getPlayer("Ntim", "Caen"));
Assert.assertEquals("Caen Ntim Suspendu", OutType.SUSPENDED, client.getPlayer("Ntim", "Caen").getOutType());
Assert.assertNotNull("Grenoble Monfray Suspendu", client.getPlayer("Monfray", "Grenoble"));
Assert.assertEquals("Grenoble Monfray Suspendu", OutType.SUSPENDED, client.getPlayer("Monfray", "Grenoble").getOutType());
Assert.assertNotNull("Grenoble DeIriondo Suspendu", client.getPlayer("De Iriondo", "Grenoble"));
Assert.assertEquals("Grenoble DeIriondo Suspendu", OutType.SUSPENDED, client.getPlayer("De Iriondo", "Grenoble").getOutType());
Assert.assertNotNull("Guingamp Quemper Suspendu", client.getPlayer("Quemper", "Guingamp"));
Assert.assertEquals("Guingamp Quemper Suspendu", OutType.SUSPENDED, client.getPlayer("Quemper", "Guingamp").getOutType());
Assert.assertNotNull("Havre Wahib Blesse", client.getPlayer("Wahib", "Havre"));
Assert.assertEquals("Havre Wahib Blesse", OutType.INJURY_RED, client.getPlayer("Wahib", "Havre").getOutType());
Assert.assertNotNull("Paris Name Suspendu", client.getPlayer("Name", "Paris FC"));
Assert.assertEquals("Paris Name Suspendu", OutType.SUSPENDED, client.getPlayer("Name", "Paris FC").getOutType());
Assert.assertNotNull("Paris Camara Suspendu", client.getPlayer("Camara", "Paris FC"));
Assert.assertEquals("Paris Camara Suspendu", OutType.SUSPENDED, client.getPlayer("Camara", "Paris FC").getOutType());
Assert.assertNotNull("Saint-Etienne Chambost Blesse", client.getPlayer("Chambost", "St Etienne"));
Assert.assertEquals("Saint-Etienne Chambost Blesse", OutType.INJURY_RED, client.getPlayer("Chambost", "St Etienne").getOutType());
Assert.assertNotNull("Sochaux Lopy Blesse", client.getPlayer("Lopy", "Sochaux"));
Assert.assertEquals("Sochaux Lopy Blesse", OutType.INJURY_RED, client.getPlayer("Lopy", "Sochaux").getOutType());
}

@Test
public void testCheckTeams2021L2() throws Exception {
List<String> mpgTeams = Arrays.asList("Ajaccio", "Amiens", "Auxerre", "Bastia", "Caen", "Dijon", "Dunkerque", "Grenoble", "Guingamp",
Expand All @@ -50,7 +105,7 @@ public void testCheckTeams2021L2() throws Exception {
}

@Test
public void testReasons() throws Exception {
public void testReasons2021() throws Exception {
InjuredSuspendedMaLigue2Client client = spy(InjuredSuspendedMaLigue2Client.build(null));
doReturn(
FileUtils.readFileToString(new File(TESTFILES_BASE, "maligue2.joueurs-blesses-et-suspendus.20210804.html"), Charset.forName("UTF-8")))
Expand Down
Loading

0 comments on commit fb64148

Please sign in to comment.