|
@@ -59,8 +59,7 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
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);
|
|
sports.add(entry);
|
|
|
}
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
} catch (final SQLException e) {
|
|
@@ -79,8 +78,7 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
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);
|
|
countries.add(entry);
|
|
|
}
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
} catch (final SQLException e) {
|
|
@@ -100,8 +98,7 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
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);
|
|
leagues.add(entry);
|
|
|
}
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
} catch (final SQLException e) {
|
|
@@ -116,14 +113,11 @@ public class GuiMysql extends Mysql {
|
|
|
dateSql = " AND DATE(gameDate) >= DATE(now())";
|
|
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, "
|
|
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 "
|
|
|
|
|
|
|
+ + "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
|
|
+ "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%' "
|
|
|
|
|
- + "ORDER BY country.prio DESC, country.name ASC";
|
|
|
|
|
|
|
+ + "AND league.name NOT LIKE '%cup%' AND league.name NOT LIKE '%group%' " + "ORDER BY country.prio DESC, country.name ASC";
|
|
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
|
|
@@ -197,8 +191,7 @@ public class GuiMysql extends Mysql {
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
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));
|
|
stat.setString(2, getLastSeason(countryId, leagueId));
|
|
|
} else {
|
|
} else {
|
|
|
String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
@@ -275,8 +268,7 @@ public class GuiMysql extends Mysql {
|
|
|
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)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
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));
|
|
stat.setString(2, getLastSeason(countryId, leagueId));
|
|
|
} else {
|
|
} else {
|
|
|
String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
@@ -381,8 +373,7 @@ public class GuiMysql extends Mysql {
|
|
|
+ "FROM SoccerResults "
|
|
+ "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 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 "
|
|
+ "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";
|
|
|
|
|
|
|
+ + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? AND DATE(gameDate) < ? AND season = ? " + "ORDER BY diff ASC";
|
|
|
List<String> allSeasons = getAllSeasons(leagueId);
|
|
List<String> allSeasons = getAllSeasons(leagueId);
|
|
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
@@ -409,11 +400,10 @@ public class GuiMysql extends Mysql {
|
|
|
while (rs.next()) {
|
|
while (rs.next()) {
|
|
|
final float diff = rs.getFloat("diff");
|
|
final float diff = rs.getFloat("diff");
|
|
|
final int numGoals = rs.getInt("numGoals");
|
|
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);
|
|
entry.addGoalStat(numGoals);
|
|
|
result.add(entry);
|
|
result.add(entry);
|
|
|
}
|
|
}
|
|
@@ -443,16 +433,14 @@ public class GuiMysql extends Mysql {
|
|
|
final ArrayList<TeamStanding> result = Lists.newArrayList();
|
|
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, "
|
|
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 "
|
|
|
|
|
|
|
+ + "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, leagueId as league, countryId as country FROM SoccerResults "
|
|
+ "(select hometeamId team, homeScore, awayScore, season, leagueId as league, countryId as country FROM SoccerResults "
|
|
|
+ "union all SELECT awayteamId, awayScore, homeScore, season, leagueId as league, countryId as country FROM SoccerResults) a "
|
|
+ "union all SELECT awayteamId, awayScore, homeScore, season, 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 " + "group by team "
|
|
|
|
|
- + "order by score desc, goal_diff desc";
|
|
|
|
|
|
|
+ + "INNER JOIN Team teamName ON team = teamName.id " + "WHERE season = ? " + "AND league = ? " + "AND country = ? "
|
|
|
|
|
+ + "AND homeScore != -1 " + "AND awayScore != -1 " + "group by team " + "order by score desc, goal_diff desc";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
|
|
|
stat.setString(1, season);
|
|
stat.setString(1, season);
|
|
@@ -461,9 +449,8 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
while (rs.next()) {
|
|
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);
|
|
result.add(ts);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -518,16 +505,12 @@ public class GuiMysql extends Mysql {
|
|
|
final String sql;
|
|
final String sql;
|
|
|
final TeamResults tr = new TeamResults();
|
|
final TeamResults tr = new TeamResults();
|
|
|
if (isHomeTeam) {
|
|
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 "
|
|
|
|
|
|
|
+ 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";
|
|
+ "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < DATE(NOW()) ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
} else {
|
|
} 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 "
|
|
|
|
|
|
|
+ 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";
|
|
+ "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < DATE(NOW()) ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -556,16 +539,12 @@ public class GuiMysql extends Mysql {
|
|
|
final String sql;
|
|
final String sql;
|
|
|
final TeamResults tr = new TeamResults();
|
|
final TeamResults tr = new TeamResults();
|
|
|
if (isHomeTeam) {
|
|
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 "
|
|
|
|
|
|
|
+ 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";
|
|
+ "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
} else {
|
|
} 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 "
|
|
|
|
|
|
|
+ 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";
|
|
+ "HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) as t";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -625,8 +604,7 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
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);
|
|
leagues.add(entry);
|
|
|
}
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
} catch (final SQLException e) {
|
|
@@ -635,8 +613,7 @@ public class GuiMysql extends Mysql {
|
|
|
return leagues;
|
|
return leagues;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<SoccerMatch> getMatches(int sportId, Integer countryId, Integer leagueId, String date, String order,
|
|
|
|
|
- boolean exactDate) {
|
|
|
|
|
|
|
+ public List<SoccerMatch> getMatches(int sportId, Integer countryId, Integer leagueId, String date, String order, boolean exactDate) {
|
|
|
final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
|
final String dateSql;
|
|
final String dateSql;
|
|
|
final String orderSql = " ORDER BY gameDate " + order;
|
|
final String orderSql = " ORDER BY gameDate " + order;
|
|
@@ -649,10 +626,9 @@ public class GuiMysql extends Mysql {
|
|
|
dateSql = "DATE(gameDate) <= '" + date + "' ";
|
|
dateSql = "DATE(gameDate) <= '" + date + "' ";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- final String sql = "SELECT res.*, " + "hTeam.name as homeTeamName, aTeam.name as awayTeamName "
|
|
|
|
|
- + "FROM SoccerResults as res " + "Join Team as hTeam ON res.homeTeamId = hTeam.id "
|
|
|
|
|
- + "Join Team as aTeam ON res.awayTeamId = aTeam.id " + "WHERE " + dateSql + "AND res.leagueId = ? "
|
|
|
|
|
- + "AND res.countryId = ? " + orderSql;
|
|
|
|
|
|
|
+ final String sql = "SELECT res.*, " + "hTeam.name as homeTeamName, aTeam.name as awayTeamName " + "FROM SoccerResults as res "
|
|
|
|
|
+ + "Join Team as hTeam ON res.homeTeamId = hTeam.id " + "Join Team as aTeam ON res.awayTeamId = aTeam.id " + "WHERE " + dateSql
|
|
|
|
|
+ + "AND res.leagueId = ? " + "AND res.countryId = ? " + orderSql;
|
|
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, leagueId);
|
|
stat.setInt(1, leagueId);
|
|
@@ -702,10 +678,9 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
while (rs.next()) {
|
|
|
- result = new League(rs.getInt(Constants.ID), rs.getString("name"), rs.getInt("lookback"),
|
|
|
|
|
- rs.getInt("betMargin"), rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"),
|
|
|
|
|
- rs.getInt("lookbackAway"), rs.getInt("betMarginHome"), rs.getInt("betMarginDraw"),
|
|
|
|
|
- rs.getInt("betMarginAway"));
|
|
|
|
|
|
|
+ result = new League(rs.getInt(Constants.ID), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin"),
|
|
|
|
|
+ rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"), rs.getInt("lookbackAway"), rs.getInt("betMarginHome"),
|
|
|
|
|
+ rs.getInt("betMarginDraw"), rs.getInt("betMarginAway"));
|
|
|
}
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
} catch (final SQLException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -722,10 +697,9 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
while (rs.next()) {
|
|
|
- result = new League(rs.getInt(Constants.ID), rs.getString("name"), rs.getInt("lookback"),
|
|
|
|
|
- rs.getInt("betMargin"), rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"),
|
|
|
|
|
- rs.getInt("lookbackAway"), rs.getInt("betMarginHome"), rs.getInt("betMarginDraw"),
|
|
|
|
|
- rs.getInt("betMarginAway"));
|
|
|
|
|
|
|
+ result = new League(rs.getInt(Constants.ID), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin"),
|
|
|
|
|
+ rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"), rs.getInt("lookbackAway"), rs.getInt("betMarginHome"),
|
|
|
|
|
+ rs.getInt("betMarginDraw"), rs.getInt("betMarginAway"));
|
|
|
}
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
} catch (final SQLException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -821,9 +795,9 @@ public class GuiMysql extends Mysql {
|
|
|
public List<BetDTO> getBetSeries(boolean includeInactive) {
|
|
public List<BetDTO> getBetSeries(boolean includeInactive) {
|
|
|
List<BetDTO> result = new ArrayList<>();
|
|
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, "
|
|
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 = ?";
|
|
|
|
|
|
|
+ + "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)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setBoolean(1, includeInactive);
|
|
stat.setBoolean(1, includeInactive);
|
|
@@ -857,7 +831,7 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, bet.getBetSeries());
|
|
stat.setInt(1, bet.getBetSeries());
|
|
|
- stat.setInt(2, bet.getGameId());
|
|
|
|
|
|
|
+ stat.setInt(2, getGameId(bet.getHomeTeam(), bet.getAwayTeam(), bet.getGameDate(), bet.getCountryId(), bet.getLeagueId()));
|
|
|
stat.setString(3, bet.getBetType());
|
|
stat.setString(3, bet.getBetType());
|
|
|
stat.setFloat(4, bet.getBet());
|
|
stat.setFloat(4, bet.getBet());
|
|
|
stat.setFloat(5, bet.getOdds());
|
|
stat.setFloat(5, bet.getOdds());
|
|
@@ -868,4 +842,100 @@ public class GuiMysql extends Mysql {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ 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(?)";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setString(1, homeTeam);
|
|
|
|
|
+ stat.setInt(2, countryId);
|
|
|
|
|
+ stat.setInt(3, leagueId);
|
|
|
|
|
+ stat.setString(4, awayTeam);
|
|
|
|
|
+ stat.setInt(5, countryId);
|
|
|
|
|
+ stat.setInt(6, leagueId);
|
|
|
|
|
+ stat.setString(7, gameDate);
|
|
|
|
|
+
|
|
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ result = rs.getInt("id");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Map<String, String> getPreviousMatches(int numberOfMatches, String homeTeamName, String awayTeamName, String date, int countryId,
|
|
|
|
|
+ int leagueId) {
|
|
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ String homeTeamSql = "SELECT * FROM SoccerResults WHERE homeTeamId = (SELECT id FROM Team WHERE name = ? AND countryId = ? AND leagueId = ?) AND DATE(gameDate) < ? ORDER BY gameDate DESC limit ?";
|
|
|
|
|
+ String awayTeamSql = "SELECT * FROM SoccerResults WHERE awayTeamId = (SELECT id FROM Team WHERE name = ? AND countryId = ? AND leagueId = ?) AND DATE(gameDate) < ? ORDER BY gameDate DESC limit ?";
|
|
|
|
|
+ String combinedSql = "SELECT * 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) < ? ORDER BY gameDate DESC LIMIT ?";
|
|
|
|
|
+ try (PreparedStatement homeTeamStat = conn.prepareStatement(homeTeamSql);
|
|
|
|
|
+ PreparedStatement awayTeamStat = conn.prepareStatement(awayTeamSql);
|
|
|
|
|
+ PreparedStatement combinedStat = conn.prepareStatement(combinedSql);) {
|
|
|
|
|
+
|
|
|
|
|
+ homeTeamStat.setString(1, homeTeamName);
|
|
|
|
|
+ homeTeamStat.setInt(2, countryId);
|
|
|
|
|
+ homeTeamStat.setInt(3, leagueId);
|
|
|
|
|
+ homeTeamStat.setString(4, date);
|
|
|
|
|
+ homeTeamStat.setInt(5, numberOfMatches);
|
|
|
|
|
+
|
|
|
|
|
+ awayTeamStat.setString(1, awayTeamName);
|
|
|
|
|
+ awayTeamStat.setInt(2, countryId);
|
|
|
|
|
+ awayTeamStat.setInt(3, leagueId);
|
|
|
|
|
+ awayTeamStat.setString(4, date);
|
|
|
|
|
+ awayTeamStat.setInt(5, numberOfMatches);
|
|
|
|
|
+
|
|
|
|
|
+ combinedStat.setString(1, homeTeamName);
|
|
|
|
|
+ combinedStat.setInt(2, countryId);
|
|
|
|
|
+ combinedStat.setInt(3, leagueId);
|
|
|
|
|
+ combinedStat.setString(4, awayTeamName);
|
|
|
|
|
+ combinedStat.setInt(5, countryId);
|
|
|
|
|
+ combinedStat.setInt(6, leagueId);
|
|
|
|
|
+ combinedStat.setString(7, date);
|
|
|
|
|
+ combinedStat.setInt(8, numberOfMatches);
|
|
|
|
|
+
|
|
|
|
|
+ ResultSet homeTeamRs = homeTeamStat.executeQuery();
|
|
|
|
|
+ ResultSet awayTeamRs = awayTeamStat.executeQuery();
|
|
|
|
|
+ ResultSet combinedTeamRs = combinedStat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ String homeTeamMeets = "";
|
|
|
|
|
+ while (homeTeamRs.next()) {
|
|
|
|
|
+ homeTeamMeets += homeTeamRs.getInt("homeScore") + "-" + homeTeamRs.getInt("awayScore") + ", ";
|
|
|
|
|
+ }
|
|
|
|
|
+ String awayTeamMeets = "";
|
|
|
|
|
+ while (awayTeamRs.next()) {
|
|
|
|
|
+ awayTeamMeets += awayTeamRs.getInt("homeScore") + "-" + awayTeamRs.getInt("awayScore") + ", ";
|
|
|
|
|
+ }
|
|
|
|
|
+ String combinedMeets = "";
|
|
|
|
|
+ while (combinedTeamRs.next()) {
|
|
|
|
|
+ combinedMeets += combinedTeamRs.getInt("homeScore") + "-" + combinedTeamRs.getInt("awayScore") + ", ";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (homeTeamMeets.length() > 2) {
|
|
|
|
|
+ result.put("PrevHomeTeam", homeTeamMeets.substring(0, homeTeamMeets.length() - 2));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.put("PrevHomeTeam", homeTeamMeets);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (awayTeamMeets.length() > 2) {
|
|
|
|
|
+ result.put("PrevAwayTeam", awayTeamMeets.substring(0, awayTeamMeets.length() - 2));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.put("PrevAwayTeam", awayTeamMeets);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (combinedMeets.length() > 2) {
|
|
|
|
|
+ result.put("PrevCombined", combinedMeets.substring(0, combinedMeets.length() - 2));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.put("PrevCombined", combinedMeets);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|