| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 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;
- }
- }
|