Add beautiful output

This commit is contained in:
2020-10-25 14:33:49 +01:00
parent 6579d3c003
commit d8e70fb1b0
10 changed files with 93 additions and 39 deletions

View File

@@ -5,9 +5,10 @@ import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.config.Configurator;
/**
* Hello world!
@@ -22,13 +23,15 @@ public class App {
private static Logger logger = LogManager.getLogger(App.class);
public static void main(String[] args) throws Exception {
ThreadContext.put("myLogLvl", "INFO");
Configurator.setRootLevel(Level.INFO);
initOptions(args);
String sql = "";
String beautifulInfo = "";
switch(mode) {
case "MatchdaysUpdater":
TLWMatchdaysUpdater matchdaysUpdater = new TLWMatchdaysUpdater(season, league, configFile);
sql = matchdaysUpdater.getUpdateSql();
beautifulInfo = matchdaysUpdater.getBeautifulInfo();
break;
case "MatchesCreatorFootball":
TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(season, league, configFile);
@@ -37,6 +40,7 @@ public class App {
case "MatchesUpdaterFootball":
TLWMatchesUpdaterFootball tlwMatchesUpdaterFootball = new TLWMatchesUpdaterFootball(season, league, configFile);
sql = tlwMatchesUpdaterFootball.getUpdateSQL();
beautifulInfo = tlwMatchesUpdaterFootball.getBeautifulInfo();
break;
case "TeamsUpdater":
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
@@ -47,17 +51,11 @@ public class App {
default:
break;
}
if (sql.equals("")) {
logger.info("No updates for season " + season + ", league " + league + ", config " + configFile);
} else {
logger.info("Executed query:\n" + sql);
}
if(!StatusHolder.getError() && !sql.equals("")) {
TippligaSQLConnector con = new TippligaSQLConnector();
// con.executeUpdate(sql);
logger.info(beautifulInfo);
}
logger.error("testerror");
logger.info("testinfo");
if(StatusHolder.getError()) {
System.exit(1);
}

View File

@@ -9,6 +9,8 @@ public abstract class BaseMatch {
protected Integer teamIdHome;
protected Integer teamIdGuest;
protected String teamNameHome = null;
protected String teamNameGuest = null;
protected Integer goalsHome = null;
protected Integer goalsGuest = null;
protected Integer matchday = null;
@@ -37,4 +39,12 @@ public abstract class BaseMatch {
public Integer getGoalsGuest() {
return this.goalsGuest;
}
public String getTeamNameHome() {
return this.teamNameHome;
}
public String getTeamNameGuest() {
return this.teamNameGuest;
}
}

View File

@@ -1,11 +1,6 @@
package de.jeyp91;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import com.google.common.collect.HashBiMap;
import com.google.common.io.Resources;
import de.jeyp91.gists.GistProvider;
import org.apache.logging.log4j.*;
import org.json.simple.JSONArray;
@@ -14,28 +9,31 @@ import org.json.simple.JSONObject;
public class TeamIDMatcher {
private static HashBiMap<Integer, Integer> ids = null;
private static Logger logger = LogManager.getLogger(TeamIDMatcher.class);
private static final Logger logger = LogManager.getLogger(TeamIDMatcher.class);
private static JSONArray teams;
private static boolean init = false;
private static void initBiMap() {
ids = HashBiMap.create();
GistProvider prov = GistProvider.getInstance();
JSONArray teams = prov.getTeamIdMatcher();
if(!init) {
ids = HashBiMap.create();
GistProvider prov = GistProvider.getInstance();
teams = prov.getTeamIdMatcher();
for(Object team:teams) {
int tippligaID = ((Long)((JSONObject) team).get("tippligaID")).intValue();
int openligaDBID = ((Long) ((JSONObject) team).get("apiFootballID")).intValue();
ids.put(tippligaID, openligaDBID);
for (Object team : teams) {
int tippligaID = ((Long) ((JSONObject) team).get("tippligaID")).intValue();
int apiFootballID = ((Long) ((JSONObject) team).get("apiFootballID")).intValue();
ids.put(tippligaID, apiFootballID);
}
init = true;
}
}
public static Integer getApiFootballIdFromTippligaId(int id) {
if(ids == null) {
initBiMap();
}
initBiMap();
if(ids.containsKey(id)) {
return ids.get(id);
} else {
logger.error("Tippliga ID: " + String.valueOf(id) + " not in ID Matcher.");
logger.error("Tippliga ID: " + id + " not in ID Matcher.");
StatusHolder.setError();
return null;
}
@@ -43,15 +41,26 @@ public class TeamIDMatcher {
public static Integer getTippligaIdFromApiFootballId(Integer id) {
if(id == null) return null;
if(ids == null) {
initBiMap();
}
initBiMap();
if(ids.inverse().containsKey(id)) {
return ids.inverse().get(id);
} else {
logger.error("API Football ID: " + String.valueOf(id) + " not in ID Matcher.");
logger.error("API Football ID: " + id + " not in ID Matcher.");
StatusHolder.setError();
return null;
}
}
public static String getTeamNameFromTippligaId(Integer id) {
initBiMap();
String name = "";
for(Object team:teams) {
int tippligaID = ((Long)((JSONObject) team).get("tippligaID")).intValue();
if(id == tippligaID) {
name = (((JSONObject) team).get("teamname")).toString();
break;
}
}
return name;
}
}

View File

@@ -125,6 +125,8 @@ public class TLWMatch extends BaseMatch{
this.formulaGuest = "";
this.status = status;
this.koMatch = koMatch;
this.teamNameHome = apiFootballMatch.getTeamNameHome();
this.teamNameGuest = apiFootballMatch.getTeamNameGuest();
}
public TLWMatch(int season, int league, int matchday, int matchNo, String matchDatetime, int status, int koMatch) {

View File

@@ -1,7 +1,5 @@
package de.jeyp91.tippliga;
import org.json.simple.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -14,6 +12,7 @@ public class TLWMatchdaysUpdater {
int league;
ArrayList<TLWMatchday> matchdaysOriginal;
ArrayList<TLWMatchday> matchdaysUpdated;
String beautifulInfo = "";
public TLWMatchdaysUpdater(int season, int league, String configPath) throws ParseException {
this.season = season;
@@ -58,27 +57,40 @@ public class TLWMatchdaysUpdater {
String condition = "WHERE season = " + matchdayOriginal.getSeason() + " " +
"AND league = " + matchdayOriginal.getLeague() + " " +
"AND matchday = " + matchdayOriginal.getMatchday() + ";\n";
String beautifulInfoStart = "Aktualisiere Saison " + matchdayOriginal.getSeason() + ", " +
"Liga " + matchdayOriginal.getLeague() + ", " +
"Spieltag " + matchdayOriginal.getMatchday() + ", ";
if (!matchdayOriginal.getDeliveryDate().equals(matchdayUpdated.getDeliveryDate())) {
updateSql += updateStart +
"delivery_date = '" + matchdayUpdated.getDeliveryDate() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Tippabgabeschluss 1 zu '" + matchdayUpdated.getDeliveryDate() + "'.\n";
}
if (!matchdayOriginal.getDeliveryDate2().equals(matchdayUpdated.getDeliveryDate2())) {
updateSql += updateStart +
"delivery_date_2 = '" + matchdayUpdated.getDeliveryDate2() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Tippabgabeschluss 2 zu '" + matchdayUpdated.getDeliveryDate2() + "'.\n";
}
if (!matchdayOriginal.getMatchdayName().equals(matchdayUpdated.getMatchdayName())) {
updateSql += updateStart +
"matchday_name = '" + matchdayUpdated.getMatchdayName() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Spieltagsname zu '" + matchdayUpdated.getMatchdayName() + "'.\n";
}
}
}
return updateSql;
}
public String getBeautifulInfo() {
return this.beautifulInfo;
}
}

View File

@@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import javax.sound.midi.SysexMessage;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -21,8 +22,9 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
ArrayList<TLWMatch> tlwMatchesOriginal;
ArrayList<TLWMatch> tlwMatchesUpdated;
public TLWMatchesUpdaterFootball(int season, int league, String configFileName) {
String beautifulInfo = "";
public TLWMatchesUpdaterFootball(int season, int league, String configFileName) {
this.season = season;
this.league = league;
@@ -79,29 +81,42 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
"AND league = " + matchOriginal.getLeague() + " " +
"AND matchday = " + matchOriginal.getMatchday() + " " +
"AND match_no = " + matchOriginal.getMatchNo() + ";\n";
String beautifulInfoStart = "Aktualisiere Saison " + matchOriginal.getSeason() + ", " +
"Liga " + matchOriginal.getLeague() + ", " +
"Spieltag " + matchOriginal.getMatchday() + ", " +
"Spielnummer " + matchOriginal.getMatchNo() + ", " +
"Spiel '" + TeamIDMatcher.getTeamNameFromTippligaId(matchOriginal.getTeamIdHome()) + "' - '" + TeamIDMatcher.getTeamNameFromTippligaId(matchOriginal.getTeamIdGuest()) + "', ";
if(matchOriginal.getTeamIdHome() != matchUpdated.getTeamIdHome()) {
updateString += updateStart +
"team_id_home = " + matchUpdated.getTeamIdHome() + " " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Heimteam zu '" + matchUpdated.getTeamNameHome() + "'.\n";
}
if(matchOriginal.getTeamIdGuest() != matchUpdated.getTeamIdGuest()) {
updateString += updateStart +
"team_id_guest = " + matchUpdated.getTeamIdGuest() + " " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Gastteam zu '" + matchUpdated.getTeamNameGuest() + "'.\n";
}
if (!matchOriginal.getMatchDateTime().equals(matchUpdated.getMatchDateTime())) {
updateString += updateStart +
"match_datetime = '" + matchUpdated.getMatchDateTime() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Spielbeginn zu '" + matchUpdated.getMatchDateTime() + "'.\n";
}
if (!matchOriginal.getStatus().equals(matchUpdated.getStatus())) {
updateString += updateStart +
"status = '" + matchUpdated.getStatus() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Status zu '" + matchUpdated.getStatus() + "'.\n";
}
@@ -150,7 +165,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
if(earliestDate.isAfter(now)) {
for(TLWMatch match : matches) {
LocalDateTime date = TLWMatchesManagerBase.getDate(match);
if (this.getDaysDifference(earliestDate, date) == 0) {
if (getDaysDifference(earliestDate, date) == 0) {
match.setStatus(0);
} else {
match.setStatus(-1);
@@ -182,4 +197,8 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
public ArrayList<TLWMatch> getTLWMatchesUpdated() {
return this.tlwMatchesUpdated;
}
public String getBeautifulInfo() {
return this.beautifulInfo;
}
}

View File

@@ -87,12 +87,12 @@ public class TippligaSQLConnector {
}
public ArrayList<TLWMatch> getMatches(String season, String league) {
String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + ";";
String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + " ORDER BY match_no ASC;";
return getMatches(queryString);
}
public ArrayList<TLWMatch> getMatches(String season, String league, String matchday) {
String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + " AND `matchday` = " + matchday + ";";
String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + " AND `matchday` = " + matchday + " ORDER BY match_no ASC;";
return getMatches(queryString);
}

View File

@@ -11,6 +11,7 @@ public class TLWMatchdayUpdaterTest {
String sql = matchdaysUpdater.getUpdateSql();
System.out.println(sql);
System.out.println(matchdaysUpdater.getBeautifulInfo());
}
@Test
@@ -20,5 +21,6 @@ public class TLWMatchdayUpdaterTest {
String sql = matchdaysUpdater.getUpdateSql();
System.out.println(sql);
System.out.println(matchdaysUpdater.getBeautifulInfo());
}
}

View File

@@ -5,18 +5,20 @@ import org.junit.Test;
public class TLWMatchesUpdaterFootballTest {
@Test
public void getUpdateSqlTest1() throws Exception {
public void getUpdateSqlTest1() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 1, "Tippliga.json");
String sql = updater.getUpdateSQL();
System.out.println(sql);
System.out.println(updater.getBeautifulInfo());
}
@Test
public void getUpdateSqlTest2() throws Exception {
public void getUpdateSqlTest2() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 2, "Tippliga.json");
String sql = updater.getUpdateSQL();
System.out.println(sql);
System.out.println(updater.getBeautifulInfo());
}
}

Binary file not shown.