Exemple #1
0
 def test_getFirstDate(self):
     dt = util.getFirstDate(2019, 9, 4)
     self.assertEqual(dt, datetime.date(2019, 9, 6))
     dt = util.getFirstDate(2017, 9, 4)
     self.assertEqual(dt, datetime.date(2017, 9, 1))
     dt = util.getFirstDate(2016, 9, 4)
     self.assertEqual(dt, datetime.date(2016, 9, 2))
Exemple #2
0
 def _seasonStartDate(self) -> datetime.date:
     syear = self._currentSeason
     # Get the first Thursday of Sept.
     rsstdt = util.getFirstDate(syear, 9, 3)
     # Get the first Monday of Sept.
     mon1dt = util.getFirstDate(syear, 9, 0)
     dt = datetime.date(syear, 9, 1) - mon1dt
     if dt.days > 0:
         # The 1st day of the month wasn't a Sunday or Monday
         # so the season starts on the 2nd Thursday
         rsstdt = rsstdt + relativedelta.relativedelta(weeks=1)
     return rsstdt
Exemple #3
0
 def _doPlayerItemParse(self, srcdata: dict, basedata: dict) -> dict:
     data = basedata.copy()
     for k, v in srcdata.items():
         if k != "yards":
             # Ignore the yards key at this level
             k = re.sub(r"([a-z])([A-Z])", r"\1_\2", k)
             k = k.lower()
             if k == "stat_id":
                 try:
                     # Now we use the yards value in the srcdata
                     # Add the statistic flags and the statistic yardage value
                     vd = sm.values(v, srcdata["yards"])
                     # Add the statistic metadata
                     vd.update(util.getStatMetadata(v))
                     data.update(vd)
                 except AssertionError as e:
                     logging.warning(
                         "Statistic metadata retrieval failed for stat_id {}: {}"
                         .format(v, e))
                     logging.warning(
                         "Offending record was {}".format(srcdata))
             else:
                 if k == "player_name":
                     k = "player_abrv_name"
                 elif k == "clubcode":
                     k = "team"
                 data[k] = v
     return data
Exemple #4
0
 def _doParse(self, srcdata: dict, basedata: dict) -> list:
     data = []
     for driveid, drive in srcdata["drives"].items():
         # The drive contains children that do not correspond
         # to a drive. If the child key is all numeric then
         # it does contain drive data.
         if re.search(r"^\d+$", driveid):
             for dik, div in drive.items():
                 if dik == "plays":
                     # div is the plays dict which contains
                     # the data we want
                     for playid, playdict in div.items():
                         ddata = basedata.copy()
                         ddata["drive_id"] = driveid
                         ddata["play_id"] = playid
                         for pk, pv in playdict.items():
                             if pk != "players":
                                 # This is an atomic valued element
                                 # so just add it as-is
                                 ddata[pk] = pv
                         if ddata["yrdln"] != "":
                             # We need to get a normalized yardline like we
                             # do in the game summary data.
                             ddata["yrdln_norm"] = util.parseYardLine(
                                 ddata["yrdln"], ddata["posteam"])
                         if "players" in playdict.keys():
                             # We have player statistics listed, therefore, we need
                             # to add a record for each player statistic
                             for pldata in self._doPlayerParse(
                                     playdict["players"], ddata):
                                 data.append(pldata)
                         else:
                             # No player statistics listed so just add the base record
                             data.append(ddata)
     return data
Exemple #5
0
 def test_getStatMetadata_3(self):
     exp = {
         "stat_id": 3,
         'stat_cat': 'team',
         'stat_desc': '1st down (rushing)',
         'stat_desc_long': 'A first down or TD occurred due to a rush.'
     }
     self.assertEqual(util.getStatMetadata(3), exp)
Exemple #6
0
 def test_getStatMetadata_5(self):
     exp = {
         "stat_id":
         5,
         'stat_cat':
         'team',
         'stat_desc':
         '1st down (penalty)',
         'stat_desc_long':
         'A first down or TD occurred due to a penalty. A play can have a first down from a pass or rush and from a penalty.'
     }
     self.assertEqual(util.getStatMetadata(5), exp)
Exemple #7
0
 def test_parseYardLine_self(self):
     self.assertEqual(util.parseYardLine("self 30", "self"), -20)
Exemple #8
0
 def test_parseYardLine_opp(self):
     self.assertEqual(util.parseYardLine("opp 30", "self"), 20)
Exemple #9
0
 def test_parseYardLine_50(self):
     self.assertEqual(util.parseYardLine("50", "self"), 0)