class PbpPushStatPrinter(ObjectPrinter): """ helper print examples of real-time (socket pushed) Play-by-Play objects. """ def __init__(self): super().__init__() self.dataden = DataDen() self.examples = 2 # number of printed examples per type self.categories = [ # db, coll, parent_api, distinct types # ('nba','event','pbp', 'event_type'), ('nhl', 'event', 'pbp', 'event_type'), # 'player', # 'boxscores' ] def print_examples(self): for db, coll, parent_api, distinct in self.categories: event_types = self.dataden.find(db, coll, parent_api).distinct(distinct) # print the array of event types print('') print('[%s] example object(s) for distinct values of field: %s ...' % (str(self.examples), distinct)) self.print(event_types, distinct) # print the unique values for the 'distinct' field for event_type in event_types: # get the objects of this type (probably many thousands!) events = self.dataden.find(db, coll, parent_api, target={distinct: event_type}) # print X examples for n, event in enumerate(events): if n >= self.examples: break # now print it self.print(event, '%s example %s' % (event_type, str(n + 1)))
def handle(self, *args, **options): """ :param args: :param options: :return: """ msg = 'updating season stats' self.stdout.write( msg ) dd = DataDen() site_sport = None for sport in options['sport']: # p = DataDenParser() # p.setup( sport, force_triggers=DataDenParser.SEASON_STATS_TRIGGERS ) seasons = dd.find(sport, 'TODO_collection', 'TODO_parent_api')
def get(request, draft_group_id): dgm = DraftGroupManager() draft_group = dgm.get_draft_group(draft_group_id) boxscores = dgm.get_game_boxscores(draft_group) dd = DataDen() game_srids = [] for b in boxscores: game_srids.append(b.srid_game) game_events = dd.find('nba', 'event', 'pbp', {'game__id': { '$in': game_srids }}) events = [] for e in game_events: events.append(e) return HttpResponse(json.dumps(events), content_type='application/json')
# # if force_triggers is set, it overrides if force_triggers is not None: triggers = force_triggers # # get and parse the corresponding objects for t in triggers: # # as a debug, print out the 'ns' and the 'parent_api', and count db = t[0] coll = t[1] parent_api = t[2] print('ns:%s.%s, parent_api:%s, target:%s' % (db, coll, parent_api, str(target))) cursor = dataden.find(db, coll, parent_api, target=target) size = cursor.count() print(' ... count: ' + str(size)) i = 1 for mongo_obj in cursor: # # create a oplog wrapper with the mongo object and signal it # so the parser takes care of the rest! if i % 100 == 0: msg = '(%s / %s)' % (str(i), str(size)) print(msg) self.parse_obj(db, coll, mongo_obj, async=async)
def handle(self, *args, **options): i = 0 play_srid = None words = [] send = False for arg in options['srids']: if i == 0: play_srid = arg if i == 1: send = True words.append(arg) i += 1 phrase = ' '.join(words) self.stdout.write('+++ nflo play objects | %s +++' % play_srid) self.stdout.write('-------------------------------------------------------') #self.stdout.write('description must contain: "%s"' % str(phrase)) self.stdout.write('') from dataden.classes import DataDen dd = DataDen() db = 'nflo' parent_api = 'pbp' # get the play object play = None target = { 'id': play_srid, # 'description': { # '$regex': phrase # } } plays = dd.find(db, 'play', parent_api, target=target) for obj in plays: play = obj # play_srid = play.get('id') #play_srid = srid # because were passing it into the command now sl = None # start location object sp = None # start possession object el = None # end location object ep = None # end possession object # start situation data situation_list_id = 'start_situation__list' situation = play.get(situation_list_id, {}) sl_srid = situation.get('location', '') locations = dd.find(db, 'location', parent_api, {'id': sl_srid, 'play__id': play_srid, 'parent_list__id': situation_list_id}) for obj in locations: sl = obj sp_srid = situation.get('possession', '') possessions = dd.find(db, 'possession', parent_api, {'id': sp_srid, 'play__id': play_srid, 'parent_list__id': situation_list_id}) for obj in possessions: sp = obj # end situation data situation_list_id = 'end_situation__list' situation = play.get(situation_list_id, {}) el_srid = situation.get('location', '') locations = dd.find(db, 'location', parent_api, {'id': el_srid, 'play__id': play_srid, 'parent_list__id': situation_list_id}) for obj in locations: el = obj ep_srid = situation.get('possession', '') possessions = dd.find(db, 'possession', parent_api, {'id': ep_srid, 'play__id': play_srid, 'parent_list__id': situation_list_id}) for obj in possessions: ep = obj sport_db = 'nflo' parent_api = 'pbp' self.stdout.write("sport_db = '%s'" % sport_db) self.stdout.write("parent_api = '%s'" % parent_api) self.stdout.write('') self.print_obj('start_location', sl, 'location', sport_db=sport_db, parent_api=parent_api, send=send) self.print_obj('start_possession', sp, 'possession', sport_db=sport_db, parent_api=parent_api, send=send) self.print_obj('end_location', el, 'location', sport_db=sport_db, parent_api=parent_api, send=send) self.print_obj('end_possession', ep, 'possession', sport_db=sport_db, parent_api=parent_api, send=send) self.print_obj('play', play, 'play', sport_db=sport_db, parent_api=parent_api, send=send) self.stdout.write('') # one more space at the end of output