Improve updater
This commit is contained in:
@@ -12,7 +12,6 @@ import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
@@ -78,7 +77,7 @@ public class APIFootballConnector {
|
||||
JSONObject object = null;
|
||||
//JSON parser object to parse read file
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource((this.season + 1) + File.separator + "API-Football" + File.separator + filename + ".json");
|
||||
URL url = Resources.getResource((this.season + 1) + "\\API-Football\\" + filename + ".json");
|
||||
String jsonConfig = null;
|
||||
|
||||
try {
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -56,7 +55,7 @@ public class APIFootballMatch extends BaseMatch {
|
||||
JSONObject object = null;
|
||||
//JSON parser object to parse read file
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource((this.season + 1) + File.separator + "API-Football" + File.separator + filename);
|
||||
URL url = Resources.getResource((this.season + 1) + "\\API-Football\\" + filename);
|
||||
String jsonConfig = null;
|
||||
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
public class TLWFootballMatchesUpdater {
|
||||
public TLWFootballMatchesUpdater() {
|
||||
|
||||
}
|
||||
|
||||
public String getUpdateSQL() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -30,7 +29,7 @@ public class TLWMatchdaysCreator {
|
||||
this.matches = matchesCreator.getMatches();
|
||||
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource(season + File.separator + configPath);
|
||||
URL url = Resources.getResource(season + "\\" + configPath);
|
||||
String jsonConfig = null;
|
||||
try {
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
public abstract class TLWMatchesCreatorBase {
|
||||
|
||||
ArrayList<TLWMatch> TLWMatches;
|
||||
APIFootballConnector conn;
|
||||
|
||||
public TLWMatchesCreatorBase() {
|
||||
this.TLWMatches = new ArrayList<>();
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import de.jeyp91.apifootball.APIFootballConnector;
|
||||
import de.jeyp91.apifootball.APIFootballMatch;
|
||||
import de.jeyp91.apifootball.APIFootballMatchesProvider;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -32,15 +31,11 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
||||
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.conn = new APIFootballConnector(season - 1);
|
||||
|
||||
this.initConfigParamsFromFile(configFileName);
|
||||
this.publicateMatchObjects();
|
||||
}
|
||||
|
||||
private void initConfigParamsFromFile(String configFileName) {
|
||||
|
||||
URL url = Resources.getResource(season + File.separator + configFileName);
|
||||
URL url = Resources.getResource(season + "\\" + configFileName);
|
||||
String jsonConfig = null;
|
||||
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
@@ -53,16 +48,16 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.publicateMatchObjects();
|
||||
}
|
||||
|
||||
private void publicateMatchObjects() {
|
||||
|
||||
APIFootballMatchesProvider provider = new APIFootballMatchesProvider(this.season);
|
||||
|
||||
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> APIFootballMatches = provider.getAPIFootballMatchesFromConfig(matchesConfig);
|
||||
ArrayList<APIFootballMatch> APIFootballMatches = getAPIFootballMatchesForMatchday(matchesConfig);
|
||||
|
||||
int tempNumberOfMatchesBackup = this.matchesPerMatchday;
|
||||
if(((JSONObject) this.matchdayConfig.get(i)).containsKey("numberOfMatches")) {
|
||||
@@ -114,6 +109,27 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<APIFootballMatch> getAPIFootballMatchesForMatchday(JSONArray config) {
|
||||
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
||||
for (Object singleConfigObject : config) {
|
||||
JSONObject singleConfig = (JSONObject) singleConfigObject;
|
||||
String type = (String) singleConfig.get("type");
|
||||
switch (type) {
|
||||
case "AllMatchesOfMatchday":
|
||||
int matchesLeague = ((Long) singleConfig.get("matchesLeague")).intValue();
|
||||
int leagueMatchday = ((Long) singleConfig.get("leagueMatchday")).intValue();
|
||||
apiFootballMatches.addAll(conn.getMatchDataByLeagueAndMatchday(matchesLeague, leagueMatchday));
|
||||
break;
|
||||
case "SingleMatch":
|
||||
int matchLeague = ((Long) singleConfig.get("matchLeague")).intValue();
|
||||
int matchId = ((Long) singleConfig.get("matchId")).intValue();
|
||||
apiFootballMatches.add(conn.getMatchDataByLeagueAndMatchID(matchLeague, matchId));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return apiFootballMatches;
|
||||
}
|
||||
|
||||
private int getDaysDifference(Date date1, Date date2) {
|
||||
long startTime = date1.getTime();
|
||||
long endTime = date2.getTime();
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -28,7 +27,7 @@ public class TLWMatchesCreatorTipperLeague extends TLWMatchesCreatorBase {
|
||||
this.matchdays = matchdays;
|
||||
|
||||
URL matchPairConfigUrl = Resources.getResource("Tipper_Match_Pair_Config.json");
|
||||
URL tipperListUrl = Resources.getResource(season + File.separator + configFileName);
|
||||
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
|
||||
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
||||
|
||||
try {
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -27,7 +26,7 @@ public class TLWMatchesCreatorTipperPokal extends TLWMatchesCreatorBase{
|
||||
this.league = league;
|
||||
this.matchdays = matchdays;
|
||||
|
||||
URL tipperListUrl = Resources.getResource(season + File.separator + configFileName);
|
||||
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
|
||||
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
||||
|
||||
this.TLWMatches = new ArrayList<>();
|
||||
|
||||
@@ -1,2 +1,65 @@
|
||||
<<<<<<< HEAD
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class TLWMatchesManagerBase {
|
||||
|
||||
protected int season;
|
||||
protected int league;
|
||||
protected int numberOfMatchdays;
|
||||
protected int matchesPerMatchday;
|
||||
protected int ko;
|
||||
|
||||
protected JSONArray matchdayConfig;
|
||||
|
||||
protected void initConfigParamsFromFile(String configFileName) {
|
||||
|
||||
URL url = Resources.getResource(season + File.separator + configFileName);
|
||||
String jsonConfig = null;
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
//Read JSON file
|
||||
JSONObject config = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
this.numberOfMatchdays = ((Long) config.get("numberOfMatchdays")).intValue();
|
||||
this.matchdayConfig = (JSONArray) config.get("matchdayConfig");
|
||||
this.ko = ((Long) config.get("ko")).intValue();
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getDaysDifference(Date date1, Date date2) {
|
||||
long startTime = date1.getTime();
|
||||
long endTime = date2.getTime();
|
||||
long diffTime = endTime - startTime;
|
||||
long diffDays = diffTime / (1000 * 60 * 60 * 24);
|
||||
return (int) diffDays;
|
||||
}
|
||||
|
||||
protected Date getDateObject(String matchdatetime) {
|
||||
Date matchDateTime = null;
|
||||
try {
|
||||
matchDateTime = new SimpleDateFormat("yyyy-MM-dd").parse(matchdatetime.substring(0, 10));
|
||||
} catch (java.text.ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return matchDateTime;
|
||||
}
|
||||
=======
|
||||
package de.jeyp91.tippliga;public class TLWMatchesManagerBase {
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
@@ -1,2 +1,93 @@
|
||||
<<<<<<< HEAD
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class TLWTeamsUpdater {
|
||||
|
||||
Integer season;
|
||||
Integer league;
|
||||
ArrayList<TLWTeam> teamsOriginal;
|
||||
ArrayList<TLWMatch> matchesUpdated;
|
||||
ArrayList<TLWTeam> missingTeams;
|
||||
|
||||
public TLWTeamsUpdater(int season, int league, ArrayList<TLWMatch> matchesUpdated) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matchesUpdated = matchesUpdated;
|
||||
missingTeams = new ArrayList<>();
|
||||
|
||||
TippligaSQLConnector conn = new TippligaSQLConnector();
|
||||
teamsOriginal = conn.getTeams(String.valueOf(season), String.valueOf(league));
|
||||
|
||||
HashSet<Integer> missingIds = this.initMissingIds();
|
||||
this.initMissingTeams(missingIds);
|
||||
}
|
||||
|
||||
private HashSet<Integer> initMissingIds() {
|
||||
HashSet<Integer> missingIds = new HashSet<>();
|
||||
|
||||
for(TLWMatch match : matchesUpdated) {
|
||||
if(isTeamMissing(match.getTeamIdHome())) {
|
||||
missingIds.add(match.getTeamIdHome());
|
||||
}
|
||||
if(isTeamMissing(match.getTeamIdGuest())) {
|
||||
missingIds.add(match.getTeamIdGuest());
|
||||
}
|
||||
}
|
||||
missingIds.remove(0);
|
||||
return missingIds;
|
||||
}
|
||||
|
||||
private void initMissingTeams(HashSet<Integer> missingIds) {
|
||||
TippligaSQLConnector conn = new TippligaSQLConnector();
|
||||
for (Integer id : missingIds) {
|
||||
ArrayList<TLWTeam> teams = conn.getTeams(String.valueOf(id));
|
||||
missingTeams.add(new TLWTeam(
|
||||
this.season,
|
||||
this.league,
|
||||
id,
|
||||
teams.get(0).getTeamName(),
|
||||
teams.get(0).getTeamNameShort(),
|
||||
teams.get(0).getTeamSymbol(),
|
||||
"",
|
||||
0
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTeamMissing(int id) {
|
||||
boolean teamMissing = true;
|
||||
for(TLWTeam team : teamsOriginal) {
|
||||
if(team.getTeamId() == id) {
|
||||
teamMissing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return teamMissing;
|
||||
}
|
||||
|
||||
public String getInsertSQL() {
|
||||
String updateSql = "";
|
||||
|
||||
for(TLWTeam team : missingTeams) {
|
||||
|
||||
updateSql += "INSERT INTO phpbb_footb_teams VALUES (" +
|
||||
team.getSeason() + ", " +
|
||||
team.getLeague() + ", " +
|
||||
team.getTeamId() + ", " +
|
||||
"'" + team.getTeamName() + "', " +
|
||||
"'" + team.getTeamNameShort() + "', " +
|
||||
"'" + team.getTeamSymbol() + "', " +
|
||||
"'" + team.getGroupId() + "', " +
|
||||
team.getMatchday() +
|
||||
");\n";
|
||||
}
|
||||
|
||||
return updateSql;
|
||||
}
|
||||
=======
|
||||
package de.jeyp91.tippliga;public class TLWTeamsUpdater {
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"api": {
|
||||
"results": 38,
|
||||
"fixtures": [
|
||||
"Regular_Season_-_1",
|
||||
"Regular_Season_-_2",
|
||||
"Regular_Season_-_3",
|
||||
"Regular_Season_-_4",
|
||||
"Regular_Season_-_5",
|
||||
"Regular_Season_-_6",
|
||||
"Regular_Season_-_7",
|
||||
"Regular_Season_-_8",
|
||||
"Regular_Season_-_9",
|
||||
"Regular_Season_-_10",
|
||||
"Regular_Season_-_11",
|
||||
"Regular_Season_-_12",
|
||||
"Regular_Season_-_13",
|
||||
"Regular_Season_-_14",
|
||||
"Regular_Season_-_15",
|
||||
"Regular_Season_-_16",
|
||||
"Regular_Season_-_17",
|
||||
"Regular_Season_-_18",
|
||||
"Regular_Season_-_19",
|
||||
"Regular_Season_-_20",
|
||||
"Regular_Season_-_21",
|
||||
"Regular_Season_-_22",
|
||||
"Regular_Season_-_23",
|
||||
"Regular_Season_-_24",
|
||||
"Regular_Season_-_25",
|
||||
"Regular_Season_-_26",
|
||||
"Regular_Season_-_27",
|
||||
"Regular_Season_-_28",
|
||||
"Regular_Season_-_29",
|
||||
"Regular_Season_-_30",
|
||||
"Regular_Season_-_31",
|
||||
"Regular_Season_-_32",
|
||||
"Regular_Season_-_33",
|
||||
"Regular_Season_-_34",
|
||||
"Regular_Season_-_35",
|
||||
"Regular_Season_-_36",
|
||||
"Regular_Season_-_37",
|
||||
"Regular_Season_-_38"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"api": {
|
||||
"results": 38,
|
||||
"fixtures": [
|
||||
"Regular_Season_-_1",
|
||||
"Regular_Season_-_2",
|
||||
"Regular_Season_-_3",
|
||||
"Regular_Season_-_4",
|
||||
"Regular_Season_-_5",
|
||||
"Regular_Season_-_6",
|
||||
"Regular_Season_-_7",
|
||||
"Regular_Season_-_8",
|
||||
"Regular_Season_-_9",
|
||||
"Regular_Season_-_10",
|
||||
"Regular_Season_-_11",
|
||||
"Regular_Season_-_12",
|
||||
"Regular_Season_-_13",
|
||||
"Regular_Season_-_14",
|
||||
"Regular_Season_-_15",
|
||||
"Regular_Season_-_16",
|
||||
"Regular_Season_-_17",
|
||||
"Regular_Season_-_18",
|
||||
"Regular_Season_-_19",
|
||||
"Regular_Season_-_20",
|
||||
"Regular_Season_-_21",
|
||||
"Regular_Season_-_22",
|
||||
"Regular_Season_-_23",
|
||||
"Regular_Season_-_24",
|
||||
"Regular_Season_-_25",
|
||||
"Regular_Season_-_26",
|
||||
"Regular_Season_-_27",
|
||||
"Regular_Season_-_28",
|
||||
"Regular_Season_-_29",
|
||||
"Regular_Season_-_30",
|
||||
"Regular_Season_-_31",
|
||||
"Regular_Season_-_32",
|
||||
"Regular_Season_-_33",
|
||||
"Regular_Season_-_34",
|
||||
"Regular_Season_-_35",
|
||||
"Regular_Season_-_36",
|
||||
"Regular_Season_-_37",
|
||||
"Regular_Season_-_38"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,18 @@
|
||||
<<<<<<< HEAD
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TLWMatchesUpdaterFootballTest {
|
||||
|
||||
@Test
|
||||
public void getMatchesTest() throws Exception {
|
||||
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 1, "Tippliga.json");
|
||||
String sql = updater.getUpdateSQL();
|
||||
|
||||
System.out.println(sql);
|
||||
}
|
||||
=======
|
||||
package de.jeyp91.tippliga;public class TLWMatchesUpdaterFootball {
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
@@ -1,2 +1,21 @@
|
||||
<<<<<<< HEAD
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TLWTeamsUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void getTeamsTest() throws Exception {
|
||||
TLWMatchesUpdaterFootball matchesUpdater = new TLWMatchesUpdaterFootball(2021, 1, "Tippliga.json");
|
||||
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(2021, 1, matchesUpdater.tlwMatchesUpdated);
|
||||
|
||||
String sql = teamsUpdater.getInsertSQL();
|
||||
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
=======
|
||||
package de.jeyp91.tippliga;public class TLWTeamsUpdaterTest {
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user