From 9937208c5eed1f1bad5e54041dd2f83f7111e078 Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Sat, 5 Jun 2021 21:38:11 +0200 Subject: [PATCH] Add support for EM Tippspiel --- .../jeyp91/apifootball/APIFootballMatch.java | 8 +- .../java/de/jeyp91/tippliga/TLWMatch.java | 12 +- .../jeyp91/tippliga/TLWMatchdaysCreator.java | 40 +++++- .../tippliga/TLWMatchesCreatorFootball.java | 20 +-- .../de/jeyp91/tippliga/TLWTeamsCreator.java | 23 +++- .../tippligaforum/TippligaSQLConnector.java | 2 +- src/main/resources/Tippliga/Ligen.json | 5 + .../Tippliga/Team_ID_Matcher_Config.json | 120 ++++++++++++++++++ .../tippliga/TLWMatchdaysCreatorTest.java | 8 ++ .../TLWMatchesCreatorFootballTest.java | 7 + .../jeyp91/tippliga/TLWTeamsCreatorTest.java | 10 ++ 11 files changed, 235 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java b/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java index 72816b7..c7c01c3 100644 --- a/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java +++ b/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java @@ -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; } diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatch.java b/src/main/java/de/jeyp91/tippliga/TLWMatch.java index 224db53..ca100ad 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatch.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatch.java @@ -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 ""; + } + } } \ No newline at end of file diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java index e22544f..f725243 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java @@ -36,6 +36,7 @@ public class TLWMatchdaysCreator { ArrayList 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 deliveryDates = getDeliveryDates(matchdayConfigJson, matchdayNumber); + ArrayList 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 getDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) { - ArrayList deliveryDates = getDefaultDeliveryDates(matchdayConfigJson, matchdayNumber); - deliveryDates.addAll(getAdditionalDeliveryDates(matchdayConfigJson, matchdayNumber)); - deliveryDates = removeDuplicates(deliveryDates); + private ArrayList getDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber, String deliveryDateMode) { + ArrayList 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 getDefaultDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) { + private ArrayList getDefaultSingleDeliveryDate(JSONObject matchdayConfigJson, int matchdayNumber) { + ArrayList deliveryDates = new ArrayList<>(); + + JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig"); + JSONObject matchesConfigPlaceholder = (JSONObject) matchesConfig.get(matchesConfig.size() - 1); + ArrayList 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 getDefaultMultipleDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) { ArrayList deliveryDates = new ArrayList<>(); JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig"); diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java b/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java index f5e55ea..9387bbc 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java @@ -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 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)); diff --git a/src/main/java/de/jeyp91/tippliga/TLWTeamsCreator.java b/src/main/java/de/jeyp91/tippliga/TLWTeamsCreator.java index 77a3cf8..7bc539c 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWTeamsCreator.java +++ b/src/main/java/de/jeyp91/tippliga/TLWTeamsCreator.java @@ -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; + } } diff --git a/src/main/java/de/jeyp91/tippligaforum/TippligaSQLConnector.java b/src/main/java/de/jeyp91/tippligaforum/TippligaSQLConnector.java index c3219be..efbfcb6 100644 --- a/src/main/java/de/jeyp91/tippligaforum/TippligaSQLConnector.java +++ b/src/main/java/de/jeyp91/tippligaforum/TippligaSQLConnector.java @@ -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(); diff --git a/src/main/resources/Tippliga/Ligen.json b/src/main/resources/Tippliga/Ligen.json index 46d3ab5..45dddf1 100644 --- a/src/main/resources/Tippliga/Ligen.json +++ b/src/main/resources/Tippliga/Ligen.json @@ -68,5 +68,10 @@ "country": "World", "name": "UEFA Europa League", "league_id": 2777 + }, + { + "country": "World", + "name": "Euro Championship", + "league_id": 403 } ] \ No newline at end of file diff --git a/src/main/resources/Tippliga/Team_ID_Matcher_Config.json b/src/main/resources/Tippliga/Team_ID_Matcher_Config.json index 2d199f1..6481b84 100644 --- a/src/main/resources/Tippliga/Team_ID_Matcher_Config.json +++ b/src/main/resources/Tippliga/Team_ID_Matcher_Config.json @@ -713,5 +713,125 @@ "teamname": "Lens", "tippligaID": 433, "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 } ] diff --git a/src/test/java/de/jeyp91/tippliga/TLWMatchdaysCreatorTest.java b/src/test/java/de/jeyp91/tippliga/TLWMatchdaysCreatorTest.java index de971c1..0d3cdfa 100644 --- a/src/test/java/de/jeyp91/tippliga/TLWMatchdaysCreatorTest.java +++ b/src/test/java/de/jeyp91/tippliga/TLWMatchdaysCreatorTest.java @@ -71,6 +71,14 @@ public class TLWMatchdaysCreatorTest { TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 98, "WTL-Pokal"); 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); } } diff --git a/src/test/java/de/jeyp91/tippliga/TLWMatchesCreatorFootballTest.java b/src/test/java/de/jeyp91/tippliga/TLWMatchesCreatorFootballTest.java index c36c1c9..c10ccb1 100644 --- a/src/test/java/de/jeyp91/tippliga/TLWMatchesCreatorFootballTest.java +++ b/src/test/java/de/jeyp91/tippliga/TLWMatchesCreatorFootballTest.java @@ -29,6 +29,13 @@ public class TLWMatchesCreatorFootballTest { public void getMatchesWTLPokalSqlTest() { TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(2021, 48, "WTL-Pokal"); 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); } } diff --git a/src/test/java/de/jeyp91/tippliga/TLWTeamsCreatorTest.java b/src/test/java/de/jeyp91/tippliga/TLWTeamsCreatorTest.java index a62f630..049da54 100644 --- a/src/test/java/de/jeyp91/tippliga/TLWTeamsCreatorTest.java +++ b/src/test/java/de/jeyp91/tippliga/TLWTeamsCreatorTest.java @@ -18,6 +18,16 @@ public class TLWTeamsCreatorTest { // System.out.println(sql); } + @Test + public void getTeamsTippligaEMTippspielTest() { + TLWMatchesCreatorFootball matchesCreator = new TLWMatchesCreatorFootball(2021, 49, "EM-Tippspiel"); + ArrayList matches = matchesCreator.getMatches(); + + TLWTeamsCreator teamCreator = new TLWTeamsCreator(2021, 49, matches); + String sql = teamCreator.getSql(); +// System.out.println(sql); + } + @Test public void getTeamsTipper1TLTest() throws ParseException { TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga");