Explorar el Código

Almost done with games table data

Axel Nordh hace 3 años
padre
commit
6e5c1ed5aa
Se han modificado 11 ficheros con 1103 adiciones y 7 borrados
  1. 48 0
      .vscode/launch.json
  2. 200 0
      Database.php
  3. 147 0
      League.php
  4. 0 0
      Match.php
  5. 80 0
      SoccerMatch.php
  6. 390 0
      SoccerMatchAnalysis.php
  7. 88 0
      Team.php
  8. 124 0
      WebFunctions.php
  9. 3 0
      fiveserver.config.js
  10. 20 7
      index.php
  11. 3 0
      styles.css

+ 48 - 0
.vscode/launch.json

@@ -0,0 +1,48 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Listen for Xdebug",
+            "type": "php",
+            "request": "launch",
+            "port": 9003
+        },
+        {
+            "name": "Launch currently open script",
+            "type": "php",
+            "request": "launch",
+            "program": "${file}",
+            "cwd": "${fileDirname}",
+            "port": 0,
+            "runtimeArgs": [
+                "-dxdebug.start_with_request=yes"
+            ],
+            "env": {
+                "XDEBUG_MODE": "debug,develop",
+                "XDEBUG_CONFIG": "client_port=${port}"
+            }
+        },
+        {
+            "name": "Launch Built-in web server",
+            "type": "php",
+            "request": "launch",
+            "runtimeArgs": [
+                "-dxdebug.mode=debug",
+                "-dxdebug.start_with_request=yes",
+                "-S",
+                "localhost:0"
+            ],
+            "program": "",
+            "cwd": "${workspaceRoot}",
+            "port": 9003,
+            "serverReadyAction": {
+                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
+                "uriFormat": "http://localhost:%s",
+                "action": "openExternally"
+            }
+        }
+    ]
+}

+ 200 - 0
Database.php

@@ -0,0 +1,200 @@
+<?php
+
+include_once 'Team.php';
+include_once 'SoccerMatch.php';
+include_once 'League.php';
+
+class Database
+{
+    private $conn;
+    function openConnection()
+    {
+        $dbhost = 'nordh.xyz';
+        $dbuser = 'OddsNy';
+        $dbPass = 'Odds1_Ny_Password';
+        $db = 'new_odds';
+
+        try {
+            $this->conn = new PDO(
+                "mysql:host=$dbhost;dbname=$db",
+                $dbuser,
+                $dbPass
+            );
+            $this->conn->setAttribute(
+                PDO::ATTR_ERRMODE,
+                PDO::ERRMODE_EXCEPTION
+            );
+        } catch (Exception $e) {
+            echo 'Exception ' . $e->getMessage();
+        }
+    }
+
+    function closeConnection($conn)
+    {
+        $conn = null;
+    }
+
+    function getConnection()
+    {
+        if (!isset($this->conn)) {
+            $this->openConnection();
+        }
+        return $this->conn;
+    }
+
+    function getTodaysPrioMatches()
+    {
+        $this->openConnection();
+
+        $result = [];
+        $sql = 'SELECT sr.*,
+            ht.id as homeTeamId, ht.name as homeTeamName, ht.countryId as homeTeamCountryId, ht.leagueId as homeTeamLeagueId,
+            awt.id as awayTeamId, awt.name as awayTeamName, awt.countryId as awayTeamCountryId, awt.leagueId as awayTeamLeagueId,
+            l.name as leagueName,
+            c.name as countryName
+            FROM SoccerResults sr
+            INNER JOIN Team ht on ht.id = sr.homeTeamId
+            INNER JOIN Team awt on awt.id = sr.awayTeamId
+            INNER JOIN League l ON l.id = sr.leagueId
+            INNER JOIN Country c ON c.id = sr.countryId
+            WHERE sr.leagueId IN (SELECT id FROM League WHERE prio = 1) AND DATE(gameDate) = DATE(NOW())';
+
+        $stat = $this->conn->query($sql);
+        $matches = $stat->fetchAll();
+
+        foreach ($matches as $match) {
+            $homeTeam = new Team(
+                $match['homeTeamId'],
+                $match['homeTeamName'],
+                $match['homeTeamCountryId'],
+                $match['countryName'],
+                $match['homeTeamLeagueId'],
+                $match['leagueName']
+            );
+            $awayTeam = new Team(
+                $match['awayTeamId'],
+                $match['awayTeamName'],
+                $match['awayTeamCountryId'],
+                $match['countryName'],
+                $match['awayTeamLeagueId'],
+                $match['leagueName']
+            );
+            $m = new SoccerMatch(
+                $match['id'],
+                $homeTeam,
+                $awayTeam,
+                $match['odds1'],
+                $match['oddsX'],
+                $match['odds2'],
+                $match['homeScore'],
+                $match['awayScore'],
+                $match['gameDate'],
+                $match['season']
+            );
+
+            $result[] = $m;
+        }
+
+        $this->closeConnection($this->conn);
+        return $result;
+    }
+
+    public function getLeagueTable($leagueId, $season, $countryId, $date)
+    {
+        $this->openConnection();
+        $result = [];
+
+        $sql = "SELECT teamName.name AS teamName,
+        COUNT(*) AS played,
+        SUM(CASE WHEN homeScore > awayScore THEN 1 ELSE 0 END) AS wins,
+        SUM(CASE WHEN awayScore > homeScore THEN 1 ELSE 0 END) AS lost,
+        SUM(CASE WHEN homeScore = awayScore THEN 1 ELSE 0 END) AS draws,
+        SUM(homeScore) AS homeScore,
+        SUM(awayScore) AS awayScore,
+        SUM(homeScore - awayScore) AS goal_diff,
+        SUM(CASE WHEN homeScore > awayScore THEN 3 ELSE 0 END + CASE WHEN homeScore = awayScore THEN 1 ELSE 0 END) AS score,
+        season
+ FROM
+   (SELECT hometeamId AS team,
+           homeScore,
+           awayScore,
+           season,
+           gameDate,
+           leagueId AS league,
+           countryId AS country
+    FROM SoccerResults
+    WHERE homeScore != -1 AND awayScore != -1 AND DATE(gameDate) < DATE(?)
+    UNION ALL
+    SELECT awayteamId AS team,
+           awayScore,
+           homeScore,
+           season,
+           gameDate,
+           leagueId AS league,
+           countryId AS country
+    FROM SoccerResults
+    WHERE homeScore != -1 AND awayScore != -1 AND DATE(gameDate) < DATE(?)) a
+ INNER JOIN Team AS teamName ON a.team = teamName.id
+ WHERE season = ? AND league = ? AND country = ?
+ GROUP BY teamName.id
+ ORDER BY score DESC, goal_diff DESC;";
+
+        $stmt = $this->conn->prepare($sql);
+
+        $stmt->bindParam(1, $season);
+        $stmt->bindParam(2, $leagueId);
+        $stmt->bindParam(3, $countryId);
+        $stmt->bindParam(4, $date);
+
+        $stmt->execute();
+
+        while ($row = $stmt->fetch()) {
+            $ts = [
+                'teamName' => $row['teamName'],
+                'wins' => $row['wins'],
+                'lost' => $row['lost'],
+                'draws' => $row['draws'],
+                'score' => $row['score'],
+                'homeScore' => $row['homeScore'],
+                'awayScore' => $row['awayScore'],
+                'goal_diff' => $row['goal_diff'],
+            ];
+            array_push($result, $ts);
+        }
+
+        $this->closeConnection($this->conn);
+        return $result;
+    }
+
+    function getLeagueInfo($leagueId)
+    {
+        $this->openConnection();
+        $sql = 'SELECT * FROM League WHERE id = ?';
+        $result = null;
+        try {
+            $stat = $this->conn->prepare($sql);
+            $stat->bindParam(1, $leagueId);
+            $stat->execute();
+
+            while ($row = $stat->fetch()) {
+                $result = new League(
+                    $row['id'],
+                    $row['name'],
+                    $row['scoringDiffLastGame'],
+                    $row['scoringTotal'],
+                    $row['winLossRatioHomeAndAway'],
+                    $row['winLossRatio'],
+                    $row['drawDiffHomeAway'],
+                    $row['drawDiffTotalGoals'],
+                    $row['drawWinningForm'],
+                    $row['drawWinningFormHomeAway']
+                );
+            }
+        } catch (PDOException $e) {
+            echo 'Connection failed: ' . $e->getMessage();
+        }
+
+        $this->closeConnection($this->conn);
+        return $result;
+    }
+}

+ 147 - 0
League.php

@@ -0,0 +1,147 @@
+<?php
+
+class League
+{
+    public $leagueId;
+    public $leagueName;
+    public $lookback;
+    public $betMargin;
+    public $lookbackHome;
+    public $lookbackDraw;
+    public $lookbackAway;
+    public $betMarginHome;
+    public $betMarginDraw;
+    public $betMarginAway;
+    public $scoringDiffLastGame;
+    public $scoringTotal;
+    public $winLossRatioHomeAndAway;
+    public $winLossRatio;
+    private $drawDiffHomeAway;
+    private $drawTotalGoals;
+    private $drawWinningForm;
+    private $drawWinningFormHomeAway;
+
+    public function __construct(
+        $leagueId,
+        $leagueName,
+        $scoringDiffLastGame,
+        $scoringTotal,
+        $winLossRatioHomeAndAway,
+        $winLossRatio,
+        $drawDiffHomeAway,
+        $drawTotalGoals,
+        $drawWinningForm,
+        $drawWinningFormHomeAway
+    ) {
+        $this->leagueId = $leagueId;
+        $this->leagueName = $leagueName;
+        $this->scoringDiffLastGame = $scoringDiffLastGame;
+        $this->scoringTotal = $scoringTotal;
+        $this->winLossRatioHomeAndAway = $winLossRatioHomeAndAway;
+        $this->winLossRatio = $winLossRatio;
+        $this->drawDiffHomeAway = $drawDiffHomeAway;
+        $this->drawTotalGoals = $drawTotalGoals;
+        $this->drawWinningForm = $drawWinningForm;
+        $this->drawWinningFormHomeAway = $drawWinningFormHomeAway;
+    }
+
+    public function getBetMargin()
+    {
+        return $this->betMargin;
+    }
+
+    public function getBetMarginAway()
+    {
+        return $this->betMarginAway;
+    }
+
+    public function getBetMarginDraw()
+    {
+        return $this->betMarginDraw;
+    }
+
+    public function getBetMarginHome()
+    {
+        return $this->betMarginHome;
+    }
+
+    public function getDrawDiffHomeAway()
+    {
+        return $this->drawDiffHomeAway;
+    }
+
+    public function getDrawTotalGoals()
+    {
+        return $this->drawTotalGoals;
+    }
+
+    public function getDrawWinningForm()
+    {
+        return $this->drawWinningForm;
+    }
+
+    public function getDrawWinningFormHomeAway()
+    {
+        return $this->drawWinningFormHomeAway;
+    }
+
+    public function getLeagueId()
+    {
+        return $this->leagueId;
+    }
+
+    public function getLeagueName()
+    {
+        return $this->leagueName;
+    }
+
+    public function getLookback()
+    {
+        return $this->lookback;
+    }
+
+    public function getLookbackAway()
+    {
+        return $this->lookbackAway;
+    }
+
+    public function getLookbackDraw()
+    {
+        return $this->lookbackDraw;
+    }
+
+    public function getLookbackHome()
+    {
+        return $this->lookbackHome;
+    }
+
+    public function getScoringDiffLastGame()
+    {
+        return $this->scoringDiffLastGame;
+    }
+
+    public function getScoringTotal()
+    {
+        return $this->scoringTotal;
+    }
+
+    public function getWinLossRatio()
+    {
+        return $this->winLossRatio;
+    }
+
+    public function getWinLossRatioHomeAndAway()
+    {
+        return $this->winLossRatioHomeAndAway;
+    }
+
+    public function setBetMargin($betMargin)
+    {
+        $this->betMargin = $betMargin;
+    }
+
+    public function setBetMarginAway($betMargin)
+    {
+        $this->betMarginAway = $betMargin;
+    }
+}

+ 0 - 0
Match.php


+ 80 - 0
SoccerMatch.php

@@ -0,0 +1,80 @@
+<?php
+
+class SoccerMatch
+{
+    private string $gameDate;
+    private Team $homeTeam;
+    private Team $awayTeam;
+
+    private int $matchId;
+    private int $homeScore; // Actual Result home
+    private int $awayScore; // Actual Result away
+    private string $season;
+
+    private string $homeTeamName;
+    private string $awayTeamName;
+    private float $odds1;
+    private float $oddsX;
+    private float $odds2;
+    private $leagueName;
+
+    public function __construct(
+        $id,
+        $homeTeam,
+        $awayTeam,
+        $odds1,
+        $oddsX,
+        $odds2,
+        $homeScore,
+        $awayScore,
+        $gameDate,
+        $season
+    ) {
+        $this->matchId = $id;
+        $this->homeTeam = $homeTeam;
+        $this->awayTeam = $awayTeam;
+        $this->odds1 = $odds1;
+        $this->oddsX = $oddsX;
+        $this->odds2 = $odds2;
+        $this->homeScore = $homeScore;
+        $this->awayScore = $awayScore;
+        $this->gameDate = $gameDate;
+        $this->season = $season;
+        $this->homeTeamName = $homeTeam->getTeamName();
+        $this->awayTeamName = $awayTeam->getTeamName();
+    }
+
+    public function getHomeTeam()
+    {
+        return $this->homeTeam;
+    }
+
+    public function getGameDate()
+    {
+        return $this->gameDate;
+    }
+
+    public function getAwayTeam()
+    {
+        return $this->awayTeam;
+    }
+
+    public function getOdds1()
+    {
+        return $this->odds1;
+    }
+
+    public function getOddsX()
+    {
+        return $this->oddsX;
+    }
+    public function getOdds2()
+    {
+        return $this->odds2;
+    }
+
+    public function getLeagueName()
+    {
+        return $this->leagueName;
+    }
+}

+ 390 - 0
SoccerMatchAnalysis.php

@@ -0,0 +1,390 @@
+<?php
+
+include_once 'Database.php';
+include_once 'SoccerMatch.php';
+
+class SoccerMatchAnalysis
+{
+    private SoccerMatch $match;
+    private Database $database;
+    private $leagueTable;
+    private $leagueTableUpdated;
+
+    public function __construct(SoccerMatch $match)
+    {
+        $this->match = $match;
+        $this->database = new Database();
+    }
+
+    /**
+     * Antalet mål som hemmalaget gjort de senaste "gamesLookback" matcherna -
+     * antalet mål för bortalaget under samma period
+     *
+     * @param int $gamesLookback - hur många matcher bakåt i tiden som ska kontrolleras
+     * @return float med skillnaden i mål mellan lagen hemma/borta
+     * @throws \Exception
+     */
+    public function getScoringDiffLastGames(int $gamesLookback): float
+    {
+        $homeRes = 0;
+        $awayRes = 0;
+
+        $sql =
+            'SELECT * FROM ' .
+            '(SELECT * FROM SoccerResults WHERE homeTeamId = ? AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) ht ' .
+            'UNION DISTINCT ' .
+            '(SELECT * FROM SoccerResults WHERE awayTeamId = ? AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?)';
+
+        $stmt = $this->database->getConnection()->prepare($sql);
+
+        $homeTeamId = $this->match->getHomeTeam()->getTeamId();
+        $leagueId = $this->match->getHomeTeam()->getTeamLeagueId();
+        $gameDate = $this->match->getGameDate();
+        $awayTeamId = $this->match->getAwayTeam()->getTeamId();
+
+        $stmt->bindParam(1, $homeTeamId, PDO::PARAM_INT);
+        $stmt->bindParam(2, $leagueId, PDO::PARAM_INT);
+        $stmt->bindParam(3, $gameDate);
+        $stmt->bindParam(4, $gamesLookback, PDO::PARAM_INT);
+
+        $stmt->bindParam(5, $awayTeamId, PDO::PARAM_INT);
+        $stmt->bindParam(6, $leagueId, PDO::PARAM_INT);
+        $stmt->bindParam(7, $gameDate);
+        $stmt->bindParam(8, $gamesLookback, PDO::PARAM_INT);
+
+        $stmt->execute();
+        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+        foreach ($rows as $row) {
+            if (
+                $this->match->getHomeTeam()->getTeamId() ===
+                (int) $row['homeTeamId']
+            ) {
+                $homeRes += (int) $row['homeScore'];
+            }
+            if (
+                $this->match->getAwayTeam()->getTeamId() ===
+                (int) $row['awayTeamId']
+            ) {
+                $awayRes += (int) $row['awayScore'];
+            }
+        }
+
+        return $homeRes - $awayRes;
+    }
+
+    /**
+     *
+     * Plocka fram antalet mål som ett specifikt lag gjort under de senaste
+     * <gamesLookback> matcherna
+     *
+     * @param int $gamesLookback - hur många matcher bakåt i tiden som ska kontrolleras
+     * @param bool $homeTeam      - är det hemma laget som ska kontrolleras i matchen
+     * @return int antalet mål som är gjorda av bestämt lag.
+     */
+    public function scoringTotal(int $gamesLookback, bool $homeTeam): int
+    {
+        $result = 0;
+        $sql =
+            'SELECT * FROM ' .
+            '(SELECT * FROM SoccerResults WHERE homeTeamId = ? AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) ht ' .
+            'UNION DISTINCT ' .
+            '(SELECT * FROM SoccerResults WHERE awayTeamId = ? AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?)';
+
+        try {
+            $stat = $this->database->getConnection()->prepare($sql);
+            $team = $homeTeam
+                ? $this->match->getHomeTeam()
+                : $this->match->getAwayTeam();
+
+            $stat->bindValue(1, $team->getTeamId(), PDO::PARAM_INT);
+            $stat->bindValue(2, $team->getTeamLeagueId(), PDO::PARAM_INT);
+            $stat->bindValue(3, $this->match->getGameDate());
+            $stat->bindValue(4, $gamesLookback, PDO::PARAM_INT);
+            $stat->bindValue(5, $team->getTeamId(), PDO::PARAM_INT);
+            $stat->bindValue(6, $team->getTeamLeagueId(), PDO::PARAM_INT);
+            $stat->bindValue(7, $this->match->getGameDate());
+            $stat->bindValue(8, $gamesLookback, PDO::PARAM_INT);
+
+            $stat->execute();
+            $rs = $stat->fetchAll(PDO::FETCH_ASSOC);
+
+            foreach ($rs as $row) {
+                if ($row['homeTeamId'] == $team->getTeamId()) {
+                    $result += $row['homeScore'];
+                } elseif ($row['awayTeamId'] == $team->getTeamId()) {
+                    $result += $row['awayScore'];
+                }
+            }
+        } catch (PDOException $e) {
+            echo 'Error: ' . $e->getMessage();
+        }
+        return $result;
+    }
+
+    /**
+     * Hämta tabell positionen för hemma eller borta laget
+     *
+     * @param bool $homeTeam - är det hemma laget som ska kontrolleras för matchen?
+     * @return int position för specifierat lag
+     */
+    public function getTablePosition(bool $homeTeam): int
+    {
+        $result = 0;
+        $this->updateLeagueTable();
+        $teamName = $homeTeam
+            ? $this->match->getHomeTeam()->getTeamName()
+            : $this->match->getAwayTeam()->getTeamName();
+        $standingOptional = array_filter($this->leagueTable, function ($p) use (
+            $teamName
+        ) {
+            return $p->getTeamName() == $teamName;
+        });
+
+        if (!empty($standingOptional)) {
+            $standing = reset($standingOptional);
+            $result = array_search($standing, $this->leagueTable);
+        }
+        return $result;
+    }
+
+    private function updateLeagueTable()
+    {
+        global $leagueTableUpdated, $leagueTable, $database, $match;
+        if ($leagueTableUpdated != $match->getGameDate()->format('Y-m-d')) {
+            $leagueTable = $database->getLeagueTable(
+                $match->getHomeTeam()->getTeamLeagueId(),
+                $match->getSeason(),
+                $match->getHomeTeam()->getCountryId(),
+                $match->getGameDate()->format('Y-m-d')
+            );
+
+            $leagueTableUpdated = $match->getGameDate()->format('Y-m-d');
+        }
+    }
+
+    /**
+     *
+     * @return Integer - hur många platser det är mellan hemma och borta laget
+     */
+    public function diffInStanding()
+    {
+        global $leagueTable, $match;
+        $result = 0;
+        $this->updateLeagueTable();
+
+        $homeTeamStandingOptional = array_values(
+            array_filter($leagueTable, function ($p) use ($match) {
+                return $p->getTeamName() ==
+                    $match->getHomeTeam()->getTeamName();
+            })
+        );
+
+        $awayTeamStandingOptional = array_values(
+            array_filter($leagueTable, function ($p) use ($match) {
+                return $p->getTeamName() ==
+                    $match->getAwayTeam()->getTeamName();
+            })
+        );
+
+        if (
+            !empty($homeTeamStandingOptional) &&
+            !empty($awayTeamStandingOptional)
+        ) {
+            $homeStanding = $homeTeamStandingOptional[0];
+            $awayStanding = $awayTeamStandingOptional[0];
+
+            $result =
+                array_search($homeStanding, $leagueTable) -
+                array_search($awayStanding, $leagueTable);
+        }
+        return $result;
+    }
+
+    /**
+     *
+     * Vinst förlust ratio för om man är enbart hemma eller bortalag.
+     *
+     * @param gamesLookback
+     * @param homeTeam
+     * @return int där vinst ger +1 lika ger 0 och förlust get -1
+     */
+    public function winLossRatio($gamesLookback, $homeTeam)
+    {
+        global $match, $database;
+        $result = 0;
+
+        $team = $homeTeam
+            ? $this->match->getHomeTeam()
+            : $this->match->getAwayTeam();
+
+        $teamSql = $homeTeam ? 'homeTeamId = ? ' : 'awayTeamId = ? ';
+        $sql =
+            'SELECT * FROM SoccerResults WHERE ' .
+            $teamSql .
+            'AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?';
+
+        $stmt = $database->getConnection()->prepare($sql);
+        $stmt->bindValue(1, $team->getTeamId(), PDO::PARAM_INT);
+        $stmt->bindValue(2, $team->getTeamLeagueId(), PDO::PARAM_INT);
+        $stmt->bindValue(3, $this->match->getGameDate(), PDO::PARAM_STR);
+        $stmt->bindValue(4, $gamesLookback, PDO::PARAM_INT);
+        $stmt->execute();
+
+        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+            $homeScore = $row['homeScore'];
+            $awayScore = $row['awayScore'];
+            if ($homeTeam) {
+                if ($homeScore > $awayScore) {
+                    $result++;
+                } elseif ($homeScore < $awayScore) {
+                    $result--;
+                }
+            } else {
+                if ($homeScore > $awayScore) {
+                    $result--;
+                } elseif ($homeScore < $awayScore) {
+                    $result++;
+                }
+            }
+        }
+
+        return $result;
+    }
+
+    public function winLossRatioHomeAndAway($homeTeam, $gamesLookback)
+    {
+        $result = 0;
+
+        $sql = 'SELECT gameDate, homeTeamId, awayTeamId, homeScore, awayScore, leagueId
+        FROM
+        (SELECT gameDate, homeTeamId, awayTeamId, homeScore, awayScore, leagueId
+        FROM SoccerResults
+        WHERE homeTeamId = ? AND leagueId = ? AND gameDate < ?
+        ORDER BY gameDate DESC
+        LIMIT ?) a
+        UNION ALL
+        SELECT gameDate, homeTeamId, awayTeamId, homeScore, awayScore, leagueId
+        FROM SoccerResults
+        WHERE awayTeamId = ? AND leagueId = ? AND gameDate < ?
+        ORDER BY gameDate DESC
+        LIMIT ?';
+
+        $team = $homeTeam
+            ? $this->match->getHomeTeam()
+            : $this->match->getAwayTeam();
+        try {
+            $teamId = $team->getTeamId();
+            $leagueId = $team->getTeamLeagueId();
+            $gameDate = $this->match->getGameDate();
+
+            $stat = $this->database->getConnection()->prepare($sql);
+            $stat->bindParam(1, $teamId, PDO::PARAM_INT);
+            $stat->bindParam(2, $leagueId, PDO::PARAM_INT);
+            $stat->bindParam(3, $gameDate, PDO::PARAM_STR);
+            $stat->bindParam(4, $gamesLookback, PDO::PARAM_INT);
+            $stat->bindParam(5, $teamId, PDO::PARAM_INT);
+            $stat->bindParam(6, $leagueId, PDO::PARAM_INT);
+            $stat->bindParam(7, $gameDate, PDO::PARAM_STR);
+            $stat->bindParam(8, $gamesLookback, PDO::PARAM_INT);
+            $stat->execute();
+            $rs = $stat->fetchAll(PDO::FETCH_ASSOC);
+
+            foreach ($rs as $row) {
+                if (
+                    $row['homeTeamId'] == $team->getTeamId() &&
+                    $row['homeScore'] > $row['awayScore']
+                ) {
+                    $result++;
+                } elseif (
+                    $row['awayTeamId'] == $team->getTeamId() &&
+                    $row['awayScore'] > $row['homeScore']
+                ) {
+                    $result++;
+                } else {
+                    $result--;
+                }
+            }
+        } catch (PDOException $e) {
+            echo $e->getMessage();
+        }
+
+        return $result;
+    }
+
+    public function goalsScoredHomeAndAway($homeTeam, $gameLookback)
+    {
+        $result = 0;
+        $team = $homeTeam
+            ? $this->match->getHomeTeam()
+            : $this->match->getAwayTeam();
+
+        $sql =
+            'SELECT * FROM ' .
+            '(SELECT * FROM SoccerResults WHERE homeTeamId = ? AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) a ' .
+            'UNION ALL ' .
+            '(SELECT * FROM SoccerResults WHERE awayTeamId = ? AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ?) ' .
+            'ORDER BY gameDate DESC ' .
+            'LIMIT ?';
+
+        try {
+            $stat = $this->database->getConnection()->prepare($sql);
+            $stat->bindParam(1, $team->getTeamId());
+            $stat->bindParam(2, $team->getTeamLeagueId());
+            $stat->bindParam(3, $this->match->getGameDate());
+            $stat->bindParam(4, $gameLookback, PDO::PARAM_INT);
+            $stat->bindParam(5, $team->getTeamId());
+            $stat->bindParam(6, $team->getTeamLeagueId());
+            $stat->bindParam(7, $this->match->getGameDate());
+            $stat->bindParam(8, $gameLookback, PDO::PARAM_INT);
+            $stat->bindParam(9, $gameLookback, PDO::PARAM_INT);
+
+            $stat->execute();
+
+            while ($row = $stat->fetch(PDO::FETCH_ASSOC)) {
+                if ($row['homeTeamId'] == $team->getTeamId()) {
+                    $result += $row['homeScore'];
+                }
+                if ($row['awayTeamId'] == $team->getTeamId()) {
+                    $result += $row['awayScore'];
+                }
+            }
+        } catch (PDOException $e) {
+            $e->getMessage();
+        }
+        return $result;
+    }
+
+    public function goalsScoredHomeOrAway($homeTeam, $gameLookback)
+    {
+        $result = 0;
+        $team = $homeTeam
+            ? $this->match->getHomeTeam()
+            : $this->match->getAwayTeam();
+        $homeOrAway = $homeTeam ? 'home' : 'away';
+        $sql =
+            'SELECT SUM(' .
+            $homeOrAway .
+            'Score) FROM SoccerResults WHERE ' .
+            $homeOrAway .
+            'TeamId = ? AND leagueId = ? AND DATE(gameDate) < ? ORDER BY gameDate DESC LIMIT ? ' .
+            'ORDER BY gameDate DESC';
+
+        try {
+            $stat = $this->database->getConnection()->prepare($sql);
+            $stat->bindParam(1, $team->getTeamId());
+            $stat->bindParam(2, $team->getTeamLeagueId());
+            $stat->bindParam(3, $this->match->getGameDate());
+            $stat->bindParam(4, $gameLookback, PDO::PARAM_INT);
+
+            $stat->execute();
+
+            while ($row = $stat->fetch(PDO::FETCH_ASSOC)) {
+                $result += $row[$homeOrAway . 'Score'];
+            }
+        } catch (PDOException $e) {
+            $e->getMessage();
+        }
+        return $result;
+    }
+}

+ 88 - 0
Team.php

@@ -0,0 +1,88 @@
+<?php
+
+class Team
+{
+    private int $teamId;
+    private string $teamName;
+    private int $countryId;
+    private string $countryName;
+    private int $teamLeagueId;
+    private string $teamLeague;
+
+    public function __construct(
+        $teamId,
+        $teamName,
+        $countryId,
+        $countryName,
+        $teamLeagueId,
+        $teamLeague
+    ) {
+        $this->teamId = $teamId;
+        $this->teamName = $teamName;
+        $this->countryId = $countryId;
+        $this->countryName = $countryName;
+        $this->teamLeagueId = $teamLeagueId;
+        $this->teamLeague = $teamLeague;
+    }
+
+    // Getters and Setters
+    public function getTeamId()
+    {
+        return $this->teamId;
+    }
+
+    public function setTeamId($teamId)
+    {
+        $this->teamId = $teamId;
+    }
+
+    public function getTeamName()
+    {
+        return $this->teamName;
+    }
+
+    public function setTeamName($teamName)
+    {
+        $this->teamName = $teamName;
+    }
+
+    public function getCountryId()
+    {
+        return $this->countryId;
+    }
+
+    public function setCountryId($countryId)
+    {
+        $this->countryId = $countryId;
+    }
+
+    public function getCountryName()
+    {
+        return $this->countryName;
+    }
+
+    public function setCountryName($countryName)
+    {
+        $this->countryName = $countryName;
+    }
+
+    public function getTeamLeagueId()
+    {
+        return $this->teamLeagueId;
+    }
+
+    public function setTeamLeagueId($teamLeagueId)
+    {
+        $this->teamLeagueId = $teamLeagueId;
+    }
+
+    public function getTeamLeague()
+    {
+        return $this->teamLeague;
+    }
+
+    public function setTeamLeague($teamLeague)
+    {
+        $this->teamLeague = $teamLeague;
+    }
+}

+ 124 - 0
WebFunctions.php

@@ -0,0 +1,124 @@
+<?php
+
+include_once 'SoccerMatchAnalysis.php';
+include_once 'SoccerMatch.php';
+include_once 'Database.php';
+
+class WebFunctions
+{
+    function createMatchTable($matches)
+    {
+        echo '<table>';
+        echo '<th>GameDate</th>';
+        echo '<th>League</th>';
+        echo '<th>Home Team</th>';
+        echo '<th>Away Team</th>';
+
+        echo '<th>Odds 1</th>';
+        echo '<th>Odds X</th>';
+        echo '<th>Odds 2</th>';
+
+        echo '<th>Bet On</th>';
+        echo '<th>Bet Amount</th>';
+
+        echo '<th>Submit</th>';
+
+        foreach ($matches as $match) {
+            $this->createMatchRow($match);
+        }
+
+        echo '</table>';
+    }
+
+    function createMatchRow(SoccerMatch $match)
+    {
+        echo '<tr>';
+
+        echo '<td>' . $match->getGameDate() . '</td>';
+        echo '<td>' . $match->getHomeTeam()->getTeamLeague() . '</td>';
+
+        echo '<td>' . $match->getHomeTeam()->getTeamName() . '</td>';
+        echo '<td>' . $match->getAwayTeam()->getTeamName() . '</td>';
+        echo '<td>' . $match->getOdds1() . '</td>';
+        echo '<td>' . $match->getOddsX() . '</td>';
+        echo '<td>' . $match->getOdds2() . '</td>';
+
+        echo '<td>' . $this->getAnalysisValue($match);
+
+        echo '</tr>';
+    }
+
+    private function getAnalysisValue(SoccerMatch $match)
+    {
+        $database = new Database();
+        $result = 'No bet';
+        $analysis = new SoccerMatchAnalysis($match);
+        $leagueInfo = $database->getLeagueInfo(
+            $match->getHomeTeam()->getTeamLeagueId()
+        );
+        if ($leagueInfo != null) {
+            $homeWinsCount = $analysis->winLossRatio(
+                $leagueInfo->getWinLossRatio(),
+                true
+            );
+            $awayWinsCount = $analysis->winLossRatio(
+                $leagueInfo->getWinLossRatio(),
+                false
+            );
+            $homeWinLossRatioCount = $analysis->winLossRatioHomeAndAway(
+                true,
+                $leagueInfo->getWinLossRatioHomeAndAway()
+            );
+
+            $awayWinLossRatioCount = $analysis->winLossRatioHomeAndAway(
+                false,
+                $leagueInfo->getWinLossRatioHomeAndAway()
+            );
+
+            $homeScoringTotal = $analysis->scoringTotal(
+                $leagueInfo->getScoringTotal(),
+                true
+            );
+            $awayScoringTotal = $analysis->scoringTotal(
+                $leagueInfo->getScoringTotal(),
+                false
+            );
+
+            $scoringDiffLastGames = $analysis->getScoringDiffLastGames(
+                $leagueInfo->getScoringDiffLastGame()
+            );
+
+            $winsCountDiff = $homeWinsCount - $awayWinsCount;
+            $winLossRatioDiff = $homeWinLossRatioCount - $awayWinLossRatioCount;
+            $scoringTotalDiff = $homeScoringTotal - $awayScoringTotal;
+
+            if (
+                $scoringDiffLastGames < 0 &&
+                $winsCountDiff < 0 &&
+                $winLossRatioDiff < 0 &&
+                $scoringTotalDiff < 0
+            ) {
+                $result =
+                    ($scoringDiffLastGames +
+                        $winsCountDiff +
+                        $winLossRatioDiff +
+                        $scoringTotalDiff) /
+                    4;
+            } elseif (
+                $scoringDiffLastGames > 0 &&
+                $winsCountDiff > 0 &&
+                $winLossRatioDiff > 0 &&
+                $scoringTotalDiff > 0
+            ) {
+                $result =
+                    ($scoringDiffLastGames +
+                        $winsCountDiff +
+                        $winLossRatioDiff +
+                        $scoringTotalDiff) /
+                    4;
+            }
+        }
+
+        return $result;
+    }
+}

+ 3 - 0
fiveserver.config.js

@@ -0,0 +1,3 @@
+module.exports = {
+    php: "D:\\Programming\\php-8\\php.exe"
+}

+ 20 - 7
index.php

@@ -1,18 +1,31 @@
-<head>
+<?php
+
+include_once 'Database.php';
+include_once 'WebFunctions.php';
+?>
 
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset='utf-8'>
+    <meta http-equiv='X-UA-Compatible'>
+    <title>Odds webspace</title>
+    <meta name='viewport' content='width=device-width, initial-scale=1'>
+    <link rel='stylesheet' type='text/css' media='screen' href='styles.css'>
 </head>
 
 <body>
 
+
 <h1> Odds better </h1>
 
 
 <?php
-
-
-
+$database = new Database();
+$matches = $database->getTodaysPrioMatches();
+$wf = new WebFunctions();
+$wf->createMatchTable($matches);
 ?>
+</body>
 
-
-
-</body>
+</html>

+ 3 - 0
styles.css

@@ -0,0 +1,3 @@
+table, th {
+    border: 1px solid black;
+}