|
@@ -11,6 +11,9 @@ import java.time.LocalDateTime;
|
|
|
import java.util.AbstractMap;
|
|
import java.util.AbstractMap;
|
|
|
import java.util.AbstractMap.SimpleEntry;
|
|
import java.util.AbstractMap.SimpleEntry;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import org.eclipse.jetty.util.log.Log;
|
|
|
|
|
|
|
|
import com.google.common.base.Strings;
|
|
import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
@@ -25,674 +28,622 @@ import objects.TeamStanding;
|
|
|
|
|
|
|
|
public class GuiMysql extends Mysql {
|
|
public class GuiMysql extends Mysql {
|
|
|
|
|
|
|
|
- private static final BigDecimal INCREMENT = new BigDecimal(0.2);
|
|
|
|
|
- private static final GuiMysql instance = new GuiMysql();
|
|
|
|
|
- private final Connection conn;
|
|
|
|
|
-
|
|
|
|
|
- private GuiMysql() {
|
|
|
|
|
- super();
|
|
|
|
|
- conn = this.getConnection();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public static GuiMysql getInstance() {
|
|
|
|
|
- return instance;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<SimpleEntry<Integer, String>> getSports() {
|
|
|
|
|
-
|
|
|
|
|
- final ArrayList<AbstractMap.SimpleEntry<Integer, String>> sports = Lists.newArrayList();
|
|
|
|
|
- try {
|
|
|
|
|
- final String sql = "SELECT id, name FROM Sport";
|
|
|
|
|
- PreparedStatement stmt;
|
|
|
|
|
- stmt = conn.prepareStatement(sql);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
- sports.add(entry);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return sports;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<SimpleEntry<Integer, String>> getCountries() {
|
|
|
|
|
-
|
|
|
|
|
- final ArrayList<AbstractMap.SimpleEntry<Integer, String>> countries = Lists.newArrayList();
|
|
|
|
|
- try {
|
|
|
|
|
- final String sql = "SELECT id, name FROM Country";
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
- countries.add(entry);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return countries;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<SimpleEntry<Integer, String>> getLeagues(int sportId, int countryId) {
|
|
|
|
|
-
|
|
|
|
|
- final ArrayList<AbstractMap.SimpleEntry<Integer, String>> leagues = Lists.newArrayList();
|
|
|
|
|
- try {
|
|
|
|
|
- final String sql = "SELECT id, name FROM League WHERE sportId = ? AND countryId = ? ORDER BY name ASC";
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, sportId);
|
|
|
|
|
- stmt.setInt(2, countryId);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
- leagues.add(entry);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return leagues;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<SoccerMatch> getUpcomingMatches(String sportResultTable, int sportId) {
|
|
|
|
|
- final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
|
|
|
- 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%' "
|
|
|
|
|
- + "ORDER BY country.prio DESC, country.name ASC";
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final SoccerMatch sm = new SoccerMatch();
|
|
|
|
|
- final Team homeTeam = new Team();
|
|
|
|
|
- final Team awayTeam = new Team();
|
|
|
|
|
-
|
|
|
|
|
- homeTeam.setTeamId(rs.getInt("homeTeamId"));
|
|
|
|
|
- awayTeam.setTeamId(rs.getInt("awayTeamId"));
|
|
|
|
|
- homeTeam.setTeamName(rs.getString("homeTeamName"));
|
|
|
|
|
- awayTeam.setTeamName(rs.getString("awayTeamName"));
|
|
|
|
|
- homeTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
- awayTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
- homeTeam.setTeamLeague(rs.getString("leagueName"));
|
|
|
|
|
- awayTeam.setTeamLeague(rs.getString("leagueName"));
|
|
|
|
|
- homeTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
- awayTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
- homeTeam.setCountryName(rs.getString("countryName"));
|
|
|
|
|
- awayTeam.setCountryName(rs.getString("countryName"));
|
|
|
|
|
-
|
|
|
|
|
- sm.setAwayScore(rs.getInt("awayScore"));
|
|
|
|
|
- sm.setHomeScore(rs.getInt("homeScore"));
|
|
|
|
|
- sm.setHomeTeam(homeTeam);
|
|
|
|
|
- sm.setAwayTeam(awayTeam);
|
|
|
|
|
- sm.setMatchId(rs.getInt("id"));
|
|
|
|
|
- sm.setOdds1(rs.getFloat("odds1"));
|
|
|
|
|
- sm.setOddsX(rs.getFloat("oddsX"));
|
|
|
|
|
- sm.setOdds2(rs.getFloat("odds2"));
|
|
|
|
|
- sm.setGameDate(LocalDateTime.parse(rs.getString("gameDate")));
|
|
|
|
|
- sm.setCountryPrio(rs.getBoolean("prio"));
|
|
|
|
|
-
|
|
|
|
|
- matches.add(sm);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return matches;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<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 && homeTeamId = ?";
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, teamId);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- returnValue.add(rs.getFloat("avgScored"));
|
|
|
|
|
- returnValue.add(rs.getFloat("avgConceded"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return returnValue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<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 && awayTeamId = ?";
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, teamId);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- returnValue.add(rs.getFloat("avgScored"));
|
|
|
|
|
- returnValue.add(rs.getFloat("avgConceded"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return returnValue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<Float> getLeagueAvarages(int leagueId, int countryId) {
|
|
|
|
|
- final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
|
|
- final String sql = "SELECT AVG(homeScore) avgHomeScore, AVG(awayScore) as avgAwayScore"
|
|
|
|
|
- + " FROM SoccerResults WHERE leagueId = ? AND countryId = ?";
|
|
|
|
|
-
|
|
|
|
|
- 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 {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, leagueId);
|
|
|
|
|
- stmt.setInt(2, countryId);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- returnValue.add(rs.getFloat("avgHomeScore"));
|
|
|
|
|
- returnValue.add(rs.getFloat("avgAwayScore"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- final PreparedStatement goalStmt = conn.prepareStatement(goalsSql);
|
|
|
|
|
- goalStmt.setInt(1, leagueId);
|
|
|
|
|
- goalStmt.setInt(2, countryId);
|
|
|
|
|
- goalStmt.setString(3, getLastSeason(countryId, leagueId));
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet goalRs = goalStmt.executeQuery();
|
|
|
|
|
- while (goalRs.next()) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return returnValue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<OverUnder> getStatsOverUnder(int leagueId) {
|
|
|
|
|
-
|
|
|
|
|
- final DecimalFormat df = new DecimalFormat("##.##");
|
|
|
|
|
- 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 && homeTeamId = SoccerResults.homeTeamId 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 && awayTeamId = SoccerResults.awayTeamId GROUP BY awayTeamId) as sAway ON SoccerResults.awayTeamId = sAway.awayTeamId "
|
|
|
|
|
- + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? " + "ORDER BY diff ASC";
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, leagueId);
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final float diff = rs.getFloat("diff");
|
|
|
|
|
- final int numGoals = rs.getInt("numGoals");
|
|
|
|
|
- // final Float formatted = Float.valueOf(df.format(diff));
|
|
|
|
|
- // final Float formatted = BigDecimal.valueOf(diff).setScale(1,
|
|
|
|
|
- // BigDecimal.ROUND_HALF_DOWN).floatValue();
|
|
|
|
|
- final Float formatted = round(new BigDecimal(diff), INCREMENT, RoundingMode.HALF_UP).floatValue();
|
|
|
|
|
-
|
|
|
|
|
- final OverUnder entry = result.stream().filter(ou -> ou.getKey().compareTo(formatted) == 0).findFirst()
|
|
|
|
|
- .orElse(new OverUnder(formatted));
|
|
|
|
|
- entry.addGoalStat(numGoals);
|
|
|
|
|
- result.add(entry);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public BigDecimal round(BigDecimal value, BigDecimal increment, RoundingMode roundingMode) {
|
|
|
|
|
- if (increment.signum() == 0) {
|
|
|
|
|
- // 0 increment does not make much sense, but prevent division by 0
|
|
|
|
|
- return value;
|
|
|
|
|
- } else {
|
|
|
|
|
- final BigDecimal divided = value.divide(increment, 0, roundingMode);
|
|
|
|
|
- final BigDecimal result = divided.multiply(increment);
|
|
|
|
|
- return result.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public BigDecimal getIncrement() {
|
|
|
|
|
- return INCREMENT;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<TeamStanding> getLeagueTable(int leagueId, String season, int countryId) {
|
|
|
|
|
- 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, leagueId as league, countryId as country FROM SoccerResults "
|
|
|
|
|
- + "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";
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
-
|
|
|
|
|
- stmt.setString(1, season);
|
|
|
|
|
- stmt.setInt(2, leagueId);
|
|
|
|
|
- stmt.setInt(3, countryId);
|
|
|
|
|
-
|
|
|
|
|
- final String tempSql = sql.replaceAll("\\?", "%s");
|
|
|
|
|
- System.out.println(String.format(tempSql, season, leagueId, countryId));
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.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("homeScore"), rs.getFloat("awayScore"), rs.getFloat("goal_diff"));
|
|
|
|
|
- result.add(ts);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- System.out.println("Sql vid fel: " + sql);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public boolean getParsingStarted(int countryId, int leagueId) {
|
|
|
|
|
- boolean returnValue = false;
|
|
|
|
|
- final String sql = "SELECT parsedYear FROM League WHERE id = ? AND countryId = ?";
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, leagueId);
|
|
|
|
|
- stmt.setInt(2, countryId);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final String parsedYear = rs.getString("parsedYear");
|
|
|
|
|
- if (!Strings.isNullOrEmpty(parsedYear)) {
|
|
|
|
|
- returnValue = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return returnValue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- 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";
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, leagueId);
|
|
|
|
|
- stmt.setInt(2, countryId);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- season = rs.getString("season");
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return season;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public TeamResults getTeamResults(int teamId, int numResults, boolean isHomeTeam) {
|
|
|
|
|
- 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";
|
|
|
|
|
- } 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";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = conn.prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, teamId);
|
|
|
|
|
- stat.setInt(2, numResults);
|
|
|
|
|
- final ResultSet rs = stat.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final int draws = rs.getInt("draws");
|
|
|
|
|
- final int wins = rs.getInt("wins");
|
|
|
|
|
- final int lost = rs.getInt("lost");
|
|
|
|
|
- tr.setDraws(draws);
|
|
|
|
|
- tr.setWins(wins);
|
|
|
|
|
- tr.setLosses(lost);
|
|
|
|
|
- tr.setCount(wins + draws + lost);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- stat.close();
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return tr;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public TeamResults getTeamResultsTest(int teamId, int numResults, boolean isHomeTeam, String date) {
|
|
|
|
|
- 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";
|
|
|
|
|
- } 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";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = conn.prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, teamId);
|
|
|
|
|
- stat.setString(2, date);
|
|
|
|
|
- stat.setInt(3, numResults);
|
|
|
|
|
- final ResultSet rs = stat.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final int draws = rs.getInt("draws");
|
|
|
|
|
- final int wins = rs.getInt("wins");
|
|
|
|
|
- final int lost = rs.getInt("lost");
|
|
|
|
|
- tr.setDraws(draws);
|
|
|
|
|
- tr.setWins(wins);
|
|
|
|
|
- tr.setLosses(lost);
|
|
|
|
|
- tr.setCount(wins + draws + lost);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- stat.close();
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return tr;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<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 ArrayList<SimpleEntry<Integer, String>> result = new ArrayList<>();
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- if (date.equals("")) {
|
|
|
|
|
- stat.setString(1, "DATE(NOW())");
|
|
|
|
|
- } else {
|
|
|
|
|
- stat.setString(1, date);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stat.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- result.add(new SimpleEntry<>(rs.getInt("id"), rs.getString("name")));
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<SimpleEntry<Integer, String>> getLeaguesByDate(int sportId, int countryId, String date) {
|
|
|
|
|
- final ArrayList<AbstractMap.SimpleEntry<Integer, String>> leagues = Lists.newArrayList();
|
|
|
|
|
- try {
|
|
|
|
|
- final String sql
|
|
|
|
|
- = "SELECT id, name FROM League WHERE id IN (SELECT leagueId FROM SoccerResults WHERE sportId = ? AND countryId = ? AND DATE(gameDate) = ?)";
|
|
|
|
|
- // final String sql = "SELECT id, name FROM League WHERE sportId = ? AND
|
|
|
|
|
- // countryId = ? ORDER BY name ASC";
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
- stmt.setInt(1, sportId);
|
|
|
|
|
- stmt.setInt(2, countryId);
|
|
|
|
|
- stmt.setString(3, date);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
- leagues.add(entry);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return leagues;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ArrayList<SoccerMatch> getMatches(int sportId, Integer countryId, Integer leagueId, String date, String order) {
|
|
|
|
|
- final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
|
|
|
- final String dateSql;
|
|
|
|
|
- final String orderSql = " ORDER BY gameDate " + order;
|
|
|
|
|
- if (date.equals("")) {
|
|
|
|
|
- dateSql = "DATE(gameDate) = DATE(NOW()) ";
|
|
|
|
|
- } else {
|
|
|
|
|
- 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.awayTeam = aTeam.id "
|
|
|
|
|
- + "WHERE " + dateSql + "AND res.leagueId = ? " + "AND res.countryId = ? " + orderSql;
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stmt = conn.prepareStatement(sql);
|
|
|
|
|
-
|
|
|
|
|
- stmt.setInt(1, leagueId);
|
|
|
|
|
- stmt.setInt(2, countryId);
|
|
|
|
|
-
|
|
|
|
|
- final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- final SoccerMatch sm = new SoccerMatch();
|
|
|
|
|
- final Team homeTeam = new Team();
|
|
|
|
|
- final Team awayTeam = new Team();
|
|
|
|
|
-
|
|
|
|
|
- homeTeam.setTeamId(rs.getInt("homeTeamId"));
|
|
|
|
|
- awayTeam.setTeamId(rs.getInt("awayTeamId"));
|
|
|
|
|
- homeTeam.setTeamName(rs.getString("homeTeamName"));
|
|
|
|
|
- awayTeam.setTeamName(rs.getString("awayTeamName"));
|
|
|
|
|
- homeTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
- awayTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
- homeTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
- awayTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
-
|
|
|
|
|
- sm.setAwayScore(rs.getInt("awayScore"));
|
|
|
|
|
- sm.setHomeScore(rs.getInt("homeScore"));
|
|
|
|
|
- sm.setHomeTeam(homeTeam);
|
|
|
|
|
- sm.setAwayTeam(awayTeam);
|
|
|
|
|
- sm.setMatchId(rs.getInt("id"));
|
|
|
|
|
- sm.setOdds1(rs.getFloat("odds1"));
|
|
|
|
|
- sm.setOddsX(rs.getFloat("oddsX"));
|
|
|
|
|
- sm.setOdds2(rs.getFloat("odds2"));
|
|
|
|
|
- sm.setGameDate(LocalDateTime.parse(rs.getString("gameDate")));
|
|
|
|
|
- sm.setSeason(rs.getString("season"));
|
|
|
|
|
-
|
|
|
|
|
- matches.add(sm);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return matches;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public League getLeagueInfo(String teamLeague) {
|
|
|
|
|
- final String sql = "SELECT * FROM League WHERE name = ?";
|
|
|
|
|
- League result = null;
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setString(1, teamLeague);
|
|
|
|
|
- final ResultSet rs = stat.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- result = new League(rs.getInt("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) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public League getLeagueInfo(int leagueId) {
|
|
|
|
|
- final String sql = "SELECT * FROM League WHERE id = ?";
|
|
|
|
|
- League result = null;
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, leagueId);
|
|
|
|
|
- final ResultSet rs = stat.executeQuery();
|
|
|
|
|
-
|
|
|
|
|
- while (rs.next()) {
|
|
|
|
|
- result = new League(rs.getInt("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) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setTeamMarginHome(int teamId, int marginHome) {
|
|
|
|
|
- final String sql = "UPDATE Team SET marginHome = ? WHERE id = ?";
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, marginHome);
|
|
|
|
|
- stat.setInt(2, teamId);
|
|
|
|
|
-
|
|
|
|
|
- stat.executeUpdate();
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setTeamMarginDraw(int teamId, int marginDraw) {
|
|
|
|
|
- final String sql = "UPDATE Team SET marginDraw = ? WHERE id = ?";
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, marginDraw);
|
|
|
|
|
- stat.setInt(2, teamId);
|
|
|
|
|
-
|
|
|
|
|
- stat.executeUpdate();
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setTeamMarginAway(int teamId, int marginAway) {
|
|
|
|
|
- final String sql = "UPDATE Team SET marginAway = ? WHERE id = ?";
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, marginAway);
|
|
|
|
|
- stat.setInt(2, teamId);
|
|
|
|
|
-
|
|
|
|
|
- stat.executeUpdate();
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setTeamLookbackHome(int teamId, int lookbackHome) {
|
|
|
|
|
- final String sql = "UPDATE Team SET lookbackHome = ? WHERE id = ?";
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, lookbackHome);
|
|
|
|
|
- stat.setInt(2, teamId);
|
|
|
|
|
-
|
|
|
|
|
- stat.executeUpdate();
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setTeamLookbackDraw(int teamId, int lookbackDraw) {
|
|
|
|
|
- final String sql = "UPDATE Team SET lookbackDraw = ? WHERE id = ?";
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, lookbackDraw);
|
|
|
|
|
- stat.setInt(2, teamId);
|
|
|
|
|
-
|
|
|
|
|
- stat.executeUpdate();
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setTeamLookbackAway(int teamId, int lookbackAway) {
|
|
|
|
|
- final String sql = "UPDATE Team SET lookbackAway = ? WHERE id = ?";
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- final PreparedStatement stat = getConnection().prepareStatement(sql);
|
|
|
|
|
- stat.setInt(1, lookbackAway);
|
|
|
|
|
- stat.setInt(2, teamId);
|
|
|
|
|
-
|
|
|
|
|
- stat.executeUpdate();
|
|
|
|
|
-
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private static final BigDecimal INCREMENT = BigDecimal.valueOf(0.2);
|
|
|
|
|
+ private static final GuiMysql instance = new GuiMysql();
|
|
|
|
|
+ private final Connection conn;
|
|
|
|
|
+
|
|
|
|
|
+ private GuiMysql() {
|
|
|
|
|
+ super();
|
|
|
|
|
+ conn = this.getConnection();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static GuiMysql getInstance() {
|
|
|
|
|
+ return instance;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<SimpleEntry<Integer, String>> getSports() {
|
|
|
|
|
+
|
|
|
|
|
+ final ArrayList<AbstractMap.SimpleEntry<Integer, String>> sports = Lists.newArrayList();
|
|
|
|
|
+ final String sql = "SELECT id, name FROM Sport";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
+ sports.add(entry);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return sports;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<SimpleEntry<Integer, String>> getCountries() {
|
|
|
|
|
+
|
|
|
|
|
+ final ArrayList<AbstractMap.SimpleEntry<Integer, String>> countries = Lists.newArrayList();
|
|
|
|
|
+ final String sql = "SELECT id, name FROM Country";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
+ countries.add(entry);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return countries;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<SimpleEntry<Integer, String>> getLeagues(int sportId, int countryId) {
|
|
|
|
|
+
|
|
|
|
|
+ final ArrayList<AbstractMap.SimpleEntry<Integer, String>> leagues = Lists.newArrayList();
|
|
|
|
|
+ final String sql = "SELECT id, name FROM League WHERE sportId = ? AND countryId = ? ORDER BY name ASC";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, sportId);
|
|
|
|
|
+ stat.setInt(2, countryId);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
+ leagues.add(entry);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return leagues;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<SoccerMatch> getUpcomingMatches(String sportResultTable) {
|
|
|
|
|
+ final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
|
|
|
+ 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%' "
|
|
|
|
|
+ + "ORDER BY country.prio DESC, country.name ASC";
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final SoccerMatch sm = new SoccerMatch();
|
|
|
|
|
+ final Team homeTeam = new Team();
|
|
|
|
|
+ final Team awayTeam = new Team();
|
|
|
|
|
+
|
|
|
|
|
+ homeTeam.setTeamId(rs.getInt("homeTeamId"));
|
|
|
|
|
+ awayTeam.setTeamId(rs.getInt("awayTeamId"));
|
|
|
|
|
+ homeTeam.setTeamName(rs.getString("homeTeamName"));
|
|
|
|
|
+ awayTeam.setTeamName(rs.getString("awayTeamName"));
|
|
|
|
|
+ homeTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
+ awayTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
+ homeTeam.setTeamLeague(rs.getString("leagueName"));
|
|
|
|
|
+ awayTeam.setTeamLeague(rs.getString("leagueName"));
|
|
|
|
|
+ homeTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
+ awayTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
+ homeTeam.setCountryName(rs.getString("countryName"));
|
|
|
|
|
+ awayTeam.setCountryName(rs.getString("countryName"));
|
|
|
|
|
+
|
|
|
|
|
+ sm.setAwayScore(rs.getInt("awayScore"));
|
|
|
|
|
+ sm.setHomeScore(rs.getInt("homeScore"));
|
|
|
|
|
+ sm.setHomeTeam(homeTeam);
|
|
|
|
|
+ sm.setAwayTeam(awayTeam);
|
|
|
|
|
+ sm.setMatchId(rs.getInt("id"));
|
|
|
|
|
+ sm.setOdds1(rs.getFloat("odds1"));
|
|
|
|
|
+ sm.setOddsX(rs.getFloat("oddsX"));
|
|
|
|
|
+ sm.setOdds2(rs.getFloat("odds2"));
|
|
|
|
|
+ sm.setGameDate(LocalDateTime.parse(rs.getString("gameDate")));
|
|
|
|
|
+ sm.setCountryPrio(rs.getBoolean("prio"));
|
|
|
|
|
+
|
|
|
|
|
+ matches.add(sm);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return matches;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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 && homeTeamId = ?";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ returnValue.add(rs.getFloat("avgScored"));
|
|
|
|
|
+ returnValue.add(rs.getFloat("avgConceded"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return returnValue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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 && awayTeamId = ?";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ returnValue.add(rs.getFloat("avgScored"));
|
|
|
|
|
+ returnValue.add(rs.getFloat("avgConceded"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return returnValue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<Float> getLeagueAvarages(int leagueId, int countryId) {
|
|
|
|
|
+ final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
|
|
+ final String sql = "SELECT AVG(homeScore) avgHomeScore, AVG(awayScore) as avgAwayScore"
|
|
|
|
|
+ + " FROM SoccerResults WHERE leagueId = ? AND countryId = ?";
|
|
|
|
|
+
|
|
|
|
|
+ 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 stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
|
|
+ stat.setInt(2, countryId);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ returnValue.add(rs.getFloat("avgHomeScore"));
|
|
|
|
|
+ returnValue.add(rs.getFloat("avgAwayScore"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ final PreparedStatement goalStmt = conn.prepareStatement(goalsSql);
|
|
|
|
|
+ goalStmt.setInt(1, leagueId);
|
|
|
|
|
+ goalStmt.setInt(2, countryId);
|
|
|
|
|
+ goalStmt.setString(3, getLastSeason(countryId, leagueId));
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet goalRs = goalStmt.executeQuery();
|
|
|
|
|
+ while (goalRs.next()) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return returnValue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<OverUnder> getStatsOverUnder(int leagueId) {
|
|
|
|
|
+
|
|
|
|
|
+ final DecimalFormat df = new DecimalFormat("##.##");
|
|
|
|
|
+ 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 && homeTeamId = SoccerResults.homeTeamId 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 && awayTeamId = SoccerResults.awayTeamId GROUP BY awayTeamId) as sAway ON SoccerResults.awayTeamId = sAway.awayTeamId "
|
|
|
|
|
+ + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? " + "ORDER BY diff ASC";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ 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 OverUnder entry = result.stream().filter(ou -> ou.getKey().compareTo(formatted) == 0).findFirst()
|
|
|
|
|
+ .orElse(new OverUnder(formatted));
|
|
|
|
|
+ entry.addGoalStat(numGoals);
|
|
|
|
|
+ result.add(entry);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public BigDecimal round(BigDecimal value, BigDecimal increment, RoundingMode roundingMode) {
|
|
|
|
|
+ if (increment.signum() == 0) {
|
|
|
|
|
+ // 0 increment does not make much sense, but prevent division by 0
|
|
|
|
|
+ return value;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ final BigDecimal divided = value.divide(increment, 0, roundingMode);
|
|
|
|
|
+ final BigDecimal result = divided.multiply(increment);
|
|
|
|
|
+ return result.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public BigDecimal getIncrement() {
|
|
|
|
|
+ return INCREMENT;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<TeamStanding> getLeagueTable(int leagueId, String season, int countryId) {
|
|
|
|
|
+ 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, leagueId as league, countryId as country FROM SoccerResults "
|
|
|
|
|
+ + "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";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+
|
|
|
|
|
+ stat.setString(1, season);
|
|
|
|
|
+ stat.setInt(2, leagueId);
|
|
|
|
|
+ stat.setInt(3, countryId);
|
|
|
|
|
+
|
|
|
|
|
+ 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("homeScore"), rs.getFloat("awayScore"),
|
|
|
|
|
+ rs.getFloat("goal_diff"));
|
|
|
|
|
+ result.add(ts);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ Log.getLog().info("Sql vid fel: %s", sql);
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public boolean getParsingStarted(int countryId, int leagueId) {
|
|
|
|
|
+ boolean returnValue = false;
|
|
|
|
|
+ final String sql = "SELECT parsedYear FROM League WHERE id = ? AND countryId = ?";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
|
|
+ stat.setInt(2, countryId);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final String parsedYear = rs.getString("parsedYear");
|
|
|
|
|
+ if (!Strings.isNullOrEmpty(parsedYear)) {
|
|
|
|
|
+ returnValue = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return returnValue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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";
|
|
|
|
|
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stmt.setInt(1, leagueId);
|
|
|
|
|
+ stmt.setInt(2, countryId);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stmt.executeQuery();
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ season = rs.getString("season");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return season;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public TeamResults getTeamResults(int teamId, int numResults, boolean isHomeTeam) {
|
|
|
|
|
+ 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";
|
|
|
|
|
+ } 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";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, teamId);
|
|
|
|
|
+ stat.setInt(2, numResults);
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final int draws = rs.getInt("draws");
|
|
|
|
|
+ final int wins = rs.getInt("wins");
|
|
|
|
|
+ final int lost = rs.getInt("lost");
|
|
|
|
|
+ tr.setDraws(draws);
|
|
|
|
|
+ tr.setWins(wins);
|
|
|
|
|
+ tr.setLosses(lost);
|
|
|
|
|
+ tr.setCount(wins + draws + lost);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return tr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public TeamResults getTeamResultsTest(int teamId, int numResults, boolean isHomeTeam, String date) {
|
|
|
|
|
+ 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";
|
|
|
|
|
+ } 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";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, teamId);
|
|
|
|
|
+ stat.setString(2, date);
|
|
|
|
|
+ stat.setInt(3, numResults);
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final int draws = rs.getInt("draws");
|
|
|
|
|
+ final int wins = rs.getInt("wins");
|
|
|
|
|
+ final int lost = rs.getInt("lost");
|
|
|
|
|
+ tr.setDraws(draws);
|
|
|
|
|
+ tr.setWins(wins);
|
|
|
|
|
+ tr.setLosses(lost);
|
|
|
|
|
+ tr.setCount(wins + draws + lost);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return tr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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 ArrayList<SimpleEntry<Integer, String>> result = new ArrayList<>();
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ if (date.equals("")) {
|
|
|
|
|
+ stat.setString(1, "DATE(NOW())");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ stat.setString(1, date);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ result.add(new SimpleEntry<>(rs.getInt("id"), rs.getString("name")));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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 sportId = ? AND countryId = ? AND DATE(gameDate) = ?)";
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, sportId);
|
|
|
|
|
+ stat.setInt(2, countryId);
|
|
|
|
|
+ stat.setString(3, date);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt("id"), rs.getString("name"));
|
|
|
|
|
+ leagues.add(entry);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return leagues;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<SoccerMatch> getMatches(int sportId, Integer countryId, Integer leagueId, String date, String order) {
|
|
|
|
|
+ final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
|
|
|
+ final String dateSql;
|
|
|
|
|
+ final String orderSql = " ORDER BY gameDate " + order;
|
|
|
|
|
+ if (date.equals("")) {
|
|
|
|
|
+ dateSql = "DATE(gameDate) = DATE(NOW()) ";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ 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.awayTeam = aTeam.id " + "WHERE " + dateSql + "AND res.leagueId = ? "
|
|
|
|
|
+ + "AND res.countryId = ? " + orderSql;
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
|
|
+ stat.setInt(2, countryId);
|
|
|
|
|
+
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ final SoccerMatch sm = new SoccerMatch();
|
|
|
|
|
+ final Team homeTeam = new Team();
|
|
|
|
|
+ final Team awayTeam = new Team();
|
|
|
|
|
+
|
|
|
|
|
+ homeTeam.setTeamId(rs.getInt("homeTeamId"));
|
|
|
|
|
+ awayTeam.setTeamId(rs.getInt("awayTeamId"));
|
|
|
|
|
+ homeTeam.setTeamName(rs.getString("homeTeamName"));
|
|
|
|
|
+ awayTeam.setTeamName(rs.getString("awayTeamName"));
|
|
|
|
|
+ homeTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
+ awayTeam.setTeamLeagueId(rs.getInt("leagueId"));
|
|
|
|
|
+ homeTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
+ awayTeam.setCountryId(rs.getInt("countryId"));
|
|
|
|
|
+
|
|
|
|
|
+ sm.setAwayScore(rs.getInt("awayScore"));
|
|
|
|
|
+ sm.setHomeScore(rs.getInt("homeScore"));
|
|
|
|
|
+ sm.setHomeTeam(homeTeam);
|
|
|
|
|
+ sm.setAwayTeam(awayTeam);
|
|
|
|
|
+ sm.setMatchId(rs.getInt("id"));
|
|
|
|
|
+ sm.setOdds1(rs.getFloat("odds1"));
|
|
|
|
|
+ sm.setOddsX(rs.getFloat("oddsX"));
|
|
|
|
|
+ sm.setOdds2(rs.getFloat("odds2"));
|
|
|
|
|
+ sm.setGameDate(LocalDateTime.parse(rs.getString("gameDate")));
|
|
|
|
|
+ sm.setSeason(rs.getString("season"));
|
|
|
|
|
+
|
|
|
|
|
+ matches.add(sm);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return matches;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public League getLeagueInfo(String teamLeague) {
|
|
|
|
|
+ final String sql = "SELECT * FROM League WHERE name = ?";
|
|
|
|
|
+ League result = null;
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setString(1, teamLeague);
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ result = new League(rs.getInt("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) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public League getLeagueInfo(int leagueId) {
|
|
|
|
|
+ final String sql = "SELECT * FROM League WHERE id = ?";
|
|
|
|
|
+ League result = null;
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, leagueId);
|
|
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
|
|
+
|
|
|
|
|
+ while (rs.next()) {
|
|
|
|
|
+ result = new League(rs.getInt("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) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setTeamMarginHome(int teamId, int marginHome) {
|
|
|
|
|
+ final String sql = "UPDATE Team SET marginHome = ? WHERE id = ?";
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, marginHome);
|
|
|
|
|
+ stat.setInt(2, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ stat.executeUpdate();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setTeamMarginDraw(int teamId, int marginDraw) {
|
|
|
|
|
+ final String sql = "UPDATE Team SET marginDraw = ? WHERE id = ?";
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, marginDraw);
|
|
|
|
|
+ stat.setInt(2, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ stat.executeUpdate();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setTeamMarginAway(int teamId, int marginAway) {
|
|
|
|
|
+ final String sql = "UPDATE Team SET marginAway = ? WHERE id = ?";
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, marginAway);
|
|
|
|
|
+ stat.setInt(2, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ stat.executeUpdate();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setTeamLookbackHome(int teamId, int lookbackHome) {
|
|
|
|
|
+ final String sql = "UPDATE Team SET lookbackHome = ? WHERE id = ?";
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, lookbackHome);
|
|
|
|
|
+ stat.setInt(2, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ stat.executeUpdate();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setTeamLookbackDraw(int teamId, int lookbackDraw) {
|
|
|
|
|
+ final String sql = "UPDATE Team SET lookbackDraw = ? WHERE id = ?";
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, lookbackDraw);
|
|
|
|
|
+ stat.setInt(2, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ stat.executeUpdate();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setTeamLookbackAway(int teamId, int lookbackAway) {
|
|
|
|
|
+ final String sql = "UPDATE Team SET lookbackAway = ? WHERE id = ?";
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
|
|
+ stat.setInt(1, lookbackAway);
|
|
|
|
|
+ stat.setInt(2, teamId);
|
|
|
|
|
+
|
|
|
|
|
+ stat.executeUpdate();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|