本文整理汇总了Python中models.insight.Insight.query方法的典型用法代码示例。如果您正苦于以下问题:Python Insight.query方法的具体用法?Python Insight.query怎么用?Python Insight.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.insight.Insight
的用法示例。
在下文中一共展示了Insight.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doOverallAwardInsights
# 需要导入模块: from models.insight import Insight [as 别名]
# 或者: from models.insight.Insight import query [as 别名]
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
示例2: doOverallMatchInsights
# 需要导入模块: from models.insight import Insight [as 别名]
# 或者: from models.insight.Insight import query [as 别名]
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
示例3: doOverallAwardInsights
# 需要导入模块: from models.insight import Insight [as 别名]
# 或者: from models.insight.Insight import query [as 别名]
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