First version with ability to create database for new season

This commit is contained in:
2020-09-27 19:05:20 +02:00
parent b97e15be7d
commit 283efc775b
75 changed files with 106536 additions and 0 deletions

View File

@@ -0,0 +1,225 @@
package de.jeyp91.tippliga;
import java.sql.ResultSet;
import java.sql.SQLException;
import de.jeyp91.BaseMatch;
import de.jeyp91.TeamIDMatcher;
import de.jeyp91.apifootball.APIFootballMatch;
import de.jeyp91.openligadb.OpenLigaDBMatch;
/**
*
*/
public class TLWMatch extends BaseMatch {
public final Integer STATUS_NOTSTARTED = 0;
public final Integer STATUS_STARTED = 1;
public final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
public final Integer STATUS_FINISHED = 3;
private Integer season = null;
private Integer league = null;
private Integer matchNo = null;
private String groupId = null;
private String formulaHome = null;
private String formulaGuest = null;
private Integer status = null;
private Integer koMatch = 0;
private Integer goalsOvertimeHome = null;
private Integer goalsOvertimeGuest = null;
private Integer showTable = null;
private String trend = null;
private Float odd1 = null;
private Float oddX = null;
private Float odd2 = null;
private Float rating = null;
public TLWMatch(ResultSet rset) {
final int SEASON = 1;
final int LEAGUE = 2;
final int MATCH_NO = 3;
final int TEAM_ID_HOME = 4;
final int TEAM_ID_GUEST = 5;
final int GOALS_HOME = 6;
final int GOALS_GUEST = 7;
final int MATCHDAY = 8;
final int STATUS = 9;
final int MATCH_DATETIME = 10;
final int GROUP_ID = 11;
final int FORMULA_HOME = 12;
final int FORMULA_GUEST = 13;
final int KO_MATCH = 14;
final int GOALS_OVERTIME_HOME = 15;
final int GOALS_OVERTIME_GUEST = 16;
final int SHOW_TABLE = 17;
final int TREND = 18;
final int ODD1 = 19;
final int ODDX = 20;
final int ODD2 = 21;
final int RATING = 22;
try {
this.season = Integer.parseInt(rset.getString(SEASON));
this.league = Integer.parseInt(rset.getString(LEAGUE));
this.matchNo = Integer.parseInt(rset.getString(MATCH_NO));
this.teamIdHome = Integer.parseInt(rset.getString(TEAM_ID_HOME));
this.teamIdGuest = Integer.parseInt(rset.getString(TEAM_ID_GUEST));
this.goalsHome = rset.getString(GOALS_HOME).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_HOME));
this.goalsGuest = rset.getString(GOALS_GUEST).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_GUEST));
this.matchday = Integer.parseInt(rset.getString(MATCHDAY));
this.status = Integer.parseInt(rset.getString(STATUS));
this.matchDatetime = rset.getString(MATCH_DATETIME);
this.groupId = rset.getString(GROUP_ID);
this.formulaHome = rset.getString(FORMULA_HOME);
this.formulaGuest = rset.getString(FORMULA_GUEST);
this.koMatch = Integer.parseInt(rset.getString(KO_MATCH));
this.goalsOvertimeHome = rset.getString(GOALS_OVERTIME_HOME).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_OVERTIME_HOME));
this.goalsOvertimeGuest = rset.getString(GOALS_OVERTIME_GUEST).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_OVERTIME_GUEST));
this.showTable = Integer.parseInt(rset.getString(SHOW_TABLE));
this.trend = rset.getString(TREND);
this.odd1 = Float.parseFloat(rset.getString(ODD1));
this.oddX = Float.parseFloat(rset.getString(ODDX));
this.odd2 = Float.parseFloat(rset.getString(ODD2));
this.rating = Float.parseFloat(rset.getString(RATING));
} catch (SQLException e) {
/* TODO */
e.printStackTrace();
}
}
public TLWMatch(OpenLigaDBMatch oldbmatch, int season, int league, int matchday, int matchNo) {
this.season = season;
this.league = league;
this.matchday = matchday;
this.matchNo = matchNo;
this.teamIdHome = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(oldbmatch.getTeamIdHome());
this.teamIdGuest = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(oldbmatch.getTeamIdGuest());
this.goalsHome = oldbmatch.getGoalsHome();
this.goalsGuest = oldbmatch.getGoalsGuest();
this.matchDatetime = oldbmatch.getMatchDateTime().replace("T", " ");
this.groupId = "";
this.formulaHome = "";
this.formulaGuest = "";
this.status = 0;
}
public TLWMatch(APIFootballMatch APIFootballMatch, int season, int league, int matchday, int matchNo, int status, int koMatch) {
this.season = season;
this.league = league;
this.matchday = matchday;
this.matchNo = matchNo;
this.teamIdHome = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(APIFootballMatch.getTeamIdHome());
this.teamIdGuest = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(APIFootballMatch.getTeamIdGuest());
this.goalsHome = APIFootballMatch.getGoalsHome();
this.goalsGuest = APIFootballMatch.getGoalsGuest();
this.matchDatetime = APIFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19);
this.groupId = "";
this.formulaHome = "";
this.formulaGuest = "";
this.status = status;
this.koMatch = koMatch;
}
public TLWMatch(int season, int league, int matchday, int matchNo, String matchDatetime, int status, int koMatch) {
this.season = season;
this.matchday = matchday;
this.league = league;
this.matchNo = matchNo;
this.formulaHome = "D";
this.formulaGuest = "D";
this.status = status;
this.koMatch = koMatch;
this.matchDatetime = matchDatetime;
}
public TLWMatch(int season, int league, int matchday, int matchNo, int teamIdHome, int teamIdGuest, String matchDatetime) {
this.season = season;
this.matchday = matchday;
this.league = league;
this.matchNo = matchNo;
this.teamIdHome = teamIdHome;
this.teamIdGuest = teamIdGuest;
this.matchDatetime = matchDatetime;
this.status = 0;
}
public Integer getSeason() {
return this.season;
}
public Integer getLeague() {
return this.league;
}
public Integer getMatchNo() {
return this.matchNo;
}
public Integer getStatus() {
return this.status;
}
public Integer getKoMatch() {
return this.koMatch;
}
public String getGroupId() {
return this.groupId;
}
public Integer isSameMatch(OpenLigaDBMatch compareMatch) {
if(this.getSeason() != compareMatch.getSeason()) {
return COMPARISON_DIFFERENT;
}
if(this.getMatchday() != compareMatch.getMatchday()) {
return COMPARISON_DIFFERENT;
}
if(this.getTeamIdHome() != compareMatch.getTeamIdHome()) {
return COMPARISON_DIFFERENT;
}
if(this.getTeamIdGuest() != compareMatch.getTeamIdGuest()) {
return COMPARISON_DIFFERENT;
}
String thisDateTime = this.getMatchDateTime().replace("T", " ");
String tempDateTime = compareMatch.getMatchDateTime().replace("T", " ");
if(!tempDateTime.equals(thisDateTime)) {
return COMPARISON_DIFFERENT_DATETIME;
}
if(this.goalsHome != compareMatch.getGoalsHome() ||
this.goalsGuest != compareMatch.getGoalsGuest()) {
return COMPARISON_DIFFERENT_RESULT;
}
return COMPARISON_IDENTICAL;
}
public String getSQLQueryReplace() {
String query = "REPLACE INTO phpbb_footb_matches VALUES (" +
this.season + ", " +
this.league + ", " +
this.matchNo + ", " +
nullToSqlEmptyString(this.teamIdHome) + ", " +
nullToSqlEmptyString(this.teamIdGuest) + ", " +
nullToSqlEmptyString(this.goalsHome) + ", " +
nullToSqlEmptyString(this.goalsGuest) + ", " +
this.matchday + ", " +
this.status + ", " +
"'" + this.matchDatetime + "', " +
"'" + this.groupId + "', " +
"'" + this.formulaHome + "', " +
"'" + this.formulaGuest + "', " +
nullToSqlEmptyString(this.koMatch) + ", " +
nullToSqlEmptyString(this.goalsOvertimeHome) + ", " +
nullToSqlEmptyString(this.goalsOvertimeGuest) + ", " +
nullToSqlEmptyString(this.showTable) + ", " +
"'0.00','0.00','0.00','0.00');";
return query;
}
private String nullToSqlEmptyString(Integer number) {
return number != null ? number.toString() : "''";
}
}