(season, conference, position, school, playerId, excludeGarbageTime)
| 90 | }; |
| 91 | |
| 92 | const getPlayerUsage = async (season, conference, position, school, playerId, excludeGarbageTime) => { |
| 93 | let filters = []; |
| 94 | let params = []; |
| 95 | let index = 1; |
| 96 | |
| 97 | if (season) { |
| 98 | filters.push(`g.season = $${index}`); |
| 99 | params.push(season); |
| 100 | index++; |
| 101 | } |
| 102 | |
| 103 | if (conference) { |
| 104 | filters.push(`LOWER(c.abbreviation) = LOWER($${index})`); |
| 105 | params.push(conference); |
| 106 | index++; |
| 107 | } |
| 108 | |
| 109 | if (position) { |
| 110 | filters.push(`LOWER(po.abbreviation) = LOWER($${index})`); |
| 111 | params.push(position); |
| 112 | index++; |
| 113 | } |
| 114 | |
| 115 | if (school) { |
| 116 | filters.push(`LOWER(t.school) = LOWER($${index})`); |
| 117 | params.push(school); |
| 118 | index++; |
| 119 | } |
| 120 | |
| 121 | if (playerId) { |
| 122 | filters.push(`a.id = $${index}`); |
| 123 | params.push(playerId); |
| 124 | index++; |
| 125 | } |
| 126 | |
| 127 | let filter = filters.length ? `WHERE ${filters.join(' AND ')}` : ''; |
| 128 | |
| 129 | const results = await db.any(` |
| 130 | WITH plays AS ( |
| 131 | SELECT DISTINCT g.season, |
| 132 | t.id AS team_id, |
| 133 | t.school, |
| 134 | c.name AS conference, |
| 135 | a.id, |
| 136 | a.name, |
| 137 | po.abbreviation AS position, |
| 138 | COUNT(DISTINCT p.id) AS plays, |
| 139 | COUNT(DISTINCT p.id) FILTER(WHERE p.play_type_id IN (3,4,6,7,24,26,36,51,67)) AS pass_plays, |
| 140 | COUNT(DISTINCT p.id) FILTER(WHERE p.play_type_id IN (5,9,29,39,68)) AS rush_plays, |
| 141 | COUNT(DISTINCT p.id) FILTER(WHERE p.down = 1) AS first_downs, |
| 142 | COUNT(DISTINCT p.id) FILTER(WHERE p.down = 2) AS second_downs, |
| 143 | COUNT(DISTINCT p.id) FILTER(WHERE p.down = 3) AS third_downs, |
| 144 | COUNT(DISTINCT p.id) FILTER(WHERE (p.down = 2 AND p.distance >= 8) OR (p.down IN (3,4) AND p.distance >= 5)) AS passing_downs, |
| 145 | COUNT(DISTINCT p.id) FILTER(WHERE p.distance < 5 OR (p.down = 2 AND p.distance < 8)) AS standard_downs |
| 146 | FROM game AS g |
| 147 | INNER JOIN game_team AS gt ON g.id = gt.game_id |
| 148 | INNER JOIN team AS t ON gt.team_id = t.id |
| 149 | INNER JOIN conference_team AS ct ON t.id = ct.team_id AND ct.start_year <= g.season AND (ct.end_year >= g.season OR ct.end_year IS NULL) |
nothing calls this directly
no outgoing calls
no test coverage detected