Skip to content

Commit

Permalink
fg ep
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSCar committed Dec 9, 2023
1 parent 8de7d26 commit 5d8a1b8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 6 deletions.
17 changes: 15 additions & 2 deletions app/ppa/ppa.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,19 @@ module.exports = (db, Sentry) => {
error: 'Something went wrong.'
});
}
}
};

const getFGEP = async (req, res) => {
try {
let results = await service.getFGEP();
res.send(results);
} catch (err) {
Sentry.captureException(err);
res.status(500).send({
error: 'Something went wrong.'
});
}
};

return {
getPP,
Expand All @@ -196,6 +208,7 @@ module.exports = (db, Sentry) => {
getPPAByGame,
getPPAByPlayerGame,
getPPAByPlayerSeason,
getPregameWP
getPregameWP,
getFGEP
}
}
1 change: 1 addition & 0 deletions app/ppa/ppa.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ module.exports = (app, db, middlewares, Sentry) => {
app.route('/ppa/players/season').get(middlewares, controller.getPPAByPlayerSeason);
app.route('/metrics/wp').get(middlewares, controller.getWP);
app.route('/metrics/wp/pregame').get(middlewares, controller.getPregameWP);
app.route('/metrics/fg/ep').get(middlewares, controller.getFGEP);
}
18 changes: 16 additions & 2 deletions app/ppa/ppa.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const gaussian = require('gaussian');
const gaussianDistro = gaussian(0, Math.pow(14.5, 2));
const axios = require('axios');

module.exports = (db) => {

Expand Down Expand Up @@ -684,13 +683,28 @@ module.exports = (db) => {
}));
};

const getFGEP = async () => {
let results = await db.any(`
SELECT yards_to_goal, (yards_to_goal + 17) AS distance, expected_points
FROM fg_ep
ORDER BY yards_to_goal
`);

return results.map(r => ({
yardsToGoal: r.yards_to_goal,
distance: r.distance,
expectedPoints: r.expected_points
}));
};

return {
getPP,
getWP,
getPPAByTeam,
getPPAByGame,
getPPAByPlayerGame,
getPPAByPlayerSeason,
getPregameWP
getPregameWP,
getFGEP
}
}
43 changes: 42 additions & 1 deletion swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"swagger": "2.0",
"info": {
"description": "This is an API for accessing all sorts of college football data. Please note that API keys should be supplied with \"Bearer \" prepended (e.g. \"Bearer your_key\"). API keys can be acquired from the CollegeFootballData.com website.",
"version": "4.5.1",
"version": "4.5.2",
"title": "College Football Data API",
"contact": {
"email": "[email protected]"
Expand Down Expand Up @@ -2294,6 +2294,33 @@
}
}
},
"/metrics/fg/ep": {
"get": {
"tags": [
"metrics"
],
"summary": "Field Goal Expected Points",
"description": "Field Goal Expected Poitns",
"operationId": "getFGEP",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/FieldGoalExpectedPoints"
}
}
},
"400": {
"description": "error"
}
}
}
},
"/metrics/wp": {
"get": {
"tags": [
Expand Down Expand Up @@ -4569,6 +4596,20 @@
}
}
},
"FieldGoalExpectedPoints": {
"type": "object",
"properties": {
"yardsToGoal": {
"type": "integer"
},
"distance": {
"type": "integer"
},
"expectedPoints": {
"type": "number"
}
}
},
"TeamSeasonStat": {
"type": "object",
"properties": {
Expand Down
29 changes: 28 additions & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
swagger: "2.0"
info:
description: This is an API for accessing all sorts of college football data. Please note that API keys should be supplied with "Bearer " prepended (e.g. "Bearer your_key"). API keys can be acquired from the CollegeFootballData.com website.
version: 4.5.1
version: 4.5.2
title: College Football Data API
contact:
email: [email protected]
Expand Down Expand Up @@ -1581,6 +1581,24 @@ paths:
$ref: "#/definitions/PlayerSeasonPPA"
"400":
description: error
/metrics/fg/ep:
get:
tags:
- metrics
summary: Field Goal Expected Points
description: Field Goal Expected Poitns
operationId: getFGEP
produces:
- application/json
responses:
"200":
description: successful operation
schema:
type: array
items:
$ref: "#/definitions/FieldGoalExpectedPoints"
"400":
description: error
/metrics/wp:
get:
tags:
Expand Down Expand Up @@ -3099,6 +3117,15 @@ definitions:
type: integer
predictedPoints:
type: number
FieldGoalExpectedPoints:
type: object
properties:
yardsToGoal:
type: integer
distance:
type: integer
expectedPoints:
type: number
TeamSeasonStat:
type: object
properties:
Expand Down

0 comments on commit 5d8a1b8

Please sign in to comment.