Ver Fonte

Uppdaterat parser

Axel Nordh há 2 anos atrás
pai
commit
918ebb5bc9

+ 2 - 2
Odds/src/main/Main.java

@@ -50,9 +50,9 @@ public class Main {
         final OddsPortal op = new OddsPortal();
 
         System.out.println("Getting One days ago matches");
-        op.getMatches(LocalDateTime.now().plusDays(-1));
+        //op.getMatches(LocalDateTime.now().plusDays(-1));
         System.out.println("Getting Today days ago matches");
-        op.getMatches(LocalDateTime.now().plusDays(0));
+        //op.getMatches(LocalDateTime.now().plusDays(0));
         System.out.println("Getting Tomorrows matches");
         op.getMatches(LocalDateTime.now().plusDays(1));
         System.out.println("Getting Next days matches");

+ 4 - 43
Odds/src/parser/OddsPortal.java

@@ -54,6 +54,7 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
         getMatchesByDateSelenium(dateFormatted);
         System.out.println(
                 "Done with date " + dateFormatted + " took " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");
+        stopwatch.stop();
     }
 
     private int getCountryId(List<WebElement> links) {
@@ -174,45 +175,6 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
 
                 setOdds(result, firstResultsDiv);
 
-                /*
-
-                if (subDivs.size() == 3) {
-                    WebElement competitionsDiv = subDivs.get(0);
-                    List<WebElement> links = competitionsDiv.findElements(By.xpath(".//a"));
-
-                    countryId = getCountryId(links);
-                    leagueId = getLeagueId(links);
-                    result.setLeagueId(leagueId);
-                    result.setCountryId(countryId);
-
-                    WebElement firstResultsDiv = subDivs.get(2);
-
-                    setGameDate(result, firstResultsDiv);
-
-                    setTeamsInfo(result, firstResultsDiv);
-
-                    setScoring(result, firstResultsDiv);
-
-                    setOdds(result, firstResultsDiv);
-
-                } else if (subDivs.size() == 1) {
-
-                    result.setLeagueId(leagueId);
-                    result.setCountryId(countryId);
-                    WebElement firstResultsDiv = subDivs.get(0);
-
-                    setGameDate(result, firstResultsDiv);
-                    setTeamsInfo(result, firstResultsDiv);
-
-                    setScoring(result, firstResultsDiv);
-
-                    setOdds(result, firstResultsDiv);
-                } else {
-                    somethingWrong = true;
-                    String message = "Subdiv size = " + subDivs.size();
-                    Logger.getGlobal().log(Level.WARNING, message);
-                }
-                 */
                 if (!somethingWrong) {
                     final Mysql mysql = Mysql.getInstance();
 
@@ -226,7 +188,6 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
                         mysql.addResults(resultsToInsert);
                         resultsToInsert.clear();
                     }
-
                 }
                 divs = driver
                         .findElements(By.xpath(DIV_CONTAINS_CLASS_TABS_DIV_NOT_CLASS_DIV_1_DIV));
@@ -247,13 +208,12 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
         Logger.getGlobal().log(Level.INFO, message);
         Mysql.getInstance().addResults(resultsToInsert);
         resultsToInsert.clear();
-        driver.close();
+
         driver.quit();
     }
 
     private void setGameDate(ResultDTO result, WebElement firstResultsDiv) {
         final List<Integer> time = new ArrayList<>();
-        //String datePath = "./div/div/div/div/div/p";
         String datePath = "./div/div/div//p";
         if (checkIfElementExists(firstResultsDiv, datePath)) {
             String timeText = firstResultsDiv.findElement(By.xpath(datePath)).getText();
@@ -291,7 +251,8 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
     }
 
     private void setScoring(ResultDTO result, WebElement firstResultsDiv) {
-        String resultPath = "./div/div/div[2]/div/div/div/div/div";
+        // String resultPath = "./div/div/div[2]/div/div/div/div/div";
+        String resultPath = "./div/div/div[1]/div[2]/div/div/div/div/div";
 
         if (checkIfElementExists(firstResultsDiv, resultPath)) {
             List<WebElement> scoringDivs = firstResultsDiv.findElements(By.xpath(resultPath));

+ 2 - 2
OddsJavaFx/src/controllers/AnalysisTestController.java

@@ -298,9 +298,9 @@ public class AnalysisTestController implements Initializable {
             int homeWinsCount = analysis.winLossRatio(leagueInfo.getWinLossRatio(), true);
             int awayWinsCount = analysis.winLossRatio(leagueInfo.getWinLossRatio(), false);
 
-            int homeWinLossRatioCount = analysis.winLossRationHomeAndAway(true,
+            int homeWinLossRatioCount = analysis.winLossRatioHomeAndAway(true,
                     leagueInfo.getWinLossRatioHomeAndAway());
-            int awayWinLossRatioCount = analysis.winLossRationHomeAndAway(false,
+            int awayWinLossRatioCount = analysis.winLossRatioHomeAndAway(false,
                     leagueInfo.getWinLossRatioHomeAndAway());
 
             int homeScoringTotal = analysis.scoringTotal(leagueInfo.getScoringTotal(), true);

+ 2 - 2
OddsJavaFx/src/controllers/PastResultsController.java

@@ -513,9 +513,9 @@ public class PastResultsController implements Initializable {
                 int homeWinsCount = analysis.winLossRatio(leagueInfo.getWinLossRatio(), true);
                 int awayWindCount = analysis.winLossRatio(leagueInfo.getWinLossRatio(), false);
 
-                int homeWinLossRatioCount = analysis.winLossRationHomeAndAway(true,
+                int homeWinLossRatioCount = analysis.winLossRatioHomeAndAway(true,
                         leagueInfo.getWinLossRatioHomeAndAway());
-                int awayWinLossRatioCount = analysis.winLossRationHomeAndAway(false,
+                int awayWinLossRatioCount = analysis.winLossRatioHomeAndAway(false,
                         leagueInfo.getWinLossRatioHomeAndAway());
 
                 int homeScoringTotal = analysis.scoringTotal(leagueInfo.getScoringTotal(), true);

+ 84 - 30
OddsJavaFx/src/controllers/StryktipsetController.java

@@ -10,6 +10,7 @@ import javafx.scene.control.*;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.util.Callback;
 import objects.League;
+import objects.Percentages;
 import objects.SoccerMatch;
 import objects.SoccerMatchAnalysis;
 import parser.Svenskaspel;
@@ -18,6 +19,7 @@ import java.math.RoundingMode;
 import java.net.URL;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
+import java.time.LocalDateTime;
 import java.util.*;
 
 @SuppressWarnings("rawtypes")
@@ -34,6 +36,7 @@ public class StryktipsetController implements Initializable {
     TableColumn<SoccerMatchAnalysis, Integer> scoringTotalColumn = new TableColumn<>("Scoring Total");
     TableColumn<SoccerMatchAnalysis, Integer> winCountColumn = new TableColumn<>("Win Count");
     TableColumn<SoccerMatchAnalysis, Integer> winLossRatioColumn = new TableColumn<>("Win/loss Ratio");
+    TableColumn<SoccerMatchAnalysis, Integer> percentagesColumn = new TableColumn<>("percentages");
     TableColumn<SoccerMatchAnalysis, Void> bet1Column = new TableColumn<>("1");
     TableColumn<SoccerMatchAnalysis, Void> betXColumn = new TableColumn<>("X");
     TableColumn<SoccerMatchAnalysis, Void> bet2Column = new TableColumn<>("2");
@@ -44,6 +47,8 @@ public class StryktipsetController implements Initializable {
     Button getMatchesButton;
     @FXML
     DatePicker date;
+    @FXML
+    Button calculateTestData;
 
     Map<String, League> leagueInfoMap = new HashMap<>();
 
@@ -69,42 +74,44 @@ public class StryktipsetController implements Initializable {
         scoringTotalColumn.setCellValueFactory(new PropertyValueFactory<>("scoringTotal"));
         winCountColumn.setCellValueFactory(new PropertyValueFactory<>("winCount"));
         winLossRatioColumn.setCellValueFactory(new PropertyValueFactory<>("winLossRatio"));
+        percentagesColumn.setCellValueFactory(new PropertyValueFactory<>("percentages"));
 
-        Callback<TableColumn<SoccerMatchAnalysis, Void>, TableCell<SoccerMatchAnalysis, Void>> cellFactory = new Callback<TableColumn<SoccerMatchAnalysis, Void>, TableCell<SoccerMatchAnalysis, Void>>() {
-            @Override
-            public TableCell<SoccerMatchAnalysis, Void> call(final TableColumn<SoccerMatchAnalysis, Void> param) {
-                return new TableCell<SoccerMatchAnalysis, Void>() {
-
-                    private final CheckBox checkbox = new CheckBox();
-
-                    {
-                        checkbox.setOnAction((ActionEvent event) -> {
-                            SoccerMatch data = getTableView().getItems().get(getIndex());
-
-                            addToBets(data);
-                        });
-                    }
-
+        Callback<TableColumn<SoccerMatchAnalysis, Void>, TableCell<SoccerMatchAnalysis, Void>> cellFactory =
+                new Callback<TableColumn<SoccerMatchAnalysis, Void>, TableCell<SoccerMatchAnalysis, Void>>() {
                     @Override
-                    public void updateItem(Void item, boolean empty) {
-                        super.updateItem(item, empty);
-                        if (empty) {
-                            setGraphic(null);
-                        } else {
-                            setGraphic(checkbox);
-                        }
+                    public TableCell<SoccerMatchAnalysis, Void> call(final TableColumn<SoccerMatchAnalysis, Void> param) {
+                        return new TableCell<SoccerMatchAnalysis, Void>() {
+
+                            private final CheckBox checkbox = new CheckBox();
+
+                            {
+                                checkbox.setOnAction((ActionEvent event) -> {
+                                    SoccerMatch data = getTableView().getItems().get(getIndex());
+
+                                    addToBets(data);
+                                });
+                            }
+
+                            @Override
+                            public void updateItem(Void item, boolean empty) {
+                                super.updateItem(item, empty);
+                                if (empty) {
+                                    setGraphic(null);
+                                } else {
+                                    setGraphic(checkbox);
+                                }
+                            }
+
+                        };
                     }
-
                 };
-            }
-        };
 
         bet1Column.setCellFactory(cellFactory);
         betXColumn.setCellFactory(cellFactory);
         bet2Column.setCellFactory(cellFactory);
 
         gameViewTable.getColumns().addAll(homeTeamNameColumn, awayTeamNameColumn, countryNameColumn, leagueNameColumn,
-                scoringDiffLastGamesColumn, scoringTotalColumn, winCountColumn, winLossRatioColumn,
+                scoringDiffLastGamesColumn, scoringTotalColumn, winCountColumn, winLossRatioColumn, percentagesColumn,
                 bet1Column, betXColumn, bet2Column);
         gameViewTable.setEditable(true);
     }
@@ -116,6 +123,31 @@ public class StryktipsetController implements Initializable {
     private void addMatchesToTable(List<SoccerMatchAnalysis> matches) {
         ObservableList<SoccerMatchAnalysis> currentMatches = FXCollections.<SoccerMatchAnalysis>observableArrayList();
 
+        GuiMysql db = GuiMysql.getInstance();
+        for (SoccerMatchAnalysis match : matches) {
+            League l = db.getLeagueInfo(match.getHomeTeam().getTeamLeagueId());
+            Percentages percentages = new Percentages();
+            int homeScore = match.scoringTotal(l.getScoringTotal(), true);
+            int awayScore = match.scoringTotal(l.getScoringTotal(), false);
+
+            db.getTotalGoalStat(percentages, l.getLeagueId(),l.getScoringTotal(),
+                    homeScore - awayScore);
+
+            db.getScoringDiffLastGames(percentages, l.getLeagueId(), l.getScoringDiffLastGame(),
+                    match.getScoringDiffLastGames(l.getScoringDiffLastGame()));
+
+            int winLossHAHome = match.winLossRatioHomeAndAway(true, l.getWinLossRatioHomeAndAway());
+            int winLossHAAway = match.winLossRatioHomeAndAway(false, l.getWinLossRatioHomeAndAway());
+            db.getWinLossRatioHomeAndAwayStatistics(percentages, l.getLeagueId(), l.getWinLossRatioHomeAndAway(),
+                    winLossHAHome-winLossHAAway);
+
+            int winLossHome = match.winLossRatio(l.getWinLossRatio(), true);
+            int winLossAway = match.winLossRatio(l.getWinLossRatio(), false);
+            match.winLossRatio(l.getWinLossRatio(), false);
+            db.getWinLossRatioStatisticsGames(percentages,l.getLeagueId(),l.getWinLossRatio(),winLossHome-winLossAway);
+
+            match.setPercentages(percentages.getCalculation());
+        }
         currentMatches.addAll(matches);
 
         gameViewTable.getItems().addAll(currentMatches);
@@ -137,10 +169,7 @@ public class StryktipsetController implements Initializable {
             match.setScoringDiffValue(match.getScoringDiffLastGames(info.getScoringDiffLastGame()));
             match.setScoringTotal(match.scoringTotal(info.getScoringTotal(), true) - match.scoringTotal(info.getScoringTotal(), false));
             match.setWinCount(match.winLossRatio(info.getWinLossRatio(), true) - match.winLossRatio(info.getWinLossRatio(), false));
-            match.setWinLossRatio(
-                    match.winLossRationHomeAndAway(true, info.getWinLossRatioHomeAndAway()) -
-                            match.winLossRationHomeAndAway(false, info.getWinLossRatioHomeAndAway())
-            );
+            match.setWinLossRatio(match.winLossRatioHomeAndAway(true, info.getWinLossRatioHomeAndAway()) - match.winLossRatioHomeAndAway(false, info.getWinLossRatioHomeAndAway()));
         }
 
         addMatchesToTable(matches);
@@ -155,4 +184,29 @@ public class StryktipsetController implements Initializable {
         return info;
     }
 
+    @FXML
+    private void calculateTestData() {
+
+        List<League> prioLeagues = GuiMysql.getInstance().getLeaguesWithPrio();
+
+        int i = 1;
+        for (League l : prioLeagues) {
+
+            System.out.println("Starting " + i++ + "/" + prioLeagues.size() + " " + LocalDateTime.now() + " with " +
+                    l.getLeagueName());
+/*            GuiMysql.getInstance().calculateWinLossRatioHomeAndAwayStat(l.getLeagueId(),
+                    l.getWinLossRatioHomeAndAway()); */
+GuiMysql.getInstance().addScoringDiffStatistics(l.getLeagueId(), l.getScoringDiffLastGame());
+/*
+                GuiMysql.getInstance().calculateWinLossRatioStat(l.getLeagueId(),
+                    l.getWinLossRatioHomeAndAway());
+                    */
+
+            /*
+            List<SoccerMatchAnalysis> matches = GuiMysql.getInstance().getSoccerMatchesWithGoalStats(l.getLeagueId(),
+                    LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE), l.getScoringTotal());
+            System.out.println("Finished " + LocalDateTime.now()+ " with " + l.getLeagueName());
+            */
+        }
+    }
 }

+ 130 - 0
OddsJavaFx/src/cronjob/updateStatistics.java

@@ -0,0 +1,130 @@
+package cronjob;
+
+import data.GuiMysql;
+import objects.*;
+
+import java.sql.*;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static objects.Constants.*;
+
+public class updateStatistics {
+    private static final String USERNAME = "OddsNy";
+    private static final String PASSWORD = "Odds1_Ny_Password";
+    private static final String DATABASE = "new_odds";
+    private static final String URL = "jdbc:mysql://nordh.xyz:3306/";
+    private static final String TIMEZONE_FIX = "?useUnicode=true&useJDBCCompliantTimezoneShift=true" +
+            "&useLegacyDatetimeCode=false&serverTimezone=UTC";
+    Connection conn;
+
+    List<League> leagues = new ArrayList<>();
+
+    public updateStatistics() {
+        GuiMysql db = GuiMysql.getInstance();
+        leagues.addAll(db.getLeaguesWithPrio());
+        List<SoccerMatchAnalysis> matchesToUpdate = getMatchesToUpdate(getLastUpdatedStatisticsDate());
+
+        System.out.println("Matches to update " + matchesToUpdate.size());
+        for (SoccerMatchAnalysis match : matchesToUpdate) {
+            Optional<League> ol = leagues.stream().filter(f -> f.getLeagueName() == match.getLeagueName()).findFirst();
+            League l;
+            if (ol.isPresent()) {
+                l = ol.get();
+            } else {
+                System.out.println("League " + match.getLeagueName() + " not found in leagues");
+                continue;
+            }
+            int homeTeamRes = match.scoringTotal(l.getScoringTotal(), true);
+            int awayTeamRes = match.scoringTotal(l.getScoringTotal(), false);
+            int diff = homeTeamRes - awayTeamRes;
+            db.addTotalGoalStat(match,l.getScoringTotal(), l.getLeagueId(), diff);
+
+            homeTeamRes = match.winLossRatio(l.getWinLossRatio(), true);
+            awayTeamRes = match.winLossRatio(l.getScoringTotal(), false);
+            diff = homeTeamRes - awayTeamRes;
+            db.addWinLossRatioStat(match,l.getLeagueId(),l.getScoringTotal(), diff);
+
+            homeTeamRes = match.winLossRatioHomeAndAway(true, l.getWinLossRatioHomeAndAway());
+            awayTeamRes = match.winLossRatioHomeAndAway(false, l.getWinLossRatioHomeAndAway());
+            diff = homeTeamRes - awayTeamRes;
+            db.addWinLossRatioHomeAndAwayStat(match, l.getLeagueId(), l.getWinLossRatioHomeAndAway(), diff);
+
+            diff = match.getScoringDiffLastGames(l.getScoringDiffLastGame());
+            db.addScoringDiffLastGamesStatistics(match,l.getLeagueId(), l.getScoringDiffLastGame(), diff);
+        }
+
+        updateLastStatsRun(LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
+    }
+
+    private void updateLastStatsRun(String date) {
+        String sql = "UPDATE Settings SET value = ? WHERE name = 'statisticsUpdated'";
+        try (PreparedStatement stat = getConnection().prepareStatement(sql)) {
+            stat.setString(1, date);
+            stat.executeUpdate();
+        }catch (SQLException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void main(String[] args) {
+        new updateStatistics();
+    }
+
+    private List<SoccerMatchAnalysis> getMatchesToUpdate(String lastUpdatedStatisticsDate) {
+        String sql = "SELECT * FROM SoccerResults WHERE prio = 1 AND DATE(gameDate) > ?";
+        List<SoccerMatchAnalysis> result = new ArrayList<>();
+        try (PreparedStatement stat = getConnection().prepareStatement(sql)) {
+            stat.setString(1, lastUpdatedStatisticsDate);
+
+            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)));
+            }
+
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+    public String getLastUpdatedStatisticsDate() {
+        String sql = "SELECT value FROM Settings WHERE name = 'statisticsUpdated'";
+        String result = "1970-01-01";
+
+        try (PreparedStatement stat = getConnection().prepareStatement(sql)) {
+            ResultSet rs = stat.executeQuery();
+
+            while (rs.next()) {
+                result = rs.getString("value");
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+
+    protected Connection getConnection() {
+        if (conn == null) {
+            try {
+                conn = DriverManager.getConnection(URL + DATABASE + TIMEZONE_FIX, USERNAME, PASSWORD);
+            } catch (final SQLException e) {
+                throw new RuntimeException(e.getMessage(), e);
+            }
+        }
+        return conn;
+    }
+
+}

+ 549 - 188
OddsJavaFx/src/data/GuiMysql.java

@@ -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();
+        }
+    }
 }

+ 6 - 0
OddsJavaFx/src/fxml/Stryktipset.fxml

@@ -6,6 +6,7 @@
 <?import javafx.scene.control.TableView?>
 <?import javafx.scene.layout.AnchorPane?>
 <?import javafx.scene.layout.FlowPane?>
+<?import javafx.scene.layout.Pane?>
 <?import javafx.scene.layout.VBox?>
 
 <AnchorPane xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.StryktipsetController">
@@ -27,6 +28,11 @@
                   </AnchorPane>
               </items>
             </SplitPane>
+            <Pane prefHeight="200.0" prefWidth="200.0">
+               <children>
+                  <Button mnemonicParsing="false" onAction="#calculateTestData" text="TestButton" />
+               </children>
+            </Pane>
          </children>
       </VBox>
    </children>

+ 134 - 0
OddsJavaFx/src/objects/Percentages.java

@@ -0,0 +1,134 @@
+package objects;
+
+public class Percentages {
+
+    private int scoringDiffHomeWin = 0;
+    private int scoringDiffDraw = 0;
+    private int scoringDiffAwayWin = 0;
+    private int totalGoalsHomeWin = 0;
+    private int totalGoalsDraw = 0;
+    private int totalGoalsAwayWin = 0;
+    private int winLossRatioHomeAndAwayHomeWin = 0;
+    private int winLossRatioHomeAndAwayDraw = 0;
+    private int winLossRatioHomeAndAwayAwayWin = 0;
+    private int winLossRatioHomeWin = 0;
+    private int winLossRatioDraw = 0;
+    private int winLossRatioAwayWin = 0;
+
+    public int getTotalGoalsHomeWin() {
+        return totalGoalsHomeWin;
+    }
+
+    public void setTotalGoalsHomeWin(int totalGoalsHomeWin) {
+        this.totalGoalsHomeWin = totalGoalsHomeWin;
+    }
+
+    public int getTotalGoalsDraw() {
+        return totalGoalsDraw;
+    }
+
+    public void setTotalGoalsDraw(int totalGoalsDraw) {
+        this.totalGoalsDraw = totalGoalsDraw;
+    }
+
+    public int getWinLossRatioHomeAndAwayHomeWin() {
+        return winLossRatioHomeAndAwayHomeWin;
+    }
+
+    public void setWinLossRatioHomeAndAwayHomeWin(int winLossRatioHomeAndAwayHomeWin) {
+        this.winLossRatioHomeAndAwayHomeWin = winLossRatioHomeAndAwayHomeWin;
+    }
+
+    public int getWinLossRatioHomeAndAwayDraw() {
+        return winLossRatioHomeAndAwayDraw;
+    }
+
+    public void setWinLossRatioHomeAndAwayDraw(int winLossRatioHomeAndAwayDraw) {
+        this.winLossRatioHomeAndAwayDraw = winLossRatioHomeAndAwayDraw;
+    }
+
+    public int getWinLossRatioHomeAndAwayAwayWin() {
+        return winLossRatioHomeAndAwayAwayWin;
+    }
+
+    public void setWinLossRatioHomeAndAwayAwayWin(int winLossRatioHomeAndAwayAwayWin) {
+        this.winLossRatioHomeAndAwayAwayWin = winLossRatioHomeAndAwayAwayWin;
+    }
+
+    public int getWinLossRatioHomeWin() {
+        return winLossRatioHomeWin;
+    }
+
+    public void setWinLossRatioHomeWin(int winLossRatioHomeWin) {
+        this.winLossRatioHomeWin = winLossRatioHomeWin;
+    }
+
+    public int getWinLossRatioDraw() {
+        return winLossRatioDraw;
+    }
+
+    public void setWinLossRatioDraw(int winLossRatioDraw) {
+        this.winLossRatioDraw = winLossRatioDraw;
+    }
+
+    public int getWinLossRatioAwayWin() {
+        return winLossRatioAwayWin;
+    }
+
+    public void setWinLossRatioAwayWin(int winLossRatioAwayWin) {
+        this.winLossRatioAwayWin = winLossRatioAwayWin;
+    }
+
+    public int getTotalGoalsAwayWin() {
+        return totalGoalsAwayWin;
+    }
+
+    public void setTotalGoalsAwayWin(int totalGoalsAwayWin) {
+        this.totalGoalsAwayWin = totalGoalsAwayWin;
+    }
+
+    public int getScoringDiffHomeWin() {
+        return scoringDiffHomeWin;
+    }
+
+    public void setScoringDiffHomeWin(int homeWin) {
+        scoringDiffHomeWin = homeWin;
+    }
+
+    public int getScoringDiffDraw() {
+        return scoringDiffDraw;
+    }
+
+    public void setScoringDiffDraw(int draws) {
+        scoringDiffDraw = draws;
+    }
+
+    public int getScoringDiffAwayWin() {
+        return scoringDiffAwayWin;
+    }
+
+    public void setScoringDiffAwayWin(int awayWin) {
+        scoringDiffAwayWin = awayWin;
+    }
+
+    public String getCalculation() {
+        int homeWinValues = scoringDiffHomeWin > 0 ? 1 : 0 + totalGoalsHomeWin > 0 ? 1 : 0 + winLossRatioHomeWin > 0
+                ? 1 : 0 + winLossRatioHomeAndAwayHomeWin > 0 ? 1 : 0;
+        int drawWinValues = scoringDiffDraw > 0 ? 1 : 0 + totalGoalsDraw > 0 ? 1 : 0 + winLossRatioDraw > 0 ? 1 :
+                0 + winLossRatioHomeAndAwayDraw > 0 ? 1 : 0;
+        int awayWinValues = scoringDiffAwayWin > 0 ? 1 : 0 + totalGoalsAwayWin > 0 ? 1 : 0 + winLossRatioAwayWin > 0
+                ? 1 : 0 + winLossRatioHomeAndAwayAwayWin > 0 ? 1 : 0;
+
+        float homeWin =
+                (scoringDiffHomeWin + totalGoalsHomeWin + winLossRatioHomeWin + winLossRatioHomeAndAwayHomeWin) / (float) homeWinValues;
+        float draws =
+                (scoringDiffDraw + totalGoalsDraw + winLossRatioDraw + winLossRatioHomeAndAwayDraw) / (float) drawWinValues;
+        float awayWin =
+                (scoringDiffAwayWin + totalGoalsAwayWin + winLossRatioAwayWin + winLossRatioHomeAndAwayAwayWin) / (float) awayWinValues;
+
+        float sum = homeWin + draws + awayWin;
+
+
+        return "(" + homeWin/sum + "%, " + draws/sum + "%, " + awayWin/sum + "%)";
+    }
+}

+ 21 - 2
OddsJavaFx/src/objects/SoccerMatchAnalysis.java

@@ -19,6 +19,9 @@ public class SoccerMatchAnalysis extends SoccerMatch {
     private int scoringTotal;
     private int winCount;
     private int winLossRatio;
+    private String percentages;
+
+    private int scoringTotalValue;
 
     public SoccerMatchAnalysis(SoccerMatch match) {
         setMatchData(match);
@@ -29,6 +32,14 @@ public class SoccerMatchAnalysis extends SoccerMatch {
         return winLossRatio;
     }
 
+    public String getPercentages() {
+        return percentages;
+    }
+
+    public void setPercentages(String value){
+        percentages = value;
+    }
+
     public void setWinLossRatio(int winLossRatio) {
         this.winLossRatio = winLossRatio;
     }
@@ -108,7 +119,7 @@ public class SoccerMatchAnalysis extends SoccerMatch {
 
     /**
      * Plocka fram antalet mål som ett specifikt lag gjort under de senaste
-     * <gamesLookback> matcherna
+     * gamesLookback matcherna
      *
      * @param gamesLookback - hur många matcher bakåt i tiden som ska kontrolleras
      * @param homeTeam      - är det hemma laget som ska kontrolleras i matchen
@@ -253,7 +264,7 @@ public class SoccerMatchAnalysis extends SoccerMatch {
         return result;
     }
 
-    public int winLossRationHomeAndAway(boolean homeTeam, int gamesLookback) {
+    public int winLossRatioHomeAndAway(boolean homeTeam, int gamesLookback) {
         int result = 0;
 
         String sql = "SELECT * FROM " + "(SELECT * FROM SoccerResults WHERE homeTeamId = ? AND leagueId = ? AND DATE" +
@@ -352,4 +363,12 @@ public class SoccerMatchAnalysis extends SoccerMatch {
         }
         return result;
     }
+
+    public int getScoringTotalValue() {
+        return scoringTotalValue;
+    }
+
+    public void setScoringTotalValue(int value) {
+        scoringTotalValue = value;
+    }
 }

+ 2 - 2
OddsJavaFx/src/parser/Svenskaspel.java

@@ -56,8 +56,8 @@ public class Svenskaspel {
         for (WebElement match : matches) {
             List<String> teamNames = GetNames(match);
             soccerMatches.add(GuiMysql.getInstance().getMatch(date,
-                    teamNames.get(0).trim().replace(" ", "%"),
-                    teamNames.get(1).trim().replace(" ", "%")));
+                    teamNames.get(0).trim().replace(" ", "%") + "%",
+                    teamNames.get(1).trim().replace(" ", "%") + "%"));
         }
 
         for (SoccerMatch match : soccerMatches) {

+ 3 - 3
OddsJavaFx/src/tests/AnalysisBettDrawTester.java

@@ -143,9 +143,9 @@ public class AnalysisBettDrawTester extends TestClass {
             int awayTotalGoalsHomeAway = analysis.goalsScoredHomeAndAway(false, leagueInfo.getDrawDiffHomeAway());
             int totalGoalsHomeAwayDecider = homeTotalGoalsHomeAway - awayTotalGoalsHomeAway;
 
-            int homeFormHomeAndAway = analysis.winLossRationHomeAndAway(true,
+            int homeFormHomeAndAway = analysis.winLossRatioHomeAndAway(true,
                     leagueInfo.getDrawWinningFormHomeAway());
-            int awayFormHomeAndAway = analysis.winLossRationHomeAndAway(false,
+            int awayFormHomeAndAway = analysis.winLossRatioHomeAndAway(false,
                     leagueInfo.getDrawWinningFormHomeAway());
             int formHomeAwayDecider = homeFormHomeAndAway - awayFormHomeAndAway;
 
@@ -250,7 +250,7 @@ public class AnalysisBettDrawTester extends TestClass {
             betsList.add(bet);
             placedBets.put(soccerMatch.decider, betsList);
 
-            // För att täcka upp föregående bets
+            // F�r att t�cka upp f�reg�ende bets
 
 //            float currentBetAmount = 0;
 ////            betSeries.sort((b1, b2) -> Float.compare(b2.getBetAmount(), b1.getBetAmount()));

+ 2 - 2
OddsJavaFx/src/tests/AnalysisBettTester.java

@@ -76,9 +76,9 @@ public class AnalysisBettTester extends TestClass {
             int homeWinsCount = analysis.winLossRatio(leagueInfo.getWinLossRatio(), true);
             int awayWinsCount = analysis.winLossRatio(leagueInfo.getWinLossRatio(), false);
 
-            int homeWinLossRatioCount = analysis.winLossRationHomeAndAway(true,
+            int homeWinLossRatioCount = analysis.winLossRatioHomeAndAway(true,
                     leagueInfo.getWinLossRatioHomeAndAway());
-            int awayWinLossRatioCount = analysis.winLossRationHomeAndAway(false,
+            int awayWinLossRatioCount = analysis.winLossRatioHomeAndAway(false,
                     leagueInfo.getWinLossRatioHomeAndAway());
 
             int homeScoringTotal = analysis.scoringTotal(leagueInfo.getScoringTotal(), true);

+ 4 - 4
OddsJavaFx/src/tests/RelevanceTest.java

@@ -223,8 +223,8 @@ public class RelevanceTest extends TestClass {
 
         for (SoccerMatch soccerMatch : matches) {
             SoccerMatchAnalysis analysis = new SoccerMatchAnalysis(soccerMatch);
-            int homeWinsCount = analysis.winLossRationHomeAndAway(true, gamesLookback);
-            int awayWinsCount = analysis.winLossRationHomeAndAway(false, gamesLookback);
+            int homeWinsCount = analysis.winLossRatioHomeAndAway(true, gamesLookback);
+            int awayWinsCount = analysis.winLossRatioHomeAndAway(false, gamesLookback);
 
             int diff = homeWinsCount - awayWinsCount;
 
@@ -282,8 +282,8 @@ public class RelevanceTest extends TestClass {
             int homeWinsCount = analysis.winLossRatio(winLossRatio, true);
             int awayWindCount = analysis.winLossRatio(winLossRatio, false);
 
-            int homeWinLossRatioCount = analysis.winLossRationHomeAndAway(true, winLossRationHomeAndAway);
-            int awayWinLossRatioCount = analysis.winLossRationHomeAndAway(false, winLossRationHomeAndAway);
+            int homeWinLossRatioCount = analysis.winLossRatioHomeAndAway(true, winLossRationHomeAndAway);
+            int awayWinLossRatioCount = analysis.winLossRatioHomeAndAway(false, winLossRationHomeAndAway);
 
             int homeScoringTotal = analysis.scoringTotal(scoringTotal, true);
             int awayScoringTotal = analysis.scoringTotal(scoringTotal, false);