本文整理汇总了Python中models.robot.Robot.get_by_id_async方法的典型用法代码示例。如果您正苦于以下问题:Python Robot.get_by_id_async方法的具体用法?Python Robot.get_by_id_async怎么用?Python Robot.get_by_id_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.robot.Robot
的用法示例。
在下文中一共展示了Robot.get_by_id_async方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_team_details
# 需要导入模块: from models.robot import Robot [as 别名]
# 或者: from models.robot.Robot import get_by_id_async [as 别名]
def render_team_details(cls, handler, team, year, is_canonical):
media_future = media_query.TeamYearMediaQuery(team.key.id(), year).fetch_async()
social_media_future = media_query.TeamSocialMediaQuery(team.key.id()).fetch_async()
robot_future = Robot.get_by_id_async('{}_{}'.format(team.key.id(), year))
team_districts_future = team_query.TeamDistrictsQuery(team.key.id()).fetch_async()
participation_future = team_query.TeamParticipationQuery(team.key.id()).fetch_async()
events_sorted, matches_by_event_key, awards_by_event_key, valid_years = TeamDetailsDataFetcher.fetch(team, year, return_valid_years=True)
if not events_sorted:
return None
participation = []
season_wlt_list = []
offseason_wlt_list = []
year_match_avg_list = []
current_event = None
matches_upcoming = None
short_cache = False
for event in events_sorted:
event_matches = matches_by_event_key.get(event.key, [])
event_awards = AwardHelper.organizeAwards(awards_by_event_key.get(event.key, []))
matches_organized = MatchHelper.organizeMatches(event_matches)
if event.now:
current_event = event
matches_upcoming = MatchHelper.upcomingMatches(event_matches)
if event.within_a_day:
short_cache = True
if year == 2015:
display_wlt = None
match_avg = EventHelper.calculateTeamAvgScoreFromMatches(team.key_name, event_matches)
year_match_avg_list.append(match_avg)
qual_avg, elim_avg, _, _ = match_avg
else:
qual_avg = None
elim_avg = None
wlt = EventHelper.calculateTeamWLTFromMatches(team.key_name, event_matches)
if event.event_type_enum in EventType.SEASON_EVENT_TYPES:
season_wlt_list.append(wlt)
else:
offseason_wlt_list.append(wlt)
if wlt["win"] + wlt["loss"] + wlt["tie"] == 0:
display_wlt = None
else:
display_wlt = wlt
team_rank = None
if event.rankings:
for element in event.rankings:
if str(element[1]) == str(team.team_number):
team_rank = element[0]
break
participation.append({'event': event,
'matches': matches_organized,
'wlt': display_wlt,
'qual_avg': qual_avg,
'elim_avg': elim_avg,
'rank': team_rank,
'awards': event_awards})
season_wlt = None
offseason_wlt = None
if year == 2015:
year_wlt = None
year_qual_scores = []
year_elim_scores = []
for _, _, event_qual_scores, event_elim_scores in year_match_avg_list:
year_qual_scores += event_qual_scores
year_elim_scores += event_elim_scores
year_qual_avg = float(sum(year_qual_scores)) / len(year_qual_scores) if year_qual_scores != [] else None
year_elim_avg = float(sum(year_elim_scores)) / len(year_elim_scores) if year_elim_scores != [] else None
else:
year_qual_avg = None
year_elim_avg = None
season_wlt = {"win": 0, "loss": 0, "tie": 0}
offseason_wlt = {"win": 0, "loss": 0, "tie": 0}
for wlt in season_wlt_list:
season_wlt["win"] += wlt["win"]
season_wlt["loss"] += wlt["loss"]
season_wlt["tie"] += wlt["tie"]
if season_wlt["win"] + season_wlt["loss"] + season_wlt["tie"] == 0:
season_wlt = None
for wlt in offseason_wlt_list:
offseason_wlt["win"] += wlt["win"]
offseason_wlt["loss"] += wlt["loss"]
offseason_wlt["tie"] += wlt["tie"]
if offseason_wlt["win"] + offseason_wlt["loss"] + offseason_wlt["tie"] == 0:
offseason_wlt = None
medias_by_slugname = MediaHelper.group_by_slugname([media for media in media_future.get_result()])
image_medias = MediaHelper.get_images(media_future.get_result())
social_medias = sorted(social_media_future.get_result(), key=MediaHelper.social_media_sorter)
preferred_image_medias = filter(lambda x: team.key in x.preferred_references, image_medias)
#.........这里部分代码省略.........
示例2: render_team_details
# 需要导入模块: from models.robot import Robot [as 别名]
# 或者: from models.robot.Robot import get_by_id_async [as 别名]
def render_team_details(cls, handler, team, year, is_canonical):
hof_award_future = award_query.TeamEventTypeAwardsQuery(team.key.id(), EventType.CMP_FINALS, AwardType.CHAIRMANS).fetch_async()
hof_video_future = media_query.TeamTagMediasQuery(team.key.id(), MediaTag.CHAIRMANS_VIDEO).fetch_async()
hof_presentation_future = media_query.TeamTagMediasQuery(team.key.id(), MediaTag.CHAIRMANS_PRESENTATION).fetch_async()
hof_essay_future = media_query.TeamTagMediasQuery(team.key.id(), MediaTag.CHAIRMANS_ESSAY).fetch_async()
media_future = media_query.TeamYearMediaQuery(team.key.id(), year).fetch_async()
social_media_future = media_query.TeamSocialMediaQuery(team.key.id()).fetch_async()
robot_future = Robot.get_by_id_async("{}_{}".format(team.key.id(), year))
team_districts_future = team_query.TeamDistrictsQuery(team.key.id()).fetch_async()
participation_future = team_query.TeamParticipationQuery(team.key.id()).fetch_async()
hof_awards = hof_award_future.get_result()
hof_video = hof_video_future.get_result()
hof_presentation = hof_presentation_future.get_result()
hof_essay = hof_essay_future.get_result()
hall_of_fame = {
"is_hof": len(hof_awards) > 0,
"years": [award.year for award in hof_awards],
"media": {
"video": hof_video[0].youtube_url_link if len(hof_video) > 0 else None,
"presentation": hof_presentation[0].youtube_url_link if len(hof_presentation) > 0 else None,
"essay": hof_essay[0].external_link if len(hof_essay) > 0 else None,
},
}
events_sorted, matches_by_event_key, awards_by_event_key, valid_years = TeamDetailsDataFetcher.fetch(team, year, return_valid_years=True)
if not events_sorted:
return None
district_name = None
district_abbrev = None
team_district_points = None
team_districts = team_districts_future.get_result()
for district in team_districts:
if district and district.year == year:
district_abbrev = district.abbreviation
district_name = district.display_name
if district.rankings:
team_district_points = next(
iter(filter(lambda r: r['team_key'] == team.key_name,
district.rankings)), None)
break
participation = []
season_wlt_list = []
offseason_wlt_list = []
year_match_avg_list = []
current_event = None
matches_upcoming = None
short_cache = False
for event in events_sorted:
event_matches = matches_by_event_key.get(event.key, [])
event_awards = AwardHelper.organizeAwards(awards_by_event_key.get(event.key, []))
matches_organized = MatchHelper.organizeMatches(event_matches)
if event.now:
current_event = event
matches_upcoming = MatchHelper.upcomingMatches(event_matches)
if event.within_a_day:
short_cache = True
if year == 2015:
display_wlt = None
match_avg = EventHelper.calculateTeamAvgScoreFromMatches(team.key_name, event_matches)
year_match_avg_list.append(match_avg)
qual_avg, elim_avg, _, _ = match_avg
else:
qual_avg = None
elim_avg = None
wlt = EventHelper.calculateTeamWLTFromMatches(team.key_name, event_matches)
if event.event_type_enum in EventType.SEASON_EVENT_TYPES:
season_wlt_list.append(wlt)
else:
offseason_wlt_list.append(wlt)
if wlt["win"] + wlt["loss"] + wlt["tie"] == 0:
display_wlt = None
else:
display_wlt = wlt
team_rank = None
if event.details and event.details.rankings2:
for ranking in event.details.rankings2:
if ranking['team_key'] == team.key.id():
team_rank = ranking['rank']
break
video_ids = []
playlist = ""
for level in Match.COMP_LEVELS:
matches = matches_organized[level]
for match in matches:
video_ids += [video.split("?")[0] for video in match.youtube_videos]
if video_ids:
playlist_title = u"{} (Team {})".format(event.name, team.team_number)
playlist = u"https://www.youtube.com/watch_videos?video_ids={}&title={}"
playlist = playlist.format(u",".join(video_ids), playlist_title)
#.........这里部分代码省略.........
示例3: render_team_details
# 需要导入模块: from models.robot import Robot [as 别名]
# 或者: from models.robot.Robot import get_by_id_async [as 别名]
def render_team_details(cls, handler, team, year, is_canonical):
media_future = media_query.TeamYearMediaQuery(team.key.id(), year).fetch_async()
robot_future = Robot.get_by_id_async('{}_{}'.format(team.key.id(), year))
team_districts_future = team_query.TeamDistrictsQuery(team.key.id()).fetch_async()
events_sorted, matches_by_event_key, awards_by_event_key, valid_years = TeamDetailsDataFetcher.fetch(team, year, return_valid_years=True)
if not events_sorted:
return None
participation = []
year_wlt_list = []
year_match_avg_list = []
current_event = None
matches_upcoming = None
short_cache = False
for event in events_sorted:
event_matches = matches_by_event_key.get(event.key, [])
event_awards = AwardHelper.organizeAwards(awards_by_event_key.get(event.key, []))
matches_organized = MatchHelper.organizeMatches(event_matches)
if event.now:
current_event = event
matches_upcoming = MatchHelper.upcomingMatches(event_matches)
if event.within_a_day:
short_cache = True
if year == 2015:
display_wlt = None
match_avg = EventHelper.calculateTeamAvgScoreFromMatches(team.key_name, event_matches)
year_match_avg_list.append(match_avg)
qual_avg, elim_avg, _, _ = match_avg
else:
qual_avg = None
elim_avg = None
wlt = EventHelper.calculateTeamWLTFromMatches(team.key_name, event_matches)
year_wlt_list.append(wlt)
if wlt["win"] + wlt["loss"] + wlt["tie"] == 0:
display_wlt = None
else:
display_wlt = wlt
team_rank = None
if event.rankings:
for element in event.rankings:
if str(element[1]) == str(team.team_number):
team_rank = element[0]
break
participation.append({'event': event,
'matches': matches_organized,
'wlt': display_wlt,
'qual_avg': qual_avg,
'elim_avg': elim_avg,
'rank': team_rank,
'awards': event_awards})
if year == 2015:
year_wlt = None
year_qual_scores = []
year_elim_scores = []
for _, _, event_qual_scores, event_elim_scores in year_match_avg_list:
year_qual_scores += event_qual_scores
year_elim_scores += event_elim_scores
year_qual_avg = float(sum(year_qual_scores)) / len(year_qual_scores) if year_qual_scores != [] else None
year_elim_avg = float(sum(year_elim_scores)) / len(year_elim_scores) if year_elim_scores != [] else None
else:
year_qual_avg = None
year_elim_avg = None
year_wlt = {"win": 0, "loss": 0, "tie": 0}
for wlt in year_wlt_list:
year_wlt["win"] += wlt["win"]
year_wlt["loss"] += wlt["loss"]
year_wlt["tie"] += wlt["tie"]
if year_wlt["win"] + year_wlt["loss"] + year_wlt["tie"] == 0:
year_wlt = None
medias_by_slugname = MediaHelper.group_by_slugname([media for media in media_future.get_result()])
district_name = None
district_abbrev = None
team_districts = team_districts_future.get_result()
if year in team_districts:
district_key = team_districts[year]
district_abbrev = district_key[4:]
district_type = DistrictType.abbrevs[district_abbrev]
district_name = DistrictType.type_names[district_type]
handler.template_values.update({
"is_canonical": is_canonical,
"team": team,
"participation": participation,
"year": year,
"years": valid_years,
"year_wlt": year_wlt,
"year_qual_avg": year_qual_avg,
"year_elim_avg": year_elim_avg,
"current_event": current_event,
#.........这里部分代码省略.........