Add support for EM Tippspiel

This commit is contained in:
2021-06-05 21:38:11 +02:00
parent af28e5cb6f
commit 089b8eba08
11 changed files with 235 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ public class APIFootballMatch extends BaseMatch {
private final int leagueId; private final int leagueId;
private final String teamNameHome; private final String teamNameHome;
private final String teamNameGuest; private final String teamNameGuest;
private final 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 {
@@ -22,8 +23,9 @@ public class APIFootballMatch extends BaseMatch {
this.teamNameGuest = ((JSONObject) json.get("awayTeam")).get("team_name").toString(); this.teamNameGuest = ((JSONObject) json.get("awayTeam")).get("team_name").toString();
this.goalsHome = getNumberOrNull(json.get("goalsHomeTeam")); this.goalsHome = getNumberOrNull(json.get("goalsHomeTeam"));
this.goalsGuest = getNumberOrNull(json.get("goalsAwayTeam")); this.goalsGuest = getNumberOrNull(json.get("goalsAwayTeam"));
this.round = json.get("round").toString();
try { try {
this.matchday = getMatchdayFromRoundString(season, json.get("round").toString(), this.leagueId); this.matchday = getMatchdayFromRoundString(season, this.round, this.leagueId);
} catch (Exception e) { } catch (Exception e) {
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() + "'");
} }
@@ -61,6 +63,10 @@ public class APIFootballMatch extends BaseMatch {
return this.teamNameGuest; return this.teamNameGuest;
} }
public String getRound() {
return this.round;
}
public void setShowTable(boolean showTable) { public void setShowTable(boolean showTable) {
this.showTable = showTable; this.showTable = showTable;
} }

View File

@@ -100,7 +100,7 @@ public class TLWMatch extends BaseMatch{
this.goalsHome = apiFootballMatch.getGoalsHome(); this.goalsHome = apiFootballMatch.getGoalsHome();
this.goalsGuest = apiFootballMatch.getGoalsGuest(); this.goalsGuest = apiFootballMatch.getGoalsGuest();
this.matchDatetime = apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19); this.matchDatetime = apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19);
this.groupId = ""; this.groupId = this.getGroupFromMatchdayString(apiFootballMatch.getRound());
this.formulaHome = ""; this.formulaHome = "";
this.formulaGuest = ""; this.formulaGuest = "";
this.status = status; this.status = status;
@@ -235,7 +235,7 @@ public class TLWMatch extends BaseMatch{
nullToSqlEmptyString(this.goalsOvertimeHome) + ", " + nullToSqlEmptyString(this.goalsOvertimeHome) + ", " +
nullToSqlEmptyString(this.goalsOvertimeGuest) + ", " + nullToSqlEmptyString(this.goalsOvertimeGuest) + ", " +
nullToSqlEmptyString(this.showTable) + ", " + nullToSqlEmptyString(this.showTable) + ", " +
"'0.00','0.00','0.00','0.00'"; "'','0.00','0.00','0.00','0.00'";
} }
private String nullToSqlEmptyString(Integer number) { private String nullToSqlEmptyString(Integer number) {
@@ -267,4 +267,12 @@ public class TLWMatch extends BaseMatch{
this.goalsGuest = apiFootballMatch.getGoalsGuest(); this.goalsGuest = apiFootballMatch.getGoalsGuest();
this.matchDatetime = apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19); 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 "";
}
}
} }

View File

@@ -36,6 +36,7 @@ public class TLWMatchdaysCreator {
ArrayList<TLWMatchday> matchdays = new ArrayList<>(); ArrayList<TLWMatchday> matchdays = new ArrayList<>();
JSONArray matchdaysConfig = (JSONArray) this.configObject.get("matchdayConfig"); JSONArray matchdaysConfig = (JSONArray) this.configObject.get("matchdayConfig");
String deliveryDateMode = this.configObject.containsKey("deliveryDateMode") ? this.configObject.get("deliveryDateMode").toString() : "";
for (Object matchdayConfig : matchdaysConfig) { for (Object matchdayConfig : matchdaysConfig) {
JSONObject matchdayConfigJson = (JSONObject) matchdayConfig; JSONObject matchdayConfigJson = (JSONObject) matchdayConfig;
@@ -47,7 +48,7 @@ public class TLWMatchdaysCreator {
numberOfMatches = Integer.parseInt(matchdayConfigJson.get("numberOfMatches").toString()); 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); TLWMatchday matchday = new TLWMatchday(this.season, this.league, matchdayNumber, 0, deliveryDates.get(0), deliveryDates.get(1), deliveryDates.get(2), matchdayName, numberOfMatches);
matchdays.add(matchday); matchdays.add(matchday);
@@ -78,17 +79,44 @@ public class TLWMatchdaysCreator {
return matchdayName; return matchdayName;
} }
private ArrayList<String> getDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) { private ArrayList<String> getDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber, String deliveryDateMode) {
ArrayList<String> deliveryDates = getDefaultDeliveryDates(matchdayConfigJson, matchdayNumber); ArrayList<String> deliveryDates;
deliveryDates.addAll(getAdditionalDeliveryDates(matchdayConfigJson, matchdayNumber)); switch(deliveryDateMode) {
deliveryDates = removeDuplicates(deliveryDates); 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) { while(deliveryDates.size() < 3) {
deliveryDates.add(""); deliveryDates.add("");
} }
return deliveryDates; 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<>(); ArrayList<String> deliveryDates = new ArrayList<>();
JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig"); JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig");

View File

@@ -18,6 +18,7 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
int ko; int ko;
int nextMatchNo = 1; int nextMatchNo = 1;
JSONArray matchdayConfig; JSONArray matchdayConfig;
JSONObject config;
public TLWMatchesCreatorFootball(int season, int league, String configFileName) { public TLWMatchesCreatorFootball(int season, int league, String configFileName) {
@@ -28,19 +29,20 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
this.conn = APIFootballConnector.getAPIFootballConnectorInstance(season - 1); this.conn = APIFootballConnector.getAPIFootballConnectorInstance(season - 1);
TippligaConfigProvider prov = new TippligaConfigProvider(season); TippligaConfigProvider prov = new TippligaConfigProvider(season);
JSONObject config = prov.getTippligaConfig(configFileName); this.config = prov.getTippligaConfig(configFileName);
this.numberOfMatchdays = ((Long) config.get("numberOfMatchdays")).intValue(); this.numberOfMatchdays = ((Long) this.config.get("numberOfMatchdays")).intValue();
this.matchdayConfig = (JSONArray) config.get("matchdayConfig"); this.matchdayConfig = (JSONArray) this.config.get("matchdayConfig");
this.ko = ((Long) config.get("ko")).intValue(); 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++) { for(int i = 0; i < this.matchdayConfig.size(); i++) {
int TLWMatchday = ((Long) ((JSONObject) this.matchdayConfig.get(i)).get("TLWMatchday")).intValue(); int TLWMatchday = ((Long) ((JSONObject) this.matchdayConfig.get(i)).get("TLWMatchday")).intValue();
JSONArray matchesConfig = (JSONArray)((JSONObject) this.matchdayConfig.get(i)).get("matchesConfig"); JSONArray matchesConfig = (JSONArray)((JSONObject) this.matchdayConfig.get(i)).get("matchesConfig");
ArrayList<APIFootballMatch> apiFootballMatchesForMatchday = getAPIFootballMatchesForMatchday(matchesConfig); ArrayList<APIFootballMatch> apiFootballMatchesForMatchday = getAPIFootballMatchesForMatchday(matchesConfig);
@@ -59,7 +61,9 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
this.nextMatchNo++; this.nextMatchNo++;
int status = 0; int status = 0;
LocalDateTime matchDateTime = TLWMatchesManagerBase.getDate(match); 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; status = -1;
} }
this.TLWMatches.add(new TLWMatch(match, this.season, this.league, TLWMatchday, matchNo, status, this.ko)); this.TLWMatches.add(new TLWMatch(match, this.season, this.league, TLWMatchday, matchNo, status, this.ko));

View File

@@ -39,8 +39,8 @@ public class TLWTeamsCreator {
String teamName = teams.get(0).getTeamName(); String teamName = teams.get(0).getTeamName();
String teamNameShort = teams.get(0).getTeamNameShort(); String teamNameShort = teams.get(0).getTeamNameShort();
String teamSymbol = teams.get(0).getTeamSymbol(); String teamSymbol = teams.get(0).getTeamSymbol();
String groupId = ""; String groupId = getGroup(id);
int matchday = 0; int matchday = getMatchday(id);
sql += "REPLACE INTO phpbb_footb_teams VALUES ('"; sql += "REPLACE INTO phpbb_footb_teams VALUES ('";
sql += this.season; sql += this.season;
sql += "', '"; sql += "', '";
@@ -61,4 +61,23 @@ public class TLWTeamsCreator {
} }
return sql; 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;
}
} }

View File

@@ -53,7 +53,7 @@ public class TippligaSQLConnector {
"&allowMultiQueries=true" + "&allowMultiQueries=true" +
"&useSSL=false"; "&useSSL=false";
try { try {
con = DriverManager.getConnection(jdbcUrlProd); con = DriverManager.getConnection(jdbcUrlLocalhost);
} catch (SQLException e) { } catch (SQLException e) {
/* TODO */ /* TODO */
e.printStackTrace(); e.printStackTrace();

View File

@@ -68,5 +68,10 @@
"country": "World", "country": "World",
"name": "UEFA Europa League", "name": "UEFA Europa League",
"league_id": 2777 "league_id": 2777
},
{
"country": "World",
"name": "Euro Championship",
"league_id": 403
} }
] ]

View File

@@ -713,5 +713,125 @@
"teamname": "Lens", "teamname": "Lens",
"tippligaID": 433, "tippligaID": 433,
"apiFootballID": 116 "apiFootballID": 116
},
{
"teamname": "Belgien",
"tippligaID": 717,
"apiFootballID": 1
},
{
"teamname": "Frankreich",
"tippligaID": 909,
"apiFootballID": 2
},
{
"teamname": "Kroatien",
"tippligaID": 783,
"apiFootballID": 3
},
{
"teamname": "Russland",
"tippligaID": 837,
"apiFootballID": 4
},
{
"teamname": "Schweden",
"tippligaID": 846,
"apiFootballID": 5
},
{
"teamname": "Polen",
"tippligaID": 932,
"apiFootballID": 24
},
{
"teamname": "Ukraine",
"tippligaID": 936,
"apiFootballID": 772
},
{
"teamname": "Italien",
"tippligaID": 913,
"apiFootballID": 768
},
{
"teamname": "Spanien",
"tippligaID": 927,
"apiFootballID": 9
},
{
"teamname": "Türkei",
"tippligaID": 879,
"apiFootballID": 777
},
{
"teamname": "England",
"tippligaID": 908,
"apiFootballID": 10
},
{
"teamname": "Tschechien",
"tippligaID": 876,
"apiFootballID": 770
},
{
"teamname": "Finnland",
"tippligaID": 747,
"apiFootballID": 1099
},
{
"teamname": "Deutschland",
"tippligaID": 906,
"apiFootballID": 25
},
{
"teamname": "Österreich",
"tippligaID": 825,
"apiFootballID": 775
},
{
"teamname": "Niederlande",
"tippligaID": 918,
"apiFootballID": 1118
},
{
"teamname": "Portugal",
"tippligaID": 922,
"apiFootballID": 27
},
{
"teamname": "Schweiz",
"tippligaID": 923,
"apiFootballID": 15
},
{
"teamname": "Dänemark",
"tippligaID": 905,
"apiFootballID": 21
},
{
"teamname": "Wales",
"tippligaID": 894,
"apiFootballID": 767
},
{
"teamname": "Ungarn",
"tippligaID": 886,
"apiFootballID": 769
},
{
"teamname": "Slowakei",
"tippligaID": 925,
"apiFootballID": 773
},
{
"teamname": "Schottland",
"tippligaID": 845,
"apiFootballID": 1108
},
{
"teamname": "Nordmazedonien",
"tippligaID": 805,
"apiFootballID": 1105
} }
] ]

View File

@@ -71,6 +71,14 @@ public class TLWMatchdaysCreatorTest {
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 98, "WTL-Pokal"); TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 98, "WTL-Pokal");
String sql = matchdaysCreator.getMatchdaysSQL(); String sql = matchdaysCreator.getMatchdaysSQL();
// System.out.println(sql);
}
@Test
public void getMatchdaysEMTippspielSqlTest() {
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 49, "EM-Tippspiel");
String sql = matchdaysCreator.getMatchdaysSQL();
// System.out.println(sql); // System.out.println(sql);
} }
} }

View File

@@ -29,6 +29,13 @@ public class TLWMatchesCreatorFootballTest {
public void getMatchesWTLPokalSqlTest() { public void getMatchesWTLPokalSqlTest() {
TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(2021, 48, "WTL-Pokal"); TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(2021, 48, "WTL-Pokal");
String sql = creator.getSQLInsertString(); String sql = creator.getSQLInsertString();
// System.out.println(sql);
}
@Test
public void getMatchesEMTippspielSqlTest() {
TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(2021, 49, "EM-Tippspiel");
String sql = creator.getSQLInsertString();
// System.out.println(sql); // System.out.println(sql);
} }
} }

View File

@@ -18,6 +18,16 @@ public class TLWTeamsCreatorTest {
// System.out.println(sql); // System.out.println(sql);
} }
@Test
public void getTeamsTippligaEMTippspielTest() {
TLWMatchesCreatorFootball matchesCreator = new TLWMatchesCreatorFootball(2021, 49, "EM-Tippspiel");
ArrayList<TLWMatch> matches = matchesCreator.getMatches();
TLWTeamsCreator teamCreator = new TLWTeamsCreator(2021, 49, matches);
String sql = teamCreator.getSql();
// System.out.println(sql);
}
@Test @Test
public void getTeamsTipper1TLTest() throws ParseException { public void getTeamsTipper1TLTest() throws ParseException {
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga"); TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga");