Improve updater

This commit is contained in:
2020-10-04 11:53:30 +02:00
parent babfe66872
commit e57f79c18b
15 changed files with 14771 additions and 22 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -0,0 +1,11 @@
package de.jeyp91.tippliga;
public class TLWFootballMatchesUpdater {
public TLWFootballMatchesUpdater() {
}
public String getUpdateSQL() {
return "";
}
}

View File

@@ -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);

View File

@@ -7,6 +7,7 @@ import java.util.ArrayList;
public abstract class TLWMatchesCreatorBase {
ArrayList<TLWMatch> TLWMatches;
APIFootballConnector conn;
public TLWMatchesCreatorBase() {
this.TLWMatches = new ArrayList<>();

View File

@@ -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();

View File

@@ -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 {

View File

@@ -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<>();

View File

@@ -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
}

View File

@@ -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
}