本文整理汇总了Python中helpers.award_helper.AwardHelper类的典型用法代码示例。如果您正苦于以下问题:Python AwardHelper类的具体用法?Python AwardHelper怎么用?Python AwardHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AwardHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _render
def _render(self, team_number):
team = Team.get_by_id("frc" + team_number)
if not team:
return self.redirect("/error/404")
event_team_keys_future = EventTeam.query(EventTeam.team == team.key).fetch_async(1000, keys_only=True)
award_keys_future = Award.query(Award.team == team.key).fetch_async(1000, keys_only=True)
event_teams_futures = ndb.get_multi_async(event_team_keys_future.get_result())
awards_futures = ndb.get_multi_async(award_keys_future.get_result())
event_keys = [event_team_future.get_result().event for event_team_future in event_teams_futures]
events_futures = ndb.get_multi_async(event_keys)
awards_by_event = {}
for award_future in awards_futures:
award = award_future.get_result()
if award.event.id() not in awards_by_event:
awards_by_event[award.event.id()] = [award]
else:
awards_by_event[award.event.id()].append(award)
event_awards = []
current_event = None
matches_upcoming = None
short_cache = False
for event_future in events_futures:
event = event_future.get_result()
if event.now:
current_event = event
team_matches_future = Match.query(Match.event == event.key, Match.team_key_names == team.key_name)\
.fetch_async(500, keys_only=True)
matches = ndb.get_multi(team_matches_future.get_result())
matches_upcoming = MatchHelper.upcomingMatches(matches)
if event.within_a_day:
short_cache = True
if event.key_name in awards_by_event:
sorted_awards = AwardHelper.organizeAwards(awards_by_event[event.key_name])['list']
else:
sorted_awards = []
event_awards.append((event, sorted_awards))
event_awards = sorted(event_awards, key=lambda (e, _): e.start_date if e.start_date else datetime.datetime(e.year, 12, 31))
years = sorted(set([et.get_result().year for et in event_teams_futures if et.get_result().year != None]))
template_values = {'team': team,
'event_awards': event_awards,
'years': years,
'current_event': current_event,
'matches_upcoming': matches_upcoming}
if short_cache:
self._cache_expiration = self.SHORT_CACHE_EXPIRATION
path = os.path.join(os.path.dirname(__file__), '../templates/team_history.html')
return template.render(path, template_values)
示例2: _render
def _render(self, team_key, event_key):
award_keys_future = Award.query(Award.team_list == ndb.Key(Team, self.team_key), Award.event == ndb.Key(Event, event_key)).fetch_async(None, keys_only=True)
awards = ndb.get_multi(award_keys_future.get_result())
awards_dicts = [ModelToDict.awardConverter(award) for award in AwardHelper.organizeAwards(awards)]
return json.dumps(awards_dicts, ensure_ascii=True)
示例3: _render
def _render(self, event_key):
event = Event.get_by_id(event_key)
if not event:
return self.redirect("/error/404")
event.prepAwards()
event.prepMatches()
event.prepTeams()
awards = AwardHelper.organizeAwards(event.awards)
matches = MatchHelper.organizeMatches(event.matches)
teams = TeamHelper.sortTeams(event.teams)
num_teams = len(teams)
middle_value = num_teams/2
if num_teams%2 != 0:
middle_value += 1
teams_a, teams_b = teams[:middle_value], teams[middle_value:]
oprs = sorted(zip(event.oprs,event.opr_teams), reverse=True) # sort by OPR
oprs = oprs[:14] # get the top 15 OPRs
if event.within_a_day:
matches_recent = MatchHelper.recentMatches(event.matches)
matches_upcoming = MatchHelper.upcomingMatches(event.matches)
else:
matches_recent = None
matches_upcoming = None
bracket_table = {}
qf_matches = matches['qf']
sf_matches = matches['sf']
f_matches = matches['f']
if qf_matches:
bracket_table['qf'] = MatchHelper.generateBracket(qf_matches)
if sf_matches:
bracket_table['sf'] = MatchHelper.generateBracket(sf_matches)
if f_matches:
bracket_table['f'] = MatchHelper.generateBracket(f_matches)
template_values = {
"event": event,
"matches": matches,
"matches_recent": matches_recent,
"matches_upcoming": matches_upcoming,
"awards": awards,
"teams_a": teams_a,
"teams_b": teams_b,
"num_teams": num_teams,
"oprs": oprs,
"bracket_table": bracket_table,
}
if event.within_a_day:
self._cache_expiration = self.SHORT_CACHE_EXPIRATION
path = os.path.join(os.path.dirname(__file__), '../templates/event_details.html')
return template.render(path, template_values)
示例4: _render
def _render(self, event_key):
event = Event.get_by_id(event_key)
if not event:
self.abort(404)
event.prepAwardsMatchesTeams()
awards = AwardHelper.organizeAwards(event.awards)
cleaned_matches = MatchHelper.deleteInvalidMatches(event.matches)
matches = MatchHelper.organizeMatches(cleaned_matches)
teams = TeamHelper.sortTeams(event.teams)
num_teams = len(teams)
middle_value = num_teams / 2
if num_teams % 2 != 0:
middle_value += 1
teams_a, teams_b = teams[:middle_value], teams[middle_value:]
oprs = [i for i in event.matchstats['oprs'].items()] if (event.matchstats is not None and 'oprs' in event.matchstats) else []
oprs = sorted(oprs, key=lambda t: t[1], reverse=True) # sort by OPR
oprs = oprs[:15] # get the top 15 OPRs
if event.within_a_day:
matches_recent = MatchHelper.recentMatches(cleaned_matches)
matches_upcoming = MatchHelper.upcomingMatches(cleaned_matches)
else:
matches_recent = None
matches_upcoming = None
bracket_table = {}
qf_matches = matches['qf']
sf_matches = matches['sf']
f_matches = matches['f']
if qf_matches:
bracket_table['qf'] = MatchHelper.generateBracket(qf_matches)
if sf_matches:
bracket_table['sf'] = MatchHelper.generateBracket(sf_matches)
if f_matches:
bracket_table['f'] = MatchHelper.generateBracket(f_matches)
template_values = {
"event": event,
"matches": matches,
"matches_recent": matches_recent,
"matches_upcoming": matches_upcoming,
"awards": awards,
"teams_a": teams_a,
"teams_b": teams_b,
"num_teams": num_teams,
"oprs": oprs,
"bracket_table": bracket_table,
}
if event.within_a_day:
self._cache_expiration = self.SHORT_CACHE_EXPIRATION
path = os.path.join(os.path.dirname(__file__), '../templates/event_details.html')
return template.render(path, template_values)
示例5: render_team_history
def render_team_history(cls, handler, team, is_canonical):
award_futures = award_query.TeamAwardsQuery(team.key.id()).fetch_async()
event_futures = event_query.TeamEventsQuery(team.key.id()).fetch_async()
participation_future = team_query.TeamParticipationQuery(team.key.id()).fetch_async()
social_media_future = media_query.TeamSocialMediaQuery(team.key.id()).fetch_async()
awards_by_event = {}
for award in award_futures.get_result():
if award.event.id() not in awards_by_event:
awards_by_event[award.event.id()] = [award]
else:
awards_by_event[award.event.id()].append(award)
event_awards = []
current_event = None
matches_upcoming = None
short_cache = False
years = set()
for event in event_futures.get_result():
years.add(event.year)
if event.now:
current_event = event
matches = match_query.TeamEventMatchesQuery(team.key.id(), event.key.id()).fetch()
matches_upcoming = MatchHelper.upcomingMatches(matches)
if event.within_a_day:
short_cache = True
if event.key_name in awards_by_event:
sorted_awards = AwardHelper.organizeAwards(awards_by_event[event.key_name])
else:
sorted_awards = []
event_awards.append((event, sorted_awards))
event_awards = sorted(event_awards, key=lambda (e, _): e.start_date if e.start_date else datetime.datetime(e.year, 12, 31))
last_competed = None
participation_years = participation_future.get_result()
if len(participation_years) > 0:
last_competed = max(participation_years)
current_year = datetime.date.today().year
social_medias = sorted(social_media_future.get_result(), key=MediaHelper.social_media_sorter)
handler.template_values.update({
'is_canonical': is_canonical,
'team': team,
'event_awards': event_awards,
'years': sorted(years),
"social_medias": social_medias,
'current_event': current_event,
'matches_upcoming': matches_upcoming,
'last_competed': last_competed,
'current_year': current_year
})
if short_cache:
handler._cache_expiration = handler.SHORT_CACHE_EXPIRATION
return jinja2_engine.render('team_history.html', handler.template_values)
示例6: parse
def parse(self, html):
"""
Parse the awards from USFIRST.
"""
html = html.decode("utf-8", "ignore") # Clean html before feeding itno BeautifulSoup
soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)
table = soup.findAll("table")[6]
awards_by_type = {}
for tr in table.findAll("tr")[3:]:
tds = tr.findAll("td")
name_str = unicode(self._recurseUntilString(tds[0]))
award_type_enum = AwardHelper.parse_award_type(name_str)
if award_type_enum is None:
continue
team_number = None
try:
team_number = self._recurseUntilString(tds[1])
except AttributeError:
team_number = None
if team_number and team_number.isdigit():
team_number = int(team_number)
else:
team_number = None
awardee = None
if award_type_enum in AwardType.INDIVIDUAL_AWARDS:
try:
awardee_str = self._recurseUntilString(tds[2])
if awardee_str:
awardee = unicode(sanitize(awardee_str))
except TypeError:
awardee = None
if not awardee:
# Turns '' into None
awardee = None
# an award must have either an awardee or a team_number
if awardee is None and team_number is None:
continue
recipient_json = json.dumps({"team_number": team_number, "awardee": awardee})
if award_type_enum in awards_by_type:
if team_number is not None:
awards_by_type[award_type_enum]["team_number_list"].append(team_number)
awards_by_type[award_type_enum]["recipient_json_list"].append(recipient_json)
else:
awards_by_type[award_type_enum] = {
"name_str": strip_number(name_str),
"award_type_enum": award_type_enum,
"team_number_list": [team_number] if team_number is not None else [],
"recipient_json_list": [recipient_json],
}
return awards_by_type.values(), False
示例7: parse
def parse(cls, data):
"""
Parse CSV that contains awards
Format is as follows:
year, event_short, award_name_str, team_number (can be blank), awardee (can be blank)
Example:
2000,mi,Regional Finalist,45,
"""
awards_by_key = {}
csv_data = list(csv.reader(StringIO.StringIO(data), delimiter=',', skipinitialspace=True))
for award in csv_data:
year = int(award[0])
event_short = award[1]
name_str = award[2]
team_number = award[3]
awardee = award[4]
if team_number == '':
team_number = None
else:
team_number = int(team_number)
if awardee == '':
awardee = None
# an award must have either an awardee or a team_number
if awardee is None and team_number is None:
continue
if team_number is not None:
team_number_list = [team_number]
else:
team_number_list = []
recipient_json = json.dumps({
'team_number': team_number,
'awardee': awardee,
})
award_type_enum = AwardHelper.parse_award_type(name_str)
if award_type_enum is None:
# If we can't figure it out, fall back to OTHER (good for offseason events)
award_type_enum = AwardType.OTHER
award_key_name = Award.render_key_name('{}{}'.format(year, event_short), award_type_enum)
if award_key_name in awards_by_key:
if team_number is not None:
awards_by_key[award_key_name]['team_number_list'].append(team_number)
awards_by_key[award_key_name]['recipient_json_list'].append(recipient_json)
else:
awards_by_key[award_key_name] = {
'year': year,
'event_short': event_short,
'name_str': name_str,
'award_type_enum': award_type_enum,
'team_number_list': team_number_list,
'recipient_json_list': [recipient_json],
}
return awards_by_key.values()
示例8: doAwardInsights
def doAwardInsights(self, year):
"""
Calculate award insights for a given year. Returns a list of Insights.
"""
# Only fetch from DB once
keysToQuery = Award.BLUE_BANNER_KEYS.union(Award.DIVISION_FIN_KEYS).union(Award.CHAMPIONSHIP_FIN_KEYS)
awards = AwardHelper.getAwards(keysToQuery, year)
insights = []
insights += self._calculateBlueBanners(awards, year)
insights += self._calculateChampionshipStats(awards, year)
insights += self._calculateRegionalStats(awards, year)
return insights
示例9: parse
def parse(self, awards_json, event_key):
"""
Parse JSON that contains a list of awards where each award is a dict of:
name_str: String of award name. ex: "Tournament Winner" or "Dean's List Finalist"
team_key: String in the format "frcXXX" for the team that won the award. Can be null.
awardee: String corresponding to the name of an individual that won the award. Can be null.
"""
try:
awards = json.loads(awards_json)
except:
raise ParserInputException("Invalid JSON. Please check input.")
awards_by_key = {}
for award in awards:
if type(award) is not dict:
raise ParserInputException("Awards must be dicts.")
name_str = award.get('name_str', None)
team_key = award.get('team_key', None)
awardee = award.get('awardee', None)
if name_str is None:
raise ParserInputException("Award must have a 'name_str'")
if team_key and not re.match(r'frc\d+', str(team_key)):
raise ParserInputException("Bad team_key: '{}'. Must follow format 'frcXXX' or be null.".format(team_key))
award_type_enum = AwardHelper.parse_award_type(name_str)
if award_type_enum is None:
raise ParserInputException("Cannot determine award type from: '{}'. Please contact a www.thebluealliance.com admin.".format(name_str))
recipient_json = json.dumps({
'team_number': int(team_key[3:]) if team_key else None,
'awardee': awardee,
})
award_key_name = Award.render_key_name(event_key, award_type_enum)
if award_key_name in awards_by_key:
if team_key is not None:
awards_by_key[award_key_name]['team_key_list'].append(team_key)
awards_by_key[award_key_name]['recipient_json_list'].append(recipient_json)
else:
awards_by_key[award_key_name] = {
'name_str': name_str,
'award_type_enum': award_type_enum,
'team_key_list': [team_key] if team_key else [],
'recipient_json_list': [recipient_json],
}
return awards_by_key.values()
示例10: render_team_history
def render_team_history(cls, handler, team, is_canonical):
award_futures = award_query.TeamAwardsQuery(team.key.id()).fetch_async()
event_futures = event_query.TeamEventsQuery(team.key.id()).fetch_async()
awards_by_event = {}
for award in award_futures.get_result():
if award.event.id() not in awards_by_event:
awards_by_event[award.event.id()] = [award]
else:
awards_by_event[award.event.id()].append(award)
event_awards = []
current_event = None
matches_upcoming = None
short_cache = False
years = set()
for event in event_futures.get_result():
years.add(event.year)
if event.now:
current_event = event
matches = match_query.TeamEventMatchesQuery(team.key.id(), event.key.id()).fetch()
matches_upcoming = MatchHelper.upcomingMatches(matches)
if event.within_a_day:
short_cache = True
if event.key_name in awards_by_event:
sorted_awards = AwardHelper.organizeAwards(awards_by_event[event.key_name])
else:
sorted_awards = []
event_awards.append((event, sorted_awards))
event_awards = sorted(event_awards, key=lambda (e, _): e.start_date if e.start_date else datetime.datetime(e.year, 12, 31))
handler.template_values.update({
'is_canonical': is_canonical,
'team': team,
'event_awards': event_awards,
'years': sorted(years),
'current_event': current_event,
'matches_upcoming': matches_upcoming
})
if short_cache:
handler._cache_expiration = handler.SHORT_CACHE_EXPIRATION
path = os.path.join(os.path.dirname(__file__), '../templates/team_history.html')
return template.render(path, handler.template_values)
示例11: parse
def parse(self, response):
awards_by_type = {}
for award in response['Awards']:
team_number = award['teamNumber']
if self.valid_team_nums is not None and team_number not in self.valid_team_nums:
continue
award_type_enum = AwardHelper.parse_award_type(award['name'])
if award_type_enum is None:
continue
recipient_json = json.dumps({
'team_number': team_number,
'awardee': award['person'],
})
if award_type_enum in awards_by_type:
if team_number is not None:
awards_by_type[award_type_enum]['team_number_list'].append(team_number)
awards_by_type[award_type_enum]['recipient_json_list'].append(recipient_json)
else:
awards_by_type[award_type_enum] = {
'name_str': award['name'],
'award_type_enum': award_type_enum,
'team_number_list': [team_number] if team_number is not None else [],
'recipient_json_list': [recipient_json],
}
awards = []
for award in awards_by_type.values():
awards.append(Award(
id=Award.render_key_name(self.event.key_name, award['award_type_enum']),
name_str=award['name_str'],
award_type_enum=award['award_type_enum'],
year=self.event.year,
event=self.event.key,
event_type_enum=self.event.event_type_enum,
team_list=[ndb.Key(Team, 'frc{}'.format(team_number)) for team_number in award['team_number_list']],
recipient_json_list=award['recipient_json_list']
))
return awards
示例12: render_team_details
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)
#.........这里部分代码省略.........
示例13: test_build
def test_build(self):
expected = {}
expected['notification_type'] = NotificationType.type_names[NotificationType.AWARDS]
expected['message_data'] = {}
expected['message_data']['event_name'] = self.event.name
expected['message_data']['event_key'] = self.event.key_name
expected['message_data']['awards'] = [ModelToDict.awardConverter(award) for award in AwardHelper.organizeAwards(self.event.awards)]
data = self.notification._build_dict()
self.assertEqual(expected, data)
示例14: get
def get(self):
self._require_registration()
user = self.user_bundle.account.key
now = datetime.datetime.now()
year = self.request.get('year')
if year and year.isdigit():
year = int(year)
else:
year = now.year
team_favorites_future = Favorite.query(Favorite.model_type == ModelType.TEAM, ancestor=user).fetch_async()
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)
favorite_teams = [team_future.get_result() for team_future in favorite_teams_future]
favorite_teams_events_futures = []
favorite_teams_awards_futures = {}
for team in favorite_teams:
favorite_teams_events_futures.append(TeamYearEventsQuery(team.key_name, year).fetch_async())
favorite_teams_awards_futures[team.key.id()] = TeamYearAwardsQuery(team.key_name, year).fetch_async()
past_events_by_event = {}
live_events_by_event = {}
future_events_by_event = {}
favorite_event_team_keys = []
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) # Sort by date
for event in events:
favorite_event_team_keys.append(ndb.Key(EventTeam, '{}_{}'.format(event.key.id(), team.key.id())))
if event.within_a_day:
if event.key_name not in live_events_by_event:
live_events_by_event[event.key_name] = (event, [])
live_events_by_event[event.key_name][1].append(team)
elif event.start_date < now:
if event.key_name not in past_events_by_event:
past_events_by_event[event.key_name] = (event, [])
past_events_by_event[event.key_name][1].append(team)
else:
if event.key_name not in future_events_by_event:
future_events_by_event[event.key_name] = (event, [])
future_events_by_event[event.key_name][1].append(team)
event_team_awards = defaultdict(lambda: defaultdict(list))
for team_key, awards_future in favorite_teams_awards_futures.items():
for award in awards_future.get_result():
event_team_awards[award.event.id()][team_key].append(award)
ndb.get_multi(favorite_event_team_keys) # Warms context cache
past_events_with_teams = []
for event, teams in past_events_by_event.itervalues():
teams_and_statuses = []
for team in teams:
event_team = EventTeam.get_by_id('{}_{}'.format(event.key.id(), team.key.id())) # Should be in context cache
status_str = {
'alliance': EventTeamStatusHelper.generate_team_at_event_alliance_status_string(team.key.id(), event_team.status),
'playoff': EventTeamStatusHelper.generate_team_at_event_playoff_status_string(team.key.id(), event_team.status),
}
teams_and_statuses.append((
team,
event_team.status,
status_str,
AwardHelper.organizeAwards(event_team_awards[event.key.id()][team.key.id()])
))
teams_and_statuses.sort(key=lambda x: x[0].team_number)
past_events_with_teams.append((event, teams_and_statuses))
past_events_with_teams.sort(key=lambda x: x[0].name)
past_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoStartDate(x[0]))
past_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoEndDate(x[0]))
live_events_with_teams = []
for event, teams in live_events_by_event.itervalues():
teams_and_statuses = []
for team in teams:
event_team = EventTeam.get_by_id('{}_{}'.format(event.key.id(), team.key.id())) # Should be in context cache
status_str = {
'alliance': EventTeamStatusHelper.generate_team_at_event_alliance_status_string(team.key.id(), event_team.status),
'playoff': EventTeamStatusHelper.generate_team_at_event_playoff_status_string(team.key.id(), event_team.status),
}
teams_and_statuses.append((
team,
event_team.status,
status_str
))
teams_and_statuses.sort(key=lambda x: x[0].team_number)
live_events_with_teams.append((event, teams_and_statuses))
live_events_with_teams.sort(key=lambda x: x[0].name)
live_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoStartDate(x[0]))
live_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoEndDate(x[0]))
future_events_with_teams = []
for event, teams in future_events_by_event.itervalues():
teams.sort(key=lambda t: t.team_number)
#.........这里部分代码省略.........
示例15: render_team_details
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)
#.........这里部分代码省略.........