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 1 commit
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
3 changes: 2 additions & 1 deletion src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,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 lastDayReached = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getLastDayReached();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using always getLastDayReached is perhaps the best solution ...

// 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 || (daysPeriod == 1 && lastDayReached == 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
4 changes: 3 additions & 1 deletion src/main/java/org/blondin/mpg/stats/model/Championship.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ 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().getDay() <= 1
&& getInfos().getAnnualStats().getCurrentDay().getLastDayReached() == 0 ? 0
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using always getLastDayReached is perhaps the best solution ...

: getInfos().getAnnualStats().getCurrentDay().getDay();
players.forEach(p -> p.getStats().setCurrentSeasonDay(currentSeasonDay));
players.forEach(p -> p.getStats().setPreviousMaxSeasonDay(previousMaxSeasonDay));
maxDaySetOnPlayer = true;
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/blondin/mpg/stats/model/CurrentDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ public class CurrentDay {
@JsonProperty("lD")
private int lastDayReached;

@JsonProperty("p")
private int played;

public int getDay() {
return day;
}
Expand All @@ -23,8 +20,4 @@ public int getLastDayReached() {
return lastDayReached;
}

public int getPlayed() {
return played;
}

}
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
1 change: 1 addition & 0 deletions src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ 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);
Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team ..."));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Blas Ludovic"));
Expand Down