def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() popular_teams_events = TeamHelper.getPopularTeamsEvents(week_events) # Only show special webcasts that aren't also hosting an event special_webcasts = [] for special_webcast in FirebasePusher.get_special_webcasts(): add = True for event in week_events: if event.now and event.webcast: for event_webcast in event.webcast: if (special_webcast.get('type', '') == event_webcast.get('type', '') and special_webcast.get('channel', '') == event_webcast.get('channel', '') and special_webcast.get('file', '') == event_webcast.get('file', '')): add = False break if not add: break if add: special_webcasts.append(special_webcast) self.template_values.update({ "events": week_events, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, "popular_teams_events": popular_teams_events, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() year = datetime.datetime.now().year special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ "events": week_events, "year": year, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) insights = ndb.get_multi([ ndb.Key(Insight, Insight.renderKeyName(year, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values() ]) for insight in insights: if insight: self.template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/index_insights.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): kickoff_datetime_est = datetime.datetime.strptime( self.template_values['kickoff_datetime'], "%Y-%m-%dT%H:%M:%S" ) if 'kickoff_datetime' in self.template_values else None kickoff_datetime_utc = pytz.utc.localize(kickoff_datetime_est + datetime.timedelta(hours=5)) special_webcasts = FirebasePusher.get_special_webcasts() is_kickoff = datetime.datetime.now( ) >= kickoff_datetime_est - datetime.timedelta( days=1) # turn on 1 day before week_events = EventHelper.getWeekEvents() self.template_values.update({ 'events': week_events, 'is_kickoff': is_kickoff, 'kickoff_datetime_est': kickoff_datetime_est, 'kickoff_datetime_utc': kickoff_datetime_utc, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) path = os.path.join(os.path.dirname(__file__), "../templates/index_kickoff.html") return template.render(path, self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ "events": week_events, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ "events": week_events, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): kickoff_datetime_utc = datetime.datetime.strptime( self.template_values['kickoff_datetime'], "%Y-%m-%dT%H:%M:%S" ) if 'kickoff_datetime' in self.template_values else None week_events = EventHelper.getWeekEvents() special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ "events": week_events, 'kickoff_datetime_utc': kickoff_datetime_utc, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_offseason.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): kickoff_datetime_utc = datetime.datetime.strptime( self.template_values['kickoff_datetime'], "%Y-%m-%dT%H:%M:%S" ) if 'kickoff_datetime' in self.template_values else None week_events = EventHelper.getWeekEvents() special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ "events": week_events, 'kickoff_datetime_utc': kickoff_datetime_utc, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_offseason.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ "events": EventHelper.getWeekEvents(), 'kickoff_datetime_utc': SeasonHelper.kickoff_datetime_utc(), "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) return jinja2_engine.render('index/index_offseason.html', self.template_values)
def _render(self, *args, **kw): effective_season_year = SeasonHelper.effective_season_year() special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ 'seasonstart_datetime_utc': SeasonHelper.first_event_datetime_utc(effective_season_year), 'events': EventHelper.getWeekEvents(), "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) return jinja2_engine.render('index/index_buildseason.html', self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() year = datetime.datetime.now().year special_webcasts = FirebasePusher.get_special_webcasts() self.template_values.update({ "events": week_events, "year": year, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) insights = ndb.get_multi([ndb.Key(Insight, Insight.renderKeyName(year, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values()]) for insight in insights: if insight: self.template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/index_insights.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): kickoff_datetime_est = datetime.datetime.strptime( self.template_values['kickoff_datetime'], "%Y-%m-%dT%H:%M:%S" ) if 'kickoff_datetime' in self.template_values else None kickoff_datetime_utc = pytz.utc.localize( kickoff_datetime_est + datetime.timedelta(hours=5)) special_webcasts = FirebasePusher.get_special_webcasts() is_kickoff = datetime.datetime.now() >= kickoff_datetime_est - datetime.timedelta(days=1) # turn on 1 day before week_events = EventHelper.getWeekEvents() self.template_values.update({ 'events': week_events, 'is_kickoff': is_kickoff, 'kickoff_datetime_est': kickoff_datetime_est, 'kickoff_datetime_utc': kickoff_datetime_utc, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) path = os.path.join(os.path.dirname(__file__), "../templates/index_kickoff.html") return template.render(path, self.template_values)
def _render(self, *args, **kw): special_webcasts = FirebasePusher.get_special_webcasts() effective_season_year = SeasonHelper.effective_season_year() self.template_values.update({ 'events': EventHelper.getWeekEvents(), 'is_kickoff': SeasonHelper.is_kickoff_at_least_one_day_away( year=effective_season_year), 'kickoff_datetime_est': SeasonHelper.kickoff_datetime_est(effective_season_year), 'kickoff_datetime_utc': SeasonHelper.kickoff_datetime_utc(effective_season_year), "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, }) return jinja2_engine.render('index/index_kickoff.html', self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() popular_teams_events = TeamHelper.getPopularTeamsEvents(week_events) # Only show special webcasts that aren't also hosting an event special_webcasts = [] for special_webcast in FirebasePusher.get_special_webcasts(): add = True for event in week_events: if event.now and event.webcast: for event_webcast in event.webcast: if (special_webcast.get( 'type', '') == event_webcast.get('type', '') and special_webcast.get('channel', '') == event_webcast.get('channel', '') and special_webcast.get('file', '') == event_webcast.get('file', '')): add = False break if not add: break if add: special_webcasts.append(special_webcast) self.template_values.update({ "events": week_events, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, "popular_teams_events": popular_teams_events, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() special_webcasts = FirebasePusher.get_special_webcasts() events = {} for event in week_events: events[event.key.id()] = event # Calculate popular teams # Get cached team keys event_team_keys = memcache.get_multi(events.keys(), namespace='event-team-keys') # Get uncached team keys to_query = set(events.keys()).difference(event_team_keys.keys()) event_teams_futures = [ (event_key, EventTeam.query( EventTeam.event == ndb.Key(Event, event_key)).fetch_async( projection=[EventTeam.team])) for event_key in to_query ] # Merge cached and uncached team keys for event_key, event_teams in event_teams_futures: event_team_keys[event_key] = [ et.team.id() for et in event_teams.get_result() ] memcache.set_multi(event_team_keys, 60 * 60 * 24, namespace='event-team-keys') team_keys = [] team_events = {} for event_key, event_team_keys in event_team_keys.items(): team_keys += event_team_keys for team_key in event_team_keys: team_events[team_key] = events[event_key] # Get cached counts team_favorite_counts = memcache.get_multi( team_keys, namespace='team-favorite-counts') # Get uncached counts to_count = set(team_keys).difference(team_favorite_counts.keys()) count_futures = [ (team_key, Favorite.query(Favorite.model_key == team_key).count_async()) for team_key in to_count ] # Merge cached and uncached counts for team_key, count_future in count_futures: team_favorite_counts[team_key] = count_future.get_result() memcache.set_multi(team_favorite_counts, 60 * 60 * 24, namespace='team-favorite-counts') # Sort to get top popular teams popular_team_keys = [] for team_key, _ in sorted(team_favorite_counts.items(), key=lambda tc: -tc[1])[:25]: popular_team_keys.append(ndb.Key(Team, team_key)) popular_teams = sorted(ndb.get_multi(popular_team_keys), key=lambda team: team.team_number) popular_teams_events = [] for team in popular_teams: popular_teams_events.append((team, team_events[team.key.id()])) self.template_values.update({ "events": week_events, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, "popular_teams_events": popular_teams_events, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() special_webcasts = FirebasePusher.get_special_webcasts() events = {} for event in week_events: events[event.key.id()] = event # Calculate popular teams # Get cached team keys event_team_keys = memcache.get_multi(events.keys(), namespace='event-team-keys') # Get uncached team keys to_query = set(events.keys()).difference(event_team_keys.keys()) event_teams_futures = [( event_key, EventTeam.query(EventTeam.event == ndb.Key(Event, event_key)).fetch_async(projection=[EventTeam.team]) ) for event_key in to_query] # Merge cached and uncached team keys for event_key, event_teams in event_teams_futures: event_team_keys[event_key] = [et.team.id() for et in event_teams.get_result()] memcache.set_multi(event_team_keys, 60*60*24, namespace='event-team-keys') team_keys = [] team_events = {} for event_key, event_team_keys in event_team_keys.items(): team_keys += event_team_keys for team_key in event_team_keys: team_events[team_key] = events[event_key] # Get cached counts team_favorite_counts = memcache.get_multi(team_keys, namespace='team-favorite-counts') # Get uncached counts to_count = set(team_keys).difference(team_favorite_counts.keys()) count_futures = [( team_key, Favorite.query(Favorite.model_key == team_key).count_async() ) for team_key in to_count] # Merge cached and uncached counts for team_key, count_future in count_futures: team_favorite_counts[team_key] = count_future.get_result() memcache.set_multi(team_favorite_counts, 60*60*24, namespace='team-favorite-counts') # Sort to get top popular teams popular_team_keys = [] for team_key, _ in sorted(team_favorite_counts.items(), key=lambda tc: -tc[1])[:25]: popular_team_keys.append(ndb.Key(Team, team_key)) popular_teams = sorted(ndb.get_multi(popular_team_keys), key=lambda team: team.team_number) popular_teams_events = [] for team in popular_teams: popular_teams_events.append((team, team_events[team.key.id()])) self.template_values.update({ "events": week_events, "any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts), "special_webcasts": special_webcasts, "popular_teams_events": popular_teams_events, }) path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html') return template.render(path, self.template_values)