Bladeren bron

Just updates

Axel Nordh 3 jaren geleden
bovenliggende
commit
da3a016fa1

+ 1 - 1
Odds/pom.xml

@@ -45,7 +45,7 @@
 	<dependency>
  	   <groupId>net.sourceforge.htmlunit</groupId>
 	   <artifactId>htmlunit</artifactId>
-	   <version>2.62.0</version>
+	   <version>2.64.0</version>
 	</dependency>
 	<dependency>
 	   <groupId>com.github.jbytecode</groupId>

+ 15 - 11
Odds/src/parser/OddsPortal.java

@@ -67,17 +67,21 @@ public class OddsPortal implements ParserJoinedFunctions {
 		final String soccerUrl = "https://oddsportal.com/matches/soccer/" + date;
 		// final String hockeyUrl = "https://oddsportal.com/matches/hockey/" + date;
 
-		final WebClient webClient = new WebClient();
-		webClient.getOptions().setUseInsecureSSL(true);
-		webClient.getOptions().setCssEnabled(false);
-		webClient.getOptions().setJavaScriptEnabled(true);
-		webClient.getOptions().setThrowExceptionOnScriptError(false);
-		Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
-
-		webClient.waitForBackgroundJavaScript(3000);
-		parseSoccerMatches(soccerUrl, webClient, date);
-
-		webClient.close();
+		try (final WebClient webClient = new WebClient()) {
+			webClient.getOptions().setUseInsecureSSL(true);
+			webClient.getOptions().setCssEnabled(false);
+			webClient.getOptions().setJavaScriptEnabled(true);
+			webClient.getOptions().setThrowExceptionOnScriptError(false);
+			Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
+
+			webClient.waitForBackgroundJavaScript(3000);
+			parseSoccerMatches(soccerUrl, webClient, date);
+
+		} catch (Exception e) {
+			System.out.println("Webclient failed " + e.getMessage());
+			e.printStackTrace();
+		}
+//		webClient.close();
 	}
 
 	private void parseSoccerMatches(final String soccerUrl, final WebClient webClient, String date) {

+ 1 - 1
OddsJavaFx/src/controllers/MainController.java

@@ -167,7 +167,7 @@ public class MainController implements Initializable {
 			matchTabController.filterLeagueMatches(leagueSelector.getValue(), getCountryIdFromSelector());
 			updateStatsTableButton.setDisable(false);
 			final List<Float> leagueAvareges = GuiMysql.getInstance().getLeagueAvarages(getLeagueIdFromSelector(), getCountryIdFromSelector(),
-					"NOW()");
+					DATE_FORMAT.format(new Date()));
 
 			avgLeagueHomeScoreTxt.setText(leagueAvareges.get(0).toString());
 			avgLeagueAwayScoreTxt.setText(leagueAvareges.get(1).toString());

+ 4 - 7
OddsJavaFx/src/controllers/MatchTabController.java

@@ -114,7 +114,6 @@ import objects.TeamResults;
 		awayWinColumn.setCellValueFactory(new MapValueFactory<>(Constants.AWAY_WIN));
 		scoringScore.setCellValueFactory(new MapValueFactory<>("scoringScore"));
 
-//		betSeries.setCellValueFactory(new PropertyValueFactory<>("betSeries"));
 		betSeries.setCellValueFactory(i -> {
 			return Bindings.createObjectBinding(() -> i.getValue().optionProperty());
 		});
@@ -147,6 +146,7 @@ import objects.TeamResults;
 				.collect(Collectors.toCollection(LinkedList::new)));
 
 		lastBetSeries = GuiMysql.getInstance().getBetSeriesEndNumber();
+		betSeriesOptions.add(String.valueOf(lastBetSeries + 1));
 
 		betObservableList.addAll(dbBetSeries);
 	}
@@ -168,12 +168,6 @@ import objects.TeamResults;
 			return c;
 		});
 
-//		betSeries.setCellFactory(TextFieldTableCell.forTableColumn(new IntegerStringConverter()));
-//		betSeries.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setBetSeries(e.getNewValue()));
-
-//		gameDate.setCellFactory(TextFieldTableCell.forTableColumn());
-//		gameDate.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setGameDate(e.getNewValue()));
-
 		match.setCellFactory(TextFieldTableCell.forTableColumn());
 		match.setOnEditCommit(e -> e.getTableView().getItems().get(e.getTablePosition().getRow()).setMatch(e.getNewValue()));
 		betType.setCellFactory(TextFieldTableCell.forTableColumn());
@@ -291,6 +285,7 @@ import objects.TeamResults;
 									+ (avgAwayScoreThisSeason.get(0) * avgHomeScoreThisSeason.get(1))), GuiMysql.getInstance().getIncrement(),
 									RoundingMode.HALF_UP));
 			match.put("addToBetslip", false);
+			match.put("id", soccerMatch.getMatchId());
 
 			matches.add(match);
 		}
@@ -370,6 +365,8 @@ import objects.TeamResults;
 			betDTO.setBetType("O/U 1.5");
 			betDTO.setWinAmount(-1);
 
+			betDTO.setGameId(Integer.valueOf(selectedRow.get("id").toString()));
+
 			betObservableList.add(betDTO);
 		} else {
 			System.out.println("No row selected");

+ 12 - 10
OddsJavaFx/src/controllers/PastResultsController.java

@@ -177,20 +177,20 @@ import tests.objects.Standing;
 	}
 
 	@FXML private void countrySelected(ActionEvent event) {
-		if (getCountryIdFromSelector() != null) {
+		if (getCountryIdFromSelector() > 0) {
 			getLeaguesAtDate(getCountryIdFromSelector());
 			leagueSelector.setDisable(false);
 		}
 	}
 
-	private Integer getCountryIdFromSelector() {
+	private int getCountryIdFromSelector() {
 		Optional<SimpleEntry<Integer, String>> o = countriesList.stream().filter(p -> p.getValue().equals(countrySelector.getValue())).findFirst();
-		return o.isPresent() ? o.get().getKey() : null;
+		return o.isPresent() ? o.get().getKey() : -1;
 	}
 
-	private Integer getLeagueIdFromSelector() {
+	private int getLeagueIdFromSelector() {
 		Optional<SimpleEntry<Integer, String>> o = leaguesList.stream().filter(p -> p.getValue().equals(leagueSelector.getValue())).findFirst();
-		return o.isPresent() ? o.get().getKey() : null;
+		return o.isPresent() ? o.get().getKey() : -1;
 	}
 
 	private float getAvgGoalsWithSameDiff(int countryId, int leagueId, int placementDiff) {
@@ -270,7 +270,7 @@ import tests.objects.Standing;
 
 	@FXML private void leagueSelected(ActionEvent event) {
 		updateStandingsTable();
-		if (getCountryIdFromSelector() != null) {
+		if (getCountryIdFromSelector() > 0) {
 			List<SoccerMatch> matchesList = db.getMatches(db.getSportId(MainController.SOCCER), getCountryIdFromSelector(),
 					db.getLeagueId(db.getSportId(MainController.SOCCER), getCountryIdFromSelector(), leagueSelector.getValue()),
 					date.getValue().toString(), "ASC", true);
@@ -363,9 +363,11 @@ import tests.objects.Standing;
 	}
 
 	@FXML private void updateStandingsTable() {
-		String seasonFromDate = GuiMysql.getInstance().getSeasonFromDate(getCountryIdFromSelector(), getLeagueIdFromSelector(),
-				date.getValue().toString());
-		MatchStatTabController.getInstance().setLeagueStandingsTable(getLeagueIdFromSelector(), seasonFromDate, getCountryIdFromSelector(),
-				date.getValue().toString());
+		int countryId = getCountryIdFromSelector();
+		if (countryId > 0) {
+			String seasonFromDate = GuiMysql.getInstance().getSeasonFromDate(countryId, getLeagueIdFromSelector(), date.getValue().toString());
+			MatchStatTabController.getInstance().setLeagueStandingsTable(getLeagueIdFromSelector(), seasonFromDate, countryId,
+					date.getValue().toString());
+		}
 	}
 }

+ 4 - 4
OddsJavaFx/src/data/GuiMysql.java

@@ -298,7 +298,7 @@ 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) < ?";
+				+ " FROM SoccerResults WHERE leagueId = ? AND countryId = ? AND DATE(gameDate) < DATE(?)";
 
 		try (PreparedStatement stat = conn.prepareStatement(sql);) {
 			stat.setInt(1, leagueId);
@@ -434,10 +434,10 @@ 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, "
+		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, "
+				+ "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 "

+ 1 - 1
OddsJavaFx/src/fxml/OddsFxBuilder.fxml

@@ -30,7 +30,7 @@
                   <Button fx:id="getMoreLeagueInfo" disable="true" mnemonicParsing="false" onAction="#getMoreLeagueInfo" text="Get more league info" />
                   <Button fx:id="updateStatsTableButton" disable="true" mnemonicParsing="false" onAction="#updateStatsTable" text="Update Statistics" />
                   <Button fx:id="showMatchStatsButton" disable="true" mnemonicParsing="false" onAction="#setMatchStatInfo" text="Show match stats" />
-                  <Button onAction="#getMoreLeagueInfo" text="Get this years stats" />
+                  <Button onAction="#getLeagueInfo" text="Get this years stats" />
                </children>
             </FlowPane>
          </top>

+ 1 - 2
OddsJavaFx/src/objects/BetDTO.java

@@ -19,6 +19,7 @@ public class BetDTO {
 	int countryId;
 	int leagueId;
 	private String leagueName;
+	private final StringProperty option = new SimpleStringProperty();
 
 	public BetDTO(int betSeries, String match, String betType, float bet, float odds, String result) {
 		super();
@@ -150,8 +151,6 @@ public class BetDTO {
 		return leagueName;
 	}
 
-	private final StringProperty option = new SimpleStringProperty();
-
 	public int getBetSeries() {
 		return Integer.valueOf(option.get());
 	}