示例#1
0
def insert_batter(bats):
    Player.create(**{
            "name": "George Burdell",
            "name_id": "burdege01",
            "bats": bats,
            "throws": Handedness.RIGHT.value,
        })
示例#2
0
def insert_pitcher(throws):
    Player.create(**{
            "name": "George Burdell",
            "name_id": "burdege02",
            "bats": Handedness.RIGHT.value,
            "throws": throws
        })
示例#3
0
 def test_queries(self):
     assert not self.page._exists_in_db()
     self.page.update_db()
     assert self.page._exists_in_db()
     Player.get(Player.name == "Pat Venditte"
                and Player.name_id == "vendipa01"
                and Player.bats == Handedness.LEFT.value
                and Player.throws == Handedness.BOTH.value)
示例#4
0
def _insert_mock_player(name: str, name_id: str) -> None:
    fields = {
            "name": name,
            "name_id": name_id,
            "bats": Handedness.RIGHT.value,
            "throws": Handedness.RIGHT.value,
        }
    if Player.get_or_none(Player.name_id == name_id) is None:
        Player.create(**fields)
示例#5
0
 def __init_name_to_db_ids(self) -> None:
     self.__name_to_db_ids = {}
     for n, nid in self.get_name_name_ids():
         if n not in self.__name_to_db_ids:
             self.__name_to_db_ids[n] = []
         db_player = Player.get(Player.name_id == nid)
         self.__name_to_db_ids[n].append(db_player.id)
     self.__name_to_db_ids = {
         name: tuple(ids)
         for name, ids in self.__name_to_db_ids.items()
     }
示例#6
0
 def _run_queries(self) -> None:
     fields = self.__get_handedness()
     fields["name"] = self._player_info.h1.text
     fields["name_id"] = self._link.name_id
     with db.atomic():
         Player.create(**fields)
示例#7
0
 def get_batter_handedness(self, bid: int) -> int:
     if bid not in self._bat_hand:
         hand = Player.get(Player.id == bid).bats
         self._bat_hand[bid] = hand
     return self._bat_hand[bid]
示例#8
0
 def get_pitcher_handedness(self, pid: int) -> int:
     if pid not in self._pit_hand:
         hand = Player.get(Player.id == pid).throws
         self._pit_hand[pid] = hand
     return self._pit_hand[pid]
示例#9
0
 def _id_of_name_id(name_id: str) -> int:
     return Player.get(Player.name_id == name_id).id