Only update result if api football match is finished

This commit is contained in:
Julian Arndt
2023-08-20 11:55:53 +02:00
parent 29f00f39aa
commit b411f5d57f
4 changed files with 48 additions and 37 deletions

View File

@@ -2,10 +2,18 @@ package de.jeyp91;
public abstract class BaseMatch { public abstract class BaseMatch {
public static final Integer COMPARISON_IDENTICAL = 0; public static final Integer STATUS_NOTSTARTED = 0;
public static final Integer COMPARISON_DIFFERENT = 1; public static final Integer STATUS_STARTED = 1;
public static final Integer COMPARISON_DIFFERENT_DATETIME = 2; public static final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
public static final Integer COMPARISON_DIFFERENT_RESULT = 3; public static final Integer STATUS_FINISHED = 3;
public static final Integer STATUS_NOT_EVALUATED = 4;
public enum COMPARISON {
IDENTICAL,
DIFFERENT,
DIFFERENT_DATETIME,
DIFFERENT_RESULT
}
protected Integer teamIdHome; protected Integer teamIdHome;
protected Integer teamIdGuest; protected Integer teamIdGuest;
@@ -19,8 +27,8 @@ public abstract class BaseMatch {
protected Integer goalsPenaltyGuest = null; protected Integer goalsPenaltyGuest = null;
protected Integer matchday = null; protected Integer matchday = null;
protected String matchDatetime = null; protected String matchDatetime = null;
protected Integer status = null;
protected Integer updateStatus = COMPARISON_IDENTICAL; protected COMPARISON updateStatus = COMPARISON.IDENTICAL;
public Integer getMatchday() { public Integer getMatchday() {
return this.matchday; return this.matchday;
@@ -70,9 +78,17 @@ public abstract class BaseMatch {
return this.teamNameGuest; return this.teamNameGuest;
} }
public void setUpdateStatus(Integer newStatus) { this.updateStatus = newStatus; } public void setStatus(int status) {
this.status = status;
}
public Integer getUpdateStatus() { public Integer getStatus() {
return this.status;
}
public void setUpdateStatus(COMPARISON newStatus) { this.updateStatus = newStatus; }
public COMPARISON getUpdateStatus() {
return this.updateStatus; return this.updateStatus;
} }
} }

View File

@@ -6,11 +6,11 @@ import org.json.simple.JSONObject;
public class APIFootballMatch extends BaseMatch { public class APIFootballMatch extends BaseMatch {
private final int matchId; private int matchId;
private final int leagueId; private int leagueId;
private final String teamNameHome; private String teamNameHome;
private final String teamNameGuest; private String teamNameGuest;
private final String round; private String round;
private Boolean showTable = null; private Boolean showTable = null;
public APIFootballMatch(JSONObject json, int season) throws Exception { public APIFootballMatch(JSONObject json, int season) throws Exception {
@@ -30,6 +30,7 @@ public class APIFootballMatch extends BaseMatch {
throw new Exception("Did not find matchday for league '" + this.leagueId + "': '" + json.get("round").toString() + "'"); throw new Exception("Did not find matchday for league '" + this.leagueId + "': '" + json.get("round").toString() + "'");
} }
this.matchDatetime = (String) json.get("event_date"); this.matchDatetime = (String) json.get("event_date");
this.status = parseStatus(json.get("statusShort").toString());
this.parseResult(json); this.parseResult(json);
} }
@@ -76,6 +77,17 @@ public class APIFootballMatch extends BaseMatch {
return this.showTable; return this.showTable;
} }
private int parseStatus(String statusShort) {
switch (statusShort) {
case "TBD":
case "NS": return 0;
case "FT":
case "AET":
case "PEN": return 3;
default: return 1;
}
}
private void parseResult(JSONObject json) { private void parseResult(JSONObject json) {
Object resultFulltime = ((JSONObject) json.get("score")).get("fulltime"); Object resultFulltime = ((JSONObject) json.get("score")).get("fulltime");
if(resultFulltime != null) { if(resultFulltime != null) {

View File

@@ -14,19 +14,12 @@ import org.apache.logging.log4j.Logger;
*/ */
public class TLWMatch extends BaseMatch{ public class TLWMatch extends BaseMatch{
public static final Integer STATUS_NOTSTARTED = 0;
public static final Integer STATUS_STARTED = 1;
public static final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
public static final Integer STATUS_FINISHED = 3;
public static final Integer STATUS_NOT_EVALUATED = 4;
private Integer season = null; private Integer season = null;
private Integer league = null; private Integer league = null;
private Integer matchNo = null; private Integer matchNo = null;
private String groupId = null; private String groupId = null;
private String formulaHome = null; private String formulaHome = null;
private String formulaGuest = null; private String formulaGuest = null;
private Integer status = null;
private Integer koMatch = 0; private Integer koMatch = 0;
private Integer showTable = null; private Integer showTable = null;
private String trend = null; private String trend = null;
@@ -172,10 +165,6 @@ public class TLWMatch extends BaseMatch{
return this.matchNo; return this.matchNo;
} }
public Integer getStatus() {
return this.status;
}
public Integer getKoMatch() { public Integer getKoMatch() {
return this.koMatch; return this.koMatch;
} }
@@ -267,10 +256,6 @@ public class TLWMatch extends BaseMatch{
this.goalsOvertimeGuest = goals; this.goalsOvertimeGuest = goals;
} }
public void setStatus(int status) {
this.status = status;
}
public void setMatchDateTime(String matchDateTime) { public void setMatchDateTime(String matchDateTime) {
this.matchDatetime = matchDateTime; this.matchDatetime = matchDateTime;
} }

View File

@@ -56,7 +56,7 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
} }
updateBeautifulInfo(tlwMatchesOriginalMatchday, tlwMatchesUpdatedMatchday); updateBeautifulInfo(tlwMatchesOriginalMatchday, tlwMatchesUpdatedMatchday);
tlwMatchesUpdatedMatchday.removeIf(tlwMatch -> tlwMatch.getUpdateStatus() != TLWMatch.COMPARISON_DIFFERENT_RESULT); tlwMatchesUpdatedMatchday.removeIf(tlwMatch -> tlwMatch.getUpdateStatus() != TLWMatch.COMPARISON.DIFFERENT_RESULT);
if(tlwMatchesUpdatedMatchday.size() > 0) this.tlwMatchesUpdated.add(tlwMatchesUpdatedMatchday); if(tlwMatchesUpdatedMatchday.size() > 0) this.tlwMatchesUpdated.add(tlwMatchesUpdatedMatchday);
} }
} }
@@ -82,15 +82,13 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
try { try {
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy); TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy);
tlwMatchesCopy.remove(tlwMatch); tlwMatchesCopy.remove(tlwMatch);
if(Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_STARTED) if(Objects.equals(apiFootballMatch.getStatus(), TLWMatch.STATUS_FINISHED)) {
|| Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_PROVISIONAL_RESULT_AVAILABLE)
|| Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_FINISHED)) {
if(!Objects.equals(tlwMatch.getGoalsHome(), apiFootballMatch.getGoalsHome()) if(!Objects.equals(tlwMatch.getGoalsHome(), apiFootballMatch.getGoalsHome())
|| !Objects.equals(tlwMatch.getGoalsGuest(), apiFootballMatch.getGoalsGuest()) || !Objects.equals(tlwMatch.getGoalsGuest(), apiFootballMatch.getGoalsGuest())
) { ) {
tlwMatch.setGoalsHome(apiFootballMatch.getGoalsHome()); tlwMatch.setGoalsHome(apiFootballMatch.getGoalsHome());
tlwMatch.setGoalsGuest(apiFootballMatch.getGoalsGuest()); tlwMatch.setGoalsGuest(apiFootballMatch.getGoalsGuest());
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT); tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
} }
if(tlwMatch.getKoMatch() == 1 && if(tlwMatch.getKoMatch() == 1 &&
this.betKOType == 2 && this.betKOType == 2 &&
@@ -99,7 +97,7 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
) { ) {
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome()); tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome());
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest()); tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest());
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT); tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
} }
if(tlwMatch.getKoMatch() == 1 && if(tlwMatch.getKoMatch() == 1 &&
(this.betKOType == 1 || this.betKOType == 3) && (this.betKOType == 1 || this.betKOType == 3) &&
@@ -109,7 +107,7 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
) { ) {
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsPenaltyHome()); tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsPenaltyHome());
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsPenaltyGuest()); tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsPenaltyGuest());
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT); tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
} }
if(tlwMatch.getKoMatch() == 1 && if(tlwMatch.getKoMatch() == 1 &&
(this.betKOType == 1 || this.betKOType == 3) && (this.betKOType == 1 || this.betKOType == 3) &&
@@ -119,10 +117,10 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
) { ) {
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome()); tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome());
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest()); tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest());
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT); tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
} }
if(Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_PROVISIONAL_RESULT_AVAILABLE)) { if(Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_PROVISIONAL_RESULT_AVAILABLE)) {
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT); tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
} }
} }
} catch (NullPointerException ignored) { } catch (NullPointerException ignored) {