Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix efficiency for first day of season #196

Merged
merged 4 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A clear and concise description of what the bug is, with a copy/paste of Java ex

Depending your championship, join data files set in attachment.

1. The MPG Mobile App JSon *Response* of these *Request* on https://api.mpg.football (use the browser network monitor - F12, see wiki [Get MPG data for opening a bug](https://github.com/axel3rd/mpg-coach-bot/wiki/Get-MPG-data-for-opening-a-bug) for more details):
1. The MPG Mobile App JSon *Response* of these *Request* on https://api.mpg.football (see wiki [Get MPG data for opening a bug](https://github.com/axel3rd/mpg-coach-bot/wiki/Get-MPG-data-for-opening-a-bug) for authentication and details):

| Feature | URL | Reason |
| --- | --- | --- |
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static void processGames(League league, ApiClients apiClients, Config config) {
LOG.info("\nTransactions proposal ...");
CurrentDay cd = apiClients.getStats().getStats(ChampionshipTypeWrapper.toStats(league.getChampionship())).getInfos()
.getAnnualStats().getCurrentDay();
if (cd.getLastDayReached() < cd.getDay()) {
if (!cd.isStatsDayReached()) {
LOG.info("\nWARNING: Last day stats have not fully reached! Please retry tomorrow");
}
List<Player> playersAvailable = apiClients.getMpg().getAvailablePlayers(league.getDivisionId()).getList();
Expand Down Expand Up @@ -449,9 +449,9 @@ private static List<Player> calculateEfficiency(List<Player> players, MpgStatsCl
}

private static int getCurrentDay(MpgStatsClient stats, ChampionshipStatsType championship) {
int daysPeriod = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getDay();
int daysPeriod = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getDayReached();
// If league not started, we take the number of day of season, because average will be on this period
if (daysPeriod == 0 || stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getPlayed() == 0) {
if (daysPeriod == 0) {
// The previous season statistics could be null, in this case current annual max day is used
daysPeriod = stats.getStats(championship).getInfos().getLastStats() == null
? stats.getStats(championship).getInfos().getAnnualStats().getMaxDay()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<Player> getPlayers() {
// If last season statistics does not exist (Dominos L2 in 2019 use case, first one in MPG), current annual max day is used
final int previousMaxSeasonDay = getInfos().getLastStats() == null ? getInfos().getAnnualStats().getMaxDay()
: getInfos().getLastStats().getMaxDay();
final int currentSeasonDay = getInfos().getAnnualStats().getCurrentDay().getDay();
final int currentSeasonDay = getInfos().getAnnualStats().getCurrentDay().getDayReached();
players.forEach(p -> p.getStats().setCurrentSeasonDay(currentSeasonDay));
players.forEach(p -> p.getStats().setPreviousMaxSeasonDay(previousMaxSeasonDay));
maxDaySetOnPlayer = true;
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/org/blondin/mpg/stats/model/CurrentDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@ public class CurrentDay {
@JsonProperty("lD")
private int lastDayReached;

@JsonProperty("p")
private int played;

public int getDay() {
return day;
}

public int getLastDayReached() {
public int getDayReached() {
return lastDayReached;
}

public int getPlayed() {
return played;
public boolean isStatsDayReached() {
return day == lastDayReached;
}

}
6 changes: 3 additions & 3 deletions src/main/java/org/blondin/mpg/stats/model/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Stats {
* @return number of goals
*/
public int getGoals(int days) {
if (currentSeasonDay <= 1 && days <= 0) {
if (currentSeasonDay <= 0 && days <= 0) {
return oldGoals;
}
if (days <= 0) {
Expand All @@ -67,7 +67,7 @@ public int getGoals(int days) {
* @return note
*/
public double getAverage(int days) {
if (currentSeasonDay <= 1 && days <= 0) {
if (currentSeasonDay <= 0 && days <= 0) {
return oldAverage;
}
if (days <= 0) {
Expand Down Expand Up @@ -98,7 +98,7 @@ public double getAverage(int days) {
* @return number of matchs
*/
public int getMatchs(int days) {
if (currentSeasonDay <= 1 && days <= 0) {
if (currentSeasonDay <= 0 && days <= 0) {
return oldMatchs;
}
if (days <= 0) {
Expand Down
18 changes: 14 additions & 4 deletions src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ public void testCaptainNotOnMainPitch() throws Exception {
doReturn(true).when(config).isTeampUpdate();
doReturn(false).when(config).isTacticalSubstitutes();
executeMainProcess(config);
Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Blas Ludovic"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Blas Ludovic)"));
// Day 1 => efficiency with "Recent Focus" or global is the same
Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Rajkovic Predrag | 6.00 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| A | Laborde Gaëtan | 15.40 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Bamba Jonathan"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Bamba Jonathan)"));
}

@Test
Expand All @@ -100,8 +103,11 @@ public void testCaptainAlreadySelected() throws Exception {
doReturn(true).when(config).isTeampUpdate();
doReturn(false).when(config).isTacticalSubstitutes();
executeMainProcess(config);
// Day 1 => efficiency with "Recent Focus" or global is the same
Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Rajkovic Predrag | 6.00 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| A | Laborde Gaëtan | 15.40 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team ..."));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Bamba Jonathan"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Botman Sven"));
}

@Test
Expand All @@ -120,9 +126,13 @@ public void testCaptainAdd() throws Exception {
Config config = spy(getConfig());
doReturn(true).when(config).isTeampUpdate();
doReturn(false).when(config).isTacticalSubstitutes();
doReturn(true).when(config).isEfficiencyRecentFocus();
executeMainProcess(config);
// Day 1 => efficiency with "Recent Focus" or global is the same
Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Rajkovic Predrag | 6.00 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("| A | Laborde Gaëtan | 15.40 |"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team ..."));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Blas Ludovic"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Bamba Jonathan"));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/blondin/mpg/root/MpgClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testMockCoachNotEmpty() throws Exception {
Assert.assertNotNull(coach);
Assert.assertTrue(coach.getComposition() > 0);
Assert.assertEquals("mpg_match_team_formation_MLAX7HMK_3_1_1_5_6", coach.getIdMatch());
Assert.assertEquals("mpg_championship_player_195883", coach.getCaptain());
Assert.assertEquals("mpg_championship_player_220237", coach.getCaptain());
}

@Test
Expand Down
32 changes: 23 additions & 9 deletions src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ public void testPlayersWithSameName() {
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-2.20210804.json")));
MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port());
Assert.assertEquals(25, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_2).getPlayer("Ba Pape Ibnou").getPrice());
Assert.assertEquals(1, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_2).getInfos().getAnnualStats().getCurrentDay().getDayReached());
Assert.assertFalse(mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_2).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached());
}

@Test
public void testEfficiencyRecentFocus() {
stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.leagues.20190406.json")));
stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20190406.json")));
stubFor(get("/leagues/Ligue-1")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.ligue-1.20190406.json")));
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20190406.json")));
MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port());

Assert.assertEquals(30, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().getDayReached());
Assert.assertTrue(mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached());
testEfficiencyRecentFocusNeymar(mpgStatsClient);
testEfficiencyRecentFocusMBappe(mpgStatsClient);
testEfficiencyRecentFocusTrapp(mpgStatsClient);
Expand Down Expand Up @@ -83,16 +86,27 @@ private void testEfficiencyRecentFocusTrapp(MpgStatsClient mpgStatsClient) {

@Test
public void testMockAllLeagues() {
stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.leagues.20181017.json")));
stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20181017.json")));
stubFor(get("/leagues/Ligue-1")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.ligue-1.20181017.json")));
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20181017.json")));
stubFor(get("/leagues/Premier-League")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.premier-league.20181017.json")));
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20181017.json")));
stubFor(get("/leagues/Liga")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.liga.20181017.json")));
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.liga.20181017.json")));

MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port());

Assert.assertEquals(8, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().getDayReached());
Assert.assertTrue(mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached());

Assert.assertEquals(8,
mpgStatsClient.getStats(ChampionshipStatsType.PREMIER_LEAGUE).getInfos().getAnnualStats().getCurrentDay().getDayReached());
Assert.assertTrue(
mpgStatsClient.getStats(ChampionshipStatsType.PREMIER_LEAGUE).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached());

Assert.assertEquals(8, mpgStatsClient.getStats(ChampionshipStatsType.LIGA).getInfos().getAnnualStats().getCurrentDay().getDayReached());
Assert.assertTrue(mpgStatsClient.getStats(ChampionshipStatsType.LIGA).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached());

for (ChampionshipStatsType type : Arrays.asList(ChampionshipStatsType.LIGUE_1, ChampionshipStatsType.PREMIER_LEAGUE,
ChampionshipStatsType.LIGA)) {
Championship championship = mpgStatsClient.getStats(type);
Expand All @@ -103,15 +117,15 @@ public void testMockAllLeagues() {
@Test
public void testLocalMapping() throws Exception {
for (String subFile : Arrays.asList("ligue-1", "premier-league", "liga")) {
Championship championship = new ObjectMapper().readValue(new File("src/test/resources/__files", "mpgstats." + subFile + ".20181017.json"),
Championship championship = new ObjectMapper().readValue(new File("src/test/resources/__files", "mlnstats." + subFile + ".20181017.json"),
Championship.class);
subChampionshipTest(championship, subFile);
}
}

@Test
public void testLocalMappingRefresh() throws Exception {
LeaguesRefresh refresh = new ObjectMapper().readValue(new File("src/test/resources/__files", "mpgstats.leagues.20181017.json"),
LeaguesRefresh refresh = new ObjectMapper().readValue(new File("src/test/resources/__files", "mlnstats.builds.20181017.json"),
LeaguesRefresh.class);
Assert.assertNotNull(refresh);
Assert.assertNotNull(refresh.getDate(1));
Expand Down
18 changes: 11 additions & 7 deletions src/test/resources/__files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ The `XXX` should be replaced by a use case scenario (like date, some league, dat
| `mlnstats.ligue-2.XXX.json` | https://api.mlnstats.com/leagues/Ligue-2 | MpgStats for **Ligue 2 (France)** |
| `mlnstats.premier-league.XXX.json` | https://api.mlnstats.com/leagues/Premier-League | MpgStats for **Premiere League (England)** |
| `mlnstats.serie-a.XXX.json` | https://api.mlnstats.com/leagues/Serie-A | MpgStats for **Seria A (Italia)** |
| `mpgstats.leagues.XXX.json` | https://www.mpgstats.fr/json/leagues.json | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.liga.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Liga | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.ligue-1.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-1 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.ligue-2.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-2 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.premier-league.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Premier-League | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.serie-a.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Serie-A | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |

### Players Injury / Suspended

Expand All @@ -63,4 +57,14 @@ The `XXX` should be replaced by a use case scenario (like date, some league, dat
| `mpg.dashboard.XXX.json` | https://api.monpetitgazon.com/user/dashboard | MPG **dashboard** |
| `mpg.mercato.XXX.json` | https://api.monpetitgazon.com/league/[leagueId]/mercato | MPG league **mercato** |
| `mpg.transfer.buy.XXX.json` | https://api.monpetitgazon.com/league/[leagueId]/transfer/buy | MPG league **transfer** |
| `mpg.user-signIn.XXX.json` | https://api.monpetitgazon.com/user/signIn | **Login** |
| `mpg.user-signIn.XXX.json` | https://api.monpetitgazon.com/user/signIn | **Login** |

### Players statistics (deprecated since 15 December 2019)

| **File** | **URL** | **Description** |
| `mpgstats.leagues.XXX.json` | https://www.mpgstats.fr/json/leagues.json | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.liga.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Liga | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.ligue-1.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-1 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.ligue-2.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-2 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.premier-league.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Premier-League | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
| `mpgstats.serie-a.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Serie-A | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) |
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"composition": "343",
"playersOnPitch": {
"1": "mpg_championship_player_104407",
"2": "mpg_championship_player_155335",
"3": "mpg_championship_player_38580",
"4": "mpg_championship_player_52573",
"5": "mpg_championship_player_213940",
"6": "mpg_championship_player_195883",
"7": "mpg_championship_player_441240",
"8": "mpg_championship_player_159967",
"2": "mpg_championship_player_220237",
"3": "mpg_championship_player_52573",
"4": "mpg_championship_player_38580",
"5": "mpg_championship_player_195883",
"6": "mpg_championship_player_441240",
"7": "mpg_championship_player_159967",
"8": "mpg_championship_player_213940",
"9": "mpg_championship_player_167443",
"10": "mpg_championship_player_168539",
"11": "mpg_championship_player_193454",
"12": "mpg_championship_player_220237",
"10": "mpg_championship_player_193454",
"11": "mpg_championship_player_168539",
"12": "mpg_championship_player_155335",
"13": "mpg_championship_player_437753",
"14": "mpg_championship_player_61170",
"15": "mpg_championship_player_240146",
Expand All @@ -22,5 +22,5 @@
},
"tacticalSubs": [
],
"captain": "mpg_championship_player_195883"
"captain": "mpg_championship_player_220237"
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"starterId": "mpg_championship_player_168539"
}
],
"captain": "mpg_championship_player_195883"
"captain": "mpg_championship_player_220237"
},
"nextGameWeek": {
"gameWeekNumber": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"composition": "343",
"playersOnPitch": {
"1": "mpg_championship_player_104407",
"2": "mpg_championship_player_155335",
"3": "mpg_championship_player_38580",
"4": "mpg_championship_player_52573",
"5": "mpg_championship_player_213940",
"6": "mpg_championship_player_195883",
"7": "mpg_championship_player_441240",
"8": "mpg_championship_player_159967",
"2": "mpg_championship_player_220237",
"3": "mpg_championship_player_52573",
"4": "mpg_championship_player_38580",
"5": "mpg_championship_player_195883",
"6": "mpg_championship_player_441240",
"7": "mpg_championship_player_159967",
"8": "mpg_championship_player_213940",
"9": "mpg_championship_player_167443",
"10": "mpg_championship_player_168539",
"11": "mpg_championship_player_193454",
"12": "mpg_championship_player_220237",
"10": "mpg_championship_player_193454",
"11": "mpg_championship_player_168539",
"12": "mpg_championship_player_155335",
"13": "mpg_championship_player_437753",
"14": "mpg_championship_player_61170",
"15": "mpg_championship_player_240146",
Expand All @@ -22,5 +22,5 @@
},
"tacticalSubs": [
],
"captain": "mpg_championship_player_213940"
"captain": "mpg_championship_player_195883"
}
Loading