def _createInsight(self, data, name, year): """ Create Insight object given data, name, and year """ return Insight(id=Insight.renderKeyName(year, name), name=name, year=year, data_json=json.dumps(data))
def doOverallAwardInsights(self): """ Calculate award insights across all years. Returns a list of Insights. """ insights = [] year_regional_winners = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.REGIONAL_DISTRICT_WINNERS], Insight.year != 0).fetch(1000) regional_winners = defaultdict(int) for insight in year_regional_winners: for number, team_list in insight.data: for team in team_list: regional_winners[team] += number year_blue_banners = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], Insight.year != 0).fetch(1000) blue_banners = defaultdict(int) for insight in year_blue_banners: for number, team_list in insight.data: for team in team_list: blue_banners[team] += number year_rca_winners = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], Insight.year != 0).fetch(1000) rca_winners = defaultdict(int) for insight in year_rca_winners: for team in insight.data: rca_winners[team] += 1 year_world_champions = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], Insight.year != 0).fetch(1000) world_champions = defaultdict(int) for insight in year_world_champions: for team in insight.data: world_champions[team] += 1 # Sorting regional_winners = self._sortTeamWinsDict(regional_winners) blue_banners = self._sortTeamWinsDict(blue_banners) rca_winners = self._sortTeamWinsDict(rca_winners) world_champions = self._sortTeamWinsDict(world_champions) # Creating Insights if regional_winners: insights.append(self._createInsight(regional_winners, Insight.INSIGHT_NAMES[Insight.REGIONAL_DISTRICT_WINNERS], 0)) if blue_banners: insights.append(self._createInsight(blue_banners, Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], 0)) if rca_winners: insights.append(self._createInsight(rca_winners, Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], 0)) if world_champions: insights.append(self._createInsight(world_champions, Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], 0)) return insights
def _render(self): template_values = { 'valid_years': VALID_YEARS, } insight_futures = [Insight.get_by_id_async(Insight.renderKeyName(0, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values()] for insight_future in insight_futures: insight = insight_future.get_result() if insight: template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/insights.html') return template.render(path, template_values)
def _render(self, year): template_values = { 'valid_years': VALID_YEARS, 'selected_year': year, } insight_futures = [Insight.get_by_id_async(Insight.renderKeyName(year, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values()] for insight_future in insight_futures: insight = insight_future.get_result() if insight: template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/insights_details.html') return template.render(path, template_values) if tba_config.CONFIG["memcache"]: memcache.set(memcache_key, html, 86400)
def _render(self, year): self.template_values.update({ 'valid_years': VALID_YEARS, 'selected_year': year, }) insights = ndb.get_multi([ ndb.Key(Insight, Insight.renderKeyName(year, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values() ]) last_updated = None for insight in insights: if insight: self.template_values[insight.name] = insight if last_updated is None: last_updated = insight.updated else: last_updated = max(last_updated, insight.updated) self.template_values[ 'year_specific_insights_template'] = 'event_partials/event_insights_{}.html'.format( year) self.template_values['last_updated'] = last_updated return jinja2_engine.render('insights_details.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): self.template_values.update({ 'valid_years': VALID_YEARS, }) insights = ndb.get_multi([ndb.Key(Insight, Insight.renderKeyName(0, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values()]) for insight in insights: if insight: self.template_values[insight.name] = insight return jinja2_engine.render('insights.html', self.template_values)
def _render(self): self.template_values.update({ 'valid_years': VALID_YEARS, }) insights = ndb.get_multi([ndb.Key(Insight, Insight.renderKeyName(0, 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/insights.html') return template.render(path, self.template_values)
def _render(self, year): template_values = { 'valid_years': VALID_YEARS, 'selected_year': year, } 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: template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/insights_details.html') return template.render(path, template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() template_values = { "events": week_events, } insights = ndb.get_multi([ndb.Key(Insight, Insight.renderKeyName(2013, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values()]) for insight in insights: if insight: template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/index_insights.html') return template.render(path, template_values)
def _render(self, year): self.template_values.update({ 'valid_years': VALID_YEARS, 'selected_year': year, }) 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 self.template_values['year_specific_insights_template'] = 'event_partials/event_insights_{}.html'.format(year) return jinja2_engine.render('insights_details.html', self.template_values)
def _render(self, *args, **kw): year = datetime.datetime.now().year event_keys = Event.query(Event.year == year, Event.event_type_enum.IN(EventType.CMP_EVENT_TYPES)).fetch(100, keys_only=True) events = [event_key.get() for event_key in event_keys] template_values = { "events": events, } 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: template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/index_champs.html') return template.render(path, template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() year = datetime.datetime.now().year self.template_values.update({ "events": week_events, "year": year, }) 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 doOverallMatchInsights(self): """ Calculate match insights across all years. Returns a list of Insights. """ insights = [] year_num_matches = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.NUM_MATCHES], Insight.year != 0).fetch(1000) num_matches = [] for insight in year_num_matches: num_matches.append((insight.year, insight.data)) # Creating Insights if num_matches: insights.append(self._createInsight(num_matches, Insight.INSIGHT_NAMES[Insight.NUM_MATCHES], 0)) return insights
def _render(self, *args, **kw): year = datetime.datetime.now().year event_keys = Event.query(Event.year == year, Event.event_type_enum.IN(EventType.CMP_EVENT_TYPES)).fetch(100, keys_only=True) events = [event_key.get() for event_key in event_keys] self.template_values.update({ "events": events, "year": year, }) 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_champs.html') return template.render(path, self.template_values)
def _render(self, *args, **kw): week_events = EventHelper.getWeekEvents() template_values = { "events": week_events, } insights = ndb.get_multi([ ndb.Key(Insight, Insight.renderKeyName(2013, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values() ]) for insight in insights: if insight: template_values[insight.name] = insight path = os.path.join(os.path.dirname(__file__), '../templates/index_insights.html') return template.render(path, template_values)
def _render(self): self.template_values.update({ 'valid_years': VALID_YEARS, }) insights = ndb.get_multi([ndb.Key(Insight, Insight.renderKeyName(0, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values()]) last_updated = None for insight in insights: if insight: self.template_values[insight.name] = insight if last_updated is None: last_updated = insight.updated else: last_updated = max(last_updated, insight.updated) self.template_values['last_updated'] = last_updated return jinja2_engine.render('insights.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): self.template_values.update({ 'valid_years': VALID_YEARS, }) insights = ndb.get_multi([ ndb.Key(Insight, Insight.renderKeyName(0, insight_name)) for insight_name in Insight.INSIGHT_NAMES.values() ]) last_updated = None for insight in insights: if insight: self.template_values[insight.name] = insight if last_updated is None: last_updated = insight.updated else: last_updated = max(last_updated, insight.updated) self.template_values['last_updated'] = last_updated return jinja2_engine.render('insights.html', self.template_values)
def doOverallMatchInsights(self): """ Calculate match insights across all years. Returns a list of Insights. """ insights = [] year_num_matches = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.NUM_MATCHES], Insight.year != 0).fetch(1000) num_matches = [] for insight in year_num_matches: num_matches.append((insight.year, insight.data)) # Creating Insights if num_matches: insights.append( self._createInsight(num_matches, Insight.INSIGHT_NAMES[Insight.NUM_MATCHES], 0)) return insights
def doOverallAwardInsights(self): """ Calculate award insights across all years. Returns a list of Insights. """ insights = [] year_regional_winners = Insight.query( Insight.name == Insight.INSIGHT_NAMES[ Insight.REGIONAL_DISTRICT_WINNERS], Insight.year != 0).fetch(1000) regional_winners = defaultdict(int) for insight in year_regional_winners: for number, team_list in insight.data: for team in team_list: regional_winners[team] += number year_blue_banners = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], Insight.year != 0).fetch(1000) blue_banners = defaultdict(int) for insight in year_blue_banners: for number, team_list in insight.data: for team in team_list: blue_banners[team] += number year_rca_winners = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], Insight.year != 0).fetch(1000) rca_winners = defaultdict(int) for insight in year_rca_winners: for team in insight.data: rca_winners[team] += 1 year_world_champions = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], Insight.year != 0).fetch(1000) world_champions = defaultdict(list) for insight in year_world_champions: for team in insight.data: world_champions[team].append(insight.year) year_division_winners = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.DIVISION_WINNERS], Insight.year != 0).fetch(1000) division_winners = defaultdict(list) for insight in year_division_winners: for team in insight.data: division_winners[team].append(insight.year) year_successful_elim_teamups = Insight.query( Insight.name == Insight.INSIGHT_NAMES[ Insight.SUCCESSFUL_ELIM_TEAMUPS], Insight.year != 0).fetch(1000) successful_elim_teamups = defaultdict(int) for insight in year_successful_elim_teamups: for teams in insight.data: for pairs in itertools.combinations(teams, 2): successful_elim_teamups[tuple(sorted(pairs))] += 1 successful_elim_teamups_sorted = defaultdict(list) for teams, num_wins in successful_elim_teamups.items(): sorted_teams = sorted(teams, key=lambda team_key: int(team_key[3:])) successful_elim_teamups_sorted[num_wins].append(sorted_teams) successful_elim_teamups_sorted = sorted( successful_elim_teamups_sorted.items(), key=lambda x: -x[0]) # Sorting regional_winners = self._sortTeamWinsDict(regional_winners) blue_banners = self._sortTeamWinsDict(blue_banners) rca_winners = self._sortTeamWinsDict(rca_winners) world_champions = self._sortTeamYearWinsDict(world_champions) division_winners = self._sortTeamYearWinsDict(division_winners) # Creating Insights if regional_winners: insights.append( self._createInsight( regional_winners, Insight.INSIGHT_NAMES[Insight.REGIONAL_DISTRICT_WINNERS], 0)) if blue_banners: insights.append( self._createInsight( blue_banners, Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], 0)) if rca_winners: insights.append( self._createInsight(rca_winners, Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], 0)) if world_champions: insights.append( self._createInsight( world_champions, Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], 0)) if division_winners: insights.append( self._createInsight( division_winners, Insight.INSIGHT_NAMES[Insight.DIVISION_WINNERS], 0)) if year_successful_elim_teamups: insights.append( self._createInsight( successful_elim_teamups_sorted, Insight.INSIGHT_NAMES[Insight.SUCCESSFUL_ELIM_TEAMUPS], 0)) return insights
def doOverallAwardInsights(self): """ Calculate award insights across all years. Returns a list of Insights. """ insights = [] year_regional_winners = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.REGIONAL_DISTRICT_WINNERS], Insight.year != 0).fetch(1000) regional_winners = defaultdict(int) for insight in year_regional_winners: for number, team_list in insight.data: for team in team_list: regional_winners[team] += number year_blue_banners = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], Insight.year != 0).fetch(1000) blue_banners = defaultdict(int) for insight in year_blue_banners: for number, team_list in insight.data: for team in team_list: blue_banners[team] += number year_rca_winners = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], Insight.year != 0).fetch(1000) rca_winners = defaultdict(int) for insight in year_rca_winners: for team in insight.data: rca_winners[team] += 1 year_world_champions = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], Insight.year != 0).fetch(1000) world_champions = defaultdict(int) for insight in year_world_champions: for team in insight.data: world_champions[team] += 1 year_successful_elim_teamups = Insight.query(Insight.name == Insight.INSIGHT_NAMES[Insight.SUCCESSFUL_ELIM_TEAMUPS], Insight.year != 0).fetch(1000) successful_elim_teamups = defaultdict(int) for insight in year_successful_elim_teamups: for teams in insight.data: for pairs in itertools.combinations(teams, 2): successful_elim_teamups[tuple(sorted(pairs))] += 1 successful_elim_teamups_sorted = defaultdict(list) for teams, num_wins in successful_elim_teamups.items(): sorted_teams = sorted(teams, key=lambda team_key: int(team_key[3:])) successful_elim_teamups_sorted[num_wins].append(sorted_teams) successful_elim_teamups_sorted = sorted(successful_elim_teamups_sorted.items(), key=lambda x: -x[0]) # Sorting regional_winners = self._sortTeamWinsDict(regional_winners) blue_banners = self._sortTeamWinsDict(blue_banners) rca_winners = self._sortTeamWinsDict(rca_winners) world_champions = self._sortTeamWinsDict(world_champions) # Creating Insights if regional_winners: insights.append(self._createInsight(regional_winners, Insight.INSIGHT_NAMES[Insight.REGIONAL_DISTRICT_WINNERS], 0)) if blue_banners: insights.append(self._createInsight(blue_banners, Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], 0)) if rca_winners: insights.append(self._createInsight(rca_winners, Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], 0)) if world_champions: insights.append(self._createInsight(world_champions, Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], 0)) if year_successful_elim_teamups: insights.append(self._createInsight(successful_elim_teamups_sorted, Insight.INSIGHT_NAMES[Insight.SUCCESSFUL_ELIM_TEAMUPS], 0)) return insights
def doOverallAwardInsights(self): """ Calculate award insights across all years. Returns a list of Insights. """ insights = [] year_regional_winners = Insight.query( Insight.name == Insight.INSIGHT_NAMES[ Insight.REGIONAL_DISTRICT_WINNERS], Insight.year != 0).fetch(1000) regional_winners = {} for insight in year_regional_winners: for number, team_list in insight.data: for team in team_list: if team in regional_winners: regional_winners[team] += number else: regional_winners[team] = number year_blue_banners = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], Insight.year != 0).fetch(1000) blue_banners = {} for insight in year_blue_banners: for number, team_list in insight.data: for team in team_list: if team in blue_banners: blue_banners[team] += number else: blue_banners[team] = number year_rca_winners = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], Insight.year != 0).fetch(1000) rca_winners = {} for insight in year_rca_winners: for team in insight.data: if team in rca_winners: rca_winners[team] += 1 else: rca_winners[team] = 1 year_world_champions = Insight.query( Insight.name == Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], Insight.year != 0).fetch(1000) world_champions = {} for insight in year_world_champions: for team in insight.data: if team in world_champions: world_champions[team] += 1 else: world_champions[team] = 1 # Sorting regional_winners = self._sortTeamWinsDict(regional_winners) blue_banners = self._sortTeamWinsDict(blue_banners) rca_winners = self._sortTeamWinsDict(rca_winners) world_champions = self._sortTeamWinsDict(world_champions) # Creating Insights if regional_winners: insights.append( self._createInsight( regional_winners, Insight.INSIGHT_NAMES[Insight.REGIONAL_DISTRICT_WINNERS], 0)) if blue_banners: insights.append( self._createInsight( blue_banners, Insight.INSIGHT_NAMES[Insight.BLUE_BANNERS], 0)) if rca_winners: insights.append( self._createInsight(rca_winners, Insight.INSIGHT_NAMES[Insight.RCA_WINNERS], 0)) if world_champions: insights.append( self._createInsight( world_champions, Insight.INSIGHT_NAMES[Insight.WORLD_CHAMPIONS], 0)) return insights