MCPcopy Create free account
hub / github.com/CFBD/cfb-api / getAdvancedGameStats

Function getAdvancedGameStats

app/stats/stats.service.js:637–886  ·  view source on GitHub ↗
(
    year,
    team,
    week,
    opponent,
    excludeGarbageTime,
    seasonType
  )

Source from the content-addressed store, hash-verified

635 };
636
637 const getAdvancedGameStats = async (
638 year,
639 team,
640 week,
641 opponent,
642 excludeGarbageTime,
643 seasonType
644 ) => {
645 let filter = "WHERE ";
646 let params = [];
647 let index = 1;
648
649 if (year) {
650 filter += `g.season = $${index}`;
651 params.push(year);
652 index++;
653 }
654
655 if (team) {
656 filter += ` ${year ? "AND " : ""}LOWER(t.school) = LOWER($${index})`;
657 params.push(team);
658 index++;
659 }
660
661 if (opponent) {
662 filter += ` ${
663 params.length ? "AND " : ""
664 }LOWER(t2.school) = LOWER($${index})`;
665 params.push(opponent);
666 index++;
667 }
668
669 if (week) {
670 filter += ` ${params.length ? "AND " : ""}g.week = $${index}`;
671 params.push(week);
672 index++;
673 }
674
675 if (seasonType && seasonType.toLowerCase() !== "both") {
676 filter += ` ${params.length ? "AND " : ""}g.season_type = $${index}`;
677 params.push(seasonType);
678 index++;
679 }
680
681 const results = await db.any(
682 `
683 WITH plays AS (
684 SELECT g.id,
685 g.season,
686 g.week,
687 t.school,
688 t2.school AS opponent,
689 p.drive_id,
690 p.down,
691 p.distance,
692 p.yards_gained,
693 CASE
694 WHEN p.offense_id = t.id THEN 'offense'

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected