Add several improvements for EM
This commit is contained in:
@@ -12,6 +12,8 @@ import org.json.simple.JSONObject;
|
||||
|
||||
import java.time.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
private static final Logger logger = LogManager.getLogger(TLWMatchesUpdaterFootball.class);
|
||||
@@ -38,9 +40,8 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
TippligaSQLConnector tippligaSQLConnector = TippligaSQLConnector.getInstance();
|
||||
for (Object singleMatchdayConfig : this.matchdayConfig) {
|
||||
int tlwMatchday = ((Long) ((JSONObject) singleMatchdayConfig).get("TLWMatchday")).intValue();
|
||||
JSONArray matchesConfig = (JSONArray) ((JSONObject) singleMatchdayConfig).get("matchesConfig");
|
||||
|
||||
ArrayList<APIFootballMatch> apiFootballMatches = apiFootballMatchesProvider.getAPIFootballMatchesFromConfig(matchesConfig);
|
||||
ArrayList<APIFootballMatch> apiFootballMatches = apiFootballMatchesProvider.getAPIFootballMatchesFromConfig((JSONObject) singleMatchdayConfig);
|
||||
|
||||
ArrayList<TLWMatch> tlwMatchesOriginalMatchday = tippligaSQLConnector.getMatches(String.valueOf(this.season), String.valueOf(this.league), String.valueOf(tlwMatchday));
|
||||
ArrayList<TLWMatch> tlwMatchesUpdatedMatchday = new ArrayList<>();
|
||||
@@ -64,6 +65,10 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
updateShowTable(tlwMatchesUpdatedMatchday, apiFootballMatches);
|
||||
updateStatus(tlwMatchesUpdatedMatchday);
|
||||
}
|
||||
if(now.isBefore(firstMatchOriginal)) {
|
||||
updateStatus(tlwMatchesUpdatedMatchday);
|
||||
addPlaceholderMatches(tlwMatchesUpdatedMatchday, (JSONObject) singleMatchdayConfig);
|
||||
}
|
||||
|
||||
this.tlwMatchesOriginal.addAll(tlwMatchesOriginalMatchday);
|
||||
this.tlwMatchesUpdated.addAll(tlwMatchesUpdatedMatchday);
|
||||
@@ -135,6 +140,14 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
"Spiel in Tabelle einberechnen zu '" + (matchUpdated.getShowTable() == 1 ? "falsch" : "wahr") + "'.\n";
|
||||
}
|
||||
|
||||
if (!matchOriginal.getKoMatch().equals(matchUpdated.getKoMatch())) {
|
||||
updateString += updateStart +
|
||||
"ko_match = '" + (matchUpdated.getKoMatch() ? "1" : "0") + "' " +
|
||||
condition;
|
||||
this.beautifulInfo += beautifulInfoStart +
|
||||
"KO zu '" + (matchUpdated.getKoMatch() ? "wahr" : "falsch") + "'.\n";
|
||||
}
|
||||
|
||||
|
||||
return updateString;
|
||||
}
|
||||
@@ -145,30 +158,80 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
ArrayList<APIFootballMatch> missingMatches = new ArrayList<>();
|
||||
|
||||
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
|
||||
try {
|
||||
if(getMatchingMatch(apiFootballMatch, tlwMatches) == null) {
|
||||
missingMatches.add(apiFootballMatch);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
|
||||
if(getMatchingMatch(apiFootballMatch, tlwMatches) == null) {
|
||||
missingMatches.add(apiFootballMatch);
|
||||
}
|
||||
}
|
||||
|
||||
for (APIFootballMatch missingMatch : missingMatches) {
|
||||
boolean done = false;
|
||||
for(TLWMatch tlwMatch : tlwMatches) {
|
||||
if(tlwMatch.getTeamIdHome() == 0 && tlwMatch.getTeamIdGuest() == 0) {
|
||||
// update placeholder match based on matching match datetime
|
||||
for (TLWMatch tlwMatch : tlwMatches) {
|
||||
if ( tlwMatch.getTeamIdHome() == 0 && tlwMatch.getTeamIdGuest() == 0
|
||||
&& Objects.equals(tlwMatch.getMatchDateTime(), missingMatch.getMatchDateTime().replace("T", " ").substring(0, 19))
|
||||
&& !Objects.equals(tlwMatch.getFormulaHome(), "")
|
||||
&& !Objects.equals(tlwMatch.getFormulaGuest(), "")) {
|
||||
tlwMatch.updateMatch(missingMatch);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// update empty match
|
||||
if(!done) {
|
||||
for (TLWMatch tlwMatch : tlwMatches) {
|
||||
if (tlwMatch.getTeamIdHome() == 0 && tlwMatch.getTeamIdGuest() == 0
|
||||
&& Objects.equals(tlwMatch.getFormulaHome(), "")
|
||||
&& Objects.equals(tlwMatch.getFormulaGuest(), "")) {
|
||||
tlwMatch.updateMatch(missingMatch);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!done) {
|
||||
logger.error("Could not add missing match: " + this.season + ", " + this.league + ", " + tlwMatches.get(0).getMatchday() + ", " + missingMatch.getTeamNameHome() + " - " + missingMatch.getTeamNameGuest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPlaceholderMatches(ArrayList<TLWMatch> tlwMatches,
|
||||
JSONObject matchdayConfig) {
|
||||
ArrayList<TLWMatch> placeholderMatches = new ArrayList<>();
|
||||
ArrayList<TLWMatch> tlwMatchesCopy = new ArrayList<>(tlwMatches);
|
||||
JSONArray matchesConfig = (JSONArray) matchdayConfig.get("matchesConfig");
|
||||
for (Object singleMatchConfig : matchesConfig) {
|
||||
// check if type placeholderSingleMatch
|
||||
if(((JSONObject) singleMatchConfig).get("type").equals("PlaceholderSingleMatch")) {
|
||||
String formulaHome = (String) ((JSONObject) singleMatchConfig).get("formulaHome");
|
||||
String formulaGuest = (String) ((JSONObject) singleMatchConfig).get("formulaGuest");
|
||||
String matchDateTime = (String) ((JSONObject) singleMatchConfig).get("placeholderDatetime");
|
||||
TLWMatch placeholderMatch = new TLWMatch(formulaHome, formulaGuest, matchDateTime);
|
||||
placeholderMatches.add(placeholderMatch);
|
||||
}
|
||||
}
|
||||
// filter placeholderMatches by checking if they are already in tlwMatches
|
||||
Iterator<TLWMatch> placeholderIterator = placeholderMatches.iterator();
|
||||
while (placeholderIterator.hasNext()) {
|
||||
TLWMatch placeholderMatch = placeholderIterator.next();
|
||||
Iterator<TLWMatch> tlwMatchIterator = tlwMatchesCopy.iterator();
|
||||
while (tlwMatchIterator.hasNext()) {
|
||||
TLWMatch tlwMatch = tlwMatchIterator.next();
|
||||
if (TLWMatch.isSameMatchPlaceholder(tlwMatch, placeholderMatch)) {
|
||||
tlwMatchIterator.remove();
|
||||
placeholderIterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check if total number of matches is not too high
|
||||
if(tlwMatches.size() + placeholderMatches.size() > (Integer.parseInt(matchdayConfig.get("numberOfMatches").toString()))) {
|
||||
logger.error("Too many matches in config: " + this.season + ", " + this.league + ", " + tlwMatches.get(0).getMatchday());
|
||||
} else {
|
||||
// add placeholderMatches to tlwMatches
|
||||
tlwMatches.addAll(placeholderMatches);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMatchDateTimes(
|
||||
ArrayList<TLWMatch> tlwMatches,
|
||||
ArrayList<APIFootballMatch> apiFootballMatches)
|
||||
@@ -195,10 +258,13 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
if(earliestDate.isAfter(now)) {
|
||||
for(TLWMatch match : matches) {
|
||||
LocalDateTime date = TLWMatchesManagerBase.getDate(match);
|
||||
if (getDaysDifference(earliestDate, date) == 0) {
|
||||
int daysDifference = TLWMatchesManagerBase.getDaysDifference(earliestDate, date);
|
||||
if (daysDifference == 0) {
|
||||
match.setStatus(0);
|
||||
} else {
|
||||
} else if (daysDifference > 0 && daysDifference < 7) {
|
||||
match.setStatus(-1);
|
||||
} else {
|
||||
match.setStatus(-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,7 +279,23 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
try {
|
||||
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy);
|
||||
tlwMatchesCopy.remove(tlwMatch);
|
||||
tlwMatch.setShowTable(apiFootballMatch.getShowTable());
|
||||
tlwMatch.setShowTable(apiFootballMatch.getShowTable() == 0);
|
||||
} catch (NullPointerException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateKo(
|
||||
ArrayList<TLWMatch> tlwMatches,
|
||||
ArrayList<APIFootballMatch> apiFootballMatches)
|
||||
{
|
||||
ArrayList<TLWMatch> tlwMatchesCopy = new ArrayList<>(tlwMatches);
|
||||
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
|
||||
try {
|
||||
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy);
|
||||
tlwMatchesCopy.remove(tlwMatch);
|
||||
tlwMatch.setKoMatch(apiFootballMatch.getKoMatch());
|
||||
} catch (NullPointerException ignored) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user