Add support for EM Tippspiel
This commit is contained in:
@@ -10,6 +10,7 @@ public class APIFootballMatch extends BaseMatch {
|
||||
private final int leagueId;
|
||||
private final String teamNameHome;
|
||||
private final String teamNameGuest;
|
||||
private final String round;
|
||||
private Boolean showTable = null;
|
||||
|
||||
public APIFootballMatch(JSONObject json, int season) throws Exception {
|
||||
@@ -22,8 +23,9 @@ public class APIFootballMatch extends BaseMatch {
|
||||
this.teamNameGuest = ((JSONObject) json.get("awayTeam")).get("team_name").toString();
|
||||
this.goalsHome = getNumberOrNull(json.get("goalsHomeTeam"));
|
||||
this.goalsGuest = getNumberOrNull(json.get("goalsAwayTeam"));
|
||||
this.round = json.get("round").toString();
|
||||
try {
|
||||
this.matchday = getMatchdayFromRoundString(season, json.get("round").toString(), this.leagueId);
|
||||
this.matchday = getMatchdayFromRoundString(season, this.round, this.leagueId);
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Did not find matchday for league '" + this.leagueId + "': '" + json.get("round").toString() + "'");
|
||||
}
|
||||
@@ -61,6 +63,10 @@ public class APIFootballMatch extends BaseMatch {
|
||||
return this.teamNameGuest;
|
||||
}
|
||||
|
||||
public String getRound() {
|
||||
return this.round;
|
||||
}
|
||||
|
||||
public void setShowTable(boolean showTable) {
|
||||
this.showTable = showTable;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class TLWMatch extends BaseMatch{
|
||||
this.goalsHome = apiFootballMatch.getGoalsHome();
|
||||
this.goalsGuest = apiFootballMatch.getGoalsGuest();
|
||||
this.matchDatetime = apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19);
|
||||
this.groupId = "";
|
||||
this.groupId = this.getGroupFromMatchdayString(apiFootballMatch.getRound());
|
||||
this.formulaHome = "";
|
||||
this.formulaGuest = "";
|
||||
this.status = status;
|
||||
@@ -235,7 +235,7 @@ public class TLWMatch extends BaseMatch{
|
||||
nullToSqlEmptyString(this.goalsOvertimeHome) + ", " +
|
||||
nullToSqlEmptyString(this.goalsOvertimeGuest) + ", " +
|
||||
nullToSqlEmptyString(this.showTable) + ", " +
|
||||
"'0.00','0.00','0.00','0.00'";
|
||||
"'','0.00','0.00','0.00','0.00'";
|
||||
}
|
||||
|
||||
private String nullToSqlEmptyString(Integer number) {
|
||||
@@ -267,4 +267,12 @@ public class TLWMatch extends BaseMatch{
|
||||
this.goalsGuest = apiFootballMatch.getGoalsGuest();
|
||||
this.matchDatetime = apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19);
|
||||
}
|
||||
|
||||
private String getGroupFromMatchdayString(String matchdayString) {
|
||||
if(matchdayString.startsWith("Group ")) {
|
||||
return matchdayString.substring(6, 7);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public class TLWMatchdaysCreator {
|
||||
ArrayList<TLWMatchday> matchdays = new ArrayList<>();
|
||||
|
||||
JSONArray matchdaysConfig = (JSONArray) this.configObject.get("matchdayConfig");
|
||||
String deliveryDateMode = this.configObject.containsKey("deliveryDateMode") ? this.configObject.get("deliveryDateMode").toString() : "";
|
||||
for (Object matchdayConfig : matchdaysConfig) {
|
||||
JSONObject matchdayConfigJson = (JSONObject) matchdayConfig;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class TLWMatchdaysCreator {
|
||||
numberOfMatches = Integer.parseInt(matchdayConfigJson.get("numberOfMatches").toString());
|
||||
}
|
||||
|
||||
ArrayList<String> deliveryDates = getDeliveryDates(matchdayConfigJson, matchdayNumber);
|
||||
ArrayList<String> deliveryDates = getDeliveryDates(matchdayConfigJson, matchdayNumber, deliveryDateMode);
|
||||
|
||||
TLWMatchday matchday = new TLWMatchday(this.season, this.league, matchdayNumber, 0, deliveryDates.get(0), deliveryDates.get(1), deliveryDates.get(2), matchdayName, numberOfMatches);
|
||||
matchdays.add(matchday);
|
||||
@@ -78,17 +79,44 @@ public class TLWMatchdaysCreator {
|
||||
return matchdayName;
|
||||
}
|
||||
|
||||
private ArrayList<String> getDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) {
|
||||
ArrayList<String> deliveryDates = getDefaultDeliveryDates(matchdayConfigJson, matchdayNumber);
|
||||
deliveryDates.addAll(getAdditionalDeliveryDates(matchdayConfigJson, matchdayNumber));
|
||||
deliveryDates = removeDuplicates(deliveryDates);
|
||||
private ArrayList<String> getDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber, String deliveryDateMode) {
|
||||
ArrayList<String> deliveryDates;
|
||||
switch(deliveryDateMode) {
|
||||
case "single":
|
||||
deliveryDates = getDefaultSingleDeliveryDate(matchdayConfigJson, matchdayNumber);
|
||||
break;
|
||||
case "multiple":
|
||||
default:
|
||||
deliveryDates = getDefaultMultipleDeliveryDates(matchdayConfigJson, matchdayNumber);
|
||||
deliveryDates.addAll(getAdditionalDeliveryDates(matchdayConfigJson, matchdayNumber));
|
||||
deliveryDates = removeDuplicates(deliveryDates);
|
||||
break;
|
||||
}
|
||||
while(deliveryDates.size() < 3) {
|
||||
deliveryDates.add("");
|
||||
}
|
||||
return deliveryDates;
|
||||
}
|
||||
|
||||
private ArrayList<String> getDefaultDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) {
|
||||
private ArrayList<String> getDefaultSingleDeliveryDate(JSONObject matchdayConfigJson, int matchdayNumber) {
|
||||
ArrayList<String> deliveryDates = new ArrayList<>();
|
||||
|
||||
JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig");
|
||||
JSONObject matchesConfigPlaceholder = (JSONObject) matchesConfig.get(matchesConfig.size() - 1);
|
||||
ArrayList<TLWMatch> matchesOfMatchday = getMatchesForMatchday(matches, matchdayNumber);
|
||||
if(matchesOfMatchday.size() == 0) {
|
||||
deliveryDates.add(matchesConfigPlaceholder.get("placeholderDatetime").toString());
|
||||
}
|
||||
else {
|
||||
LocalDateTime firstMatchDate = TLWMatchesManagerBase.getFirstMatchtimeTLW(matchesOfMatchday);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
deliveryDates.add(firstMatchDate.format(formatter));
|
||||
}
|
||||
|
||||
return deliveryDates;
|
||||
}
|
||||
|
||||
private ArrayList<String> getDefaultMultipleDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) {
|
||||
ArrayList<String> deliveryDates = new ArrayList<>();
|
||||
|
||||
JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig");
|
||||
|
||||
@@ -18,6 +18,7 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
||||
int ko;
|
||||
int nextMatchNo = 1;
|
||||
JSONArray matchdayConfig;
|
||||
JSONObject config;
|
||||
|
||||
public TLWMatchesCreatorFootball(int season, int league, String configFileName) {
|
||||
|
||||
@@ -28,19 +29,20 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
||||
this.conn = APIFootballConnector.getAPIFootballConnectorInstance(season - 1);
|
||||
|
||||
TippligaConfigProvider prov = new TippligaConfigProvider(season);
|
||||
JSONObject config = prov.getTippligaConfig(configFileName);
|
||||
this.config = prov.getTippligaConfig(configFileName);
|
||||
|
||||
this.numberOfMatchdays = ((Long) config.get("numberOfMatchdays")).intValue();
|
||||
this.matchdayConfig = (JSONArray) config.get("matchdayConfig");
|
||||
this.ko = ((Long) config.get("ko")).intValue();
|
||||
this.numberOfMatchdays = ((Long) this.config.get("numberOfMatchdays")).intValue();
|
||||
this.matchdayConfig = (JSONArray) this.config.get("matchdayConfig");
|
||||
this.ko = ((Long) this.config.get("ko")).intValue();
|
||||
String deliveryDateMode = this.config.containsKey("deliveryDateMode") ? this.config.get("deliveryDateMode").toString() : "";
|
||||
|
||||
this.publicateMatchObjects();
|
||||
this.publicateMatchObjects(deliveryDateMode);
|
||||
}
|
||||
|
||||
private void publicateMatchObjects() {
|
||||
|
||||
private void publicateMatchObjects(String deliveryDateMode) {
|
||||
for(int i = 0; i < this.matchdayConfig.size(); i++) {
|
||||
int TLWMatchday = ((Long) ((JSONObject) this.matchdayConfig.get(i)).get("TLWMatchday")).intValue();
|
||||
|
||||
JSONArray matchesConfig = (JSONArray)((JSONObject) this.matchdayConfig.get(i)).get("matchesConfig");
|
||||
ArrayList<APIFootballMatch> apiFootballMatchesForMatchday = getAPIFootballMatchesForMatchday(matchesConfig);
|
||||
|
||||
@@ -59,7 +61,9 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
||||
this.nextMatchNo++;
|
||||
int status = 0;
|
||||
LocalDateTime matchDateTime = TLWMatchesManagerBase.getDate(match);
|
||||
if(firstDate != null && TLWMatchesManagerBase.getDaysDifference(firstDate, matchDateTime) >= 1) {
|
||||
if(!deliveryDateMode.equals("single")
|
||||
&& firstDate != null
|
||||
&& TLWMatchesManagerBase.getDaysDifference(firstDate, matchDateTime) >= 1) {
|
||||
status = -1;
|
||||
}
|
||||
this.TLWMatches.add(new TLWMatch(match, this.season, this.league, TLWMatchday, matchNo, status, this.ko));
|
||||
|
||||
@@ -39,8 +39,8 @@ public class TLWTeamsCreator {
|
||||
String teamName = teams.get(0).getTeamName();
|
||||
String teamNameShort = teams.get(0).getTeamNameShort();
|
||||
String teamSymbol = teams.get(0).getTeamSymbol();
|
||||
String groupId = "";
|
||||
int matchday = 0;
|
||||
String groupId = getGroup(id);
|
||||
int matchday = getMatchday(id);
|
||||
sql += "REPLACE INTO phpbb_footb_teams VALUES ('";
|
||||
sql += this.season;
|
||||
sql += "', '";
|
||||
@@ -61,4 +61,23 @@ public class TLWTeamsCreator {
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
String getGroup(Integer teamId) {
|
||||
for(TLWMatch match: matches) {
|
||||
if(teamId.equals(match.getTeamIdHome()) || teamId.equals(match.getTeamIdGuest())) {
|
||||
return match.getGroupId();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
int getMatchday(Integer teamId) {
|
||||
int matchday = 0;
|
||||
for(TLWMatch match: matches) {
|
||||
if(teamId.equals(match.getTeamIdHome()) || teamId.equals(match.getTeamIdGuest())) {
|
||||
matchday = matchday > match.getMatchday() ? matchday : match.getMatchday();
|
||||
}
|
||||
}
|
||||
return matchday;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TippligaSQLConnector {
|
||||
"&allowMultiQueries=true" +
|
||||
"&useSSL=false";
|
||||
try {
|
||||
con = DriverManager.getConnection(jdbcUrlProd);
|
||||
con = DriverManager.getConnection(jdbcUrlLocalhost);
|
||||
} catch (SQLException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user