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();
|
||||
|
||||
@@ -68,5 +68,10 @@
|
||||
"country": "World",
|
||||
"name": "UEFA Europa League",
|
||||
"league_id": 2777
|
||||
},
|
||||
{
|
||||
"country": "World",
|
||||
"name": "Euro Championship",
|
||||
"league_id": 403
|
||||
}
|
||||
]
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,16 @@ public class TLWTeamsCreatorTest {
|
||||
// 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
|
||||
public void getTeamsTipper1TLTest() throws ParseException {
|
||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga");
|
||||
|
||||
Reference in New Issue
Block a user