This commit is contained in:
RochesterX
2025-11-28 11:10:09 -05:00
parent f697d4afea
commit 4d5c8d743f
3 changed files with 225 additions and 0 deletions

125
server.js
View File

@@ -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;