|
|
@@ -29,6 +29,9 @@ public class GuiMysql extends Mysql {
|
|
|
private static final String AWAY_SCORE = "awayScore";
|
|
|
private static final String HOME_SCORE = "homeScore";
|
|
|
private static final String COUNTRY_NAME = "countryName";
|
|
|
+ private static final String ODDS_1 = "odds1";
|
|
|
+ private static final String ODDS_X = "oddsX";
|
|
|
+ private static final String ODDS_2 = "odds2";
|
|
|
private static final String DRAWS = "draws";
|
|
|
private static final String DATE_FORMAT = "yyyy-MM-dd";
|
|
|
private static final String AWAY_TEAM_ID = "awayTeamId";
|
|
|
@@ -36,6 +39,7 @@ public class GuiMysql extends Mysql {
|
|
|
private static final String LEAGUE_NAME = "leagueName";
|
|
|
private static final BigDecimal INCREMENT = BigDecimal.valueOf(0.2);
|
|
|
private static final GuiMysql instance = new GuiMysql();
|
|
|
+ public static final String GAME_DATE = "gameDate";
|
|
|
private final Connection conn;
|
|
|
|
|
|
protected GuiMysql() {
|
|
|
@@ -93,9 +97,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public Bet getAnalysisBet(int betId) {
|
|
|
Bet result = null;
|
|
|
- String sql = "SELECT * FROM AnalysisBetTable abt "
|
|
|
- + "INNER JOIN SoccerResults sr ON abt.matchId = sr.id "
|
|
|
- + "WHERE abt.id = ?";
|
|
|
+ String sql = "SELECT * FROM AnalysisBetTable abt " + "INNER JOIN SoccerResults sr ON abt.matchId = sr.id " +
|
|
|
+ "WHERE abt.id = ?";
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, betId);
|
|
|
@@ -112,9 +115,8 @@ public class GuiMysql extends Mysql {
|
|
|
match.setLeagueName(homeTeam.getTeamLeague());
|
|
|
match.setCountryName(homeTeam.getCountryName());
|
|
|
|
|
|
- result = new Bet(rs.getInt("id"), match, rs.getString("bet"), rs.getFloat("betAmount"),
|
|
|
- rs.getFloat("betOdds"),
|
|
|
- Status.valueOf(rs.getString("status")), rs.getInt("coveredBetId"));
|
|
|
+ result = new Bet(rs.getInt("id"), match, rs.getString("bet"), rs.getFloat("betAmount"), rs.getFloat(
|
|
|
+ "betOdds"), Status.valueOf(rs.getString("status")), rs.getInt("coveredBetId"));
|
|
|
}
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
@@ -126,9 +128,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<Bet> getAnalysisBets() {
|
|
|
List<Bet> result = new ArrayList<>();
|
|
|
- String sql = "SELECT * FROM AnalysisBetTable abt "
|
|
|
- + "INNER JOIN SoccerResults sr ON abt.matchId = sr.id "
|
|
|
- + "WHERE status IN ('LOST', 'OPEN', 'COVERED')";
|
|
|
+ String sql = "SELECT * FROM AnalysisBetTable abt " + "INNER JOIN SoccerResults sr ON abt.matchId = sr.id " +
|
|
|
+ "WHERE status IN ('LOST', 'OPEN', 'COVERED')";
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
ResultSet rs = stat.executeQuery();
|
|
|
@@ -145,8 +146,7 @@ public class GuiMysql extends Mysql {
|
|
|
match.setCountryName(homeTeam.getCountryName());
|
|
|
|
|
|
result.add(new Bet(rs.getInt("id"), match, rs.getString("bet"), rs.getFloat("betAmount"),
|
|
|
- rs.getFloat("betOdds"),
|
|
|
- Status.valueOf(rs.getString("status")), rs.getInt("coveredBetId")));
|
|
|
+ rs.getFloat("betOdds"), Status.valueOf(rs.getString("status")), rs.getInt("coveredBetId")));
|
|
|
}
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
@@ -158,14 +158,13 @@ public class GuiMysql extends Mysql {
|
|
|
public List<Bet> getAnalysisBetStatistics() {
|
|
|
List<Bet> result = new ArrayList<>();
|
|
|
|
|
|
- String sql = "SELECT sr.id as soccerMatchId, ht.id as homeTeamId, awt.id as awayTeamId, sr.odds1, sr.oddsX, sr.odds2, "
|
|
|
- + "sr.homeScore, sr.awayScore, sr.gameDate, sr.season, l.name as leagueName, abt.id as betId, abt.bet, abt.betAmount, abt.betOdds "
|
|
|
- + "FROM AnalysisBetTable abt "
|
|
|
- + "INNER JOIN SoccerResults sr ON abt.matchId = sr.id "
|
|
|
- + "INNER JOIN Team ht ON ht.id = sr.homeTeamId "
|
|
|
- + "INNER JOIN Team awt ON awt.id = sr.awayTeamId "
|
|
|
- + "INNER JOIN League l ON l.id = sr.leagueId "
|
|
|
- + "WHERE abt.status != 'OPEN'";
|
|
|
+ String sql =
|
|
|
+ "SELECT sr.id as soccerMatchId, ht.id as homeTeamId, awt.id as awayTeamId, sr.odds1, sr.oddsX, " +
|
|
|
+ "sr.odds2, " + "sr.homeScore, sr.awayScore, sr.gameDate, sr.season, l.name as leagueName, abt" +
|
|
|
+ ".id as betId, abt" + ".bet, abt.betAmount, abt.betOdds " + "FROM AnalysisBetTable abt " +
|
|
|
+ "INNER JOIN SoccerResults sr ON abt.matchId = sr.id " + "INNER JOIN Team ht ON ht.id = sr" +
|
|
|
+ ".homeTeamId " + "INNER JOIN Team awt ON awt.id = sr.awayTeamId " + "INNER JOIN League l ON l" +
|
|
|
+ ".id = sr.leagueId " + "WHERE abt.status != 'OPEN'";
|
|
|
|
|
|
try (PreparedStatement stat = getConnection().prepareStatement(sql)) {
|
|
|
ResultSet rs = stat.executeQuery();
|
|
|
@@ -173,8 +172,8 @@ public class GuiMysql extends Mysql {
|
|
|
while (rs.next()) {
|
|
|
Team homeTeam = getTeam(rs.getInt(HOME_TEAM_ID));
|
|
|
Team awayTeam = getTeam(rs.getInt(AWAY_TEAM_ID));
|
|
|
- SoccerMatch match = new SoccerMatch(rs.getInt("soccerMatchId"), homeTeam, awayTeam,
|
|
|
- rs.getFloat("odds1"), rs.getFloat("oddsX"), rs.getFloat("odds2"), rs.getInt(HOME_SCORE),
|
|
|
+ SoccerMatch match = new SoccerMatch(rs.getInt("soccerMatchId"), homeTeam, awayTeam, rs.getFloat(
|
|
|
+ "odds1"), rs.getFloat("oddsX"), rs.getFloat("odds2"), rs.getInt(HOME_SCORE),
|
|
|
rs.getInt(AWAY_SCORE), LocalDateTime.parse(rs.getString("gameDate")), rs.getString(SEASON));
|
|
|
match.setLeagueName(rs.getString(LEAGUE_NAME));
|
|
|
|
|
|
@@ -191,7 +190,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<Float> getAvgAwayScore(int teamId) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
- final String sql = "SELECT AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults WHERE awayScore != -1 AND awayTeamId = ?";
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults " +
|
|
|
+ "WHERE awayScore != -1 AND awayTeamId = ?";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
|
|
|
|
@@ -215,11 +215,11 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<Float> getAvgAwayScoreThisSeason(int teamId, int countryId, int leagueId, String gameDate) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
- final String sql = "SELECT AVG(homeScore) as avgConcededSeason, AVG(awayScore) as avgScoredSeason FROM SoccerResults WHERE awayScore != -1 AND awayTeamId = ? AND season = ? AND DATE(gameDate) < ? ORDER BY gameDate ASC";
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgConcededSeason, AVG(awayScore) as avgScoredSeason FROM " +
|
|
|
+ "SoccerResults WHERE awayScore != -1 AND awayTeamId = ? AND season = ? AND DATE(gameDate) < ? ORDER " + "BY gameDate ASC";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
|
- if (Strings.isNullOrEmpty(gameDate)
|
|
|
- || getSeasonFromDate(countryId, leagueId, gameDate).equals(getLastSeason(countryId, leagueId))) {
|
|
|
+ if (Strings.isNullOrEmpty(gameDate) || getSeasonFromDate(countryId, leagueId, gameDate).equals(getLastSeason(countryId, leagueId))) {
|
|
|
stat.setString(2, getLastSeason(countryId, leagueId));
|
|
|
} else {
|
|
|
String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
|
@@ -247,7 +247,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<Float> getAvgHomeScore(int teamId) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
- final String sql = "SELECT AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults WHERE homeScore != -1 AND homeTeamId = ?";
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults " +
|
|
|
+ "WHERE homeScore != -1 AND homeTeamId = ?";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
|
|
|
|
@@ -271,12 +272,12 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<Float> getAvgHomeScoreThisSeason(int teamId, int countryId, int leagueId, String gameDate) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
- final String sql = "SELECT AVG(homeScore) as avgScoredSeason, AVG(awayScore) as avgConcededSeason FROM SoccerResults WHERE homeScore != -1 AND homeTeamId = ? AND season = ? AND DATE(gameDate) < ? ORDER BY gameDate ASC";
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgScoredSeason, AVG(awayScore) as avgConcededSeason FROM " +
|
|
|
+ "SoccerResults WHERE homeScore != -1 AND homeTeamId = ? AND season = ? AND DATE(gameDate) < ? ORDER " + "BY gameDate ASC";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
|
|
|
|
- if (Strings.isNullOrEmpty(gameDate)
|
|
|
- || getSeasonFromDate(countryId, leagueId, gameDate).equals(getLastSeason(countryId, leagueId))) {
|
|
|
+ if (Strings.isNullOrEmpty(gameDate) || getSeasonFromDate(countryId, leagueId, gameDate).equals(getLastSeason(countryId, leagueId))) {
|
|
|
stat.setString(2, getLastSeason(countryId, leagueId));
|
|
|
} else {
|
|
|
String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
|
@@ -322,11 +323,10 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<BetDTO> getBetSeries(boolean includeInactive) {
|
|
|
List<BetDTO> result = new ArrayList<>();
|
|
|
- String sql = "SELECT ab.*, sr.gameDate as gameDate, sr.id as gameId, sr.homeScore as homeScore, sr.awayScore as awayScore, "
|
|
|
- + "ht.name as homeTeam, aw.name as awayTeam " + "FROM ActiveBets ab "
|
|
|
- + "INNER JOIN SoccerResults sr ON ab.gameId = sr.id "
|
|
|
- + "INNER JOIN Team ht ON sr.homeTeamId = ht.id " + "INNER JOIN Team aw ON sr.awayTeamId = aw.id "
|
|
|
- + "WHERE done = ? ORDER BY series ASC, sr.gameDate DESC";
|
|
|
+ String sql = "SELECT ab.*, sr.gameDate as gameDate, sr.id as gameId, sr.homeScore as homeScore, sr.awayScore "
|
|
|
+ + "as awayScore, " + "ht.name as homeTeam, aw.name as awayTeam " + "FROM ActiveBets ab " + "INNER " +
|
|
|
+ "JOIN SoccerResults sr ON ab.gameId = sr.id " + "INNER JOIN Team ht ON sr.homeTeamId = ht.id " +
|
|
|
+ "INNER JOIN Team aw ON sr.awayTeamId = aw.id " + "WHERE done = ? ORDER BY series ASC, sr.gameDate DESC";
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setBoolean(1, includeInactive);
|
|
|
@@ -381,8 +381,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
- rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString(
|
|
|
+ "name"));
|
|
|
countries.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -392,7 +392,9 @@ public class GuiMysql extends Mysql {
|
|
|
}
|
|
|
|
|
|
public List<SimpleEntry<Integer, String>> getCountriesBySport(int sportId, String date) {
|
|
|
- final String sql = "SELECT * FROM Country WHERE id IN (SELECT DISTINCT(countryId) FROM SoccerResults WHERE DATE(gameDate) = ?) ORDER BY prio DESC, name ASC";
|
|
|
+ final String sql =
|
|
|
+ "SELECT * FROM Country WHERE id IN (SELECT DISTINCT(countryId) FROM SoccerResults WHERE " + "DATE" +
|
|
|
+ "(gameDate) = ?) ORDER BY prio DESC, name ASC";
|
|
|
final ArrayList<SimpleEntry<Integer, String>> result = new ArrayList<>();
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
if (date.equals("")) {
|
|
|
@@ -415,7 +417,9 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public int getGameId(String homeTeam, String awayTeam, String gameDate, int countryId, int leagueId) {
|
|
|
int result = -1;
|
|
|
- String sql = "SELECT id FROM SoccerResults WHERE homeTeamId = (SELECT id FROM Team WHERE name = ? AND countryId = ? AND leagueId = ?) AND awayTeamId = (SELECT id FROM Team WHERE name = ? AND countryId = ? AND leagueId = ?) AND DATE(gameDate) = DATE(?)";
|
|
|
+ String sql = "SELECT id FROM SoccerResults WHERE homeTeamId = (SELECT id FROM Team WHERE name = ? AND " +
|
|
|
+ "countryId = ? AND leagueId = ?) AND awayTeamId = (SELECT id FROM Team WHERE name = ? AND countryId " +
|
|
|
+ "=" + " ? AND leagueId = ?) AND DATE(gameDate) = DATE(?)";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setString(1, homeTeam);
|
|
|
stat.setInt(2, countryId);
|
|
|
@@ -440,7 +444,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public Map<Integer, Integer> getGoalAvgThisSeason(int leagueId, int countryId) {
|
|
|
Map<Integer, Integer> returnValue = new HashMap<>();
|
|
|
- final String goalsSql = "SELECT (homeScore + awayScore) as totalGoals, count(*) as count FROM SoccerResults WHERE leagueId = ? AND countryId = ? AND season = ? GROUP BY totalGoals ORDER BY totalGoals asc";
|
|
|
+ final String goalsSql = "SELECT (homeScore + awayScore) as totalGoals, count(*) as count FROM SoccerResults "
|
|
|
+ + "WHERE leagueId = ? AND countryId = ? AND season = ? GROUP BY totalGoals ORDER BY totalGoals asc";
|
|
|
try (PreparedStatement goalStmt = conn.prepareStatement(goalsSql)) {
|
|
|
goalStmt.setInt(1, leagueId);
|
|
|
goalStmt.setInt(2, countryId);
|
|
|
@@ -469,7 +474,9 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public String getLastSeason(Integer countryId, Integer leagueId) {
|
|
|
String season = "";
|
|
|
- final String sql = "SELECT season FROM SoccerResults WHERE leagueId = ? AND countryId = ? ORDER BY season DESC limit 1";
|
|
|
+ final String sql =
|
|
|
+ "SELECT season FROM SoccerResults WHERE leagueId = ? AND countryId = ? ORDER BY season " + "DESC " +
|
|
|
+ "limit 1";
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
stmt.setInt(1, leagueId);
|
|
|
stmt.setInt(2, countryId);
|
|
|
@@ -487,8 +494,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<Float> getLeagueAvarages(int leagueId, int countryId, String gameDate) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
- final String sql = "SELECT AVG(homeScore) avgHomeScore, AVG(awayScore) as avgAwayScore"
|
|
|
- + " FROM SoccerResults WHERE leagueId = ? AND countryId = ? AND DATE(gameDate) < DATE(?)";
|
|
|
+ final String sql = "SELECT AVG(homeScore) avgHomeScore, AVG(awayScore) as avgAwayScore" + " FROM " +
|
|
|
+ "SoccerResults WHERE leagueId = ? AND countryId = ? AND DATE(gameDate) < DATE(?)";
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql);) {
|
|
|
stat.setInt(1, leagueId);
|
|
|
@@ -517,9 +524,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
while (rs.next()) {
|
|
|
result = new League(rs.getInt(Constants.ID), rs.getString("name"), rs.getInt("scoringDiffLastGame"),
|
|
|
- rs.getInt("scoringTotal"),
|
|
|
- rs.getInt("winLossRatioHomeAndAway"), rs.getInt("winLossRatio"), rs.getInt("drawDiffHomeAway"),
|
|
|
- rs.getInt("drawDiffTotalGoals"), rs.getInt("drawWinningForm"),
|
|
|
+ rs.getInt("scoringTotal"), rs.getInt("winLossRatioHomeAndAway"), rs.getInt("winLossRatio"),
|
|
|
+ rs.getInt("drawDiffHomeAway"), rs.getInt("drawDiffTotalGoals"), rs.getInt("drawWinningForm"),
|
|
|
rs.getInt("drawWinningFormHomeAway"));
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -538,9 +544,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
while (rs.next()) {
|
|
|
result = new League(rs.getInt(Constants.ID), rs.getString("name"), rs.getInt("scoringDiffLastGame"),
|
|
|
- rs.getInt("scoringTotal"),
|
|
|
- rs.getInt("winLossRatioHomeAndAway"), rs.getInt("winLossRatio"), rs.getInt("drawDiffHomeAway"),
|
|
|
- rs.getInt("drawDiffTotalGoals"), rs.getInt("drawWinningForm"),
|
|
|
+ rs.getInt("scoringTotal"), rs.getInt("winLossRatioHomeAndAway"), rs.getInt("winLossRatio"),
|
|
|
+ rs.getInt("drawDiffHomeAway"), rs.getInt("drawDiffTotalGoals"), rs.getInt("drawWinningForm"),
|
|
|
rs.getInt("drawWinngingFormHomeAway"));
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -561,8 +566,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
- rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString(
|
|
|
+ "name"));
|
|
|
leagues.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -573,7 +578,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<SimpleEntry<Integer, String>> getLeaguesByDate(int sportId, int countryId, String date) {
|
|
|
final ArrayList<AbstractMap.SimpleEntry<Integer, String>> leagues = Lists.newArrayList();
|
|
|
- final String sql = "SELECT id, name FROM League WHERE id IN (SELECT leagueId FROM SoccerResults WHERE countryId = ? AND DATE(gameDate) = ?)";
|
|
|
+ final String sql = "SELECT id, name FROM League WHERE id IN (SELECT leagueId FROM SoccerResults WHERE " +
|
|
|
+ "countryId = ? AND DATE(gameDate) = ?)";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, countryId);
|
|
|
stat.setString(2, date);
|
|
|
@@ -581,8 +587,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
- rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString(
|
|
|
+ "name"));
|
|
|
leagues.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -594,21 +600,17 @@ public class GuiMysql extends Mysql {
|
|
|
public List<TeamStanding> getLeagueTable(int leagueId, String season, int countryId, String date) {
|
|
|
final ArrayList<TeamStanding> result = Lists.newArrayList();
|
|
|
|
|
|
- final String sql = "SELECT teamName.name as teamName, count(*) played, "
|
|
|
- + "count(case when homeScore > awayScore then 1 end) wins, "
|
|
|
- + "count(case when awayScore> homeScore then 1 end) lost, "
|
|
|
- + "count(case when homeScore = awayScore then 1 end) draws, "
|
|
|
- + "sum(homeScore) homeScore, " + "sum(awayScore) awayScore, "
|
|
|
- + "sum(homeScore) - sum(awayScore) goal_diff, " + "sum("
|
|
|
- + "case when homeScore > awayScore then 3 else 0 end + case "
|
|
|
- + "WHEN homeScore = awayScore then 1 else 0 end) score, "
|
|
|
- + "season FROM "
|
|
|
- + "(select hometeamId team, homeScore, awayScore, season, gameDate, leagueId as league, countryId as country FROM SoccerResults "
|
|
|
- + "union all SELECT awayteamId, awayScore, homeScore, season, gameDate, leagueId as league, countryId as country FROM SoccerResults) a "
|
|
|
- + "INNER JOIN Team teamName ON team = teamName.id " + "WHERE season = ? " + "AND league = ? "
|
|
|
- + "AND country = ? "
|
|
|
- + "AND homeScore != -1 " + "AND awayScore != -1 AND DATE(gameDate) < DATE(?) group by team "
|
|
|
- + "order by score desc, goal_diff desc";
|
|
|
+ final String sql = "SELECT teamName.name as teamName, count(*) played, " + "count(case when homeScore > " +
|
|
|
+ "awayScore then 1 end) wins, " + "count(case when awayScore> homeScore then 1 end) lost, " + "count" +
|
|
|
+ "(case when homeScore = awayScore then 1 end) draws, " + "sum(homeScore) homeScore, " + "sum" +
|
|
|
+ "(awayScore) awayScore, " + "sum(homeScore) - sum(awayScore) goal_diff, " + "sum(" + "case when " +
|
|
|
+ "homeScore > awayScore then 3 else 0 end + case " + "WHEN homeScore = awayScore then 1 else 0 end) " +
|
|
|
+ "score, " + "season FROM " + "(select hometeamId team, homeScore, awayScore, season, gameDate, " +
|
|
|
+ "leagueId as league, countryId as " + "country FROM SoccerResults " + "union all SELECT awayteamId, " +
|
|
|
+ "awayScore, homeScore, season, gameDate, leagueId as league, countryId" + " as country FROM " +
|
|
|
+ "SoccerResults) a " + "INNER JOIN Team teamName ON team = teamName.id " + "WHERE season = ? " + "AND " +
|
|
|
+ "league = ? " + "AND country = ? " + "AND homeScore != -1 " + "AND awayScore != -1 AND DATE(gameDate)" +
|
|
|
+ " < DATE(?) group by team " + "order by score desc, goal_diff desc";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
|
stat.setString(1, season);
|
|
|
@@ -618,10 +620,9 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
while (rs.next()) {
|
|
|
- final TeamStanding ts = new TeamStanding(rs.getString("teamName"), rs.getInt("wins"), rs.getInt("lost"),
|
|
|
- rs.getInt(DRAWS),
|
|
|
- rs.getInt("score"), rs.getFloat(Constants.HOME_SCORE), rs.getFloat(Constants.AWAY_SCORE),
|
|
|
- rs.getFloat("goal_diff"));
|
|
|
+ final TeamStanding ts = new TeamStanding(rs.getString("teamName"), rs.getInt("wins"), rs.getInt("lost"
|
|
|
+ ), rs.getInt(DRAWS), rs.getInt("score"), rs.getFloat(Constants.HOME_SCORE),
|
|
|
+ rs.getFloat(Constants.AWAY_SCORE), rs.getFloat("goal_diff"));
|
|
|
result.add(ts);
|
|
|
}
|
|
|
|
|
|
@@ -634,8 +635,7 @@ public class GuiMysql extends Mysql {
|
|
|
}
|
|
|
|
|
|
public List<SoccerMatch> getMatches(int sportId, Integer countryId, Integer leagueId, String date, String order,
|
|
|
- boolean exactDate,
|
|
|
- boolean onlyPrio) {
|
|
|
+ boolean exactDate, boolean onlyPrio) {
|
|
|
final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
|
final String dateSql;
|
|
|
final String orderSql = " ORDER BY gameDate " + order;
|
|
|
@@ -667,15 +667,11 @@ public class GuiMysql extends Mysql {
|
|
|
onlyPrioSql = "";
|
|
|
}
|
|
|
|
|
|
- final String sql = "SELECT res.*, c.name as countryName, l.name as leagueName, "
|
|
|
- + "hTeam.name as homeTeamName, aTeam.name as awayTeamName "
|
|
|
- + "FROM SoccerResults as res "
|
|
|
- + "INNER Join Team as hTeam ON res.homeTeamId = hTeam.id AND res.leagueId = hTeam.leagueId "
|
|
|
- + "INNER Join Team as aTeam ON res.awayTeamId = aTeam.id AND res.leagueId = hTeam.leagueId "
|
|
|
- + "INNER JOIN League l ON res.leagueId = l.id "
|
|
|
- + "INNER JOIN Country c ON res.countryId = c.id "
|
|
|
- + "WHERE " + dateSql + leagueSql
|
|
|
- + countrySql + onlyPrioSql + orderSql;
|
|
|
+ final String sql = "SELECT res.*, c.name as countryName, l.name as leagueName, " + "hTeam.name as " +
|
|
|
+ "homeTeamName, aTeam.name as awayTeamName " + "FROM SoccerResults as res " + "INNER Join Team as " +
|
|
|
+ "hTeam ON res.homeTeamId = hTeam.id AND res.leagueId = hTeam.leagueId " + "INNER Join Team as aTeam " +
|
|
|
+ "ON res.awayTeamId = aTeam.id AND res.leagueId = hTeam.leagueId " + "INNER JOIN League l ON res" +
|
|
|
+ ".leagueId = l.id " + "INNER JOIN Country c ON res.countryId = c.id " + "WHERE " + dateSql + leagueSql + countrySql + onlyPrioSql + orderSql;
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
if (leagueId != null && countryId != null) {
|
|
|
stat.setInt(1, leagueId);
|
|
|
@@ -757,14 +753,19 @@ public class GuiMysql extends Mysql {
|
|
|
}
|
|
|
|
|
|
public Map<String, String> getPreviousMatches(int numberOfMatches, String homeTeamName, String awayTeamName,
|
|
|
- String date, int countryId,
|
|
|
- int leagueId) {
|
|
|
+ String date, int countryId, int leagueId) {
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
|
|
|
- String homeTeamSql = "SELECT * FROM SoccerResults sr INNER JOIN Team t ON sr.homeTeamId = t.id WHERE t.name = ? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC limit ?";
|
|
|
- String awayTeamSql = "SELECT * FROM SoccerResults sr INNER JOIN Team t ON sr.awayTeamId = t.id WHERE t.name = ? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC limit ?";
|
|
|
- String combinedSql = "SELECT * FROM SoccerResults sr INNER JOIN Team homeTeam ON homeTeamId = homeTeam.id INNER JOIN Team awayTeam ON sr.awayTeamId = awayTeam.id WHERE homeTeam.name = ? AND awayTeam.name = ? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?";
|
|
|
- String combinedReverseSql = "SELECT * FROM SoccerResults sr INNER JOIN Team homeTeam ON homeTeamId = homeTeam.id INNER JOIN Team awayTeam ON sr.awayTeamId = awayTeam.id WHERE homeTeam.name = ? AND awayTeam.name = ? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?";
|
|
|
+ String homeTeamSql = "SELECT * FROM SoccerResults sr INNER JOIN Team t ON sr.homeTeamId = t.id WHERE t.name " +
|
|
|
+ "=" + " ? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC limit ?";
|
|
|
+ String awayTeamSql = "SELECT * FROM SoccerResults sr INNER JOIN Team t ON sr.awayTeamId = t.id WHERE t.name " +
|
|
|
+ "=" + " ? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC limit ?";
|
|
|
+ String combinedSql =
|
|
|
+ "SELECT * FROM SoccerResults sr INNER JOIN Team homeTeam ON homeTeamId = homeTeam.id " + "INNER JOIN " +
|
|
|
+ "Team awayTeam ON sr.awayTeamId = awayTeam.id WHERE homeTeam.name = ? AND awayTeam.name = " + "? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?";
|
|
|
+ String combinedReverseSql = "SELECT * FROM SoccerResults sr INNER JOIN Team homeTeam ON homeTeamId = " +
|
|
|
+ "homeTeam" + ".id INNER JOIN Team awayTeam ON sr.awayTeamId = awayTeam.id WHERE homeTeam.name = ? AND" +
|
|
|
+ " awayTeam" + ".name = ? AND sr.leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?";
|
|
|
try (PreparedStatement homeTeamStat = conn.prepareStatement(homeTeamSql);
|
|
|
PreparedStatement awayTeamStat = conn.prepareStatement(awayTeamSql);
|
|
|
PreparedStatement combinedStat = conn.prepareStatement(combinedSql);
|
|
|
@@ -811,8 +812,7 @@ public class GuiMysql extends Mysql {
|
|
|
}
|
|
|
String combinedReversedMeets = "";
|
|
|
while (combinedReversedTeamRs.next()) {
|
|
|
- combinedReversedMeets += combinedReversedTeamRs.getInt(HOME_SCORE) + "-"
|
|
|
- + combinedReversedTeamRs.getInt(AWAY_SCORE) + ", ";
|
|
|
+ combinedReversedMeets += combinedReversedTeamRs.getInt(HOME_SCORE) + "-" + combinedReversedTeamRs.getInt(AWAY_SCORE) + ", ";
|
|
|
}
|
|
|
if (homeTeamMeets.length() > 2) {
|
|
|
result.put("PrevHomeTeam", homeTeamMeets.substring(0, homeTeamMeets.length() - 2));
|
|
|
@@ -831,8 +831,8 @@ public class GuiMysql extends Mysql {
|
|
|
}
|
|
|
|
|
|
if (combinedReversedMeets.length() > 2) {
|
|
|
- result.put("PrevReversedCombined",
|
|
|
- combinedReversedMeets.substring(0, combinedReversedMeets.length() - 2));
|
|
|
+ result.put("PrevReversedCombined", combinedReversedMeets.substring(0,
|
|
|
+ combinedReversedMeets.length() - 2));
|
|
|
} else {
|
|
|
result.put("PrevReversedCombined", combinedReversedMeets);
|
|
|
}
|
|
|
@@ -845,7 +845,9 @@ public class GuiMysql extends Mysql {
|
|
|
}
|
|
|
|
|
|
public String getSeasonFromDate(int countryId, int leagueId, String gameDate) {
|
|
|
- String sql = "SELECT season FROM SoccerResults WHERE DATE(gameDate) = ? AND countryId = ? AND leagueId = ? LIMIT 1";
|
|
|
+ String sql =
|
|
|
+ "SELECT season FROM SoccerResults WHERE DATE(gameDate) = ? AND countryId = ? AND leagueId = ? " +
|
|
|
+ "LIMIT 1";
|
|
|
String returnValue = "";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
if (Strings.isNullOrEmpty(gameDate)) {
|
|
|
@@ -875,8 +877,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
- rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString(
|
|
|
+ "name"));
|
|
|
sports.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -896,12 +898,16 @@ public class GuiMysql extends Mysql {
|
|
|
df.setRoundingMode(RoundingMode.HALF_DOWN);
|
|
|
final ArrayList<OverUnder> result = Lists.newArrayList();
|
|
|
|
|
|
- final String sql = "SELECT ((sHome.avgScored * sAway.avgConceded) + (sAway.avgScored * sHome.avgConceded)) as diff, (homeScore + awayScore) as numGoals "
|
|
|
- + "FROM SoccerResults "
|
|
|
- + "INNER JOIN (SELECT homeTeamId, AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults WHERE homeScore != -1 AND homeTeamId = SoccerResults.homeTeamId AND DATE(gameDate) < ? AND season = ? AND leagueId = ? GROUP BY homeTeamId) as sHome ON SoccerResults.homeTeamId = sHome.homeTeamId "
|
|
|
- + "INNER JOIN (SELECT awayTeamId, AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults WHERE awayScore != -1 AND awayTeamId = SoccerResults.awayTeamId AND DATE(gameDate) < ? AND season = ? AND leagueId = ? GROUP BY awayTeamId) as sAway ON SoccerResults.awayTeamId = sAway.awayTeamId "
|
|
|
- + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? AND DATE(gameDate) < ? AND season = ? "
|
|
|
- + "ORDER BY diff ASC";
|
|
|
+ final String sql = "SELECT ((sHome.avgScored * sAway.avgConceded) + (sAway.avgScored * sHome.avgConceded)) " +
|
|
|
+ "as" + " diff, (homeScore + awayScore) as numGoals " + "FROM SoccerResults " + "INNER JOIN (SELECT " +
|
|
|
+ "homeTeamId, AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM " + "SoccerResults WHERE" +
|
|
|
+ " homeScore != -1 AND homeTeamId = SoccerResults.homeTeamId AND DATE(gameDate) < ?" + " AND season = " +
|
|
|
+ "? AND leagueId = ? GROUP BY homeTeamId) as sHome ON SoccerResults.homeTeamId = sHome" + ".homeTeamId" +
|
|
|
+ " " + "INNER JOIN (SELECT awayTeamId, AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM" +
|
|
|
+ " " + "SoccerResults WHERE awayScore != -1 AND awayTeamId = SoccerResults.awayTeamId AND DATE" +
|
|
|
+ "(gameDate) < ?" + " AND season = ? AND leagueId = ? GROUP BY awayTeamId) as sAway ON SoccerResults" +
|
|
|
+ ".awayTeamId = sAway" + ".awayTeamId " + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? " +
|
|
|
+ "AND DATE(gameDate) < ? AND season = ? " + "ORDER BY diff ASC";
|
|
|
List<String> allSeasons = getAllSeasons(leagueId);
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
@@ -928,12 +934,11 @@ public class GuiMysql extends Mysql {
|
|
|
while (rs.next()) {
|
|
|
final float diff = rs.getFloat("diff");
|
|
|
final int numGoals = rs.getInt("numGoals");
|
|
|
- final Float formatted = round(BigDecimal.valueOf(diff), INCREMENT, RoundingMode.HALF_UP)
|
|
|
- .floatValue();
|
|
|
+ final Float formatted =
|
|
|
+ round(BigDecimal.valueOf(diff), INCREMENT, RoundingMode.HALF_UP).floatValue();
|
|
|
|
|
|
- final OverUnder entry = result.stream().filter(ou -> ou.getKey().compareTo(formatted) == 0)
|
|
|
- .findFirst()
|
|
|
- .orElse(new OverUnder(formatted));
|
|
|
+ final OverUnder entry =
|
|
|
+ result.stream().filter(ou -> ou.getKey().compareTo(formatted) == 0).findFirst().orElse(new OverUnder(formatted));
|
|
|
entry.addGoalStat(numGoals);
|
|
|
result.add(entry);
|
|
|
}
|
|
|
@@ -949,11 +954,17 @@ public class GuiMysql extends Mysql {
|
|
|
df.setRoundingMode(RoundingMode.HALF_DOWN);
|
|
|
final ArrayList<OverUnder> result = Lists.newArrayList();
|
|
|
|
|
|
- final String sql = "SELECT (homeScore + awayScore) as numGoals, count(case when homeScore = awayScore then 1 end) draws, ROUND((sHome.avgScored * sAway.avgConceded) + (sAway.avgScored * sHome.avgConceded),1) roundedDiff, count(*) as numGames "
|
|
|
- + "FROM SoccerResults "
|
|
|
- + "INNER JOIN (SELECT homeTeamId, AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults WHERE homeScore != -1 AND homeTeamId = SoccerResults.homeTeamId AND DATE(gameDate) < ? AND leagueId = ? GROUP BY homeTeamId) as sHome ON SoccerResults.homeTeamId = sHome.homeTeamId "
|
|
|
- + "INNER JOIN (SELECT awayTeamId, AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults WHERE awayScore != -1 AND awayTeamId = SoccerResults.awayTeamId AND DATE(gameDate) < ? AND leagueId = ? GROUP BY awayTeamId) as sAway ON SoccerResults.awayTeamId = sAway.awayTeamId "
|
|
|
- + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? AND DATE(gameDate) < ? GROUP BY roundedDiff;";
|
|
|
+ final String sql = "SELECT (homeScore + awayScore) as numGoals, count(case when homeScore = awayScore then 1 "
|
|
|
+ + "end) draws, ROUND((sHome.avgScored * sAway.avgConceded) + (sAway.avgScored * sHome.avgConceded),1)" +
|
|
|
+ " " + "roundedDiff, count(*) as numGames " + "FROM SoccerResults " + "INNER JOIN (SELECT homeTeamId, " +
|
|
|
+ "AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM " + "SoccerResults WHERE homeScore " +
|
|
|
+ "!= -1 AND homeTeamId = SoccerResults.homeTeamId AND DATE(gameDate) < ?" + " AND leagueId = ? GROUP " +
|
|
|
+ "BY homeTeamId) as sHome ON SoccerResults.homeTeamId = sHome.homeTeamId " + "INNER JOIN (SELECT " +
|
|
|
+ "awayTeamId, AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM " + "SoccerResults WHERE" +
|
|
|
+ " awayScore != -1 AND awayTeamId = SoccerResults.awayTeamId AND DATE(gameDate) < ?" + " AND leagueId " +
|
|
|
+ "= ? GROUP BY awayTeamId) as sAway ON SoccerResults.awayTeamId = sAway.awayTeamId " + "WHERE " +
|
|
|
+ "homeScore != -1 AND awayScore != -1 AND leagueId = ? AND DATE(gameDate) < ? GROUP BY " +
|
|
|
+ "roundedDiff;";
|
|
|
|
|
|
List<String> allSeasons = getAllSeasons(leagueId);
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
@@ -978,9 +989,8 @@ public class GuiMysql extends Mysql {
|
|
|
final float diff = rs.getFloat("roundedDiff");
|
|
|
final int numGoals = rs.getInt("numGoals");
|
|
|
|
|
|
- final OverUnder entry = result.stream().filter(ou -> ou.getKey().compareTo(diff) == 0)
|
|
|
- .findFirst()
|
|
|
- .orElse(new OverUnder(diff));
|
|
|
+ final OverUnder entry =
|
|
|
+ result.stream().filter(ou -> ou.getKey().compareTo(diff) == 0).findFirst().orElse(new OverUnder(diff));
|
|
|
entry.addGoalStat(numGoals);
|
|
|
entry.setDraws(rs.getInt(DRAWS));
|
|
|
entry.setTotalGames(rs.getInt("numGames"));
|
|
|
@@ -995,10 +1005,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public Team getTeam(int teamId) {
|
|
|
Team result = null;
|
|
|
- String sql = "SELECT t.*, c.name as countryName, l.name AS leagueName FROM Team t "
|
|
|
- + "INNER JOIN Country c ON t.countryId = c.id "
|
|
|
- + "INNER JOIN League l ON t.leagueId = l.id "
|
|
|
- + "WHERE t.id = ? ";
|
|
|
+ String sql = "SELECT t.*, c.name as countryName, l.name AS leagueName FROM Team t " + "INNER JOIN Country c " +
|
|
|
+ "ON t.countryId = c.id " + "INNER JOIN League l ON t.leagueId = l.id " + "WHERE t.id = ? ";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
|
|
|
|
@@ -1018,17 +1026,15 @@ public class GuiMysql extends Mysql {
|
|
|
final String sql;
|
|
|
final TeamResults tr = new TeamResults();
|
|
|
if (isHomeTeam) {
|
|
|
- sql = "SELECT count(case when homeScore > awayScore then 1 end) wins, "
|
|
|
- + "count(case when awayScore > homeScore then 1 end) lost, "
|
|
|
- + "count(case when homeScore = awayScore then 1 end) draws "
|
|
|
- + "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = ? AND "
|
|
|
- + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < DATE(NOW()) ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
+ sql = "SELECT count(case when homeScore > awayScore then 1 end) wins, " + "count(case when awayScore > " +
|
|
|
+ "homeScore then 1 end) lost, " + "count(case when homeScore = awayScore then 1 end) draws " +
|
|
|
+ "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = ? AND " + "HomeScore >= 0 AND awayScore >= " +
|
|
|
+ "0 AND DATE(gameDate) < DATE(NOW()) ORDER BY gameDate DESC " + "LIMIT ?) as t";
|
|
|
} else {
|
|
|
- sql = "SELECT count(case when homeScore < awayScore then 1 end) wins, "
|
|
|
- + "count(case when awayScore < homeScore then 1 end) lost, "
|
|
|
- + "count(case when homeScore = awayScore then 1 end) draws "
|
|
|
- + "FROM (SELECT * FROM SoccerResults WHERE awayTeamId = ? AND "
|
|
|
- + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < DATE(NOW()) ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
+ sql = "SELECT count(case when homeScore < awayScore then 1 end) wins, " + "count(case when awayScore < " +
|
|
|
+ "homeScore then 1 end) lost, " + "count(case when homeScore = awayScore then 1 end) draws " +
|
|
|
+ "FROM (SELECT * FROM SoccerResults WHERE awayTeamId = ? AND " + "HomeScore >= 0 AND awayScore >= " +
|
|
|
+ "0 AND DATE(gameDate) < DATE(NOW()) ORDER BY gameDate DESC " + "LIMIT ?) as t";
|
|
|
}
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
@@ -1056,17 +1062,15 @@ public class GuiMysql extends Mysql {
|
|
|
final String sql;
|
|
|
final TeamResults tr = new TeamResults();
|
|
|
if (isHomeTeam) {
|
|
|
- sql = "SELECT count(case when homeScore > awayScore then 1 end) wins, "
|
|
|
- + "count(case when awayScore > homeScore then 1 end) lost, "
|
|
|
- + "count(case when homeScore = awayScore then 1 end) draws "
|
|
|
- + "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = ? AND "
|
|
|
- + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
+ sql = "SELECT count(case when homeScore > awayScore then 1 end) wins, " + "count(case when awayScore > " +
|
|
|
+ "homeScore then 1 end) lost, " + "count(case when homeScore = awayScore then 1 end) draws " +
|
|
|
+ "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = ? AND " + "HomeScore >= 0 AND awayScore >= " +
|
|
|
+ "0 AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
} else {
|
|
|
- sql = "SELECT count(case when homeScore < awayScore then 1 end) wins, "
|
|
|
- + "count(case when awayScore < homeScore then 1 end) lost, "
|
|
|
- + "count(case when homeScore = awayScore then 1 end) draws "
|
|
|
- + "FROM (SELECT * FROM SoccerResults WHERE awayTeamId = ? AND "
|
|
|
- + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
+ sql = "SELECT count(case when homeScore < awayScore then 1 end) wins, " + "count(case when awayScore < " +
|
|
|
+ "homeScore then 1 end) lost, " + "count(case when homeScore = awayScore then 1 end) draws " +
|
|
|
+ "FROM (SELECT * FROM SoccerResults WHERE awayTeamId = ? AND " + "HomeScore >= 0 AND awayScore >= " +
|
|
|
+ "0 AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
}
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
@@ -1097,16 +1101,12 @@ public class GuiMysql extends Mysql {
|
|
|
final String dateSql;
|
|
|
dateSql = " AND DATE(gameDate) >= DATE(now())";
|
|
|
|
|
|
- final String sql = "SELECT res.id, homeTeamId, awayTeamId, homeScore, awayScore, overtime, odds1, oddsX, odds2, gameDate, season, res.leagueId, res.countryId, "
|
|
|
- + "hTeam.name as homeTeamName, aTeam.name as awayTeamName, " + "league.name as leagueName, "
|
|
|
- + "country.name as countryName, "
|
|
|
- + "country.prio as prio " + "FROM " + sportResultTable + " as res "
|
|
|
- + "Join Team as hTeam ON res.homeTeamId = hTeam.id "
|
|
|
- + "Join Team as aTeam ON res.awayTeamId = aTeam.id "
|
|
|
- + "Join League as league ON res.leagueId = league.id "
|
|
|
- + "Join Country as country ON res.countryId = country.id " + "WHERE homeScore = -1 " + dateSql
|
|
|
- + "AND league.name NOT LIKE '%cup%' AND league.name NOT LIKE '%group%' AND league.prio = 1 "
|
|
|
- + "ORDER BY country.prio DESC, country.name ASC";
|
|
|
+ final String sql = "SELECT res.id, homeTeamId, awayTeamId, homeScore, awayScore, overtime, odds1, oddsX, " +
|
|
|
+ "odds2, gameDate, season, res.leagueId, res.countryId, " + "hTeam.name as homeTeamName, aTeam.name as" +
|
|
|
+ " awayTeamName, " + "league.name as leagueName, " + "country.name as countryName, " + "country.prio " +
|
|
|
+ "as prio " + "FROM " + sportResultTable + " as res " + "Join Team as hTeam ON res.homeTeamId = hTeam" +
|
|
|
+ ".id " + "Join Team as aTeam ON res.awayTeamId = aTeam.id " + "Join League as league ON res.leagueId " +
|
|
|
+ "= league.id " + "Join Country as country ON res.countryId = country.id " + "WHERE homeScore = -1 " + dateSql + "AND league.name NOT LIKE '%cup%' AND league.name NOT LIKE '%group%' AND league.prio = 1 " + "ORDER BY country.prio DESC, country.name ASC";
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
|
@@ -1311,10 +1311,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public SoccerMatch getMatch(String date, String homeTeamName, String awayTeamName) {
|
|
|
SoccerMatch match = new SoccerMatch();
|
|
|
- String sql = "SELECT * FROM SoccerResults sr " +
|
|
|
- "JOIN Team ht ON ht.id = sr.homeTeamId " +
|
|
|
- "JOIN Team awt ON awt.id = sr.awayTeamId " +
|
|
|
- "WHERE DATE(sr.gameDate) = ? AND (ht.name LIKE ? OR awt.name LIKE ?)";
|
|
|
+ String sql = "SELECT * FROM SoccerResults sr " + "JOIN Team ht ON ht.id = sr.homeTeamId " + "JOIN Team awt ON" +
|
|
|
+ " awt.id = sr.awayTeamId " + "WHERE DATE(sr.gameDate) = ? AND (ht.name LIKE ? OR awt.name LIKE ?)";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setString(1, date);
|
|
|
stat.setString(2, homeTeamName);
|
|
|
@@ -1323,11 +1321,10 @@ public class GuiMysql extends Mysql {
|
|
|
ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- match = new SoccerMatch(rs.getInt("id"), getTeam(rs.getInt("homeTeamId")),
|
|
|
- getTeam(rs.getInt("awayTeamId")), rs.getFloat("odds1"),
|
|
|
- rs.getFloat("oddsX"), rs.getFloat("odds2"),
|
|
|
- rs.getInt("homeScore"), rs.getInt("awayScore"),
|
|
|
- LocalDateTime.parse(rs.getString("gameDate")), rs.getString("season"));
|
|
|
+ match = new SoccerMatch(rs.getInt("id"), getTeam(rs.getInt(HOME_TEAM_ID)), getTeam(rs.getInt(
|
|
|
+ AWAY_TEAM_ID)), rs.getFloat(ODDS_1), rs.getFloat(ODDS_X), rs.getFloat(ODDS_2), rs.getInt(
|
|
|
+ HOME_SCORE), rs.getInt(AWAY_SCORE), LocalDateTime.parse(rs.getString("gameDate")),
|
|
|
+ rs.getString(SEASON));
|
|
|
}
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -1336,29 +1333,51 @@ public class GuiMysql extends Mysql {
|
|
|
return match;
|
|
|
}
|
|
|
|
|
|
- public List<SoccerMatchCalcBestValue> getMatchesForCalcBestValues(Integer countryId, Integer leagueId, String date) {
|
|
|
+ public List<SoccerMatch> getMatchesForCalcBestValues(int leagueId) {
|
|
|
+ List<SoccerMatch> result = new ArrayList<>();
|
|
|
+ String sql = "SELECT * FROM SoccerResults WHERE leaugeId = ? ORDER BY gameDate ASC";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+ while (rs.next()) {
|
|
|
+ Team homeTeam = getTeam(rs.getInt(HOME_TEAM_ID));
|
|
|
+ Team awayTeam = getTeam(rs.getInt(AWAY_TEAM_ID));
|
|
|
+ result.add(new SoccerMatch(rs.getInt("id"), homeTeam, awayTeam, rs.getFloat(ODDS_1),
|
|
|
+ rs.getFloat(ODDS_X), rs.getFloat(ODDS_2), rs.getInt(HOME_SCORE), rs.getInt(AWAY_SCORE),
|
|
|
+ LocalDateTime.parse(rs.getString(GAME_DATE)), rs.getString(SEASON)));
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SoccerMatchCalcBestValue> getMatchesForCalcBestValues(Integer countryId, Integer leagueId,
|
|
|
+ String date) {
|
|
|
|
|
|
final ArrayList<SoccerMatchCalcBestValue> matches = Lists.newArrayList();
|
|
|
|
|
|
- String homeTeamSelect = "(SELECT count(case when homeScore > awayScore then 1 end) " +
|
|
|
- "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res.homeTeamId AND " +
|
|
|
- "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s) as t) as homeWins%s," +
|
|
|
- "(SELECT count(case when awayScore > homeScore then 1 end) " +
|
|
|
- "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res.homeTeamId AND " +
|
|
|
- "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s) as t) as homeDraws%s," +
|
|
|
- "(SELECT count(case when homeScore = awayScore then 1 end) " +
|
|
|
- "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res.homeTeamId AND " +
|
|
|
- "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s) as t) as homeLosses%s";
|
|
|
-
|
|
|
- String awayTeamSelect = "(SELECT count(case when homeScore > awayScore then 1 end) " +
|
|
|
- "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res.homeTeamId AND " +
|
|
|
- "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s) as t) as awayWins%s," +
|
|
|
- "(SELECT count(case when awayScore > homeScore then 1 end) " +
|
|
|
- "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res.homeTeamId AND " +
|
|
|
- "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s) as t) as awayDraws%s," +
|
|
|
- "(SELECT count(case when homeScore = awayScore then 1 end) " +
|
|
|
- "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res.homeTeamId AND " +
|
|
|
- "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s) as t) as awayLosses%s";
|
|
|
+ String homeTeamSelect = "(SELECT count(case when homeScore > awayScore then 1 end) " + "FROM (SELECT * FROM " +
|
|
|
+ "SoccerResults WHERE homeTeamId = res.homeTeamId AND " + "HomeScore >= 0 AND awayScore >= 0 AND DATE" +
|
|
|
+ "(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s)" + " as t) as homeWins%s," + "(SELECT " +
|
|
|
+ "count(case when awayScore > homeScore then 1 end) " + "FROM (SELECT * FROM SoccerResults WHERE " +
|
|
|
+ "homeTeamId = res.homeTeamId AND " + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res" +
|
|
|
+ ".gameDate ORDER BY gameDate DESC LIMIT %s)" + " as t) as homeDraws%s," + "(SELECT count(case when " +
|
|
|
+ "homeScore = awayScore then 1 end) " + "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res" +
|
|
|
+ ".homeTeamId AND " + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY " +
|
|
|
+ "gameDate DESC LIMIT " + "%s) as t) as homeLosses%s";
|
|
|
+
|
|
|
+ String awayTeamSelect = "(SELECT count(case when homeScore > awayScore then 1 end) " + "FROM (SELECT * FROM " +
|
|
|
+ "SoccerResults WHERE homeTeamId = res.homeTeamId AND " + "HomeScore >= 0 AND awayScore >= 0 AND DATE" +
|
|
|
+ "(gameDate) < res.gameDate ORDER BY gameDate DESC LIMIT %s)" + " as t) as awayWins%s," + "(SELECT " +
|
|
|
+ "count(case when awayScore > homeScore then 1 end) " + "FROM (SELECT * FROM SoccerResults WHERE " +
|
|
|
+ "homeTeamId = res.homeTeamId AND " + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res" +
|
|
|
+ ".gameDate ORDER BY gameDate DESC LIMIT %s)" + " as t) as awayDraws%s," + "(SELECT count(case when " +
|
|
|
+ "homeScore = awayScore then 1 end) " + "FROM (SELECT * FROM SoccerResults WHERE homeTeamId = res" +
|
|
|
+ ".homeTeamId AND " + "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < res.gameDate ORDER BY " +
|
|
|
+ "gameDate DESC LIMIT " + "%s) as t) as awayLosses%s";
|
|
|
|
|
|
StringJoiner homeTeamSqlJoiner = new StringJoiner(", ");
|
|
|
StringJoiner awayTeamSqlJoiner = new StringJoiner(", ");
|
|
|
@@ -1368,16 +1387,13 @@ public class GuiMysql extends Mysql {
|
|
|
awayTeamSqlJoiner.add(String.format(awayTeamSelect, i, i, i, i, i, i));
|
|
|
}
|
|
|
|
|
|
- final String sql = "SELECT res.*, c.name as countryName, l.name as leagueName, "
|
|
|
- + "hTeam.name as homeTeamName, aTeam.name as awayTeamName, "
|
|
|
- + homeTeamSqlJoiner + "," + awayTeamSqlJoiner + " "
|
|
|
- + "FROM SoccerResults as res "
|
|
|
- + "INNER Join Team as hTeam ON res.homeTeamId = hTeam.id AND res.leagueId = hTeam.leagueId "
|
|
|
- + "INNER Join Team as aTeam ON res.awayTeamId = aTeam.id AND res.leagueId = hTeam.leagueId "
|
|
|
- + "INNER JOIN League l ON res.leagueId = l.id "
|
|
|
- + "INNER JOIN Country c ON res.countryId = c.id "
|
|
|
- + "WHERE " + "DATE(gameDate) <= '" + date + "' " + "AND res.leagueId = ? AND res.countryId = ? "
|
|
|
- + "ORDER BY gameDate ASC";
|
|
|
+ final String sql = "SELECT res.*, c.name as countryName, l.name as leagueName, " + "hTeam.name as " +
|
|
|
+ "homeTeamName, aTeam.name as awayTeamName, " + homeTeamSqlJoiner + "," + awayTeamSqlJoiner + " " +
|
|
|
+ "FROM SoccerResults as res " + "INNER Join Team as hTeam ON res.homeTeamId = hTeam.id AND res" +
|
|
|
+ ".leagueId = hTeam.leagueId " + "INNER Join Team as aTeam ON res.awayTeamId = aTeam.id AND res" +
|
|
|
+ ".leagueId = hTeam.leagueId " + "INNER JOIN League l ON res.leagueId = l.id " + "INNER JOIN Country c" +
|
|
|
+ " ON res.countryId = c.id " + "WHERE " + "DATE(gameDate) <= '" + date + "' " + "AND res.leagueId = ? " +
|
|
|
+ "AND res.countryId = ? " + "ORDER BY gameDate ASC";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, leagueId);
|
|
|
stat.setInt(2, countryId);
|
|
|
@@ -1436,4 +1452,349 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
return matches;
|
|
|
}
|
|
|
+
|
|
|
+ public List<SoccerMatchAnalysis> getSoccerMatchesWithGoalStats(int leagueId, String date, int limit) {
|
|
|
+ List<SoccerMatchAnalysis> result = new ArrayList<>();
|
|
|
+
|
|
|
+ String sql = "SELECT sr.id, sr.gameDate, sr.homeTeamId, sr.awayTeamId, sr.odds1, sr.oddsX, sr.odds2, sr" +
|
|
|
+ ".homeScore, " +
|
|
|
+ "sr.awayScore, sr.gameDate, sr.season, " +
|
|
|
+ "(SELECT COALESCE(sum(CASE " +
|
|
|
+ "WHEN sr.homeTeamId = ih.homeTeamId THEN homeScore " +
|
|
|
+ "WHEN sr.homeTeamId = ih.awayTeamId THEN awayScore END), 0) " +
|
|
|
+ "FROM (" +
|
|
|
+ "SELECT * FROM SoccerResults sr2 " +
|
|
|
+ "WHERE (sr.homeTeamId = sr2.homeTeamId OR sr.homeTeamId = sr2.awayTeamId) AND " +
|
|
|
+ "sr2.gameDate < sr.gameDate ORDER BY gameDate DESC LIMIT ?) as ih) as homeRes, " +
|
|
|
+ "(SELECT COALESCE(sum(CASE " +
|
|
|
+ "WHEN sr.awayTeamId = ia.awayTeamId THEN awayScore " +
|
|
|
+ "WHEN sr.awayTeamId = ia.homeTeamId THEN homeScore " +
|
|
|
+ "END), 0) " +
|
|
|
+ "FROM (SELECT * FROM SoccerResults sr2 " +
|
|
|
+ "WHERE " +
|
|
|
+ "(sr.awayTeamId = sr2.awayTeamId OR sr.awayTeamId = sr2.homeTeamId) AND " +
|
|
|
+ "sr2.gameDate < sr.gameDate ORDER BY gameDate DESC LIMIT ?) as ia) as awayRes " +
|
|
|
+ "FROM SoccerResults sr " +
|
|
|
+ "WHERE LeagueId = ? AND " +
|
|
|
+ "DATE(gameDate) < ? AND homeScore >= 0 AND awayScore >= 0 " +
|
|
|
+ "ORDER BY gameDate ASC";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1,limit);
|
|
|
+ stat.setInt(2,limit);
|
|
|
+ stat.setInt(3, leagueId);
|
|
|
+ stat.setString(4,date);
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ SoccerMatchAnalysis sma = new SoccerMatchAnalysis(new SoccerMatch(rs.getInt("id"),
|
|
|
+ GuiMysql.getInstance().getTeam(rs.getInt(HOME_TEAM_ID)),
|
|
|
+ GuiMysql.getInstance().getTeam(rs.getInt(AWAY_TEAM_ID)),
|
|
|
+ rs.getFloat(ODDS_1), rs.getFloat(ODDS_X), rs.getFloat(ODDS_2), rs.getInt(HOME_SCORE),
|
|
|
+ rs.getInt(AWAY_SCORE), LocalDateTime.parse(rs.getString(GAME_DATE)), rs.getString(SEASON)));
|
|
|
+ sma.setScoringTotalValue(rs.getInt("homeRes") - rs.getInt("awayRes"));
|
|
|
+
|
|
|
+ addTotalGoalStat(sma, limit, leagueId, rs.getInt("homeRes") - rs.getInt("awayRes"));
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addTotalGoalStat(SoccerMatchAnalysis match, int lookback, int leagueId, int diff) {
|
|
|
+ String sql = "INSERT INTO TotalGoalStatistics (leagueId, diff, lookback, homeWins, draws, awayWins) VALUES " +
|
|
|
+ "(?,?,?,?,?,?) ON DUPLICATE KEY UPDATE ";
|
|
|
+ String duplicateSql;
|
|
|
+ int homeWin = 0;
|
|
|
+ int draw = 0;
|
|
|
+ int awayWin = 0;
|
|
|
+ if (match.getHomeScore() > match.getAwayScore()) {
|
|
|
+ duplicateSql = " homeWins = homeWins + 1";
|
|
|
+ homeWin++;
|
|
|
+ } else if (match.getHomeScore() == match.getAwayScore()) {
|
|
|
+ duplicateSql = " draws = draws + 1";
|
|
|
+ draw++;
|
|
|
+ } else {
|
|
|
+ duplicateSql = " awayWins = awayWins + 1";
|
|
|
+ awayWin++;
|
|
|
+ }
|
|
|
+ sql += duplicateSql;
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
+ stat.setInt(2, diff);
|
|
|
+ stat.setInt(3,lookback);
|
|
|
+ stat.setInt(4,homeWin);
|
|
|
+ stat.setInt(5,draw);
|
|
|
+ stat.setInt(6,awayWin);
|
|
|
+
|
|
|
+ stat.execute();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calculateWinLossRatioHomeAndAwayStat(int leagueId, int lookback) {
|
|
|
+ List<SoccerMatchAnalysis> matches = getMatches(leagueId);
|
|
|
+
|
|
|
+ for (SoccerMatchAnalysis match : matches) {
|
|
|
+ int homeRatio = match.winLossRatioHomeAndAway(true, lookback);
|
|
|
+ int awayRatio = match.winLossRatioHomeAndAway(false, lookback);
|
|
|
+
|
|
|
+ int diff = homeRatio - awayRatio;
|
|
|
+ addWinLossRatioHomeAndAwayStat(match, leagueId, lookback, diff);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addWinLossRatioHomeAndAwayStat(SoccerMatchAnalysis match, int leagueId, int lookback, int diff) {
|
|
|
+ String sql = "INSERT INTO WinLossRatioHomeAndAwayStatistics (lookback, leagueId, diff, homeWins, draws, " +
|
|
|
+ "awayWins) VALUES" +
|
|
|
+ " (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE ";
|
|
|
+ String duplicateSql;
|
|
|
+ int homeWin = 0;
|
|
|
+ int draw = 0;
|
|
|
+ int awayWin = 0;
|
|
|
+ if (match.getHomeScore() > match.getAwayScore()) {
|
|
|
+ duplicateSql = " homeWins = homeWins + 1";
|
|
|
+ homeWin++;
|
|
|
+ } else if (match.getHomeScore() == match.getAwayScore()) {
|
|
|
+ duplicateSql = " draws = draws + 1";
|
|
|
+ draw++;
|
|
|
+ } else {
|
|
|
+ duplicateSql = " awayWins = awayWins + 1";
|
|
|
+ awayWin++;
|
|
|
+ }
|
|
|
+
|
|
|
+ sql += duplicateSql;
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, lookback);
|
|
|
+ stat.setInt(2, leagueId);
|
|
|
+ stat.setInt(3, diff);
|
|
|
+ stat.setInt(4, homeWin);
|
|
|
+ stat.setInt(5, draw);
|
|
|
+ stat.setInt(6, awayWin);
|
|
|
+
|
|
|
+ stat.execute();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calculateWinLossRatioStat(int leagueId, int lookback) {
|
|
|
+ List<SoccerMatchAnalysis> matches = getMatches(leagueId);
|
|
|
+
|
|
|
+ for (SoccerMatchAnalysis match : matches) {
|
|
|
+ int homeRatio = match.winLossRatio(lookback, true);
|
|
|
+ int awayRatio = match.winLossRatio(lookback, false);
|
|
|
+
|
|
|
+ int diff = homeRatio - awayRatio;
|
|
|
+ addWinLossRatioStat(match, leagueId, lookback, diff);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void addWinLossRatioStat(SoccerMatchAnalysis match, int leagueId, int lookback, int diff) {
|
|
|
+ String sql = "INSERT INTO WinLossRatioStatistics (lookback, leagueId, diff, homeWins, draws, " +
|
|
|
+ "awayWins) VALUES" +
|
|
|
+ " (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE ";
|
|
|
+ String duplicateSql;
|
|
|
+ int homeWin = 0;
|
|
|
+ int draw = 0;
|
|
|
+ int awayWin = 0;
|
|
|
+ if (match.getHomeScore() > match.getAwayScore()) {
|
|
|
+ duplicateSql = " homeWins = homeWins + 1";
|
|
|
+ homeWin++;
|
|
|
+ } else if (match.getHomeScore() == match.getAwayScore()) {
|
|
|
+ duplicateSql = " draws = draws + 1";
|
|
|
+ draw++;
|
|
|
+ } else {
|
|
|
+ duplicateSql = " awayWins = awayWins + 1";
|
|
|
+ awayWin++;
|
|
|
+ }
|
|
|
+
|
|
|
+ sql += duplicateSql;
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, lookback);
|
|
|
+ stat.setInt(2, leagueId);
|
|
|
+ stat.setInt(3, diff);
|
|
|
+ stat.setInt(4, homeWin);
|
|
|
+ stat.setInt(5, draw);
|
|
|
+ stat.setInt(6, awayWin);
|
|
|
+
|
|
|
+ stat.execute();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SoccerMatchAnalysis> getMatches(int leagueId) {
|
|
|
+ List<SoccerMatchAnalysis> result = new ArrayList<>();
|
|
|
+ String sql = "SELECT * FROM SoccerResults sr WHERE leagueId = ? AND homeScore >= 0 AND awayScore >= 0 ORDER " +
|
|
|
+ "BY gameDate ASC";
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ Team homeTeam = getTeam(rs.getInt(HOME_TEAM_ID));
|
|
|
+ Team awayTeam = getTeam(rs.getInt(AWAY_TEAM_ID));
|
|
|
+ result.add(new SoccerMatchAnalysis(new SoccerMatch(rs.getInt("id"), homeTeam, awayTeam, rs.getFloat(ODDS_1),
|
|
|
+ rs.getFloat(ODDS_X), rs.getFloat(ODDS_2), rs.getInt(HOME_SCORE), rs.getInt(AWAY_SCORE),
|
|
|
+ LocalDateTime.parse(rs.getString(GAME_DATE)), rs.getString(SEASON))));
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<League> getLeaguesWithPrio() {
|
|
|
+ List<League> result = new ArrayList<>();
|
|
|
+ String sql = "SELECT * FROM League WHERE prio = 1";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ result.add(new League(rs.getInt(Constants.ID), rs.getString("name"), rs.getInt("scoringDiffLastGame"),
|
|
|
+ rs.getInt("scoringTotal"), rs.getInt("winLossRatioHomeAndAway"), rs.getInt("winLossRatio"),
|
|
|
+ rs.getInt("drawDiffHomeAway"), rs.getInt("drawDiffTotalGoals"), rs.getInt("drawWinningForm"),
|
|
|
+ rs.getInt("drawWinningFormHomeAway")));
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addScoringDiffStatistics(int leagueId, int lookback) {
|
|
|
+ List<SoccerMatchAnalysis> matches = getMatches(leagueId);
|
|
|
+
|
|
|
+ for (SoccerMatchAnalysis match : matches) {
|
|
|
+ int diff = match.getScoringDiffLastGames(lookback);
|
|
|
+ addScoringDiffLastGamesStatistics(match, leagueId, lookback, diff);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addScoringDiffLastGamesStatistics(SoccerMatchAnalysis match, int leagueId, int lookback, int diff) {
|
|
|
+ String sql = "INSERT INTO ScoringDiffLastGamesStatistics (lookback, leagueId, diff, homeWins, draws, " +
|
|
|
+ "awayWins) VALUES" +
|
|
|
+ " (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE ";
|
|
|
+ String duplicateSql;
|
|
|
+ int homeWin = 0;
|
|
|
+ int draw = 0;
|
|
|
+ int awayWin = 0;
|
|
|
+ if (match.getHomeScore() > match.getAwayScore()) {
|
|
|
+ duplicateSql = " homeWins = homeWins + 1";
|
|
|
+ homeWin++;
|
|
|
+ } else if (match.getHomeScore() == match.getAwayScore()) {
|
|
|
+ duplicateSql = " draws = draws + 1";
|
|
|
+ draw++;
|
|
|
+ } else {
|
|
|
+ duplicateSql = " awayWins = awayWins + 1";
|
|
|
+ awayWin++;
|
|
|
+ }
|
|
|
+
|
|
|
+ sql += duplicateSql;
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, lookback);
|
|
|
+ stat.setInt(2, leagueId);
|
|
|
+ stat.setInt(3, diff);
|
|
|
+ stat.setInt(4, homeWin);
|
|
|
+ stat.setInt(5, draw);
|
|
|
+ stat.setInt(6, awayWin);
|
|
|
+
|
|
|
+ stat.execute();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getScoringDiffLastGames(Percentages percentages, int leagueId, int lookback, int diff) {
|
|
|
+ String sql = "SELECT homeWins, draws, awayWins FROM ScoringDiffLastGamesStatistics WHERE leagueId = ? AND " +
|
|
|
+ "lookback = ? and diff = ?";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1,leagueId);
|
|
|
+ stat.setInt(2, lookback);
|
|
|
+ stat.setInt(3,diff);
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+ while (rs.next()) {
|
|
|
+ percentages.setScoringDiffHomeWin(rs.getInt("homeWins"));
|
|
|
+ percentages.setScoringDiffDraw(rs.getInt("draws"));
|
|
|
+ percentages.setScoringDiffAwayWin(rs.getInt("awayWins"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void getTotalGoalStat(Percentages percentages,int leagueId, int lookback, int diff) {
|
|
|
+ String sql = "SELECT homeWins, draws, awayWins FROM TotalGoalStatistics WHERE leagueId = ? AND " +
|
|
|
+ "lookback = ? and diff = ?";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1,leagueId);
|
|
|
+ stat.setInt(2, lookback);
|
|
|
+ stat.setInt(3,diff);
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+ while (rs.next()) {
|
|
|
+ percentages.setScoringDiffHomeWin(rs.getInt("homeWins"));
|
|
|
+ percentages.setScoringDiffDraw(rs.getInt("draws"));
|
|
|
+ percentages.setScoringDiffAwayWin(rs.getInt("awayWins"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void getWinLossRatioHomeAndAwayStatistics(Percentages percentages,int leagueId, int lookback, int diff) {
|
|
|
+ String sql = "SELECT homeWins, draws, awayWins FROM WinLossRatioHomeAndAwayStatistics WHERE leagueId = ? AND " +
|
|
|
+ "lookback = ? and diff = ?";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1,leagueId);
|
|
|
+ stat.setInt(2, lookback);
|
|
|
+ stat.setInt(3,diff);
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+ while (rs.next()) {
|
|
|
+ percentages.setScoringDiffHomeWin(rs.getInt("homeWins"));
|
|
|
+ percentages.setScoringDiffDraw(rs.getInt("draws"));
|
|
|
+ percentages.setScoringDiffAwayWin(rs.getInt("awayWins"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void getWinLossRatioStatisticsGames(Percentages percentages, int leagueId, int lookback, int diff) {
|
|
|
+ String sql = "SELECT homeWins, draws, awayWins FROM WinLossRatioStatistics WHERE leagueId = ? AND " +
|
|
|
+ "lookback = ? and diff = ?";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1,leagueId);
|
|
|
+ stat.setInt(2, lookback);
|
|
|
+ stat.setInt(3,diff);
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+ while (rs.next()) {
|
|
|
+ percentages.setScoringDiffHomeWin(rs.getInt("homeWins"));
|
|
|
+ percentages.setScoringDiffDraw(rs.getInt("draws"));
|
|
|
+ percentages.setScoringDiffAwayWin(rs.getInt("awayWins"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|