WebFunctions.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. include_once 'SoccerMatchAnalysis.php';
  3. include_once 'SoccerMatch.php';
  4. include_once 'Database.php';
  5. class WebFunctions
  6. {
  7. function createMatchTable($matches, $betLevel, $bankValue)
  8. {
  9. echo '<table id="soccerMatchTable" class="display">';
  10. echo '<thead>';
  11. echo '<tr>';
  12. echo '<th>GameDate</th>';
  13. echo '<th>League</th>';
  14. echo '<th>Home Team</th>';
  15. echo '<th>Away Team</th>';
  16. echo '<th>Odds 1</th>';
  17. echo '<th>Odds X</th>';
  18. echo '<th>Odds 2</th>';
  19. echo '<th>Bet On</th>';
  20. echo '<th>Bet Amount</th>';
  21. echo '<th>Submit</th>';
  22. echo '</tr>';
  23. echo '</thead>';
  24. echo '<tbody>';
  25. foreach ($matches as $match) {
  26. $this->createMatchRow($match, $betLevel, $bankValue);
  27. }
  28. echo '</tbody>';
  29. echo '</table>';
  30. }
  31. function createMatchRow(
  32. SoccerMatch $match,
  33. float $betLevel,
  34. float $bankValue
  35. ) {
  36. $analysisValue = $this->getAnalysisValue($match);
  37. if ($analysisValue != 'No bet') {
  38. echo '<tr>';
  39. echo '<td>' . $match->getGameDate() . '</td>';
  40. echo '<td>' . $match->getHomeTeam()->getTeamLeague() . '</td>';
  41. echo '<td>' . $match->getHomeTeam()->getTeamName() . '</div></td>';
  42. echo '<td>' . $match->getAwayTeam()->getTeamName() . '</td>';
  43. echo '<td><div contenteditable>' .
  44. $match->getOdds1() .
  45. '</div></td>';
  46. echo '<td><div contenteditable>' .
  47. $match->getOddsX() .
  48. '</div></td>';
  49. echo '<td><div contenteditable>' .
  50. $match->getOdds2() .
  51. '</div></td>';
  52. echo '<td>' . $analysisValue;
  53. echo '<td>' . ($bankValue * $betLevel) / 100 . '</td>';
  54. echo '<td><button id="submitRowButton">Submit</button></td>';
  55. echo '</tr>';
  56. }
  57. }
  58. private function getAnalysisValue(SoccerMatch $match)
  59. {
  60. $database = new Database();
  61. $result = 'No bet';
  62. $analysis = new SoccerMatchAnalysis($match);
  63. $leagueInfo = $database->getLeagueInfo(
  64. $match->getHomeTeam()->getTeamLeagueId()
  65. );
  66. if ($leagueInfo != null) {
  67. $homeWinsCount = $analysis->winLossRatio(
  68. $leagueInfo->getWinLossRatio(),
  69. true
  70. );
  71. $awayWinsCount = $analysis->winLossRatio(
  72. $leagueInfo->getWinLossRatio(),
  73. false
  74. );
  75. $homeWinLossRatioCount = $analysis->winLossRatioHomeAndAway(
  76. true,
  77. $leagueInfo->getWinLossRatioHomeAndAway()
  78. );
  79. $awayWinLossRatioCount = $analysis->winLossRatioHomeAndAway(
  80. false,
  81. $leagueInfo->getWinLossRatioHomeAndAway()
  82. );
  83. $homeScoringTotal = $analysis->scoringTotal(
  84. $leagueInfo->getScoringTotal(),
  85. true
  86. );
  87. $awayScoringTotal = $analysis->scoringTotal(
  88. $leagueInfo->getScoringTotal(),
  89. false
  90. );
  91. $scoringDiffLastGames = $analysis->getScoringDiffLastGames(
  92. $leagueInfo->getScoringDiffLastGame()
  93. );
  94. $winsCountDiff = $homeWinsCount - $awayWinsCount;
  95. $winLossRatioDiff = $homeWinLossRatioCount - $awayWinLossRatioCount;
  96. $scoringTotalDiff = $homeScoringTotal - $awayScoringTotal;
  97. if (
  98. $scoringDiffLastGames < 0 &&
  99. $winsCountDiff < 0 &&
  100. $winLossRatioDiff < 0 &&
  101. $scoringTotalDiff < 0
  102. ) {
  103. $result =
  104. ($scoringDiffLastGames +
  105. $winsCountDiff +
  106. $winLossRatioDiff +
  107. $scoringTotalDiff) /
  108. 4;
  109. } elseif (
  110. $scoringDiffLastGames > 0 &&
  111. $winsCountDiff > 0 &&
  112. $winLossRatioDiff > 0 &&
  113. $scoringTotalDiff > 0
  114. ) {
  115. $result =
  116. ($scoringDiffLastGames +
  117. $winsCountDiff +
  118. $winLossRatioDiff +
  119. $scoringTotalDiff) /
  120. 4;
  121. }
  122. }
  123. return $result;
  124. }
  125. public function createOutstandingBetsTable()
  126. {
  127. $database = new Database();
  128. $bets = $database->getOutstandingBets();
  129. if ($bets == null) {
  130. return;
  131. }
  132. echo '<table id="outstandingBetsTable">';
  133. echo '<thead>';
  134. echo '<tr>';
  135. echo '<th>Game date</th>';
  136. echo '<th>League</th>';
  137. echo '<th>Teams</th>';
  138. echo '<th>Bet On</th>';
  139. echo '<th>Bet Amount</th>';
  140. echo '<th>Odds</th>';
  141. echo '<th>Status</th>';
  142. echo '</tr>';
  143. echo '</thead>';
  144. foreach ($bets as $bet) {
  145. $this->createOutstandingBetsRow($bet);
  146. }
  147. echo '<tbody>';
  148. echo '</table>';
  149. }
  150. private function createOutstandingBetsRow(Bet $bet)
  151. {
  152. echo '<tr>';
  153. echo '<td>' . $bet->getGameDate() . '</td>';
  154. echo '<td>' . $bet->getLeagueName() . '</td>';
  155. echo '<td>' . $bet->getTeams() . '</td>';
  156. echo '<td>' . $bet->getBetOn() . '</td>';
  157. echo '<td>' . $bet->getBetAmount() . '</td>';
  158. echo '<td>' . $bet->getOdds() . '</td>';
  159. echo '<td>' . $bet->getStatus() . '</td>';
  160. echo '</tr>';
  161. }
  162. }