Module blaseball_mike.models.statsheet
Expand source code
from collections import OrderedDict
from .base import Base
from .. import database
class PlayerStatsheet(Base):
@classmethod
def _get_fields(cls):
id_ = "e80b9497-c604-456d-9bee-c860d4759b14"
p = cls.load(id_).get(id_)
return [cls._from_api_conversion(x) for x in p.fields]
@classmethod
def load(cls, ids):
stats = database.get_player_statsheets(ids)
stats_dict = OrderedDict()
for k, v in stats.items():
stats_dict[k] = cls(v)
return stats_dict
class TeamStatsheet(Base):
@classmethod
def _get_fields(cls):
id_ = "07b2b5bf-9eeb-4eff-9be9-d0f66c687f76"
p = cls.load(id_).get(id_)
return [cls._from_api_conversion(x) for x in p.fields]
@classmethod
def load(cls, ids):
stats = database.get_team_statsheets(ids)
stats_dict = OrderedDict()
for k, v in stats.items():
stats_dict[k] = cls(v)
return stats_dict
@Base.lazy_load("_player_stat_ids", cache_name="_player_stats", default_value=list())
def player_stats(self):
return list(PlayerStatsheet.load(self._player_stat_ids).values())
class GameStatsheet(Base):
@classmethod
def _get_fields(cls):
id_ = "f852abec-b80e-40e2-b213-f0368d4e7f57"
p = cls.load(id_).get(id_)
return [cls._from_api_conversion(x) for x in p.fields]
@classmethod
def load(cls, ids):
stats = database.get_game_statsheets(ids)
stats_dict = OrderedDict()
for k, v in stats.items():
stats_dict[k] = cls(v)
return stats_dict
@classmethod
def load_by_day(cls, season, day):
from .game import Game
games = Game.load_by_day(season, day)
return {k: g.statsheet for k, g in games.items()}
def team_stats(self):
if getattr(self, '_team_stats', None):
return self._team_stats
self._team_stats = TeamStatsheet.load([
self._home_team_stats_id,
self._away_team_stats_id,
])
return self._team_stats
@property
def away_team_stats(self):
return self.team_stats()[self._away_team_stats_id]
@away_team_stats.setter
def away_team_stats(self, value):
self._away_team_stats_id = value
self._team_stats = None
self.key_transform_lookup["away_team_stats"] = "_away_team_stats_id"
@property
def home_team_stats(self):
return self.team_stats()[self._home_team_stats_id]
@home_team_stats.setter
def home_team_stats(self, value):
self._home_team_stats_id = value
self._team_stats = None
self.key_transform_lookup["home_team_stats"] = "_home_team_stats_id"
class SeasonStatsheet(Base):
@classmethod
def _get_fields(cls):
id_ = "64392ad5-e14c-42c0-825c-c85da29addaa"
p = cls.load(id_).get(id_)
return [cls._from_api_conversion(x) for x in p.fields]
@classmethod
def load(cls, ids):
stats = database.get_season_statsheets(ids)
stats_dict = OrderedDict()
for k, v in stats.items():
stats_dict[k] = cls(v)
return stats_dict
@classmethod
def load_by_season(cls, season):
"""Season is 1 indexed."""
from .season import Season
season = Season.load(season)
return season.stats
@Base.lazy_load("_team_stat_ids", cache_name="_team_stats", default_value=list())
def team_stats(self):
return list(TeamStatsheet.load(self._team_stat_ids).values())
Classes
class GameStatsheet (data, strict=False)-
Base class for all blaseball-mike models. Provides common functionality for deserializing blaseball API responses.
To accommodate the ever-changing nature of the blaseball API, blaseball_mike mainly infers properties from the returned JSON rather than explicitly mapping each property. This means that documentation of available fields with ultimately be incomplete. The easiest way to find available properties outside of looking at the spec is to look at the
fieldsproperty to see what JSON keys have been deserialized.Expand source code
class GameStatsheet(Base): @classmethod def _get_fields(cls): id_ = "f852abec-b80e-40e2-b213-f0368d4e7f57" p = cls.load(id_).get(id_) return [cls._from_api_conversion(x) for x in p.fields] @classmethod def load(cls, ids): stats = database.get_game_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dict @classmethod def load_by_day(cls, season, day): from .game import Game games = Game.load_by_day(season, day) return {k: g.statsheet for k, g in games.items()} def team_stats(self): if getattr(self, '_team_stats', None): return self._team_stats self._team_stats = TeamStatsheet.load([ self._home_team_stats_id, self._away_team_stats_id, ]) return self._team_stats @property def away_team_stats(self): return self.team_stats()[self._away_team_stats_id] @away_team_stats.setter def away_team_stats(self, value): self._away_team_stats_id = value self._team_stats = None self.key_transform_lookup["away_team_stats"] = "_away_team_stats_id" @property def home_team_stats(self): return self.team_stats()[self._home_team_stats_id] @home_team_stats.setter def home_team_stats(self, value): self._home_team_stats_id = value self._team_stats = None self.key_transform_lookup["home_team_stats"] = "_home_team_stats_id"Ancestors
- Base
- abc.ABC
Static methods
def load(ids)-
Expand source code
@classmethod def load(cls, ids): stats = database.get_game_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dict def load_by_day(season, day)-
Expand source code
@classmethod def load_by_day(cls, season, day): from .game import Game games = Game.load_by_day(season, day) return {k: g.statsheet for k, g in games.items()}
Instance variables
var away_team_runs_by_inningvar away_team_statsvar away_team_total_battersvar home_team_runs_by_inningvar home_team_statsvar home_team_total_battersvar id
Methods
def team_stats(self)-
Expand source code
def team_stats(self): if getattr(self, '_team_stats', None): return self._team_stats self._team_stats = TeamStatsheet.load([ self._home_team_stats_id, self._away_team_stats_id, ]) return self._team_stats
class PlayerStatsheet (data, strict=False)-
Base class for all blaseball-mike models. Provides common functionality for deserializing blaseball API responses.
To accommodate the ever-changing nature of the blaseball API, blaseball_mike mainly infers properties from the returned JSON rather than explicitly mapping each property. This means that documentation of available fields with ultimately be incomplete. The easiest way to find available properties outside of looking at the spec is to look at the
fieldsproperty to see what JSON keys have been deserialized.Expand source code
class PlayerStatsheet(Base): @classmethod def _get_fields(cls): id_ = "e80b9497-c604-456d-9bee-c860d4759b14" p = cls.load(id_).get(id_) return [cls._from_api_conversion(x) for x in p.fields] @classmethod def load(cls, ids): stats = database.get_player_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dictAncestors
- Base
- abc.ABC
Static methods
def load(ids)-
Expand source code
@classmethod def load(cls, ids): stats = database.get_player_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dict
Instance variables
var at_batsvar caught_stealingvar doublesvar earned_runsvar ground_into_dpvar hit_battersvar hit_by_pitchvar hitsvar hits_allowedvar home_runsvar idvar lossesvar namevar outs_recordedvar pitches_thrownvar player_idvar quadruplesvar rbisvar runsvar stolen_basesvar strikeoutsvar struckoutsvar teamvar team_idvar triplesvar walksvar walks_issuedvar wins
class SeasonStatsheet (data, strict=False)-
Base class for all blaseball-mike models. Provides common functionality for deserializing blaseball API responses.
To accommodate the ever-changing nature of the blaseball API, blaseball_mike mainly infers properties from the returned JSON rather than explicitly mapping each property. This means that documentation of available fields with ultimately be incomplete. The easiest way to find available properties outside of looking at the spec is to look at the
fieldsproperty to see what JSON keys have been deserialized.Expand source code
class SeasonStatsheet(Base): @classmethod def _get_fields(cls): id_ = "64392ad5-e14c-42c0-825c-c85da29addaa" p = cls.load(id_).get(id_) return [cls._from_api_conversion(x) for x in p.fields] @classmethod def load(cls, ids): stats = database.get_season_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dict @classmethod def load_by_season(cls, season): """Season is 1 indexed.""" from .season import Season season = Season.load(season) return season.stats @Base.lazy_load("_team_stat_ids", cache_name="_team_stats", default_value=list()) def team_stats(self): return list(TeamStatsheet.load(self._team_stat_ids).values())Ancestors
- Base
- abc.ABC
Static methods
def load(ids)-
Expand source code
@classmethod def load(cls, ids): stats = database.get_season_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dict def load_by_season(season)-
Season is 1 indexed.
Expand source code
@classmethod def load_by_season(cls, season): """Season is 1 indexed.""" from .season import Season season = Season.load(season) return season.stats
Instance variables
var idvar team_stats
class TeamStatsheet (data, strict=False)-
Base class for all blaseball-mike models. Provides common functionality for deserializing blaseball API responses.
To accommodate the ever-changing nature of the blaseball API, blaseball_mike mainly infers properties from the returned JSON rather than explicitly mapping each property. This means that documentation of available fields with ultimately be incomplete. The easiest way to find available properties outside of looking at the spec is to look at the
fieldsproperty to see what JSON keys have been deserialized.Expand source code
class TeamStatsheet(Base): @classmethod def _get_fields(cls): id_ = "07b2b5bf-9eeb-4eff-9be9-d0f66c687f76" p = cls.load(id_).get(id_) return [cls._from_api_conversion(x) for x in p.fields] @classmethod def load(cls, ids): stats = database.get_team_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dict @Base.lazy_load("_player_stat_ids", cache_name="_player_stats", default_value=list()) def player_stats(self): return list(PlayerStatsheet.load(self._player_stat_ids).values())Ancestors
- Base
- abc.ABC
Static methods
def load(ids)-
Expand source code
@classmethod def load(cls, ids): stats = database.get_team_statsheets(ids) stats_dict = OrderedDict() for k, v in stats.items(): stats_dict[k] = cls(v) return stats_dict
Instance variables
var games_playedvar idvar lossesvar namevar player_statsvar team_idvar wins