Sfoglia il codice sorgente

Margin and lookback unique for home and away

Axel Nordh 4 anni fa
parent
commit
826e7e5f51

+ 72 - 9
OddsJavaFx/src/controllers/TestsController.java

@@ -23,8 +23,13 @@ import javafx.scene.control.ScrollPane;
 import javafx.scene.control.TextField;
 import javafx.scene.control.TextField;
 import javafx.scene.layout.AnchorPane;
 import javafx.scene.layout.AnchorPane;
 import parser.OddsPortal;
 import parser.OddsPortal;
+import tests.AwayTests;
+import tests.DrawTests;
+import tests.HomeDrawAwayTest;
+import tests.HomeTests;
 import tests.LastResultsTest;
 import tests.LastResultsTest;
 import tests.PrioCountriesAll;
 import tests.PrioCountriesAll;
+import tests.TestClass;
 
 
 public class TestsController implements Initializable {
 public class TestsController implements Initializable {
 
 
@@ -44,6 +49,10 @@ public class TestsController implements Initializable {
 	@FXML Button getLeagueInfoButton;
 	@FXML Button getLeagueInfoButton;
 	@FXML Button getMoreLeagueInfoButton;
 	@FXML Button getMoreLeagueInfoButton;
 	@FXML Button topLeaguesTest;
 	@FXML Button topLeaguesTest;
+	@FXML Button homeTest;
+	@FXML Button drawTest;
+	@FXML Button awayTest;
+	@FXML Button homeDrawAwayTest;
 
 
 
 
 	ObservableList<String> countries = FXCollections.observableArrayList();
 	ObservableList<String> countries = FXCollections.observableArrayList();
@@ -162,19 +171,37 @@ public class TestsController implements Initializable {
 		//		testSettingsPanel.setVisible(false);
 		//		testSettingsPanel.setVisible(false);
 		//		testResultsPanel.setVisible(true);
 		//		testResultsPanel.setVisible(true);
 
 
-		String betLevel = Strings.isNullOrEmpty(bettingLevel.getText())?bettingLevel.getPromptText():bettingLevel.getText();
-		String betM = Strings.isNullOrEmpty(betMargin.getText())?betMargin.getPromptText():betMargin.getText();
-		final String startBank = Strings.isNullOrEmpty(startingBank.getText())?startingBank.getPromptText():startingBank.getText();
-		final String lookBackVal = Strings.isNullOrEmpty(lookBack.getText())?lookBack.getPromptText():lookBack.getText();
-
+		final String betLevel = getBetLevel();
+		final String betM = getBetMargin();
+		final String startBank = getStartingBank();
+		final String lookBackVal = getLookback();
 
 
-		betLevel = betLevel.replace("%", "").trim();
-		betM = betM.replace("%","").trim();
 
 
-		final LastResultsTest test = new LastResultsTest();
+		final TestClass test = new LastResultsTest();
 		System.out.println("Running tests");
 		System.out.println("Running tests");
-		test.run(date.getValue().toString(), Float.valueOf(startBank), Float.valueOf(betLevel), Float.valueOf(betM),
+		test.setup(date.getValue().toString(), Float.valueOf(startBank), Float.valueOf(betLevel), Float.valueOf(betM),
 				Integer.valueOf(lookBackVal), mSportId, getCountryIdFromSelector(), getLeagueIdFromSelector());
 				Integer.valueOf(lookBackVal), mSportId, getCountryIdFromSelector(), getLeagueIdFromSelector());
+		test.runTest();
+	}
+
+	private String getLookback() {
+		return Strings.isNullOrEmpty(lookBack.getText())?lookBack.getPromptText():lookBack.getText();
+	}
+
+	private String getStartingBank() {
+		return Strings.isNullOrEmpty(startingBank.getText())?startingBank.getPromptText():startingBank.getText();
+	}
+
+	private String getBetMargin() {
+		String betM= Strings.isNullOrEmpty(betMargin.getText())?betMargin.getPromptText():betMargin.getText();
+		betM= betM.replace("%","").trim();
+		return betM;
+	}
+
+	private String getBetLevel() {
+		String betLevel = Strings.isNullOrEmpty(bettingLevel.getText())?bettingLevel.getPromptText():bettingLevel.getText();
+		betLevel = betLevel.replace("%", "").trim();
+		return betLevel;
 	}
 	}
 
 
 	@FXML
 	@FXML
@@ -231,4 +258,40 @@ public class TestsController implements Initializable {
 		final PrioCountriesAll prioCountriesAll = new PrioCountriesAll();
 		final PrioCountriesAll prioCountriesAll = new PrioCountriesAll();
 		prioCountriesAll.runTest();
 		prioCountriesAll.runTest();
 	}
 	}
+
+	@FXML
+	private void homeTestAction() {
+		final HomeTests test = new HomeTests();
+
+		test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()), Integer.valueOf(getLookback()), 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
+
+		test.runTest();
+	}
+
+	@FXML
+	private void drawTestAction() {
+		final DrawTests test = new DrawTests();
+
+		test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()), Integer.valueOf(getLookback()), 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
+
+		test.runTest();
+	}
+
+	@FXML
+	private void awayTestAction() {
+		final AwayTests test = new AwayTests();
+
+		test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()), Integer.valueOf(getLookback()), 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
+
+		test.runTest();
+	}
+
+	@FXML
+	private void homeDrawAwayTestAction() {
+		final HomeDrawAwayTest test = new HomeDrawAwayTest();
+
+		test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()), Integer.valueOf(getLookback()), 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
+
+		test.runTest();
+	}
 }
 }

+ 67 - 1
OddsJavaFx/src/data/GuiMysql.java

@@ -421,6 +421,50 @@ public class GuiMysql extends Mysql {
 		return tr;
 		return tr;
 	}
 	}
 
 
+	public TeamResults getTeamResultsTest(int teamId, int numResults, boolean isHomeTeam, String date) {
+		final String sql;
+		final TeamResults tr = new TeamResults();
+		if (isHomeTeam) {
+			sql = "SELECT count(case when homeScore > awayScore then 1 end) wins, " +
+					"count(case when awayScore > homeScore then 1 end) lost, " +
+					"count(case when homeScore = awayScore then 1 end) draws " +
+					"FROM (SELECT * FROM SoccerResults WHERE homeTeam = ? 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 awayTeam = ? AND " +
+					"HomeScore >= 0 AND awayScore >= 0 AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) as t";
+		}
+
+		try {
+			final PreparedStatement stat = conn.prepareStatement(sql);
+			stat.setInt(1, teamId);
+			stat.setString(2, date);
+			stat.setInt(3, numResults);
+			final ResultSet rs = stat.executeQuery();
+
+			while (rs.next()) {
+				final int draws = rs.getInt("draws");
+				final int wins = rs.getInt("wins");
+				final int lost = rs.getInt("lost");
+				tr.setDraws(draws);
+				tr.setWins(wins);
+				tr.setLosses(lost);
+				tr.setCount(wins+draws+lost);
+			}
+
+			stat.close();
+		} catch (final SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		return tr;
+	}
+
+
 	public ArrayList<SimpleEntry<Integer, String>> getCountriesBySport(int sportId, String date) {
 	public ArrayList<SimpleEntry<Integer, String>> getCountriesBySport(int sportId, String date) {
 		final String sql = "SELECT * FROM Country WHERE id IN (SELECT DISTINCT(countryId) FROM SoccerResults WHERE DATE(gameDate) = ?) ORDER BY prio DESC, name ASC";
 		final 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<>();
 		final ArrayList<SimpleEntry<Integer, String>> result = new ArrayList<>();
@@ -538,7 +582,29 @@ public class GuiMysql extends Mysql {
 			final ResultSet rs = stat.executeQuery();
 			final ResultSet rs = stat.executeQuery();
 
 
 			while (rs.next()) {
 			while (rs.next()) {
-				result = new League(rs.getInt("id"), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin"));
+				result = new League(rs.getInt("id"), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin"),
+						rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"), rs.getInt("lookbackAway"),
+						rs.getInt("betMarginHome"), rs.getInt("betMarginDraw"), rs.getInt("betMarginAway"));
+			}
+		} catch (final SQLException e) {
+			e.printStackTrace();
+		}
+
+		return result;
+	}
+
+	public League getLeagueInfo(int leagueId) {
+		final String sql = "SELECT * FROM League WHERE id = ?";
+		League result = null;
+		try {
+			final PreparedStatement stat = getConnection().prepareStatement(sql);
+			stat.setInt(1, leagueId);
+			final ResultSet rs = stat.executeQuery();
+
+			while (rs.next()) {
+				result = new League(rs.getInt("id"), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin"),
+						rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"), rs.getInt("lookbackAway"),
+						rs.getInt("betMarginHome"), rs.getInt("betMarginDraw"), rs.getInt("betMarginAway"));
 			}
 			}
 		} catch (final SQLException e) {
 		} catch (final SQLException e) {
 			e.printStackTrace();
 			e.printStackTrace();

+ 4 - 0
OddsJavaFx/src/fxml/Testing.fxml

@@ -55,6 +55,10 @@
                                     <TextField fx:id="betMargin" promptText="5%" />
                                     <TextField fx:id="betMargin" promptText="5%" />
                                     <Button fx:id="calcBestValues" onAction="#calcBestResultsAction" text="Calc Best values"/>
                                     <Button fx:id="calcBestValues" onAction="#calcBestResultsAction" text="Calc Best values"/>
                                     <Button fx:id="topLeaguesTest" onAction="#topLeaguesTestAction" text="Top Leagues Test"/>
                                     <Button fx:id="topLeaguesTest" onAction="#topLeaguesTestAction" text="Top Leagues Test"/>
+                                    <Button fx:id="homeTest" onAction="#homeTestAction" text="Home Test"/>
+                                    <Button fx:id="drawTest" onAction="#drawTestAction" text="Draw Test"/>
+                                    <Button fx:id="awayTest" onAction="#awayTestAction" text="Away Test"/>
+                                    <Button fx:id="homeDrawAwayTest" onAction="#homeDrawAwayTestAction" text="Combined 1X2 Test"/>
                                  </children>
                                  </children>
                               </VBox>
                               </VBox>
                            </children>
                            </children>

+ 79 - 1
OddsJavaFx/src/objects/League.java

@@ -7,14 +7,32 @@ public class League {
 	int lookback;
 	int lookback;
 	int betMargin;
 	int betMargin;
 
 
-	public League(int leagueId, String leagueName, int lookback, int betMargin) {
+	int lookbackHome;
+	int lookbackDraw;
+	int lookbackAway;
+
+	int betMarginHome;
+	int betMarginDraw;
+	int betMarginAway;
+
+	public League(int leagueId, String leagueName, int lookback, int betMargin, int lookbackHome, int lookbackDraw, int lookbackAway,
+			int betMarginHome, int betMarginDraw, int betMarginAway) {
 		this.leagueId = leagueId;
 		this.leagueId = leagueId;
 		this.leagueName = leagueName;
 		this.leagueName = leagueName;
 		this.lookback = lookback;
 		this.lookback = lookback;
 		this.betMargin = betMargin;
 		this.betMargin = betMargin;
+		this.lookbackHome = lookbackHome;
+		this.lookbackDraw = lookbackDraw;
+		this.lookbackAway = lookbackAway;
+		this.betMarginHome = betMarginHome;
+		this.betMarginDraw = betMarginDraw;
+		this.betMarginAway = betMarginAway;
 	}
 	}
 
 
 
 
+	public League() {}
+
+
 	public int getLeagueId() {
 	public int getLeagueId() {
 		return leagueId;
 		return leagueId;
 	}
 	}
@@ -40,4 +58,64 @@ public class League {
 		this.betMargin = betMargin;
 		this.betMargin = betMargin;
 	}
 	}
 
 
+
+	public int getLookbackHome() {
+		return lookbackHome;
+	}
+
+
+	public int getLookbackDraw() {
+		return lookbackDraw;
+	}
+
+
+	public int getLookbackAway() {
+		return lookbackAway;
+	}
+
+
+	public int getBetMarginHome() {
+		return betMarginHome;
+	}
+
+
+	public int getBetMarginDraw() {
+		return betMarginDraw;
+	}
+
+
+	public int getBetMarginAway() {
+		return betMarginAway;
+	}
+
+
+	public void setLookbackHome(int lookbackHome) {
+		this.lookbackHome = lookbackHome;
+	}
+
+
+	public void setLookbackDraw(int lookbackDraw) {
+		this.lookbackDraw = lookbackDraw;
+	}
+
+
+	public void setLookbackAway(int lookbackAway) {
+		this.lookbackAway = lookbackAway;
+	}
+
+
+	public void setBetMarginHome(int betMarginHome) {
+		this.betMarginHome = betMarginHome;
+	}
+
+
+	public void setBetMarginDraw(int betMarginDraw) {
+		this.betMarginDraw = betMarginDraw;
+	}
+
+
+	public void setBetMarginAway(int betMarginAway) {
+		this.betMarginAway = betMarginAway;
+	}
+
 }
 }

+ 119 - 0
OddsJavaFx/src/tests/AwayTests.java

@@ -0,0 +1,119 @@
+package tests;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+
+import data.GuiMysql;
+import objects.League;
+import objects.SoccerMatch;
+import objects.TeamResults;
+
+public class AwayTests extends TestClass {
+
+	private League leagueInfo;
+
+
+	@Override
+	public void setup(String date, float startingBank, float bettingLevel, Float betMargin, int lookBack, int sportId,
+			Integer countryId, Integer leagueId) {
+		super.setup(date, startingBank, bettingLevel, betMargin, lookBack, sportId, countryId, leagueId);
+
+		leagueInfo = getLeagueInfoById();
+	}
+
+	@Override
+	public void runTest() {
+		final ArrayList<SoccerMatch> matches = getMatches();
+
+		final float betLevel = bettingLevel / 100f;
+
+		final LocalDateTime currentDate = matches.get(0).getGameDate();
+		LocalDate localDate = currentDate.toLocalDate();
+		float betAmount = startingBank * betLevel;
+
+		int betOnGameCount = 0;
+		int wins = 0;
+
+		float bestBankResult = startingBank;
+		int bestBetMargin = 0;
+		int bestLookBack = 0;
+
+		for (int lookBack = 1; lookBack < 25; lookBack++) {
+			for (int betMargin = 1; betMargin < 35; betMargin++) {
+				final float betMarginDecimal = 1 + (betMargin / (float)100);
+				float bank = startingBank;
+				betOnGameCount = 0;
+				wins = 0;
+				for (final SoccerMatch match : matches) {
+					if (match.getHomeScore() < 0 || match.getAwayScore() < 0) {
+						continue;
+					}
+
+					final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(match.getHomeTeam().getTeamId(), lookBack, true, match.getGameDate().format(DateTimeFormatter.ISO_DATE));
+					final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(match.getAwayTeam().getTeamId(), lookBack, false, match.getGameDate().format(DateTimeFormatter.ISO_DATE));
+
+					final float awayWinPercent = (homeTeamResults.getLosses() + awayTeamResults.getWins()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
+
+					final float awayOdds = 100 / awayWinPercent;
+
+					if (localDate.isBefore(match.getGameDate().toLocalDate())) {
+						betAmount = bank * betLevel;
+						localDate = match.getGameDate().toLocalDate();
+					}
+
+					if (awayOdds * betMarginDecimal <= match.getOdds2()) {
+						betOnGameCount++;
+						bank = bank - betAmount;
+						if (match.getAwayScore() > match.getHomeScore()) {
+							wins++;
+							bank = bank + betAmount * match.getOdds2();
+						}
+					}
+
+				}
+				if (bestBankResult < bank) {
+					System.out.println("New best bank " + bank + " with lookback " + lookBack + " and betMargin " + betMargin +
+							" Bet on " + betOnGameCount + " of " + matches.size() + "(" + betOnGameCount / (float)matches.size() + ") wins " + wins + "(" + wins/Float.valueOf(betOnGameCount) + ")" +
+							" Win / game " + (bank - startingBank) / Float.valueOf(wins) + " kr");
+					bestBetMargin = betMargin;
+					bestLookBack = lookBack;
+					bestBankResult = bank;
+				} else {
+					System.out.println("NOT BEST bank " + bank + " with lookback " + lookBack + " and betMargin " + betMargin +
+							" Bet on " + betOnGameCount + " of " + matches.size() + "(" + betOnGameCount / (float)matches.size() + ") wins " + wins + "(" + wins/Float.valueOf(betOnGameCount) + ")" +
+							" Win / game " + (bank - startingBank) / Float.valueOf(wins) + " kr");
+				}
+			}
+		}
+	}
+
+	public ArrayList<SoccerMatch> getMatches() {
+		final ArrayList<SoccerMatch> result = new ArrayList<>();
+
+		final String sql = "SELECT res.*, "
+				+ "hTeam.name as homeTeamName, aTeam.name as awayTeamName "
+				+ "FROM SoccerResults as res "
+				+ "Join Team as hTeam ON res.homeTeam = hTeam.id "
+				+ "Join Team as aTeam ON res.awayTeam = aTeam.id "
+				+ "WHERE "
+				+ "res.leagueId = ? "
+				+ "ORDER BY gameDate ASC";
+
+		try {
+			final PreparedStatement stat = getConnection().prepareStatement(sql);
+			stat.setInt(1, leagueId);
+
+			result.addAll(getMatches(stat));
+		} catch (final SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		return result;
+	}
+
+}

+ 119 - 0
OddsJavaFx/src/tests/DrawTests.java

@@ -0,0 +1,119 @@
+package tests;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+
+import data.GuiMysql;
+import objects.League;
+import objects.SoccerMatch;
+import objects.TeamResults;
+
+public class DrawTests extends TestClass {
+
+	private League leagueInfo;
+
+
+	@Override
+	public void setup(String date, float startingBank, float bettingLevel, Float betMargin, int lookBack, int sportId,
+			Integer countryId, Integer leagueId) {
+		super.setup(date, startingBank, bettingLevel, betMargin, lookBack, sportId, countryId, leagueId);
+
+		leagueInfo = getLeagueInfoById();
+	}
+
+	@Override
+	public void runTest() {
+		final ArrayList<SoccerMatch> matches = getMatches();
+
+		final float betLevel = bettingLevel / 100f;
+
+		final LocalDateTime currentDate = matches.get(0).getGameDate();
+		LocalDate localDate = currentDate.toLocalDate();
+		float betAmount = startingBank * betLevel;
+
+		int betOnGameCount = 0;
+		int wins = 0;
+
+		float bestBankResult = startingBank;
+		int bestBetMargin = 0;
+		int bestLookBack = 0;
+
+		for (int lookBack = 1; lookBack < 25; lookBack++) {
+			for (int betMargin = 1; betMargin < 35; betMargin++) {
+				final float betMarginDecimal = 1 + (betMargin / (float)100);
+				float bank = startingBank;
+				betOnGameCount = 0;
+				wins = 0;
+				for (final SoccerMatch match : matches) {
+					if (match.getHomeScore() < 0 || match.getAwayScore() < 0) {
+						continue;
+					}
+
+					final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(match.getHomeTeam().getTeamId(), lookBack, true, match.getGameDate().format(DateTimeFormatter.ISO_DATE));
+					final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(match.getAwayTeam().getTeamId(), lookBack, false, match.getGameDate().format(DateTimeFormatter.ISO_DATE));
+
+					final float drawPercent = (homeTeamResults.getDraws() + awayTeamResults.getDraws()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
+
+					final float drawOdds = 100 / drawPercent;
+
+					if (localDate.isBefore(match.getGameDate().toLocalDate())) {
+						betAmount = bank * betLevel;
+						localDate = match.getGameDate().toLocalDate();
+					}
+
+					if (drawOdds * betMarginDecimal <= match.getOddsX()) {
+						betOnGameCount++;
+						bank = bank - betAmount;
+						if (match.getHomeScore() == match.getAwayScore()) {
+							wins++;
+							bank = bank + betAmount * match.getOddsX();
+						}
+					}
+
+				}
+				if (bestBankResult < bank) {
+					System.out.println("New best bank " + bank + " with lookback " + lookBack + " and betMargin " + betMargin +
+							" Bet on " + betOnGameCount + " of " + matches.size() + "(" + betOnGameCount / (float)matches.size() + ") wins " + wins + "(" + wins/Float.valueOf(betOnGameCount) + ")" +
+							" Win / game " + (bank - startingBank) / Float.valueOf(wins) + " kr");
+					bestBetMargin = betMargin;
+					bestLookBack = lookBack;
+					bestBankResult = bank;
+				} else {
+					System.out.println("NOT BEST bank " + bank + " with lookback " + lookBack + " and betMargin " + betMargin +
+							" Bet on " + betOnGameCount + " of " + matches.size() + "(" + betOnGameCount / (float)matches.size() + ") wins " + wins + "(" + wins/Float.valueOf(betOnGameCount) + ")" +
+							" Win / game " + (bank - startingBank) / Float.valueOf(wins) + " kr");
+				}
+			}
+		}
+	}
+
+	public ArrayList<SoccerMatch> getMatches() {
+		final ArrayList<SoccerMatch> result = new ArrayList<>();
+
+		final String sql = "SELECT res.*, "
+				+ "hTeam.name as homeTeamName, aTeam.name as awayTeamName "
+				+ "FROM SoccerResults as res "
+				+ "Join Team as hTeam ON res.homeTeam = hTeam.id "
+				+ "Join Team as aTeam ON res.awayTeam = aTeam.id "
+				+ "WHERE "
+				+ "res.leagueId = ? "
+				+ "ORDER BY gameDate ASC";
+
+		try {
+			final PreparedStatement stat = getConnection().prepareStatement(sql);
+			stat.setInt(1, leagueId);
+
+			result.addAll(getMatches(stat));
+		} catch (final SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		return result;
+	}
+
+}

+ 219 - 0
OddsJavaFx/src/tests/HomeDrawAwayTest.java

@@ -0,0 +1,219 @@
+package tests;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import com.google.common.collect.Lists;
+
+import data.GuiMysql;
+import objects.League;
+import objects.SoccerMatch;
+import objects.TeamResults;
+
+public class HomeDrawAwayTest extends TestClass {
+
+	private ArrayList<League> prioLeagues;
+
+	@Override
+	public void runTest() {
+		float betAmount;
+		float bank = startingBank;
+		final float betLevel = bettingLevel / 100.0f;
+
+		float homeBank = startingBank;
+		float drawBank = startingBank;
+		float awayBank = startingBank;
+
+		final ArrayList<SoccerMatch> matches = getMatches();
+
+		for (int i = 0; i < matches.size(); i++) {
+			final SoccerMatch soccerMatch = matches.get(i);
+
+			final List<SoccerMatch> matchesThisDate = matches.stream()
+					.filter(p -> p.getGameDate().format(DateTimeFormatter.ISO_DATE)
+							.equals(soccerMatch.getGameDate().format(DateTimeFormatter.ISO_DATE)))
+					.collect(Collectors.toList());
+
+			final int matchesThisDateCount = matchesThisDate.size();
+			betAmount = bank * betLevel;
+			int gamesBettedOn = 0;
+			int winsThisDay = 0;
+			final float startBank = bank;
+			for (final SoccerMatch sm : matchesThisDate) {
+				final int leagueId = sm.getHomeTeam().getTeamLeagueId();
+				final League activeLeague = prioLeagues.stream().filter(p -> p.getLeagueId() == leagueId).findFirst().get();
+
+				final String betOnThisMatch = checkWhatBet(sm, activeLeague);
+				if (!"NoBet".equals(betOnThisMatch)) {
+					if (betOnThisMatch.contains("1")) { // Spela på hemma lag
+						gamesBettedOn++;
+						bank = bank - betAmount;
+						final float homeBetAmount = (homeBank * betLevel);
+						homeBank -= homeBetAmount;
+
+						if (sm.getHomeScore() > sm.getAwayScore()) {
+							bank += betAmount * sm.getOdds1();
+							homeBank += homeBetAmount * sm.getOdds1();
+							winsThisDay++;
+						}
+					}
+					if (betOnThisMatch.contains("2")) { // Spela på borta lag
+						gamesBettedOn++;
+						bank = bank - betAmount;
+
+						final float awayBetAmount = (awayBank * betLevel);
+						awayBank -= awayBetAmount;
+						if (sm.getAwayScore() > sm.getHomeScore()) {
+							bank += betAmount * sm.getOdds2();
+							awayBank += awayBetAmount * sm.getOdds2();
+							winsThisDay++;
+						}
+					}
+					if (betOnThisMatch.contains("X")) { // Spela på bort och hemma
+						gamesBettedOn++;
+						bank = bank - betAmount;
+
+						final float drawBetAmount = (drawBank * betLevel);
+						drawBank -= drawBetAmount;
+						if (sm.getHomeScore() == sm.getAwayScore()) {
+							bank += betAmount * sm.getOddsX();
+							drawBank += drawBetAmount * sm.getOddsX();
+							winsThisDay++;
+						}
+					}
+				}
+			}
+
+			System.out.println(matchesThisDate.get(0).getGameDate() + " result " + (bank - startBank) + " current bank: " + bank +
+					" bet on " + gamesBettedOn + "/" + matchesThisDateCount + " wins " + winsThisDay);
+			i += matchesThisDate.size();
+
+		}
+
+		System.out.println("Final bank " + bank + " homeBank " + homeBank + " drawBank " + drawBank + " awayBank " + awayBank);
+	}
+
+	private String checkWhatBet(SoccerMatch sm, League activeLeague) {
+		String result = "NoBet";
+
+		final float betMarginHomeDecimal = 1 + (activeLeague.getBetMarginHome() / 100f);
+		final float betMarginDrawDecimal = 1 + (activeLeague.getBetMarginDraw() / 100f);
+		final float betMarginAwayDecimal = 1 + (activeLeague.getBetMarginAway() / 100f);
+
+		final int lookbackHome = activeLeague.getLookbackHome();
+		final int lookbackDraw = activeLeague.getLookbackDraw();
+		final int lookbackAway = activeLeague.getLookbackAway();
+
+		if (lookbackHome > 0) {
+			final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getHomeTeam().getTeamId(), activeLeague.getLookbackHome(), true, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
+			final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getAwayTeam().getTeamId(), activeLeague.getLookbackHome(), false, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
+			final float homeWinPercent = (homeTeamResults.getWins() + awayTeamResults.getLosses()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
+			final float homeOdds = 100 / homeWinPercent;
+
+			if ( /*awayTeamResults.getCount() + homeTeamResults.getCount() > 10  && */
+					activeLeague.getBetMarginHome() > 0 && homeOdds * betMarginHomeDecimal <= sm.getOdds1()) {
+				if (result.equals("NoBet")) {
+					result = "1";
+				} else {
+					result += "1";
+				}
+			}
+
+		}
+
+
+		if (lookbackDraw > 0) {
+			final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getHomeTeam().getTeamId(), activeLeague.getLookbackDraw(), true, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
+			final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getAwayTeam().getTeamId(), activeLeague.getLookbackDraw(), false, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
+			final float drawWinPercent = (homeTeamResults.getDraws() + awayTeamResults.getDraws()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
+			final float drawOdds = 100 / drawWinPercent;
+
+			if (/* awayTeamResults.getCount() + homeTeamResults.getCount() > 10 && */
+					activeLeague.getBetMarginDraw() > 0 &&
+					drawOdds * betMarginDrawDecimal <= sm.getOddsX()) {
+				if (result.equals("NoBet")) {
+					result = "X";
+				} else {
+					result += "X";
+				}
+			}
+
+		}
+
+
+		if (lookbackAway > 0) {
+			final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getHomeTeam().getTeamId(), activeLeague.getLookbackAway(), true, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
+			final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getAwayTeam().getTeamId(), activeLeague.getLookbackAway(), false, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
+			final float awayWinPercent = (awayTeamResults.getWins() + homeTeamResults.getLosses()) / Float.valueOf(awayTeamResults.getCount() + homeTeamResults.getCount()) * 100;
+			final float awayOdds = 100 / awayWinPercent;
+
+			if (/* awayTeamResults.getCount() + homeTeamResults.getCount() > 10 && */
+					activeLeague.getBetMarginHome() > 0 &&
+					awayOdds * betMarginAwayDecimal <= sm.getOdds2()) {
+				if (result.equals("NoBet")) {
+					result = "2";
+				} else {
+					result += "2";
+				}
+			}
+
+		}
+		return result;
+	}
+
+	public ArrayList<SoccerMatch> getMatches() {
+		final ArrayList<SoccerMatch> matches = new ArrayList<>();
+		prioLeagues = getPrioLeagues();
+
+		final ArrayList<String> leagueIds = Lists.newArrayList();
+		prioLeagues.forEach(p -> leagueIds.add(String.valueOf(p.getLeagueId())));
+
+		final String sql = "SELECT res.*, " +
+				"hTeam.name as homeTeamName, aTeam.name as awayTeamName " +
+				"FROM SoccerResults as res " +
+				"Join Team as hTeam ON res.homeTeam = hTeam.id " +
+				"Join Team as aTeam ON res.awayTeam = aTeam.id " +
+				"WHERE " +
+				"res.leagueId IN (" +
+				String.join(",", leagueIds) + ") " +
+				"ORDER BY gameDate ASC";
+
+
+		PreparedStatement stmt;
+		try {
+			stmt = getConnection().prepareStatement(sql);
+			matches.addAll(super.getMatches(stmt));
+		} catch (final SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		return matches;
+	}
+
+	private ArrayList<League> getPrioLeagues() {
+		final String sql = "SELECT * FROM League WHERE prio = 1";
+		final ArrayList<League> result = Lists.newArrayList();
+		try {
+			final PreparedStatement stat = getConnection().prepareStatement(sql);
+			final ResultSet rs = stat.executeQuery();
+
+			while (rs.next()) {
+				result.add(new League(rs.getInt("id"), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin"),
+						rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"), rs.getInt("lookbackAway"),
+						rs.getInt("betMarginHome"), rs.getInt("betMarginDraw"), rs.getInt("betMarginAway")));
+			}
+		} catch (final SQLException e) {
+			e.printStackTrace();
+		}
+
+		return result;
+	}
+
+
+}

+ 118 - 0
OddsJavaFx/src/tests/HomeTests.java

@@ -0,0 +1,118 @@
+package tests;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+
+import data.GuiMysql;
+import objects.League;
+import objects.SoccerMatch;
+import objects.TeamResults;
+
+public class HomeTests extends TestClass {
+
+	private League leagueInfo;
+
+
+	@Override
+	public void setup(String date, float startingBank, float bettingLevel, Float betMargin, int lookBack, int sportId,
+			Integer countryId, Integer leagueId) {
+		super.setup(date, startingBank, bettingLevel, betMargin, lookBack, sportId, countryId, leagueId);
+
+		leagueInfo = getLeagueInfoById();
+	}
+
+	@Override
+	public void runTest() {
+		final ArrayList<SoccerMatch> matches = getMatches();
+
+		final float betLevel = bettingLevel / 100f;
+
+		final LocalDateTime currentDate = matches.get(0).getGameDate();
+		LocalDate localDate = currentDate.toLocalDate();
+		float betAmount = startingBank * betLevel;
+
+		int betOnGameCount = 0;
+		int wins = 0;
+
+		float bestBankResult = startingBank;
+		int bestBetMargin = 0;
+		int bestLookBack = 0;
+
+		for (int lookBack = 1; lookBack < 25; lookBack++) {
+			for (int betMargin = 1; betMargin < 35; betMargin++) {
+				final float betMarginDecimal = 1 + (betMargin / (float)100);
+				float bank = startingBank;
+				betOnGameCount = 0;
+				wins = 0;
+				for (final SoccerMatch match : matches) {
+					if (match.getHomeScore() < 0 || match.getAwayScore() < 0) {
+						continue;
+					}
+
+					final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(match.getHomeTeam().getTeamId(), lookBack, true, match.getGameDate().format(DateTimeFormatter.ISO_DATE));
+					final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(match.getAwayTeam().getTeamId(), lookBack, false, match.getGameDate().format(DateTimeFormatter.ISO_DATE));
+
+					final float homeWinPercent = (homeTeamResults.getWins() + awayTeamResults.getLosses()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
+					final float homeOdds = 100 / homeWinPercent;
+
+					if (localDate.isBefore(match.getGameDate().toLocalDate())) {
+						betAmount = bank * betLevel;
+						localDate = match.getGameDate().toLocalDate();
+					}
+
+					if (homeOdds * betMarginDecimal <= match.getOdds1()) {
+						betOnGameCount++;
+						bank = bank - betAmount;
+						if (match.getHomeScore() > match.getAwayScore()) {
+							wins++;
+							bank = bank + betAmount * match.getOdds1();
+						}
+					}
+
+				}
+				if (bestBankResult < bank) {
+					System.out.println("New best bank " + bank + " with lookback " + lookBack + " and betMargin " + betMargin +
+							" Bet on " + betOnGameCount + " of " + matches.size() + "(" + betOnGameCount / (float)matches.size() + ") wins " + wins + "(" + wins/Float.valueOf(betOnGameCount) + ")" +
+							" Win / game " + (bank - startingBank) / Float.valueOf(wins) + " kr");
+					bestBetMargin = betMargin;
+					bestLookBack = lookBack;
+					bestBankResult = bank;
+				} else {
+					System.out.println("NOT BEST bank " + bank + " with lookback " + lookBack + " and betMargin " + betMargin +
+							" Bet on " + betOnGameCount + " of " + matches.size() + "(" + betOnGameCount / (float)matches.size() + ") wins " + wins + "(" + wins/Float.valueOf(betOnGameCount) + ")" +
+							" Win / game " + (bank - startingBank) / Float.valueOf(wins) + " kr");
+				}
+			}
+		}
+	}
+
+	public ArrayList<SoccerMatch> getMatches() {
+		final ArrayList<SoccerMatch> result = new ArrayList<>();
+
+		final String sql = "SELECT res.*, "
+				+ "hTeam.name as homeTeamName, aTeam.name as awayTeamName "
+				+ "FROM SoccerResults as res "
+				+ "Join Team as hTeam ON res.homeTeam = hTeam.id "
+				+ "Join Team as aTeam ON res.awayTeam = aTeam.id "
+				+ "WHERE "
+				+ "res.leagueId = ? "
+				+ "ORDER BY gameDate ASC";
+
+		try {
+			final PreparedStatement stat = getConnection().prepareStatement(sql);
+			stat.setInt(1, leagueId);
+
+			result.addAll(getMatches(stat));
+		} catch (final SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		return result;
+	}
+
+}

+ 9 - 8
OddsJavaFx/src/tests/LastResultsTest.java

@@ -9,19 +9,19 @@ import data.GuiMysql;
 import objects.SoccerMatch;
 import objects.SoccerMatch;
 import objects.TeamResults;
 import objects.TeamResults;
 
 
-public class LastResultsTest {
+public class LastResultsTest extends TestClass {
 
 
 	float bank;
 	float bank;
 	float betLevel;
 	float betLevel;
 	float betMarginDecimal;
 	float betMarginDecimal;
 
 
+	@Override
+	public void runTest() {
 
 
-	public void run(String date, float startingBank, float bettingLevel, Float betMargin, int lookBack, int sportId,
-			Integer countryId, Integer leagueId) {
 		bank = startingBank;
 		bank = startingBank;
 		betLevel = bettingLevel / 100;
 		betLevel = bettingLevel / 100;
 		betMarginDecimal = 1 + (betMargin / 100);
 		betMarginDecimal = 1 + (betMargin / 100);
-		final ArrayList<SoccerMatch> matches = GuiMysql.getInstance().getMatches(sportId, countryId, leagueId, date, "ASC");
+		final ArrayList<SoccerMatch> matches = getMatches(leagueId);
 
 
 		final int totalMatchCount = matches.size();
 		final int totalMatchCount = matches.size();
 
 
@@ -111,15 +111,13 @@ public class LastResultsTest {
 						continue;
 						continue;
 					}
 					}
 
 
-					final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResults(soccerMatch.getHomeTeam().getTeamId(), lookBack, true);
-					final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResults(soccerMatch.getAwayTeam().getTeamId(), lookBack, false);
+					final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(soccerMatch.getHomeTeam().getTeamId(), lookBack, true, soccerMatch.getGameDate().format(DateTimeFormatter.ISO_DATE));
+					final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(soccerMatch.getAwayTeam().getTeamId(), lookBack, false, soccerMatch.getGameDate().format(DateTimeFormatter.ISO_DATE));
 
 
 					final float homeWinPercent = (homeTeamResults.getWins() + awayTeamResults.getLosses()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
 					final float homeWinPercent = (homeTeamResults.getWins() + awayTeamResults.getLosses()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
-					final float drawPercent = (homeTeamResults.getDraws() + awayTeamResults.getDraws()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
 					final float awayWinPercent = (homeTeamResults.getLosses() + awayTeamResults.getWins()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
 					final float awayWinPercent = (homeTeamResults.getLosses() + awayTeamResults.getWins()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
 
 
 					final float homeOdds = 100 / homeWinPercent;
 					final float homeOdds = 100 / homeWinPercent;
-					final float drawOdds = 100 / drawPercent;
 					final float awayOdds = 100 / awayWinPercent;
 					final float awayOdds = 100 / awayWinPercent;
 
 
 					if (localDate.isBefore(soccerMatch.getGameDate().toLocalDate())) {
 					if (localDate.isBefore(soccerMatch.getGameDate().toLocalDate())) {
@@ -160,4 +158,7 @@ public class LastResultsTest {
 		}
 		}
 	}
 	}
 
 
+	public ArrayList<SoccerMatch> getMatches(int leagueId) {
+		return GuiMysql.getInstance().getMatches(sportId, countryId, leagueId, date, "ASC");
+	}
 }
 }

+ 19 - 48
OddsJavaFx/src/tests/PrioCountriesAll.java

@@ -1,10 +1,8 @@
 package tests;
 package tests;
 
 
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.SQLException;
-import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
@@ -15,14 +13,13 @@ import com.google.common.collect.Lists;
 import data.GuiMysql;
 import data.GuiMysql;
 import objects.League;
 import objects.League;
 import objects.SoccerMatch;
 import objects.SoccerMatch;
-import objects.Team;
 import objects.TeamResults;
 import objects.TeamResults;
 
 
-public class PrioCountriesAll {
+public class PrioCountriesAll extends TestClass {
 
 
-	Connection conn;
 	private ArrayList<League> prioLeagues;
 	private ArrayList<League> prioLeagues;
 
 
+	@Override
 	public void runTest() {
 	public void runTest() {
 		float bank = 1000;
 		float bank = 1000;
 		float betAmount = 1;
 		float betAmount = 1;
@@ -89,8 +86,8 @@ public class PrioCountriesAll {
 		int returnValue = 0;
 		int returnValue = 0;
 		final float betMarginDecimal = 1 + (league.getBetMargin() / 100f);
 		final float betMarginDecimal = 1 + (league.getBetMargin() / 100f);
 
 
-		final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResults(sm.getHomeTeam().getTeamId(), league.getLookback(), true);
-		final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResults(sm.getAwayTeam().getTeamId(), league.getLookback(), false);
+		final TeamResults homeTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getHomeTeam().getTeamId(), league.getLookback(), true, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
+		final TeamResults awayTeamResults = GuiMysql.getInstance().getTeamResultsTest(sm.getAwayTeam().getTeamId(), league.getLookback(), false, sm.getGameDate().format(DateTimeFormatter.ISO_DATE));
 
 
 		final float homeWinPercent = (homeTeamResults.getWins() + awayTeamResults.getLosses()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
 		final float homeWinPercent = (homeTeamResults.getWins() + awayTeamResults.getLosses()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
 		final float drawPercent = (homeTeamResults.getDraws() + awayTeamResults.getDraws()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
 		final float drawPercent = (homeTeamResults.getDraws() + awayTeamResults.getDraws()) / Float.valueOf(homeTeamResults.getCount() + awayTeamResults.getCount()) * 100;
@@ -110,10 +107,8 @@ public class PrioCountriesAll {
 		return returnValue;
 		return returnValue;
 	}
 	}
 
 
-	private ArrayList<SoccerMatch> getMatches() {
-		int i = 0;
-		final ArrayList<SoccerMatch> matches = Lists.newArrayList();
-
+	public ArrayList<SoccerMatch> getMatches() {
+		final ArrayList<SoccerMatch> matches = new ArrayList<>();
 		prioLeagues = getPrioLeagues();
 		prioLeagues = getPrioLeagues();
 
 
 		final ArrayList<String> leagueIds = Lists.newArrayList();
 		final ArrayList<String> leagueIds = Lists.newArrayList();
@@ -129,39 +124,13 @@ public class PrioCountriesAll {
 				String.join(",", leagueIds) + ") " +
 				String.join(",", leagueIds) + ") " +
 				"ORDER BY gameDate ASC";
 				"ORDER BY gameDate ASC";
 
 
-		try {
-			final PreparedStatement stmt = conn.prepareStatement(sql);
 
 
-			final ResultSet rs = stmt.executeQuery();
-			while (rs.next()) {
-				i++;
-				final SoccerMatch sm = new SoccerMatch();
-				final Team homeTeam = new Team();
-				final Team awayTeam = new Team();
-
-				homeTeam.setTeamId(rs.getInt("homeTeam"));
-				awayTeam.setTeamId(rs.getInt("awayTeam"));
-				homeTeam.setTeamName(rs.getString("homeTeamName"));
-				awayTeam.setTeamName(rs.getString("awayTeamName"));
-				homeTeam.setTeamLeagueId(rs.getInt("leagueId"));
-				awayTeam.setTeamLeagueId(rs.getInt("leagueId"));
-				homeTeam.setCountryId(rs.getInt("countryId"));
-				awayTeam.setCountryId(rs.getInt("countryId"));
-
-				sm.setAwayScore(rs.getInt("awayScore"));
-				sm.setHomeScore(rs.getInt("homeScore"));
-				sm.setHomeTeam(homeTeam);
-				sm.setAwayTeam(awayTeam);
-				sm.setMatchId(rs.getInt("id"));
-				sm.setOdds1(rs.getFloat("odds1"));
-				sm.setOddsX(rs.getFloat("oddsX"));
-				sm.setOdds2(rs.getFloat("odds2"));
-				sm.setGameDate(LocalDateTime.parse(rs.getString("gameDate")));
-				sm.setSeason(rs.getString("season"));
-
-				matches.add(sm);
-			}
+		PreparedStatement stmt;
+		try {
+			stmt = getConnection().prepareStatement(sql);
+			matches.addAll(super.getMatches(stmt));
 		} catch (final SQLException e) {
 		} catch (final SQLException e) {
+			// TODO Auto-generated catch block
 			e.printStackTrace();
 			e.printStackTrace();
 		}
 		}
 
 
@@ -176,7 +145,9 @@ public class PrioCountriesAll {
 			final ResultSet rs = stat.executeQuery();
 			final ResultSet rs = stat.executeQuery();
 
 
 			while (rs.next()) {
 			while (rs.next()) {
-				result.add(new League(rs.getInt("id"), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin")));
+				result.add(new League(rs.getInt("id"), rs.getString("name"), rs.getInt("lookback"), rs.getInt("betMargin"),
+						rs.getInt("lookbackHome"), rs.getInt("lookbackDraw"), rs.getInt("lookbackAway"),
+						rs.getInt("betMarginHome"), rs.getInt("betMarginDraw"), rs.getInt("betMarginAway")));
 			}
 			}
 		} catch (final SQLException e) {
 		} catch (final SQLException e) {
 			e.printStackTrace();
 			e.printStackTrace();
@@ -185,11 +156,11 @@ public class PrioCountriesAll {
 		return result;
 		return result;
 	}
 	}
 
 
-	private Connection getConnection() {
-		if (conn == null) {
-			conn = GuiMysql.getInstance().getDbConnection();
-		}
+	@Override
+	public void setup(String date, float startingBank, float bettingLevel, Float betMargin, int lookBack, int sportId, Integer countryId,
+			Integer leagueId) {
+		// TODO Auto-generated method stub
 
 
-		return conn;
 	}
 	}
+
 }
 }

+ 94 - 0
OddsJavaFx/src/tests/TestClass.java

@@ -0,0 +1,94 @@
+package tests;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+
+import com.google.common.collect.Lists;
+
+import data.GuiMysql;
+import objects.League;
+import objects.SoccerMatch;
+import objects.Team;
+
+public abstract class TestClass {
+
+	String date;
+	float startingBank;
+	float bettingLevel;
+	float betMargin;
+	int lookBack;
+	int sportId;
+	int countryId;
+	int leagueId;
+
+
+	public abstract void runTest();
+
+	public ArrayList<SoccerMatch> getMatches(PreparedStatement stmt) {
+		final ArrayList<SoccerMatch> matches = Lists.newArrayList();
+
+		try {
+
+			final ResultSet rs = stmt.executeQuery();
+			while (rs.next()) {
+				final SoccerMatch sm = new SoccerMatch();
+				final Team homeTeam = new Team();
+				final Team awayTeam = new Team();
+
+				homeTeam.setTeamId(rs.getInt("homeTeam"));
+				awayTeam.setTeamId(rs.getInt("awayTeam"));
+				homeTeam.setTeamName(rs.getString("homeTeamName"));
+				awayTeam.setTeamName(rs.getString("awayTeamName"));
+				homeTeam.setTeamLeagueId(rs.getInt("leagueId"));
+				awayTeam.setTeamLeagueId(rs.getInt("leagueId"));
+				homeTeam.setCountryId(rs.getInt("countryId"));
+				awayTeam.setCountryId(rs.getInt("countryId"));
+
+				sm.setAwayScore(rs.getInt("awayScore"));
+				sm.setHomeScore(rs.getInt("homeScore"));
+				sm.setHomeTeam(homeTeam);
+				sm.setAwayTeam(awayTeam);
+				sm.setMatchId(rs.getInt("id"));
+				sm.setOdds1(rs.getFloat("odds1"));
+				sm.setOddsX(rs.getFloat("oddsX"));
+				sm.setOdds2(rs.getFloat("odds2"));
+				sm.setGameDate(LocalDateTime.parse(rs.getString("gameDate")));
+				sm.setSeason(rs.getString("season"));
+
+				matches.add(sm);
+			}
+		} catch (final SQLException e) {
+			e.printStackTrace();
+		}
+
+		return matches;
+	}
+
+	public void setup(String date, float startingBank, float bettingLevel, Float betMargin, int lookBack, int sportId, Integer countryId,
+			Integer leagueId) {
+		this.startingBank = startingBank;
+		this.bettingLevel = bettingLevel;
+		this.betMargin = betMargin;
+		this.lookBack = lookBack;
+		this.sportId = sportId;
+		this.countryId = countryId;
+		this.leagueId = leagueId;
+		this.date = date;
+	}
+
+	public Connection getConnection() {
+		return GuiMysql.getInstance().getDbConnection();
+	}
+
+	public League getLeagueInfoById() {
+		return GuiMysql.getInstance().getLeagueInfo(leagueId);
+	}
+
+	public League getLeagueInfoByName(String leagueName) {
+		return GuiMysql.getInstance().getLeagueInfo(leagueName);
+	}
+}

+ 6 - 4
OddsJavaFx/src/web/matchTable.php

@@ -10,7 +10,9 @@ $conn->getBettingStats($leagueId);
 
 
 $matches = $conn->getMatches($countryId, $leagueId);
 $matches = $conn->getMatches($countryId, $leagueId);
 $leagueInfo = $conn->getLeagueInfo($leagueId)[0];
 $leagueInfo = $conn->getLeagueInfo($leagueId)[0];
-$betMargin = 1 + ($leagueInfo['betMargin'] / 100);
+$betMarginHome = 1 + ($leagueInfo['betMarginHome'] / 100);
+$betMarginDraw = 1 + ($leagueInfo['betMarginDraw'] / 100);
+$betMarginAway = 1 + ($leagueInfo['betMarginAway'] / 100);
 
 
 ?>
 ?>
 <head>
 <head>
@@ -45,9 +47,9 @@ $betMargin = 1 + ($leagueInfo['betMargin'] / 100);
         echo "<td>".$match['gameDate'] . "</td>";
         echo "<td>".$match['gameDate'] . "</td>";
         echo "<td>".$match['homeTeamName'] . "</td>";
         echo "<td>".$match['homeTeamName'] . "</td>";
         echo "<td>".$match['awayTeamName'] . "</td>";
         echo "<td>".$match['awayTeamName'] . "</td>";
-        echo "<td>". round((100 / $match['homeWinPercent']) * $betMargin, 2) . "</td>";
-        echo "<td>". round((100 / $match['drawPercent']) * $betMargin, 2) . "</td>";
-        echo "<td>". round((100 / $match['awayWinPercent']) * $betMargin, 2) . "</td>";
+        echo "<td>". round((100 / $match['homeWinPercent']) * $betMarginHome, 2) . "</td>";
+        echo "<td>". round((100 / $match['drawPercent']) * $betMarginDraw, 2) . "</td>";
+        echo "<td>". round((100 / $match['awayWinPercent']) * $betMarginAway, 2) . "</td>";
         echo "<td><input id='betHome' name='betHomeName' type='checkbox'/></td>";
         echo "<td><input id='betHome' name='betHomeName' type='checkbox'/></td>";
         echo "<td><input id='betOdds' name='betOddsName' type='number' step='.01'/></td>";
         echo "<td><input id='betOdds' name='betOddsName' type='number' step='.01'/></td>";
         echo "<td><input id='betAmount' name='betAmountName' type='number' step='.01'/></td>";
         echo "<td><input id='betAmount' name='betAmountName' type='number' step='.01'/></td>";

+ 17 - 7
OddsJavaFx/src/web/webDbConnection.php

@@ -80,18 +80,28 @@ class WebDbConnection {
             $match = $matches[$i];
             $match = $matches[$i];
             $league = $this->getLeagueInfo($leagueId);
             $league = $this->getLeagueInfo($leagueId);
 
 
-            $lookback = $league[0]['lookback'];
-            $betMargin = $league[0]['betMargin'];
+            $lookbackHome = $league[0]['lookbackHome'];
+            $lookbackDraw = $league[0]['lookbackDraw'];
+            $lookbackAway = $league[0]['lookbackAway'];
+            $betMarginHome = $league[0]['betMarginHome'];
+            $betMarginDraw = $league[0]['betMarginDraw'];
+            $betMarginAway = $league[0]['betMarginAway'];
             
             
-            $homeTeamResults = $this->getTeamResults($match['homeTeam'], $lookback, true)[0];
-            $awayTeamResults = $this->getTeamResults($match['awayTeam'], $lookback, false)[0];
+            $homeTeamResultsHome = $this->getTeamResults($match['homeTeam'], $lookbackHome, true)[0];
+            $homeTeamResultsAway = $this->getTeamResults($match['awayTeam'], $lookbackHome, false)[0];
+            
+            $drawTeamResultsHome = $this->getTeamResults($match['homeTeam'], $lookbackDraw, true)[0];
+            $drawTeamResultsAway = $this->getTeamResults($match['awayTeam'], $lookbackDraw, false)[0];
+            
+            $awayTeamResultsHome = $this->getTeamResults($match['homeTeam'], $lookbackAway, true)[0];
+            $awayTeamResultsAway = $this->getTeamResults($match['awayTeam'], $lookbackAway, false)[0];
             
             
             $homeTeamCount = $homeTeamResults['wins'] + $homeTeamResults['draws'] + $homeTeamResults['lost'];
             $homeTeamCount = $homeTeamResults['wins'] + $homeTeamResults['draws'] + $homeTeamResults['lost'];
             $awayTeamCount = $awayTeamResults['wins'] + $awayTeamResults['draws'] + $awayTeamResults['lost'];
             $awayTeamCount = $awayTeamResults['wins'] + $awayTeamResults['draws'] + $awayTeamResults['lost'];
             
             
-            $homeWinPercent = round((($homeTeamResults['wins'] + $awayTeamResults['lost']) / ($homeTeamCount + $awayTeamCount)) * 100,2);
-            $drawPercent = round((($homeTeamResults['draws'] + $awayTeamResults['draws']) / ($homeTeamCount + $awayTeamCount)) * 100, 2);
-            $awayWinPercent = round((($awayTeamResults['wins'] + $homeTeamResults['lost']) / ($homeTeamCount + $awayTeamCount)) * 100, 2);
+            $homeWinPercent = round((($homeTeamResultsHome['wins'] + $homeTeamResultsAway['lost']) / ($homeTeamCount + $awayTeamCount)) * 100,2);
+            $drawPercent = round((($drawTeamResultsHome['draws'] + $drawTeamResultsAway['draws']) / ($homeTeamCount + $awayTeamCount)) * 100, 2);
+            $awayWinPercent = round((($awayTeamResultsAway['wins'] + $awayTeamResultsHome['lost']) / ($homeTeamCount + $awayTeamCount)) * 100, 2);
             
             
             $match['homeWinPercent'] = $homeWinPercent;
             $match['homeWinPercent'] = $homeWinPercent;
             $match['drawPercent'] = $drawPercent;
             $match['drawPercent'] = $drawPercent;