def scouting(self, scouting_type, event_key): if scouting_type == 'match': matches = sharkscout.Mongo().scouting_matches_raw(event_key) return self._csv(event_key + '_scouting_match_', matches) elif scouting_type == 'pit': teams = sharkscout.Mongo().scouting_pit_teams(event_key) return self._csv(event_key + '_scouting_pit_', teams)
def team(self, team_key, path=None, *args): if path is None: sharkscout.Mongo().team_update(team_key) if path == 'events': sharkscout.Mongo().team_update_events(team_key, args[0]) raise cherrypy.HTTPRedirect('/team/' + team_key + '/' + args[0]) raise cherrypy.HTTPRedirect('/team/' + team_key)
def teams(self, team_page=0): page = { 'team_page': int(team_page), 'stats': sharkscout.Mongo().teams_stats(), 'teams': sharkscout.Mongo().teams_paged(team_page) } return self.display('teams', page)
def team(self, team_key, year=None): if year is None: year = date.today().year team = sharkscout.Mongo().team(team_key, year) page = { 'team': team, 'year': year, 'stats': sharkscout.Mongo().team_stats(team_key), 'can_scout': { 'match': self.can_render('scouting/' + str(year) + '/match'), 'pit': self.can_render('scouting/' + str(year) + '/pit') }, 'modified_timestamp': team['modified_timestamp'] } return self.display('team', page)
def pit(self, event_key, team_key=None): event = sharkscout.Mongo().event(event_key) team = sharkscout.Mongo().team(team_key, event['year']) if team_key else {} saved = {} if event_key and team_key: saved = sharkscout.Mongo().scouting_pit(event_key, team_key) page = { 'event': event, 'teams': event['teams'] if 'teams' in event else [], 'team': team, 'saved': saved } page['__FORM__'] = self.render( 'scouting/' + str(event['year']) + '/pit', page) return self.display('scout_pit', page)
def events(self, year=None): if year is None: year = date.today().year events = sharkscout.Mongo().events(year) page = { 'year': year, 'stats': sharkscout.Mongo().events_stats(year), 'events': events, 'events_attending': [ e for e in events if 'teams' in e and 'team_number' in cherrypy.session and 'frc' + cherrypy.session['team_number'] in e['teams'] ], 'events_active': [ e for e in events if e['start_date'] and datetime.strptime( e['start_date'], '%Y-%m-%d').date() <= date.today() and e['end_date'] and date.today() <= datetime.strptime( e['end_date'], '%Y-%m-%d').date() ], 'events_district': [], 'events_upcoming': [ e for e in events if e['start_date'] and datetime.strptime( e['start_date'], '%Y-%m-%d').date() > date.today() ] } if 'team_number' in cherrypy.session: team = sharkscout.Mongo().team( 'frc' + str(cherrypy.session['team_number'])) if 'districts' in team and str(year) in team['districts']: district = team['districts'][str(year)] page.update({ 'district': district, 'events_district': [ e for e in events if 'district' in e and e['district'] and e['district'] ['abbreviation'] == district['abbreviation'] ] }) return self.display('events', page)
def match(self, event_key, match_key=None, team_key=None): event = sharkscout.Mongo().event(event_key) matches = [m for m in event['matches'] if m['key'] == match_key] if match_key else [] match = matches[0] if matches else {} teams = { 'blue': [ ''.join([c for c in t if c.isdigit()]) for t in match['alliances']['blue']['teams'] ], 'red': [ ''.join([c for c in t if c.isdigit()]) for t in match['alliances']['red']['teams'] ] } if match else {} team = sharkscout.Mongo().team(team_key, event['year']) if team_key else {} if team: team['color'] = [ c for c in teams if str(team['team_number']) in teams[c] ] team['color'] = team['color'][0] if team['color'] else '' saved = {} if event_key and match_key and team_key: saved = sharkscout.Mongo().scouting_match(event_key, match_key, team_key) page = { 'event': event, 'match': match, 'teams': teams, 'team': team, 'saved': saved } page['__FORM__'] = self.render( 'scouting/' + str(event['year']) + '/match', page) return self.display('scout_match', page)
def stats(self, event_key, match_key): event = sharkscout.Mongo().event(event_key) matches = [m for m in event['matches'] if m['key'] == match_key] if match_key else [] match = matches[0] if matches else {} stats = sharkscout.Mongo().scouting_stats(event_key) alliance_stats = {} for alliance in match['alliances']: alliance_stats[alliance] = [ s for s in stats['individual'] if s['_id'] in match['alliances'][alliance]['teams'] ] page = { 'event': event, 'match': match, 'alliance_stats': alliance_stats } return self.display('stats', page)
def event(self, event_key, stats_matches=0): event = sharkscout.Mongo().event(event_key) page = { 'event': event, 'stats_matches': int(stats_matches), 'years': sharkscout.Mongo().event_years(event['event_code']), 'can_scout': { 'match': self.can_render('scouting/' + str(event['year']) + '/match'), 'pit': self.can_render('scouting/' + str(event['year']) + '/pit') }, 'modified_timestamp': event['modified_timestamp'] } try: stats = sharkscout.Mongo().scouting_stats(event_key, stats_matches) page['stats'] = stats['individual'] page['scatter'] = stats['scatter'] except Exception as e: page['stats'] = [] page['scatter'] = {} cherrypy.log(e) return self.display('event', page)
def matches(self, event_key): event = sharkscout.Mongo().event(event_key) matches = [] if 'matches' in event: for match in event['matches']: row = { k: match[k] for k in ['comp_level', 'match_number', 'set_number', 'time'] } for alliance in match['alliances']: for idx, team in enumerate( match['alliances'][alliance]['teams']): row[alliance + '_' + str(idx + 1)] = team matches.append(row) return self._csv(event_key + '_matches_', matches)
def received_message(self, message): message = message.data.decode() try: message = json.loads(message) if 'ping' in message: self.send({'pong': 'pong'}) if 'time_team' in message: self.send({ 'time_team': sharkscout.Mongo().team(message['time_team']) }) # Match scouting upserts if 'scouting_match' in message: for data in message['scouting_match']: if sharkscout.Mongo().scouting_match_update(data): self.send({ 'dequeue': { 'scouting_match': data }, 'toast': { 'message': 'You match scouted ' + data['match_key'] + ' ' + data['team_key'], 'type': 'success' } }) self.broadcast({ 'show': '.match-listing .' + data['match_key'] + ' .' + data['team_key'] + ' .fa-check' }) self.broadcast_others({ 'toast': { 'message': data['scouter'] + ' match scouted ' + data['match_key'] + ' ' + data['team_key'], 'type': 'success', 'mobile': False } }) # Pit scouting upserts if 'scouting_pit' in message: for data in message['scouting_pit']: if sharkscout.Mongo().scouting_pit_update(data): self.send({ 'dequeue': { 'scouting_pit': data }, 'toast': { 'message': 'You pit scouted ' + data['event_key'] + ' ' + data['team_key'], 'type': 'success' } }) self.broadcast({ 'show': '.team-listing .' + data['team_key'] + ' .fa-check' }) self.broadcast_others({ 'toast': { 'message': data['scouter'] + ' pit scouted ' + data['event_key'] + ' ' + data['team_key'], 'type': 'success', 'mobile': False } }) except json.JSONDecodeError as e: cherrypy.log(e)
def stats(self, event_key, stats_matches): stats = sharkscout.Mongo().scouting_stats(event_key, stats_matches)['individual'] return self._csv(event_key + '_scouting_stats_', stats)
def teams(self): sharkscout.Mongo().teams_update() raise cherrypy.HTTPRedirect('/teams')
def event(self, event_key): sharkscout.Mongo().event_update(event_key) raise cherrypy.HTTPRedirect('/event/' + event_key)
def events(self, year): sharkscout.Mongo().events_update(year) raise cherrypy.HTTPRedirect('/events/' + year)
help='update event website\'s favicon when updating event info', action='store_true', default=False) parser.add_argument('-m', '--mongo', dest='mongo_host', help='mongo host URL', type=str) parser.add_argument('-d', '--dump', metavar='file', help='run mongodump after any update(s)', type=str) parser.add_argument('-r', '--restore', metavar='file', help='run mongorestore before any update(s)', type=argparse.FileType('r')) args = parser.parse_args() # Massage arguments args.update_events = list(args.update_events or []) args.update_events_info = list(args.update_events_info or []) # Logging logging.getLogger('backoff').addHandler(logging.StreamHandler()) # Start MongoDB mongo = sharkscout.Mongo(args.mongo_host) mongo.index() mongo.migrate() # mongorestore build_restored = False build_dump = os.path.join(os.path.dirname(__file__), 'mongodump.gz') if os.path.exists(build_dump): if not args.restore and not mongo.tba_count: args.restore = build_dump build_restored = True if args.restore: print('Importing database from "' + args.restore + '" ...') null = open(os.devnull, 'w') subprocess.Popen([ sharkscout.Util.which('mongorestore'),