Skip to content

Commit

Permalink
comment out player leaderboards for now
Browse files Browse the repository at this point in the history
  • Loading branch information
akeaswaran committed Sep 11, 2024
1 parent dc7c94c commit e08a2f5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 85 deletions.
166 changes: 83 additions & 83 deletions frontend/cfb/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,89 +513,89 @@ function retrieveValue(dictionary, key) {
return sub;
}

router.route('/year/:year/teams/:type')
.get(async function(req, res, next) {
try {
const type = req.params.type ?? "differential";
let sortKey = req.query.sort ?? `overall.epaPerPlay`
// can't do passing/rushing/havoc differentials
if (type == "differential" && (!sortKey.includes("overall") || sortKey.includes("havocRate"))) {
sortKey = `overall.epaPerPlay`
}
const asc = (type == "defensive" && sortKey != "overall.havocRate") || (type == "offensive" && sortKey == "overall.havocRate") // adjust for defensive stats where it makes sense
const baseData = await retrieveLeagueData(req.params.year, "overall")

let content = baseData.map(t => {
let target = t[type]
return {
teamId: t.teamId,
team: t.team,
...target
}
})
content = content.filter(p => {
const nonNullValue = retrieveValue(p, sortKey) != null && retrieveValue(p, sortKey) != "NA"
const nonNullRank = retrieveValue(p, `${sortKey}Rank`) != null && retrieveValue(p, `${sortKey}Rank`) != "NA"
return nonNullRank && nonNullValue
}).sort((a, b) => {
const compVal = parseFloat(retrieveValue(a, sortKey)) - parseFloat(retrieveValue(b, sortKey))
return asc ? compVal : (-1 * compVal)
})
// return res.json(content);
return res.render("pages/cfb/leaderboard", {
teams: content,
type,
season: req.params.year,
sort: sortKey,
last_updated: await retrieveLastUpdated()
})
} catch(err) {
return next(err)
}
})

router.route('/year/:year/players/:type')
.get(async function(req, res, next) {
try {
const type = req.params.type ?? "passing";
let sortKey = req.query.sort ?? `advanced.epaPerPlay`
// // can't do passing/rushing/havoc differentials
// if (type == "differential" && (!sortKey.includes("overall") || sortKey.includes("havocRate"))) {
// sortKey = `overall.epaPerPlay`
// }
const asc = false;//(type == "defensive" && sortKey != "overall.havocRate") || (type == "offensive" && sortKey == "overall.havocRate") // adjust for defensive stats where it makes sense
let content = await retrieveLeagueData(req.params.year, type)

content = content.filter(p => {
const nonNullValue = retrieveValue(p, sortKey) != null && retrieveValue(p, sortKey) != "NA"
const nonNullRank = retrieveValue(p, `${sortKey}Rank`) != null && retrieveValue(p, `${sortKey}Rank`) != "NA"
return nonNullRank && nonNullValue
}).sort((a, b) => {
const compVal = parseFloat(retrieveValue(a, sortKey)) - parseFloat(retrieveValue(b, sortKey))
return asc ? compVal : (-1 * compVal)
})
// return res.json(content);
return res.render("pages/cfb/player_leaderboard", {
players: content,
type,
season: req.params.year,
sort: sortKey,
last_updated: await retrieveLastUpdated()
})
} catch(err) {
return next(err)
}
})

router.route('/players/:type')
.get(async function(req, res, next) {
return res.redirect(`/cfb/year/2024/players/${req.params.type}`);
})

router.route('/year/:year/players')
.get(async function(req, res, next) {
return res.redirect(`/cfb/year/${req.params.year}/players/passing`);
})
// router.route('/year/:year/teams/:type')
// .get(async function(req, res, next) {
// try {
// const type = req.params.type ?? "differential";
// let sortKey = req.query.sort ?? `overall.epaPerPlay`
// // can't do passing/rushing/havoc differentials
// if (type == "differential" && (!sortKey.includes("overall") || sortKey.includes("havocRate"))) {
// sortKey = `overall.epaPerPlay`
// }
// const asc = (type == "defensive" && sortKey != "overall.havocRate") || (type == "offensive" && sortKey == "overall.havocRate") // adjust for defensive stats where it makes sense
// const baseData = await retrieveLeagueData(req.params.year, "overall")

// let content = baseData.map(t => {
// let target = t[type]
// return {
// teamId: t.teamId,
// team: t.team,
// ...target
// }
// })
// content = content.filter(p => {
// const nonNullValue = retrieveValue(p, sortKey) != null && retrieveValue(p, sortKey) != "NA"
// const nonNullRank = retrieveValue(p, `${sortKey}Rank`) != null && retrieveValue(p, `${sortKey}Rank`) != "NA"
// return nonNullRank && nonNullValue
// }).sort((a, b) => {
// const compVal = parseFloat(retrieveValue(a, sortKey)) - parseFloat(retrieveValue(b, sortKey))
// return asc ? compVal : (-1 * compVal)
// })
// // return res.json(content);
// return res.render("pages/cfb/leaderboard", {
// teams: content,
// type,
// season: req.params.year,
// sort: sortKey,
// last_updated: await retrieveLastUpdated()
// })
// } catch(err) {
// return next(err)
// }
// })

// router.route('/year/:year/players/:type')
// .get(async function(req, res, next) {
// try {
// const type = req.params.type ?? "passing";
// let sortKey = req.query.sort ?? `advanced.epaPerPlay`
// // // can't do passing/rushing/havoc differentials
// // if (type == "differential" && (!sortKey.includes("overall") || sortKey.includes("havocRate"))) {
// // sortKey = `overall.epaPerPlay`
// // }
// const asc = false;//(type == "defensive" && sortKey != "overall.havocRate") || (type == "offensive" && sortKey == "overall.havocRate") // adjust for defensive stats where it makes sense
// let content = await retrieveLeagueData(req.params.year, type)

// content = content.filter(p => {
// const nonNullValue = retrieveValue(p, sortKey) != null && retrieveValue(p, sortKey) != "NA"
// const nonNullRank = retrieveValue(p, `${sortKey}Rank`) != null && retrieveValue(p, `${sortKey}Rank`) != "NA"
// return nonNullRank && nonNullValue
// }).sort((a, b) => {
// const compVal = parseFloat(retrieveValue(a, sortKey)) - parseFloat(retrieveValue(b, sortKey))
// return asc ? compVal : (-1 * compVal)
// })
// // return res.json(content);
// return res.render("pages/cfb/player_leaderboard", {
// players: content,
// type,
// season: req.params.year,
// sort: sortKey,
// last_updated: await retrieveLastUpdated()
// })
// } catch(err) {
// return next(err)
// }
// })

// router.route('/players/:type')
// .get(async function(req, res, next) {
// return res.redirect(`/cfb/year/2024/players/${req.params.type}`);
// })

// router.route('/year/:year/players')
// .get(async function(req, res, next) {
// return res.redirect(`/cfb/year/${req.params.year}/players/passing`);
// })

router.route('/glossary')
.get(function(req, res, next) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/views/partials/nav-header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<li><a class="dropdown-item" href="/cfb/teams/differential">Net Statistics</a></li>
<li><a class="dropdown-item" href="/cfb/teams/offensive">Offensive</a></li>
<li><a class="dropdown-item" href="/cfb/teams/defensive">Defensive</a></li>
<h6 class="dropdown-header">Player Level</h6>
<!-- <h6 class="dropdown-header">Player Level</h6>
<li><a class="dropdown-item" href="/cfb/players/passing">Passing</a></li>
<li><a class="dropdown-item" href="/cfb/players/rushing">Rushing</a></li>
<li><a class="dropdown-item" href="/cfb/players/receiving">Receiving</a></li>
<li><a class="dropdown-item" href="/cfb/players/receiving">Receiving</a></li> -->
</ul>
</li>
<li class="nav-item dropdown">
Expand Down

0 comments on commit e08a2f5

Please sign in to comment.