Only update result if api football match is finished
This commit is contained in:
@@ -2,10 +2,18 @@ package de.jeyp91;
|
||||
|
||||
public abstract class BaseMatch {
|
||||
|
||||
public static final Integer COMPARISON_IDENTICAL = 0;
|
||||
public static final Integer COMPARISON_DIFFERENT = 1;
|
||||
public static final Integer COMPARISON_DIFFERENT_DATETIME = 2;
|
||||
public static final Integer COMPARISON_DIFFERENT_RESULT = 3;
|
||||
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;
|
||||
|
||||
public enum COMPARISON {
|
||||
IDENTICAL,
|
||||
DIFFERENT,
|
||||
DIFFERENT_DATETIME,
|
||||
DIFFERENT_RESULT
|
||||
}
|
||||
|
||||
protected Integer teamIdHome;
|
||||
protected Integer teamIdGuest;
|
||||
@@ -19,8 +27,8 @@ public abstract class BaseMatch {
|
||||
protected Integer goalsPenaltyGuest = null;
|
||||
protected Integer matchday = null;
|
||||
protected String matchDatetime = null;
|
||||
|
||||
protected Integer updateStatus = COMPARISON_IDENTICAL;
|
||||
protected Integer status = null;
|
||||
protected COMPARISON updateStatus = COMPARISON.IDENTICAL;
|
||||
|
||||
public Integer getMatchday() {
|
||||
return this.matchday;
|
||||
@@ -70,9 +78,17 @@ public abstract class BaseMatch {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import org.json.simple.JSONObject;
|
||||
|
||||
public class APIFootballMatch extends BaseMatch {
|
||||
|
||||
private final int matchId;
|
||||
private final int leagueId;
|
||||
private final String teamNameHome;
|
||||
private final String teamNameGuest;
|
||||
private final String round;
|
||||
private int matchId;
|
||||
private int leagueId;
|
||||
private String teamNameHome;
|
||||
private String teamNameGuest;
|
||||
private String round;
|
||||
private Boolean showTable = null;
|
||||
|
||||
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() + "'");
|
||||
}
|
||||
this.matchDatetime = (String) json.get("event_date");
|
||||
this.status = parseStatus(json.get("statusShort").toString());
|
||||
this.parseResult(json);
|
||||
}
|
||||
|
||||
@@ -76,6 +77,17 @@ public class APIFootballMatch extends BaseMatch {
|
||||
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) {
|
||||
Object resultFulltime = ((JSONObject) json.get("score")).get("fulltime");
|
||||
if(resultFulltime != null) {
|
||||
|
||||
@@ -14,19 +14,12 @@ import org.apache.logging.log4j.Logger;
|
||||
*/
|
||||
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 league = null;
|
||||
private Integer matchNo = null;
|
||||
private String groupId = null;
|
||||
private String formulaHome = null;
|
||||
private String formulaGuest = null;
|
||||
private Integer status = null;
|
||||
private Integer koMatch = 0;
|
||||
private Integer showTable = null;
|
||||
private String trend = null;
|
||||
@@ -172,10 +165,6 @@ public class TLWMatch extends BaseMatch{
|
||||
return this.matchNo;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public Integer getKoMatch() {
|
||||
return this.koMatch;
|
||||
}
|
||||
@@ -267,10 +256,6 @@ public class TLWMatch extends BaseMatch{
|
||||
this.goalsOvertimeGuest = goals;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setMatchDateTime(String matchDateTime) {
|
||||
this.matchDatetime = matchDateTime;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -82,15 +82,13 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
|
||||
try {
|
||||
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy);
|
||||
tlwMatchesCopy.remove(tlwMatch);
|
||||
if(Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_STARTED)
|
||||
|| Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_PROVISIONAL_RESULT_AVAILABLE)
|
||||
|| Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_FINISHED)) {
|
||||
if(Objects.equals(apiFootballMatch.getStatus(), TLWMatch.STATUS_FINISHED)) {
|
||||
if(!Objects.equals(tlwMatch.getGoalsHome(), apiFootballMatch.getGoalsHome())
|
||||
|| !Objects.equals(tlwMatch.getGoalsGuest(), apiFootballMatch.getGoalsGuest())
|
||||
) {
|
||||
tlwMatch.setGoalsHome(apiFootballMatch.getGoalsHome());
|
||||
tlwMatch.setGoalsGuest(apiFootballMatch.getGoalsGuest());
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
|
||||
}
|
||||
if(tlwMatch.getKoMatch() == 1 &&
|
||||
this.betKOType == 2 &&
|
||||
@@ -99,7 +97,7 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
|
||||
) {
|
||||
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome());
|
||||
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest());
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
|
||||
}
|
||||
if(tlwMatch.getKoMatch() == 1 &&
|
||||
(this.betKOType == 1 || this.betKOType == 3) &&
|
||||
@@ -109,7 +107,7 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
|
||||
) {
|
||||
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsPenaltyHome());
|
||||
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsPenaltyGuest());
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
|
||||
}
|
||||
if(tlwMatch.getKoMatch() == 1 &&
|
||||
(this.betKOType == 1 || this.betKOType == 3) &&
|
||||
@@ -119,10 +117,10 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
|
||||
) {
|
||||
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome());
|
||||
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)) {
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
|
||||
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON.DIFFERENT_RESULT);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
|
||||
Reference in New Issue
Block a user