| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- package controllers;
- import com.google.common.base.Strings;
- import com.google.common.collect.Lists;
- import data.GuiMysql;
- import javafx.application.Platform;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.*;
- import javafx.scene.layout.AnchorPane;
- import javafx.scene.layout.Priority;
- import javafx.scene.layout.VBox;
- import objects.League;
- import org.eclipse.jetty.util.log.Log;
- import parser.OddsPortal;
- import tests.*;
- import java.net.URL;
- import java.time.LocalDate;
- import java.util.AbstractMap.SimpleEntry;
- import java.util.List;
- import java.util.Optional;
- import java.util.ResourceBundle;
- public class TestsController implements Initializable {
- @FXML
- AnchorPane basePane;
- @FXML
- AnchorPane testSettingsPanel;
- @FXML
- AnchorPane testResultsPanel;
- @FXML
- Button getResults;
- @FXML
- ScrollPane resultsPanel;
- @FXML
- DatePicker date;
- @FXML
- ComboBox<String> countrySelector;
- @FXML
- ComboBox<String> leagueSelector;
- @FXML
- TextField bettingLevel;
- @FXML
- TextField startingBank;
- @FXML
- TextField lookBack;
- @FXML
- TextField betMargin;
- @FXML
- Button calcBestValues;
- @FXML
- Button getLeagueInfoButton;
- @FXML
- Button getMoreLeagueInfoButton;
- @FXML
- Button topLeaguesTest;
- @FXML
- Button homeTest;
- @FXML
- Button drawTest;
- @FXML
- Button awayTest;
- @FXML
- Button homeDrawAwayTest;
- @FXML
- Button homeTeamTest;
- @FXML
- Button awayTeamTest;
- @FXML
- Button addedScoreTest;
- @FXML
- Button recalcTest;
- @FXML
- Button fibonacciDrawTest;
- @FXML
- VBox testPanelVBox;
- ObservableList<String> countries = FXCollections.observableArrayList();
- ObservableList<String> leagues = FXCollections.observableArrayList();
- private final List<SimpleEntry<Integer, String>> countriesList = Lists.newArrayList();
- private List<SimpleEntry<Integer, String>> leaguesList = Lists.newArrayList();
- private int mSportId;
- @Override
- public void initialize(URL arg0, ResourceBundle arg1) {
- getResults.setDisable(true);
- basePane.setPrefWidth(0.0);
- basePane.setPrefHeight(0.0);
- VBox.setVgrow(testPanelVBox, Priority.ALWAYS);
- date.valueProperty()
- .addListener((ov, oldValue, newValue) -> getResults.setDisable(newValue.isAfter(LocalDate.now())));
- countrySelector.setItems(countries);
- leagueSelector.setItems(leagues);
- testSettingsPanel.setVisible(false);
- }
- @FXML
- void getLeagueInfo() {
- final String country = countrySelector.getValue().trim();
- final String league = leagueSelector.getValue().trim();
- final OddsPortal op = new OddsPortal();
- op.getHistoricMatches("soccer", country, league, String.valueOf(LocalDate.now().getYear()));
- }
- @FXML
- private void addedScoreTestAction() {
- final AddedScoringTest test = new AddedScoringTest();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()),
- Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void analysisDrawTests() {
- final TestClass test = new AnalysisBettDrawTest();
- test.setup(date.getValue().toString(), Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), -1.0f,
- -1, GuiMysql.getInstance().getSportId("soccer"),
- getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void analysisTets() {
- final TestClass test = new AnalysisBettTest();
- test.setup(date.getValue().toString(), Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), -1.0f,
- -1, GuiMysql.getInstance().getSportId("soccer"),
- getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void awayTeamTestAction() {
- final AwayTeamWinTest test = new AwayTeamWinTest();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()),
- Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void awayTestAction() {
- final Away2Test test = new Away2Test();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()),
- Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void calcBestResultsAction() {
- final LastResultsTest test = new LastResultsTest();
- calcBestValues.setDisable(true);
- final String buttonText = calcBestValues.getText();
- Platform.runLater(() -> {
- calcBestValues.setText("RUNNING...");
- test.calcBestResults(mSportId, getCountryIdFromSelector(), getLeagueIdFromSelector());
- calcBestValues.setDisable(false);
- calcBestValues.setText(buttonText);
- });
- }
- @FXML
- private void countrySelected(ActionEvent event) {
- if (countrySelector.getValue() != null && !countrySelector.getValue().equals("Country")) {
- leagueSelector.setDisable(false);
- final int countryId = getCountryIdFromSelector();
- final int sportId = getSoccerId();
- leaguesList = GuiMysql.getInstance().getLeaguesByDate(sportId, countryId, date.getValue().toString());
- leagues.clear();
- leagues.add("League");
- leaguesList.forEach(l -> leagues.add(l.getValue()));
- }
- }
- @FXML
- private void drawTestAction() {
- final Draw2Tests test = new Draw2Tests();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()),
- Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void fibonacciDrawTestAction() {
- final TestClass test = new FibonacciDrawTest();
- test.setup(date.getValue().toString(), Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), -1.0f,
- -1, GuiMysql.getInstance().getSportId("soccer"),
- getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- private String getBetLevel() {
- String betLevel = Strings.isNullOrEmpty(bettingLevel.getText()) ? bettingLevel.getPromptText()
- : bettingLevel.getText();
- betLevel = betLevel.replace("%", "").trim();
- return betLevel;
- }
- private String getBetMargin() {
- String betM = Strings.isNullOrEmpty(betMargin.getText()) ? betMargin.getPromptText() : betMargin.getText();
- betM = betM.replace("%", "").trim();
- return betM;
- }
- private Integer getCountryIdFromSelector() {
- Optional<SimpleEntry<Integer, String>> o = countriesList.stream()
- .filter(p -> p.getValue().equals(countrySelector.getValue())).findFirst();
- return o.isPresent() ? o.get().getKey() : null;
- }
- private Integer getLeagueIdFromSelector() {
- Optional<SimpleEntry<Integer, String>> o = leaguesList.stream()
- .filter(p -> p.getValue().equals(leagueSelector.getValue())).findFirst();
- return o.isPresent() ? o.get().getKey() : null;
- }
- private String getLookback() {
- return Strings.isNullOrEmpty(lookBack.getText()) ? lookBack.getPromptText() : lookBack.getText();
- }
- @FXML
- private void getMoreLeagueInfo() {
- final String lastParsedYear = GuiMysql.getInstance().getLastParsedYear(leagueSelector.getValue().trim(),
- getCountryIdFromSelector());
- final String nextParseYear;
- if (lastParsedYear.contains("-")) {
- final String[] years = lastParsedYear.split("-");
- int firstYear = Integer.parseInt(years[0]);
- int lastYear = Integer.parseInt(years[1]);
- firstYear--;
- lastYear--;
- nextParseYear = firstYear + "-" + lastYear;
- } else if (lastParsedYear.length() == 4) {
- Integer val = Integer.valueOf(lastParsedYear);
- val--;
- nextParseYear = String.valueOf(val);
- } else {
- Log.getLog().info("Fail to get More league info for %s", lastParsedYear);
- return;
- }
- final String country = countrySelector.getValue().trim();
- final String league = leagueSelector.getValue().trim();
- final OddsPortal op = new OddsPortal();
- op.getHistoricMatches("soccer", country, league, nextParseYear);
- }
- @FXML
- private void getResults() {
- countriesList.clear();
- leaguesList.clear();
- initCountries();
- }
- private int getSoccerId() {
- if (mSportId <= 0) {
- mSportId = GuiMysql.getInstance().getSportId(MainController.SPORT);
- }
- return mSportId;
- }
- private String getStartingBank() {
- return Strings.isNullOrEmpty(startingBank.getText()) ? startingBank.getPromptText() : startingBank.getText();
- }
- @FXML
- private void goalDiffTest() {
- final TestClass test = new BetOnDifferenceTest();
- test.setup(date.getValue().toString(), Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), -1.0f,
- -1, GuiMysql.getInstance().getSportId("soccer"),
- 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();
- }
- @FXML
- private void homeTeamTestAction() {
- final HomeTeamWinTest test = new HomeTeamWinTest();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()),
- Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void homeTestAction() {
- final Home2Test test = new Home2Test();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()),
- Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- private void initCountries() {
- countrySelector.setDisable(false);
- final int sportId = getSoccerId();
- countriesList.clear();
- countriesList.addAll(GuiMysql.getInstance().getCountriesBySport(sportId, date.getValue().toString()));
- countriesList.forEach(c -> countries.add(c.getValue()));
- }
- @FXML
- private void leagueSelected(ActionEvent event) {
- if (GuiMysql.getInstance().getParsingStarted(getCountryIdFromSelector(), getLeagueIdFromSelector())) {
- getLeagueInfoButton.setDisable(true);
- getMoreLeagueInfoButton.setDisable(false);
- } else {
- getLeagueInfoButton.setDisable(false);
- getMoreLeagueInfoButton.setDisable(true);
- }
- testSettingsPanel.setVisible(true);
- }
- @FXML
- private void recalcTestAction() {
- final recalcTest test = new recalcTest();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()),
- Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void relevanceTest() {
- final TestClass test = new RelevanceTest();
- test.setup(date.getValue().toString(), Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), -1.0f,
- -1, GuiMysql.getInstance().getSportId("soccer"),
- getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void runTestAction() {
- final String betLevel = getBetLevel();
- final String betM = getBetMargin();
- final String startBank = getStartingBank();
- final String lookBackVal = getLookback();
- final TestClass test = new LastResultsTest();
- test.setup(date.getValue().toString(), Float.valueOf(startBank), Float.valueOf(betLevel), Float.valueOf(betM),
- Integer.valueOf(lookBackVal),
- mSportId, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML
- private void standingsTest() {
- final TestClass test = new LeagueTablePositionTest();
- test.runTest();
- }
- @FXML
- private void topLeaguesTestAction() {
- final PrioCountriesAllTest prioCountriesAll = new PrioCountriesAllTest();
- prioCountriesAll.runTest();
- }
- @FXML
- private void updatePrioLeagues() {
- List<League> leaguesWithPrio = GuiMysql.getInstance().getLeaguesWithPrio();
- for (League league : leaguesWithPrio) {
- long startTime = System.currentTimeMillis();
- System.out.println("Starting with " + league.getLeagueName() + " " + new java.util.Date());
- RelevanceTest test = new RelevanceTest();
- test.setup("", -1, -1, 0.0f, -1, -1, -1, league.getLeagueId());
- test.runTest();
- long endTime = System.currentTimeMillis();
- System.out.println("Done with " + league.getLeagueName() + " " + new java.util.Date()
- + " took " + new java.util.Date(System.currentTimeMillis() + (endTime - startTime)));
- }
- }
- public void runXBestGamesTest(ActionEvent actionEvent) {
- XBestRatedGamesBettingTest xBestRatedGamesBettingTest = new XBestRatedGamesBettingTest();
- xBestRatedGamesBettingTest.runTest();
- }
- }
|