diff --git a/public/home.html b/public/home.html index 44e692a..56e7127 100644 --- a/public/home.html +++ b/public/home.html @@ -39,9 +39,21 @@

Highest paydirt score

+ + + + + +

Highest offense score

+ + + + + +
diff --git a/public/home.js b/public/home.js index 84f8b51..d1371d2 100644 --- a/public/home.js +++ b/public/home.js @@ -7,6 +7,94 @@ const highest = document.querySelector("#highest"); updateHighest(); updateFavorites(); +updatePaydirt(); +updateOffense(); + +async function updateOffense() { + if (!verifyLogin()) return; + + + const offenseHeader = document.querySelector("#offense thead"); + const offenseBody = document.querySelector("#offense tbody"); + + + let resultObject = await postData("/getHighestOffense", { amount: 10 }, token); + console.log(resultObject); + + if (resultObject.matches.length === 0) { + alert("Error loading scores"); + return; + } + + offenseHeader.innerHTML = ""; + const headerRow = document.createElement("tr"); + //Object.keys(resultObject.matches[0]).forEach(attribute => { + // headerRow.innerHTML += `${attribute}`; + //}); + headerRow.innerHTML = ` + Position + Name + Team + Offense Score + `; + offenseHeader.appendChild(headerRow); + + offenseBody.innerHTML = ""; + resultObject.matches.forEach(player => { + const row = document.createElement("tr"); + + row.innerHTML = ` + ${player.Position} + ${player.PlayerName} + ${player.Team} + ${(player.OffenseScore + "000000").slice(0, 8)} + `; + offenseBody.appendChild(row); + }); +}; + +async function updatePaydirt() { + if (!verifyLogin()) return; + + + const paydirtHeader = document.querySelector("#paydirt thead"); + const paydirtBody = document.querySelector("#paydirt tbody"); + + + let resultObject = await postData("/getHighestPaydirt", { amount: 10 }, token); + console.log(resultObject); + + if (resultObject.matches.length === 0) { + alert("Error loading scores"); + return; + } + + paydirtHeader.innerHTML = ""; + const headerRow = document.createElement("tr"); + //Object.keys(resultObject.matches[0]).forEach(attribute => { + // headerRow.innerHTML += `${attribute}`; + //}); + headerRow.innerHTML = ` + Position + Name + Team + Paydirt Score + `; + paydirtHeader.appendChild(headerRow); + + paydirtBody.innerHTML = ""; + resultObject.matches.forEach(player => { + const row = document.createElement("tr"); + + row.innerHTML = ` + ${player.Position} + ${player.PlayerName} + ${player.Team} + ${(player.PaydirtScore + "000000").slice(0, 8)} + `; + paydirtBody.appendChild(row); + }); +}; async function updateHighest() { if (!verifyLogin()) return; diff --git a/server.js b/server.js index 683eda7..7503b30 100644 --- a/server.js +++ b/server.js @@ -188,6 +188,131 @@ app.post("/getHighest", authenticate, async (req, res) => { res.status(200).json({ matches: result.recordset }); }); +app.post("/getHighestOffense", authenticate, async (req, res) => { + const { amount } = req.body; + + const result = await pool.request() + .input("amount", sql.Int, amount) + .query(` +SELECT TOP (@amount) Player.[Position], Player.PlayerName, Player.Team, +SUM(total_yards) AS TotalYards, +SUM(passing_yards) AS PassingYards, +SUM(rushing_yards) AS RushingYards, +SUM(receiving_yards) AS RecievingYards, +CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END + SUM(receiving_touchdown) + SUM(rush_touchdown) AS AmendedTotalTDs, +CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END AS PassTDs, +SUM(receiving_touchdown) AS ReceivingTDs, +SUM(rush_touchdown) AS RushTDs, +SUM(offense_snaps) * 1.0 / SUM(team_offense_snaps) AS SnapPercentage, +SUM(interception) + sum(fumble_lost) AS Turnovers, +SUM(tackled_for_loss) AS TackledForLoss, + CASE + WHEN Player.Position = 'QB' + THEN SUM(qb_dropback) - SUM(pass_attempts) - SUM(qb_scramble) + ELSE 0 + END AS Sacks, +SUM(safety) AS Safties, + +SUM(total_yards) ++ ((CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END + SUM(receiving_touchdown) + SUM(rush_touchdown)) * 50) ++ (SUM(offense_snaps) * 100.0 / SUM(team_offense_snaps)) +- ((SUM(interception) + sum(fumble_lost)) * 75) +- ( + CASE + WHEN Player.Position = 'QB' + THEN SUM(qb_dropback) - SUM(pass_attempts) - SUM(qb_scramble) + ELSE 0 + END) + +- (SUM(safety) * 100.0) +AS OffenseScore, + +AvgPerYear, +(SUM(total_yards) ++ ((CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END + SUM(receiving_touchdown) + SUM(rush_touchdown)) * 50) ++ (SUM(offense_snaps) * 100.0 / SUM(team_offense_snaps)) +- ((SUM(interception) + sum(fumble_lost)) * 75) +- ( + CASE + WHEN Player.Position = 'QB' + THEN SUM(qb_dropback) - SUM(pass_attempts) - SUM(qb_scramble) + ELSE 0 + END +) +- (SUM(safety) * 100.0)) / AvgPerYear AS PaydirtScore + + +FROM Player JOIN DatasetPlayerStats ON Player.PlayerID = DatasetPlayerStats.PlayerID JOIN Contract ON Player.PlayerID = Contract.PlayerID +WHERE season = 2024 AND SeasonType = 'REG' +GROUP BY Player.PlayerID, Player.PlayerName, Player.Team, Player.[Position], Contract.AvgPerYear +ORDER BY OffenseScore DESC; + `); + + res.status(200).json({ matches: result.recordset }); +}); +app.post("/getHighestPaydirt", authenticate, async (req, res) => { + const { amount } = req.body; + + const result = await pool.request() + .input("amount", sql.Int, amount) + .query(` +SELECT TOP (@amount) Player.[Position], Player.PlayerName, Player.Team, +SUM(total_yards) AS TotalYards, +SUM(passing_yards) AS PassingYards, +SUM(rushing_yards) AS RushingYards, +SUM(receiving_yards) AS RecievingYards, +CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END + SUM(receiving_touchdown) + SUM(rush_touchdown) AS AmendedTotalTDs, +CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END AS PassTDs, +SUM(receiving_touchdown) AS ReceivingTDs, +SUM(rush_touchdown) AS RushTDs, +SUM(offense_snaps) * 1.0 / SUM(team_offense_snaps) AS SnapPercentage, +SUM(interception) + sum(fumble_lost) AS Turnovers, +SUM(tackled_for_loss) AS TackledForLoss, + CASE + WHEN Player.Position = 'QB' + THEN SUM(qb_dropback) - SUM(pass_attempts) - SUM(qb_scramble) + ELSE 0 + END AS Sacks, +SUM(safety) AS Safties, + +SUM(total_yards) ++ ((CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END + SUM(receiving_touchdown) + SUM(rush_touchdown)) * 50) ++ (SUM(offense_snaps) * 100.0 / SUM(team_offense_snaps)) +- ((SUM(interception) + sum(fumble_lost)) * 75) +- ( + CASE + WHEN Player.Position = 'QB' + THEN SUM(qb_dropback) - SUM(pass_attempts) - SUM(qb_scramble) + ELSE 0 + END) + +- (SUM(safety) * 100.0) +AS OffenseScore, + +AvgPerYear, +(SUM(total_yards) ++ ((CASE WHEN Player.Position = 'QB' THEN (SUM(pass_touchdown)) ELSE 0 END + SUM(receiving_touchdown) + SUM(rush_touchdown)) * 50) ++ (SUM(offense_snaps) * 100.0 / SUM(team_offense_snaps)) +- ((SUM(interception) + sum(fumble_lost)) * 75) +- ( + CASE + WHEN Player.Position = 'QB' + THEN SUM(qb_dropback) - SUM(pass_attempts) - SUM(qb_scramble) + ELSE 0 + END +) +- (SUM(safety) * 100.0)) / AvgPerYear AS PaydirtScore + + +FROM Player JOIN DatasetPlayerStats ON Player.PlayerID = DatasetPlayerStats.PlayerID JOIN Contract ON Player.PlayerID = Contract.PlayerID +WHERE season = 2024 AND SeasonType = 'REG' +GROUP BY Player.PlayerID, Player.PlayerName, Player.Team, Player.[Position], Contract.AvgPerYear +ORDER BY PaydirtScore DESC; + `); + + res.status(200).json({ matches: result.recordset }); +}); + app.post("/getPlayer", authenticate, async (req, res) => { const { id } = req.body;