Fix matches results updater

This commit is contained in:
Julian Arndt
2023-08-14 10:03:44 +02:00
parent 2acc6acafe
commit 23cef6f545
9 changed files with 91 additions and 19 deletions

View File

@@ -15,6 +15,8 @@ public abstract class BaseMatch {
protected Integer goalsGuest = null;
protected Integer goalsOvertimeHome = null;
protected Integer goalsOvertimeGuest = null;
protected Integer goalsPenaltyHome = null;
protected Integer goalsPenaltyGuest = null;
protected Integer matchday = null;
protected String matchDatetime = null;
@@ -52,6 +54,14 @@ public abstract class BaseMatch {
return this.goalsOvertimeGuest;
}
public Integer getGoalsPenaltyHome() {
return this.goalsPenaltyHome;
}
public Integer getGoalsPenaltyGuest() {
return this.goalsPenaltyGuest;
}
public String getTeamNameHome() {
return this.teamNameHome;
}

View File

@@ -79,14 +79,23 @@ public class APIFootballMatch extends BaseMatch {
private void parseResult(JSONObject json) {
Object resultFulltime = ((JSONObject) json.get("score")).get("fulltime");
if(resultFulltime != null) {
this.goalsHome = Integer.parseInt(resultFulltime.toString().substring(0, 1));
this.goalsGuest = Integer.parseInt(resultFulltime.toString().substring(2, 3));
String[] result = resultFulltime.toString().split("-");
this.goalsHome = Integer.parseInt(result[0]);
this.goalsGuest = Integer.parseInt(result[1]);
}
Object resultExtratime = ((JSONObject) json.get("score")).get("extratime");
if(resultExtratime != null) {
this.goalsOvertimeHome = this.goalsHome + Integer.parseInt(resultExtratime.toString().substring(0, 1));
this.goalsOvertimeGuest = this.goalsGuest + Integer.parseInt(resultExtratime.toString().substring(2, 3));
String[] result = resultExtratime.toString().split("-");
this.goalsOvertimeHome = this.goalsHome + Integer.parseInt(result[0]);
this.goalsOvertimeGuest = this.goalsGuest + Integer.parseInt(result[1]);
}
Object resultPenalty = ((JSONObject) json.get("score")).get("penalty");
if(resultPenalty != null) {
String[] result = resultPenalty.toString().split("-");
this.goalsPenaltyHome = this.goalsOvertimeHome + Integer.parseInt(result[0]);
this.goalsPenaltyGuest = this.goalsOvertimeGuest + Integer.parseInt(result[1]);
}
}
}

View File

@@ -28,8 +28,6 @@ public class TLWMatch extends BaseMatch{
private String formulaGuest = null;
private Integer status = null;
private Integer koMatch = 0;
private Integer goalsOvertimeHome = null;
private Integer goalsOvertimeGuest = null;
private Integer showTable = null;
private String trend = null;
private Float odd1 = null;

View File

@@ -18,6 +18,7 @@ public class TLWMatchesManagerBase {
protected int numberOfMatchdays;
protected int matchesPerMatchday;
protected int ko;
protected int betKOType;
protected JSONArray matchdayConfig;
@@ -28,6 +29,8 @@ public class TLWMatchesManagerBase {
this.numberOfMatchdays = ((Long) config.get("numberOfMatchdays")).intValue();
this.matchdayConfig = (JSONArray) config.get("matchdayConfig");
this.ko = ((Long) config.get("ko")).intValue();
Long parsedBetKOType = (Long) config.get("betKOType");
this.betKOType = parsedBetKOType == null ? 1 : parsedBetKOType.intValue();
}
public static ArrayList<TLWMatch> getMatchesStartingFromSecondDay(ArrayList<TLWMatch> matches) {

View File

@@ -93,6 +93,7 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
}
if(tlwMatch.getKoMatch() == 1 &&
this.betKOType == 2 &&
(!Objects.equals(tlwMatch.getGoalsOvertimeHome(), apiFootballMatch.getGoalsOvertimeHome())
|| !Objects.equals(tlwMatch.getGoalsOvertimeGuest(), apiFootballMatch.getGoalsOvertimeGuest()))
) {
@@ -100,6 +101,29 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest());
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
}
if(tlwMatch.getKoMatch() == 1 &&
(this.betKOType == 1 || this.betKOType == 3) &&
(apiFootballMatch.getGoalsPenaltyHome() != null) &&
(!Objects.equals(tlwMatch.getGoalsOvertimeHome(), apiFootballMatch.getGoalsPenaltyHome())
|| !Objects.equals(tlwMatch.getGoalsOvertimeGuest(), apiFootballMatch.getGoalsPenaltyGuest()))
) {
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsPenaltyHome());
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsPenaltyGuest());
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
}
if(tlwMatch.getKoMatch() == 1 &&
(this.betKOType == 1 || this.betKOType == 3) &&
(apiFootballMatch.getGoalsPenaltyHome() == null) &&
(!Objects.equals(tlwMatch.getGoalsOvertimeHome(), apiFootballMatch.getGoalsOvertimeHome())
|| !Objects.equals(tlwMatch.getGoalsOvertimeGuest(), apiFootballMatch.getGoalsOvertimeGuest()))
) {
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome());
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest());
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
}
if(Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_PROVISIONAL_RESULT_AVAILABLE)) {
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
}
}
} catch (NullPointerException ignored) {
@@ -120,15 +144,30 @@ public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
"Spielnummer " + matchOriginal.getMatchNo() + ", " +
"Spiel '" + TeamIDMatcher.getTeamNameFromTippligaId(matchOriginal.getTeamIdHome()) + "' - '" + TeamIDMatcher.getTeamNameFromTippligaId(matchOriginal.getTeamIdGuest()) + "', ";
if(!Objects.equals(matchOriginal.getGoalsHome(), matchUpdated.getGoalsHome()) || !Objects.equals(matchOriginal.getGoalsGuest(), matchUpdated.getGoalsGuest())) {
if(!Objects.equals(matchOriginal.getGoalsHome(), matchUpdated.getGoalsHome())
|| !Objects.equals(matchOriginal.getGoalsGuest(), matchUpdated.getGoalsGuest())) {
this.beautifulInfo += beautifulInfoStart +
"Ergebnis zu '" + matchUpdated.getGoalsHome() + ":" + matchUpdated.getGoalsGuest() + "'.\n";
}
if(matchOriginal.getKoMatch() == 1 && (!Objects.equals(matchOriginal.getGoalsOvertimeHome(), matchUpdated.getGoalsOvertimeHome()) || !Objects.equals(matchOriginal.getGoalsOvertimeGuest(), matchUpdated.getGoalsOvertimeGuest()))) {
if(matchOriginal.getKoMatch() == 1 && (!Objects.equals(matchOriginal.getGoalsOvertimeHome(), matchUpdated.getGoalsOvertimeHome())
|| !Objects.equals(matchOriginal.getGoalsOvertimeGuest(), matchUpdated.getGoalsOvertimeGuest()))) {
this.beautifulInfo += beautifulInfoStart +
"Ergebnis Nachspielzeit zu '" + matchUpdated.getGoalsOvertimeHome() + ":" + matchUpdated.getGoalsOvertimeGuest() + "'.\n";
}
if(matchOriginal.getStatus().equals(TLWMatch.STATUS_PROVISIONAL_RESULT_AVAILABLE)
&& Objects.equals(matchOriginal.getGoalsHome(), matchUpdated.getGoalsHome())
&& Objects.equals(matchOriginal.getGoalsGuest(), matchUpdated.getGoalsGuest())
&& (matchOriginal.getKoMatch() == 0 || (
matchOriginal.getKoMatch() == 1
&& Objects.equals(matchOriginal.getGoalsOvertimeHome(), matchUpdated.getGoalsOvertimeHome())
&& Objects.equals(matchOriginal.getGoalsOvertimeGuest(), matchUpdated.getGoalsOvertimeGuest())
))
) {
this.beautifulInfo += beautifulInfoStart +
"Ergebnis gespeichert.\n";
}
}
public String getBeautifulInfo() {

View File

@@ -187,6 +187,10 @@ public class TippligaWebsiteConnector {
resultParameters.put("select_" + matchNo, "on");
resultParameters.put("goals_home_" + matchNo, String.valueOf(tlwMatch.getGoalsHome()));
resultParameters.put("goals_guest_" + matchNo, String.valueOf(tlwMatch.getGoalsGuest()));
Integer goalsOverTimeHome = tlwMatch.getGoalsOvertimeHome();
Integer goalsOvertimeGuest = tlwMatch.getGoalsOvertimeGuest();
resultParameters.put("overtime_home_" + matchNo, goalsOverTimeHome == null ? "" : String.valueOf(goalsOverTimeHome));
resultParameters.put("overtime_guest_" + matchNo, goalsOvertimeGuest == null ? "" : String.valueOf(goalsOvertimeGuest));
});
String resultForm = resultParameters.entrySet()

View File

@@ -35,7 +35,15 @@ public class TippligaGoogleEventManagerTest {
@Test
public void createOrUpdateEventsForMatchdayTippligaTest() {
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 1, "Tippliga");
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2024, 1, "Tippliga");
ArrayList<TLWMatchday> matchdays = creator.getMatchdays();
matchdays.forEach(TippligaGoogleEventManager::createOrUpdateEventsForMatchday);
}
@Test
public void createOrUpdateEventsForMatchdaySupercupTest() {
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2024, 45, "Supercup");
ArrayList<TLWMatchday> matchdays = creator.getMatchdays();
matchdays.forEach(TippligaGoogleEventManager::createOrUpdateEventsForMatchday);
@@ -61,7 +69,7 @@ public class TippligaGoogleEventManagerTest {
@Test
public void createOrUpdateEventsForMatchdayWTLPokalTest() {
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 48, "WTL-Pokal");
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2024, 48, "WTL-Pokal");
ArrayList<TLWMatchday> matchdays = creator.getMatchdays();
// createOrUpdateEventsForMatchday(matchdays.get(4));

View File

@@ -6,8 +6,8 @@ public class TLWMatchesResultsUpdaterTest {
@Test
public void updateResultsTest1() {
// TLWMatchesResultsUpdater updater = new TLWMatchesResultsUpdater(2023, 2, "Tippliga");
System.out.println("Done");
return;
TLWMatchesResultsUpdater updater = new TLWMatchesResultsUpdater(2024, 48, "WTL-Pokal");
// updater.applyUpdates();
System.out.println(updater.getBeautifulInfo());
}
}

View File

@@ -4,30 +4,31 @@ import org.junit.Test;
public class TLWMatchesUpdaterFootballTest {
int season = 2024;
@Test
public void getUpdateSqlTest1() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2022, 1, "Tippliga");
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(season, 1, "Tippliga");
String sql = updater.getUpdateSQL();
// System.out.println(sql);
System.out.println(sql);
// System.out.println(updater.getBeautifulInfo());
}
@Test
public void getUpdateSqlTest2() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 2, "Tippliga");
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(season, 2, "Tippliga");
String sql = updater.getUpdateSQL();
// System.out.println(sql);
System.out.println(sql);
// System.out.println(updater.getBeautifulInfo());
}
@Test
public void getUpdateSqlTest48() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 48, "WTL-Pokal");
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(season, 48, "WTL-Pokal");
String sql = updater.getUpdateSQL();
// System.out.println(sql);
System.out.println(sql);
// System.out.println(updater.getBeautifulInfo());
}
}