| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- package controllers;
- 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;
- import org.eclipse.jetty.util.log.Log;
- 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.Button;
- import javafx.scene.control.ComboBox;
- import javafx.scene.control.DatePicker;
- import javafx.scene.control.ScrollPane;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.AnchorPane;
- import parser.OddsPortal;
- import tests.AddedScoringTest;
- import tests.AwayTeamWinTest;
- import tests.AwayTests2;
- import tests.DrawTests2;
- import tests.HomeDrawAwayTest;
- import tests.HomeTeamWinTest;
- import tests.HomeTests2;
- import tests.LastResultsTest;
- import tests.LeagueTablePositionTest;
- import tests.PrioCountriesAll;
- import tests.TestClass;
- import tests.recalcTest;
- 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;
- 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);
- date.valueProperty().addListener((ov, oldValue, newValue) -> getResults.setDisable(newValue.isAfter(LocalDate.now())));
- countrySelector.setItems(countries);
- leagueSelector.setItems(leagues);
- testSettingsPanel.setVisible(false);
- }
- @FXML private void getResults() {
- countriesList.clear();
- leaguesList.clear();
- initCountries();
- }
- @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()));
- }
- }
- 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 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()));
- }
- private int getSoccerId() {
- if (mSportId <= 0) {
- mSportId = GuiMysql.getInstance().getSportId(MainController.SPORT);
- }
- return mSportId;
- }
- @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 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();
- }
- 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 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 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 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 topLeaguesTestAction() {
- final PrioCountriesAll prioCountriesAll = new PrioCountriesAll();
- prioCountriesAll.runTest();
- }
- @FXML private void homeTestAction() {
- final HomeTests2 test = new HomeTests2();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()), Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML private void drawTestAction() {
- final DrawTests2 test = new DrawTests2();
- test.setup("", Float.valueOf(getStartingBank()), Float.valueOf(getBetLevel()), Float.valueOf(getBetMargin()), Integer.valueOf(getLookback()),
- 1, getCountryIdFromSelector(), getLeagueIdFromSelector());
- test.runTest();
- }
- @FXML private void awayTestAction() {
- final AwayTests2 test = new AwayTests2();
- 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();
- }
- @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 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 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 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 standingsTest() {
- final LeagueTablePositionTest test = new LeagueTablePositionTest();
- test.runTest();
- }
- }
|