(
year,
team,
excludeGarbageTime,
startWeek,
endWeek
)
| 142 | }; |
| 143 | |
| 144 | const getAdvancedStats = async ( |
| 145 | year, |
| 146 | team, |
| 147 | excludeGarbageTime, |
| 148 | startWeek, |
| 149 | endWeek |
| 150 | ) => { |
| 151 | let filter = "WHERE "; |
| 152 | let params = []; |
| 153 | let index = 1; |
| 154 | |
| 155 | if (year) { |
| 156 | filter += `g.season = $${index}`; |
| 157 | params.push(year); |
| 158 | index++; |
| 159 | } |
| 160 | |
| 161 | if (team) { |
| 162 | filter += ` ${year ? "AND " : ""}LOWER(t.school) = LOWER($${index})`; |
| 163 | params.push(team); |
| 164 | index++; |
| 165 | } |
| 166 | |
| 167 | if (startWeek) { |
| 168 | filter += ` AND (g.week >= $${index} OR g.season_type = 'postseason')`; |
| 169 | params.push(startWeek); |
| 170 | index++; |
| 171 | } |
| 172 | |
| 173 | if (endWeek) { |
| 174 | filter += ` AND g.week <= $${index} AND g.season_type <> 'postseason'`; |
| 175 | params.push(endWeek); |
| 176 | index++; |
| 177 | } |
| 178 | |
| 179 | const mainTask = db.any( |
| 180 | ` |
| 181 | WITH plays AS ( |
| 182 | SELECT g.id, |
| 183 | g.season, |
| 184 | t.school, |
| 185 | p.drive_id, |
| 186 | p.down, |
| 187 | p.distance, |
| 188 | p.yards_gained, |
| 189 | c.name AS conference, |
| 190 | CASE |
| 191 | WHEN p.offense_id = t.id THEN 'offense' |
| 192 | ELSE 'defense' |
| 193 | END AS o_d, |
| 194 | CASE |
| 195 | WHEN p.down = 2 AND p.distance >= 8 THEN 'passing' |
| 196 | WHEN p.down IN (3,4) AND p.distance >= 5 THEN 'passing' |
| 197 | ELSE 'standard' |
| 198 | END AS down_type, |
| 199 | CASE |
| 200 | WHEN p.play_type_id IN (20,26,34,36,37,38,39,63) THEN false |
| 201 | WHEN p.scoring = true THEN true |
nothing calls this directly
no outgoing calls
no test coverage detected