Skip to content

Data Types: Attendance

MattsFace edited this page Dec 30, 2022 · 15 revisions

Attendance Structure

Attributes are expandable and collapsable - Link to attendance dataclass

aggregatetotals : AttendanceTotals
openingstotalaway : int
  • Total amount of opening game attendance number
openingstotalhome : int
  • Total amount of opening home game attendance number
openingstotallost : int
  • Total amount of opening games lost
openingstotalytd : int
  • Total amount of opening games year to date
attendanceaverageaway : int
  • Average away game attendance
attendanceaveragehome : int
  • Average home game attendance
attendanceaverageytd : int
  • Average attendance year to date
attendancehigh : int
  • Attendance high
attendancehighdate : str
  • Attendance high date
attendancetotal : int
  • Attendance total
attendancetotalaway : int
  • Attendace total away
attendancetotalhome : int
  • Attendance total home
records : List[AttendanceRecords]
openingstotal : int
  • Total amount of openings
openingstotalaway : int
  • Total amount of opening away games
openingstotalhome : int
  • Total amount of opening home games
openingstotallost : int
  • Total amount of openings lost
gamestotal : int
  • Total amount of games
gamesawaytotal : int
  • Total amount of away games
gameshometotal : int
  • Total amount of home games
year : str
  • Year as a string
attendanceaverageaway : int
  • Average attendance for away games
attendanceaveragehome : int
  • Average attendance for home games
attendanceaverageytd : int
  • Average attendance year to date
attendancehigh : int
  • Attendance High number
attendancehighdate : str
  • Attendance high date
attendancehighgame : AttendanceHighLowGame
gamepk : int
  • Games Id number
link : str
  • games endpoint link
content : AttendanceHighLowGameContent
link : str
  • games content endpoint link
daynight : str
  • Type of time of day for game
attendancelow : int
  • Attendance low number
attendancelowdate : str
  • Attendance low date
attendancelowgame : AttendanceHighLowGame
gamepk : int
  • Games Id number
link : str
  • games endpoint link
content : AttendanceHighLowGameContent
link : str
  • games content endpoint link
daynight : str
  • Type of time of day for game
attendanceopeningaverage : int
  • Attendance opening average
attendancetotal : int
  • Attendance total
attendancetotalaway : int
  • Attendance total away
attendancetotalhome : int
  • Attendance total home
gametype : AttendenceGameType
id : str
  • Game type id
description : str
  • Game type description
team : Team
  • Team

Usage that returns Attendance objects

get_attendance

Description: Returns attendance data based on teamId, leagueId, or leagueListId. Required Parameters (at least one)

Parameters: At least one is required

Name Type Required Description Default
team_id Int Yes Insert a teamId to return directory of attendnace for a given team None
league_id Int/List[int] Yes Insert leagueId(s) to return a directory of attendanace for a specific league. Format '103,104' None
league_list_id Str Yes Insert a unique League List Identifier to return a directory of attendanace for a specific league listId. List of Options None

Other Parameters:

Name Type Required Description Default
season int No Insert year(s) to return a directory of attendance for a given season. Season year number format yyyy None
date string No Insert date to return information for attendance on a particular date. Format: MM/DD/YYYY None
gametype string No Insert gameType(s) a directory of attendance for a given gameType. For a list of all gameTypes: https://statsapi.mlb.com/api/v1/gameTypes None

Example output from MLB stats api endpoint

Mlb stats api Query:

https://statsapi.mlb.com/api/v1/attendance?teamId=110&leagueId=103&season=2014&leagueListId=mlb&gameType=D

Equivelant with python-mlb-statsapi:

>>> import mlbstatsapi
>>>
>>> mlb = mlbstatsapi.Mlb()
>>>
>>> attendance = mlb.get_attendance(team_id = 110, league_id = 103, league_list_id = 'mlb', season = 2021)
>>>
>>> print(attendance)
Attendance(aggregatetotals=AttendanceTotals(openingstotalaway=80, openingstotalhome=78, openingstotallost=3, attendanceaverageytd=13319, attendancehigh=30898, attendancehighdate=2021-07-24T00:00:00, attendancetotal=2104458, attendancetotalaway=1311229, attendancetotalhome=793229, attendanceaverageaway=16390, attendanceaveragehome=10170), records=[AttendanceRecords(openingstotal=158, openingstotalaway=80, openingstotalhome=78, openingstotallost=3, gamestotal=167, gamesawaytotal=83, gameshometotal=84, year=2021, attendanceaverageytd=13319, attendancetotal=2104458, gametype={'id': 'R', 'description': 'Regular Season'}, team=Team(id=110, link=/api/v1/teams/110, name=Baltimore Orioles), attendanceaverageaway=16390, attendanceaveragehome=10170, attendancehigh=30898, attendancehighdate=2021-07-24T00:00:00, attendancehighgame=AttendanceHighLowGame(gamepk=633195, link='/api/v1.1/game/633195/feed/live', content=AttendanceHighLowGameContent(link='/api/v1/game/633195/content'), daynight='day'), attendancelow=4147, attendancelowdate=2021-04-15T00:00:00, attendancelowgame=AttendanceHighLowGame(gamepk=634571, link='/api/v1.1/game/634571/feed/live', content=AttendanceHighLowGameContent(link='/api/v1/game/634571/content'), daynight='day'), attendancetotalaway=1311229, attendancetotalhome=793229, attendanceopeningaverage=9921, gameType=AttendenceGameType(id='R', description='Regular Season'))])