def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() events = filter(lambda e: e.official, events) elif when == "last_day_only": events = EventHelper.getEventsWithinADay() events = filter(lambda e: e.official and e.ends_today, events) else: event_keys = Event.query(Event.official == True).filter( Event.year == int(when)).fetch(500, keys_only=True) events = ndb.get_multi(event_keys) for event in events: taskqueue.add(queue_name='datafeed', url='/tasks/get/fmsapi_event_alliances/' + event.key_name, method='GET') template_values = {'events': events} if 'X-Appengine-Taskname' not in self.request.headers: # Only write out if not in taskqueue path = os.path.join( os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_alliances_enqueue.html') self.response.out.write(template.render(path, template_values))
def get(self): live_events = EventHelper.getEventsWithinADay() for event in live_events: taskqueue.add(url='/tasks/math/do/predict_match_times/{}'.format(event.key_name), method='GET') # taskqueue.add(url='/tasks/do/bluezone_update', method='GET') self.response.out.write("Enqueued time prediction for {} events".format(len(live_events)))
def get(self): live_events = EventHelper.getEventsWithinADay() for event in live_events: taskqueue.add(url='/tasks/math/do/predict_match_times/{}'.format(event.key_name), method='GET') # taskqueue.add(url='/tasks/do/bluezone_update', method='GET') self.response.out.write("Enqueued time prediction for {} events".format(len(live_events)))
def get(self): live_events = EventHelper.getEventsWithinADay() try: BlueZoneHelper.update_bluezone(live_events) except Exception, e: logging.error("BlueZone update failed") logging.exception(e)
def get(self): live_events = EventHelper.getEventsWithinADay() for event in live_events: taskqueue.add(url='/tasks/math/do/predict_match_times/{}'.format( event.key_name), method='GET') # taskqueue.add(url='/tasks/do/bluezone_update', method='GET') # Clear down events for events that aren't live status_sitevar = Sitevar.get_by_id('apistatus.down_events') if status_sitevar is not None: live_event_keys = set([e.key.id() for e in live_events]) old_status = set(status_sitevar.contents) new_status = old_status.copy() for event_key in old_status: if event_key not in live_event_keys: new_status.remove(event_key) status_sitevar.contents = list(new_status) status_sitevar.put() # Clear API Response cache ApiStatusController.clear_cache_if_needed(old_status, new_status) self.response.out.write( "Enqueued time prediction for {} events".format(len(live_events)))
def get(self): live_events = EventHelper.getEventsWithinADay() try: BlueZoneHelper.update_bluezone(live_events) except Exception, e: logging.error("BlueZone update failed") logging.exception(e)
def get(self, event_key=None): self._require_login() self._require_registration() if event_key is None: events = EventHelper.getEventsWithinADay() EventHelper.sort_events(events) self.template_values['events'] = events self.response.out.write(jinja2_engine.render('mytba_add_hot_matches_base.html', self.template_values)) return event = Event.get_by_id(event_key) if not event: self.abort(404) subscriptions_future = Subscription.query( Subscription.model_type==ModelType.MATCH, Subscription.notification_types==NotificationType.UPCOMING_MATCH, ancestor=self.user_bundle.account.key).fetch_async(projection=[Subscription.model_key]) matches = [] if event.matchstats and 'match_predictions' in event.matchstats: match_predictions = event.matchstats['match_predictions'] max_hotness = 0 min_hotness = float('inf') for match in event.matches: if not match.has_been_played and match.key.id() in match_predictions: prediction = match_predictions[match.key.id()] red_score = prediction['red']['score'] blue_score = prediction['blue']['score'] if red_score > blue_score: winner_score = red_score loser_score = blue_score else: winner_score = blue_score loser_score = red_score hotness = winner_score + 2.0*loser_score # Favor close high scoring matches max_hotness = max(max_hotness, hotness) min_hotness = min(min_hotness, hotness) match.hotness = hotness matches.append(match) existing_subscriptions = set() for sub in subscriptions_future.get_result(): existing_subscriptions.add(sub.model_key) hot_matches = [] for match in matches: match.hotness = 100 * (match.hotness - min_hotness) / (max_hotness - min_hotness) match.already_subscribed = match.key.id() in existing_subscriptions hot_matches.append(match) hot_matches = sorted(hot_matches, key=lambda match: -match.hotness) matches_dict = {'qm': hot_matches[:25]} self.template_values['event'] = event self.template_values['matches'] = matches_dict self.response.out.write(jinja2_engine.render('mytba_add_hot_matches.html', self.template_values))
def get(self, event_key=None): self._require_registration() if event_key is None: events = EventHelper.getEventsWithinADay() EventHelper.sort_events(events) self.template_values['events'] = events self.response.out.write(jinja2_engine.render('mytba_add_hot_matches_base.html', self.template_values)) return event = Event.get_by_id(event_key) if not event: self.abort(404) subscriptions_future = Subscription.query( Subscription.model_type==ModelType.MATCH, Subscription.notification_types==NotificationType.UPCOMING_MATCH, ancestor=self.user_bundle.account.key).fetch_async(projection=[Subscription.model_key]) matches = [] if event.matchstats and 'match_predictions' in event.matchstats: match_predictions = event.matchstats['match_predictions'] max_hotness = 0 min_hotness = float('inf') for match in event.matches: if not match.has_been_played and match.key.id() in match_predictions: prediction = match_predictions[match.key.id()] red_score = prediction['red']['score'] blue_score = prediction['blue']['score'] if red_score > blue_score: winner_score = red_score loser_score = blue_score else: winner_score = blue_score loser_score = red_score hotness = winner_score + 2.0*loser_score # Favor close high scoring matches max_hotness = max(max_hotness, hotness) min_hotness = min(min_hotness, hotness) match.hotness = hotness matches.append(match) existing_subscriptions = set() for sub in subscriptions_future.get_result(): existing_subscriptions.add(sub.model_key) hot_matches = [] for match in matches: match.hotness = 100 * (match.hotness - min_hotness) / (max_hotness - min_hotness) match.already_subscribed = match.key.id() in existing_subscriptions hot_matches.append(match) hot_matches = sorted(hot_matches, key=lambda match: -match.hotness) matches_dict = {'qm': hot_matches[:25]} self.template_values['event'] = event self.template_values['matches'] = matches_dict self.response.out.write(jinja2_engine.render('mytba_add_hot_matches.html', self.template_values))
def get(self): self._require_registration() current_events = filter(lambda e: e.now, EventHelper.getEventsWithinADay()) popular_teams_events = TeamHelper.getPopularTeamsEvents(current_events) popular_team_keys = set() for team, _ in popular_teams_events: popular_team_keys.add(team.key.id()) for event in current_events: event.prep_details() event.prep_matches() finished_matches = [] current_matches = [] upcoming_matches = [] ranks = {} alliances = {} for event in current_events: if not event.details: continue finished_matches += MatchHelper.recentMatches(event.matches, num=1) for i, match in enumerate(MatchHelper.upcomingMatches(event.matches, num=3)): if not match.time: continue if not event.details.predictions or match.key.id() not in event.details.predictions['match_predictions']['qual' if match.comp_level == 'qm' else 'playoff']: match.prediction = defaultdict(lambda: defaultdict(float)) match.bluezone_score = 0 else: match.prediction = event.details.predictions['match_predictions']['qual' if match.comp_level == 'qm' else 'playoff'][match.key.id()] match.bluezone_score = self.get_qual_bluezone_score(match.prediction) if match.comp_level == 'qm' else self.get_elim_bluezone_score(match.prediction) if i == 0: current_matches.append(match) else: upcoming_matches.append(match) if event.details.rankings2: for rank in event.details.rankings2: ranks[rank['team_key']] = rank['rank'] if event.alliance_selections: for i, alliance in enumerate(event.alliance_selections): for pick in alliance['picks']: alliances[pick] = i + 1 finished_matches = sorted(finished_matches, key=lambda m: m.actual_time if m.actual_time else m.time) current_matches = sorted(current_matches, key=lambda m: m.predicted_time if m.predicted_time else m.time) upcoming_matches = sorted(upcoming_matches, key=lambda m: m.predicted_time if m.predicted_time else m.time) self.template_values.update({ 'finished_matches': finished_matches, 'current_matches': current_matches, 'upcoming_matches': upcoming_matches, 'ranks': ranks, 'alliances': alliances, 'popular_team_keys': popular_team_keys, }) self.response.out.write(jinja2_engine.render('match_suggestion.html', self.template_values))
def get(self): self._require_registration() current_events = filter(lambda e: e.now, EventHelper.getEventsWithinADay()) self.template_values.update({ 'event_keys_json': json.dumps([e.key.id() for e in current_events]), }) self.response.out.write(jinja2_engine.render('match_timeline.html', self.template_values))
def get(self): self._require_registration() current_events = filter(lambda e: e.now, EventHelper.getEventsWithinADay()) for event in current_events: event.prep_details() event.prep_matches() finished_matches = [] current_matches = [] upcoming_matches = [] ranks = {} alliances = {} for event in current_events: if not event.details: continue finished_matches += MatchHelper.recentMatches(event.matches, num=1) for i, match in enumerate(MatchHelper.upcomingMatches(event.matches, num=3)): if not match.time: continue if not event.details.predictions or match.key.id() not in event.details.predictions['match_predictions']['qual' if match.comp_level == 'qm' else 'playoff']: match.prediction = defaultdict(lambda: defaultdict(float)) match.bluezone_score = 0 else: match.prediction = event.details.predictions['match_predictions']['qual' if match.comp_level == 'qm' else 'playoff'][match.key.id()] match.bluezone_score = self.get_qual_bluezone_score(match.prediction) if match.comp_level == 'qm' else self.get_elim_bluezone_score(match.prediction) if i == 0: current_matches.append(match) else: upcoming_matches.append(match) if event.details.rankings2: for rank in event.details.rankings2: ranks[rank['team_key']] = rank['rank'] if event.alliance_selections: for i, alliance in enumerate(event.alliance_selections): for pick in alliance['picks']: alliances[pick] = i + 1 finished_matches = sorted(finished_matches, key=lambda m: m.actual_time if m.actual_time else m.time) current_matches = sorted(current_matches, key=lambda m: m.predicted_time if m.predicted_time else m.time) upcoming_matches = sorted(upcoming_matches, key=lambda m: m.predicted_time if m.predicted_time else m.time) self.template_values.update({ 'finished_matches': finished_matches, 'current_matches': current_matches, 'upcoming_matches': upcoming_matches, 'ranks': ranks, 'alliances': alliances, }) self.response.out.write(jinja2_engine.render('match_suggestion.html', self.template_values))
def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() else: events = Event.query(Event.year == int(when)).fetch(500) for event in events: taskqueue.add(url="/tasks/math/do/event_matchstats/" + event.key_name, method="GET") template_values = {"event_count": len(events), "year": when} path = os.path.join(os.path.dirname(__file__), "../templates/math/event_matchstats_enqueue.html") self.response.out.write(template.render(path, template_values))
def get(self): self._require_login() self._require_registration() user = self.user_bundle.account.key now = datetime.datetime.now() team_favorites_future = Favorite.query(Favorite.model_type == ModelType.TEAM, ancestor=user).fetch_async() live_events = EventHelper.getEventsWithinADay() favorite_team_keys = map(lambda f: ndb.Key(Team, f.model_key), team_favorites_future.get_result()) favorite_teams_future = ndb.get_multi_async(favorite_team_keys) live_eventteams_futures = [] for event in live_events: live_eventteams_futures.append(EventTeamsQuery(event.key_name).fetch_async()) favorite_teams = [team_future.get_result() for team_future in favorite_teams_future] favorite_teams_events_futures = [] for team in favorite_teams: favorite_teams_events_futures.append(TeamYearEventsQuery(team.key_name, now.year).fetch_async()) live_events_with_teams = EventTeamStatusHelper.buildEventTeamStatus(live_events, live_eventteams_futures, favorite_teams) future_events_by_event = {} for team, events_future in zip(favorite_teams, favorite_teams_events_futures): events = events_future.get_result() if not events: continue EventHelper.sort_events(events) next_event = next((e for e in events if e.start_date > now and not e.within_a_day), None) if next_event: if next_event.key_name not in future_events_by_event: future_events_by_event[next_event.key_name] = (next_event, []) future_events_by_event[next_event.key_name][1].append(team) future_events_with_teams = [] for event_key, data in future_events_by_event.iteritems(): future_events_with_teams.append((data[0], TeamHelper.sortTeams(data[1]))) future_events_with_teams.sort(key=lambda x: x[0].name) future_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoStartDate(x[0])) future_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoEndDate(x[0])) self.template_values.update({ 'live_events_with_teams': live_events_with_teams, 'future_events_with_teams': future_events_with_teams, }) path = os.path.join(os.path.dirname(__file__), '../templates/mytba_live.html') self.response.out.write(template.render(path, self.template_values))
def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() events = filter(lambda e: e.official, events) elif when == "last_day_only": events = EventHelper.getEventsWithinADay() events = filter(lambda e: e.official and e.ends_today, events) else: event_keys = Event.query(Event.official == True).filter(Event.year == int(when)).fetch(500, keys_only=True) events = ndb.get_multi(event_keys) for event in events: taskqueue.add( queue_name='datafeed', url='/tasks/get/fmsapi_event_alliances/' + event.key_name, method='GET') template_values = { 'events': events } path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_alliances_enqueue.html') self.response.out.write(template.render(path, template_values))
def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() else: events = Event.query(Event.year == int(when)).fetch(500) for event in events: taskqueue.add(url='/tasks/math/do/event_matchstats/' + event.key_name, method='GET') template_values = {'event_count': len(events), 'year': when} path = os.path.join(os.path.dirname(__file__), '../templates/math/event_matchstats_enqueue.html') self.response.out.write(template.render(path, template_values))
def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() else: event_keys = Event.query(Event.official == True).filter(Event.year == int(when)).fetch(500, keys_only=True) events = ndb.get_multi(event_keys) for event in events: taskqueue.add( queue_name='usfirst', url='/tasks/get/usfirst_awards/%s' % (event.key_name), method='GET') template_values = { 'events': events, } path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_awards_enqueue.html') self.response.out.write(template.render(path, template_values))
def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() else: event_keys = Event.query(Event.official == True).filter(Event.year == int(when)).fetch(500, keys_only=True) events = ndb.get_multi(event_keys) for event in events: taskqueue.add( queue_name='usfirst', url='/tasks/get/usfirst_awards/%s' % (event.key_name), method='GET') template_values = { 'events': events, } path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_awards_enqueue.html') self.response.out.write(template.render(path, template_values))
def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() else: events = Event.query(Event.year == int(when)).fetch(500) EventHelper.sort_events(events) for event in events: taskqueue.add( queue_name='run-in-order', # Because predictions depend on past events url='/tasks/math/do/event_matchstats/' + event.key_name, method='GET') template_values = { 'event_count': len(events), 'year': when } path = os.path.join(os.path.dirname(__file__), '../templates/math/event_matchstats_enqueue.html') self.response.out.write(template.render(path, template_values))
def get(self, when): if when == "now": events = EventHelper.getEventsWithinADay() events = filter(lambda e: e.official, events) else: event_keys = Event.query(Event.official == True).filter(Event.year == int(when)).fetch(500, keys_only=True) events = ndb.get_multi(event_keys) for event in events: taskqueue.add( queue_name='datafeed', url='/tasks/get/fmsapi_matches/' + event.key_name, method='GET') template_values = { 'events': events, } if 'X-Appengine-Taskname' not in self.request.headers: # Only write out if not in taskqueue path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_enqueue.html') self.response.out.write(template.render(path, template_values))
def get(self): self._require_registration() current_events = filter(lambda e: e.now, EventHelper.getEventsWithinADay()) for event in current_events: event.prep_details() event.prep_matches() finished_matches = [] current_matches = [] upcoming_matches = [] ranks = {} for event in current_events: finished_matches += MatchHelper.recentMatches(event.matches, num=1) for i, match in enumerate(MatchHelper.upcomingMatches(event.matches, num=3)): if match.key.id() not in event.details.predictions['match_predictions']['qual' if match.comp_level == 'qm' else 'playoff']: match.prediction = defaultdict(lambda: defaultdict()) match.bluezone_score = 0 continue match.prediction = event.details.predictions['match_predictions']['qual' if match.comp_level == 'qm' else 'playoff'][match.key.id()] match.bluezone_score = self.get_qual_bluezone_score(match.prediction) if match.comp_level == 'qm' else self.get_elim_bluezone_score(match.prediction) if i == 0: current_matches.append(match) else: upcoming_matches.append(match) for rank in event.details.rankings2: ranks[rank['team_key']] = rank['rank'] finished_matches = sorted(finished_matches, key=lambda m: m.actual_time if m.actual_time else m.time) current_matches = sorted(current_matches, key=lambda m: m.predicted_time if m.predicted_time else m.time) upcoming_matches = sorted(upcoming_matches, key=lambda m: m.predicted_time if m.predicted_time else m.time) self.template_values.update({ 'finished_matches': finished_matches, 'current_matches': current_matches, 'upcoming_matches': upcoming_matches, 'ranks': ranks, }) self.response.out.write(jinja2_engine.render('match_suggestion.html', self.template_values))
def get(self): live_events = EventHelper.getEventsWithinADay() for event in live_events: taskqueue.add(url='/tasks/math/do/predict_match_times/{}'.format(event.key_name), method='GET') # taskqueue.add(url='/tasks/do/bluezone_update', method='GET') # Clear down events for events that aren't live status_sitevar = Sitevar.get_by_id('apistatus.down_events') if status_sitevar is not None: live_event_keys = set([e.key.id() for e in live_events]) old_status = set(status_sitevar.contents) new_status = old_status.copy() for event_key in old_status: if event_key not in live_event_keys: new_status.remove(event_key) status_sitevar.contents = list(new_status) status_sitevar.put() # Clear API Response cache ApiStatusController.clear_cache_if_needed(old_status, new_status) self.response.out.write("Enqueued time prediction for {} events".format(len(live_events)))
def get(self): self._require_login() self._require_registration() user = self.user_bundle.account.key now = datetime.datetime.now() team_favorites_future = Favorite.query( Favorite.model_type == ModelType.TEAM, ancestor=user).fetch_async() live_events = EventHelper.getEventsWithinADay() favorite_team_keys = map(lambda f: ndb.Key(Team, f.model_key), team_favorites_future.get_result()) favorite_teams_future = ndb.get_multi_async(favorite_team_keys) live_eventteams_futures = [] for event in live_events: live_eventteams_futures.append( EventTeamsQuery(event.key_name).fetch_async()) favorite_teams = [ team_future.get_result() for team_future in favorite_teams_future ] favorite_teams_events_futures = [] for team in favorite_teams: favorite_teams_events_futures.append( TeamYearEventsQuery(team.key_name, now.year).fetch_async()) live_events_with_teams = EventTeamStatusHelper.buildEventTeamStatus( live_events, live_eventteams_futures, favorite_teams) future_events_by_event = {} for team, events_future in zip(favorite_teams, favorite_teams_events_futures): events = events_future.get_result() if not events: continue EventHelper.sort_events(events) next_event = next( (e for e in events if e.start_date > now and not e.within_a_day), None) if next_event: if next_event.key_name not in future_events_by_event: future_events_by_event[next_event.key_name] = (next_event, []) future_events_by_event[next_event.key_name][1].append(team) future_events_with_teams = [] for event_key, data in future_events_by_event.iteritems(): future_events_with_teams.append( (data[0], TeamHelper.sortTeams(data[1]))) future_events_with_teams.sort(key=lambda x: x[0].name) future_events_with_teams.sort( key=lambda x: EventHelper.distantFutureIfNoStartDate(x[0])) future_events_with_teams.sort( key=lambda x: EventHelper.distantFutureIfNoEndDate(x[0])) self.template_values.update({ 'live_events_with_teams': live_events_with_teams, 'future_events_with_teams': future_events_with_teams, }) path = os.path.join(os.path.dirname(__file__), '../templates/mytba_live.html') self.response.out.write(template.render(path, self.template_values))
def get(self): live_events = EventHelper.getEventsWithinADay() NotificationHelper.send_upcoming_matches(live_events)
def get(self): live_events = EventHelper.getEventsWithinADay() NotificationHelper.send_upcoming_matches(live_events)