def test_game_schedule_parse(self):
        """
        as a prerequisite, parse the seasonschedule, and both home & away teams

        effectively tests the TeamHierarchy parser too
        """
        # parse the season_schedule obj
        season_oplog_obj = OpLogObjWrapper(
            self.sport, 'season_schedule', literal_eval(self.season_str))
        self.season_parser.parse(season_oplog_obj)
        self.assertEquals(1, sports.nba.models.Season.objects.filter(
            season_year=2015, season_type='reg').count())  # should have parsed 1 thing

        away_team_oplog_obj = OpLogObjWrapper(
            self.sport, 'team', literal_eval(self.away_team_str))
        self.away_team_parser.parse(away_team_oplog_obj)
        # should be 1 team in there now
        self.assertEquals(1, sports.nba.models.Team.objects.all().count())

        home_team_oplog_obj = OpLogObjWrapper(
            self.sport, 'team', literal_eval(self.home_team_str))
        self.home_team_parser.parse(home_team_oplog_obj)
        # should be 2 teams in there now
        self.assertEquals(2, sports.nba.models.Team.objects.all().count())

        # now attempt to parse the game
        game_oplog_obj = OpLogObjWrapper(
            self.sport, 'game', literal_eval(self.game_str))
        self.game_parser.parse(game_oplog_obj)
        self.assertEquals(1, sports.nba.models.Game.objects.all().count())
 def test_pst_season(self):
     obj = literal_eval(self.obj_str)
     srid = obj.get('id')  # the srid will be found in the 'id' field
     oplog_obj = OpLogObjWrapper('nba', 'season_schedule', obj)
     self.season_parser.parse(oplog_obj)
     season = sports.nba.models.Season.objects.get(srid=srid)
     self.__validate_season(season, 2015, 'pst')
 def __parse_and_send(self, unwrapped_obj, target):
     # oplog_obj = OpLogObjWrapper('nflo', 'play', unwrapped_obj)
     # self.parser.parse(oplog_obj, target=('nflo.play', 'pbp'))
     parts = target[0].split('.')
     oplog_obj = OpLogObjWrapper(parts[0], parts[1], unwrapped_obj)
     self.parser.parse(oplog_obj, target=target)
     print('self.o:', str(self.parser.o))
     print('about to call send()...')
     self.parser.send()
     print('... called send()')
Exemple #4
0
    def parse_and_send(self, unwrapped_obj, target, tag=None):
        # create a new parser instance
        self.parser = PbpEventParser()

        #
        parts = target[0].split('.')
        oplog_obj = OpLogObjWrapper(parts[0], parts[1], unwrapped_obj)
        if tag is not None:
            print('tag:', tag)

        self.parser.parse(oplog_obj, target=target)
    def test_1(self):

        cache = self.cache_class(clear=True)

        at_bat_no_description_obj = {
            'dd_updated__id':
            1469581577314,
            'game__id':
            '530ca8e9-dd8a-4c19-9ba2-1f25a2ea8818',
            'hitter_id':
            '31d992e8-1016-484a-b7c3-2b5851442cc5',
            'id':
            '5baa2323-c8cb-476a-ba1e-0c0de56b370a',
            'parent_api__id':
            'pbp',
            'pitchs': [{
                'pitch': 'c108e24b-e60e-451a-91d9-86fb576865a1'
            }, {
                'pitch': '783c97f1-9a36-4645-8de6-9d9de77bef6b'
            }, {
                'pitch': 'd113b5c5-55f4-4b73-a63d-268f1d1f44f6'
            }, {
                'pitch': 'c4573125-c646-4ca9-8232-05e8686301ee'
            }, {
                'pitch': 'd337ddf6-7b0a-495f-92db-e48fddca9c11'
            }, {
                'pitch': 'd17d7831-50db-47ee-8f43-0f57495b0903'
            }],
            'steal':
            'dc649929-dbc0-4406-845b-20059552bcd1'
        }
        # wrap it with the oplog wrapper so itll work
        data = OpLogObjWrapper.wrap(at_bat_no_description_obj, ns='mlb.at_bat')
        at_bat_no_description = MlbOpLogObj(data)

        self.assertTrue(at_bat_no_description.override_new())
 def __parse_and_send(self, unwrapped_obj, target):
     parts = target[0].split('.')
     oplog_obj = OpLogObjWrapper(parts[0], parts[1], unwrapped_obj)
     self.parser.parse(oplog_obj, target=target)
     self.parser.send()
    def parse_obj(self, db, coll, mongo_obj, async=False):
        """
        mongo_obj is a dataden object without the oplog wrapper

        this method wraps the mongo_obj so it can be signaled,
        and sends it to the parser to automatically parse it into the django db

        :param db:
        :param coll:
        :param mongo_obj:
        :return:
        """
        try:
            # print('ns: %s.%s | mongo_obj: %s' % (db, coll, mongo_obj))
            Update(OpLogObjWrapper(db, coll, mongo_obj)).send(async=async)
        except Exception as e:
            print('ns: %s.%s | mongo_obj: %s' % (db, coll, str(mongo_obj)))
            raise Exception(e)

    def setup_all(self):
        """
        call setup() on all the sports

        :return:
        """
        sports = self.__get_valid_sports()
        for sport in sports:
            self.setup(sport)

    def __get_valid_sports(self):