本文整理汇总了Python中models.match.Match.renderKeyName方法的典型用法代码示例。如果您正苦于以下问题:Python Match.renderKeyName方法的具体用法?Python Match.renderKeyName怎么用?Python Match.renderKeyName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.match.Match
的用法示例。
在下文中一共展示了Match.renderKeyName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deleteInvalidMatches
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def deleteInvalidMatches(self, match_list):
"""
A match is invalid iff it is an elim match where the match number is 3
and the same alliance won in match numbers 1 and 2 of the same set.
"""
matches_by_key = {}
for match in match_list:
matches_by_key[match.key_name] = match
return_list = []
for match in match_list:
if match.comp_level in Match.ELIM_LEVELS and match.match_number == 3 and (not match.has_been_played):
match_1 = matches_by_key.get(
Match.renderKeyName(match.event.id(), match.comp_level, match.set_number, 1)
)
match_2 = matches_by_key.get(
Match.renderKeyName(match.event.id(), match.comp_level, match.set_number, 2)
)
if (
match_1 != None
and match_2 != None
and match_1.has_been_played
and match_2.has_been_played
and match_1.winning_alliance == match_2.winning_alliance
):
try:
match.key.delete()
logging.warning("Deleting invalid match: %s" % match.key_name)
except:
logging.warning("Tried to delete invalid match, but failed: %s" % match.key_name)
continue
return_list.append(match)
return return_list
示例2: setupMatches
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def setupMatches(csv):
with open(csv, 'r') as f:
event = Event(
id = "2013test",
event_short = "test",
year = 2013
)
parsed_matches = OffseasonMatchesParser.parse(f.read())
matches = [Match(
id = Match.renderKeyName(
event,
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event = event.key,
game = Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
set_number = match.get("set_number", 0),
match_number = match.get("match_number", 0),
comp_level = match.get("comp_level", None),
team_key_names = match.get("team_key_names", None),
alliances_json = match.get("alliances_json", None)
)
for match in parsed_matches]
return matches
示例3: _process_request
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def _process_request(self, request, event_key):
matches = []
needs_time = []
for match in JSONMatchesParser.parse(request.body, self.event.year):
match = Match(
id=Match.renderKeyName(
self.event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=self.event.key,
year=self.event.year,
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None),
score_breakdown_json=match.get("score_breakdown_json", None),
time_string=match.get("time_string", None),
time=match.get("time", None),
)
if (not match.time or match.time == "") and match.time_string:
# We can calculate the real time from the time string
needs_time.append(match)
matches.append(match)
if needs_time:
try:
logging.debug("Calculating time!")
MatchHelper.add_match_times(self.event, needs_time)
except Exception, e:
logging.error("Failed to calculate match times")
示例4: get
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def get(self, year):
year_event_keys = Event.query(Event.year == int(year)).fetch(1000, keys_only=True)
final_match_keys = []
for event_key in year_event_keys:
final_match_keys.extend(Match.query(Match.event == event_key, Match.comp_level == 'f').fetch(100, keys_only=True))
match_keys_to_repair = []
for match_key in final_match_keys:
key_name = match_key.id()
if '_f0m' in key_name:
match_keys_to_repair.append(match_key)
deleted_keys = []
matches_to_repair = ndb.get_multi(match_keys_to_repair)
for match in matches_to_repair:
deleted_keys.append(match.key)
event = ndb.get_multi([match.event])[0]
match.set_number = 1
match.key = ndb.Key(Match, Match.renderKeyName(
event.key.id(),
match.comp_level,
match.set_number,
match.match_number))
MatchManipulator.createOrUpdate(matches_to_repair)
MatchManipulator.delete_keys(deleted_keys)
template_values = {'deleted_keys': deleted_keys,
'new_matches': matches_to_repair}
path = os.path.join(os.path.dirname(__file__), '../templates/math/final_matches_repair_do.html')
self.response.out.write(template.render(path, template_values))
示例5: parse
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def parse(self, response):
matches = response["MatchScores"]
match_details_by_key = {}
is_octofinals = len(matches) > 0 and matches[len(matches) - 1]["matchNumber"] > 21
for match in matches:
comp_level = get_comp_level(self.year, match["matchLevel"], match["matchNumber"], is_octofinals)
set_number, match_number = get_set_match_number(self.year, comp_level, match["matchNumber"], is_octofinals)
breakdown = {"red": {}, "blue": {}}
if "coopertition" in match:
breakdown["coopertition"] = match["coopertition"]
if "coopertitionPoints" in match:
breakdown["coopertition_points"] = match["coopertitionPoints"]
for alliance in match["Alliances"]:
color = alliance["alliance"].lower()
for key, value in alliance.items():
if key != "alliance":
breakdown[color][key] = value
match_details_by_key[
Match.renderKeyName("{}{}".format(self.year, self.event_short), comp_level, set_number, match_number)
] = breakdown
return match_details_by_key
示例6: post
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def post(self):
self._require_admin()
event_key = self.request.get('event_key')
matches_csv = self.request.get('matches_csv')
matches = OffseasonMatchesParser.parse(matches_csv)
event = Event.get_by_id(event_key)
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
game=Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in matches]
new_matches = MatchManipulator.createOrUpdate(matches)
try:
last_matches = MatchHelper.recentMatches(new_matches, 1)
upcoming_matches = MatchHelper.upcomingMatches(new_matches, 8)
except:
logging.warning("Computing last/upcoming matches for Firebase failed!")
try:
FirebasePusher.updateEvent(event, last_matches, upcoming_matches)
except:
logging.warning("Enqueuing Firebase push failed!")
self.redirect('/admin/event/{}'.format(event_key))
示例7: parse
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def parse(self, response):
"""
This currently only works for the 2015 game.
"""
matches = response["MatchScores"]
match_details_by_key = {}
set_number = 1
for match in matches:
comp_level = get_comp_level(match["matchLevel"], match["matchNumber"])
match_number = get_match_number(comp_level, match["matchNumber"])
breakdown = {"red": {}, "blue": {}}
if "coopertition" in match:
breakdown["coopertition"] = match["coopertition"]
if "coopertitionPoints" in match:
breakdown["coopertition_points"] = match["coopertitionPoints"]
for alliance in match["Alliances"]:
color = alliance["alliance"].lower()
for key, value in alliance.items():
if key != "alliance":
breakdown[color][camel_to_snake(key)] = value
match_details_by_key[
Match.renderKeyName("{}{}".format(self.year, self.event_short), comp_level, set_number, match_number)
] = breakdown
return match_details_by_key
示例8: post
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def post(self):
self._require_admin()
event_key = self.request.get('event_key')
matches_csv = self.request.get('matches_csv')
matches, _ = OffseasonMatchesParser.parse(matches_csv)
event = Event.get_by_id(event_key)
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
year=event.year,
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in matches]
MatchManipulator.createOrUpdate(matches)
self.redirect('/admin/event/{}'.format(event_key))
示例9: post
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def post(self):
self._require_admin()
event_key = self.request.get('event_key')
matches_csv = self.request.get('matches_csv')
matches = OffseasonMatchesParser.parse(matches_csv)
event = Event.get_by_id(event_key)
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
game=Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in matches]
try:
FirebasePusher.updated_event(event.key_name)
except:
logging.warning("Enqueuing Firebase push failed!")
self.redirect('/admin/event/{}'.format(event_key))
示例10: parse
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def parse(self, response):
matches = response['MatchScores']
match_details_by_key = {}
is_octofinals = len(matches) > 0 and matches[len(matches) - 1]['matchNumber'] > 23 # Hacky; this should be 24. Banking on the fact that 3 tiebreakers is rare
for match in matches:
comp_level = get_comp_level(self.year, match['matchLevel'], match['matchNumber'], is_octofinals)
set_number, match_number = get_set_match_number(self.year, comp_level, match['matchNumber'], is_octofinals)
breakdown = {
'red': {},
'blue': {},
}
if 'coopertition' in match:
breakdown['coopertition'] = match['coopertition']
if 'coopertitionPoints' in match:
breakdown['coopertition_points'] = match['coopertitionPoints']
for alliance in match['Alliances']:
color = alliance['alliance'].lower()
for key, value in alliance.items():
if key != 'alliance':
breakdown[color][key] = value
match_details_by_key[Match.renderKeyName(
'{}{}'.format(self.year, self.event_short),
comp_level,
set_number,
match_number)] = breakdown
return match_details_by_key
示例11: parse
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def parse(self, response):
matches = response['MatchScores']
match_details_by_key = {}
for match in matches:
comp_level = get_comp_level(self.year, match['matchLevel'], match['matchNumber'])
set_number, match_number = get_set_match_number(self.year, comp_level, match['matchNumber'])
breakdown = {
'red': {},
'blue': {},
}
if 'coopertition' in match:
breakdown['coopertition'] = match['coopertition']
if 'coopertitionPoints' in match:
breakdown['coopertition_points'] = match['coopertitionPoints']
for alliance in match['Alliances']:
color = alliance['alliance'].lower()
for key, value in alliance.items():
if key != 'alliance':
breakdown[color][key] = value
match_details_by_key[Match.renderKeyName(
'{}{}'.format(self.year, self.event_short),
comp_level,
set_number,
match_number)] = breakdown
return match_details_by_key
示例12: _process_request
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def _process_request(self, request, event_key):
event = Event.get_by_id(event_key)
year = int(event_key[:4])
matches = []
for match in JSONMatchesParser.parse(request.body, year):
match = Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
year=event.year,
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None),
score_breakdown_json=match.get("score_breakdown_json", None),
time_string=match.get("time_string", None),
time=match.get("time", None),
)
if (not match.time or match.time == "") and match.time_string:
# We can calculate the real time from the time string
logging.debug("Calculating time!")
MatchHelper.add_match_times(event, [match])
matches.append(match)
MatchManipulator.createOrUpdate(matches)
self.response.out.write(json.dumps({'Success': "Matches successfully updated"}))
示例13: getMatches
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def getMatches(self, event):
matches_url = self.YEAR_MATCH_RESULTS_URL_PATTERN.get(
event.year, self.DEFAULT_MATCH_RESULTS_URL_PATTERN) % (
event.year, self.EVENT_SHORT_EXCEPTIONS.get(event.event_short,
event.event_short))
match_dicts, _ = self.parse(matches_url, self.YEAR_MATCH_PARSER.get(event.year, self.DEFAULT_MATCH_PARSER))
if not match_dicts: # Matches have not been played, but qual match schedule may be out
# If this is run when there are already matches in the DB, it will overwrite scores!
# Check to make sure event has no existing matches
if len(Match.query(Match.event == event.key).fetch(1, keys_only=True)) == 0:
logging.warning("No matches found for {}. Trying to parse qual match schedule.".format(event.key.id()))
qual_match_sched_url = self.MATCH_SCHEDULE_QUAL_URL_PATTERN % (
event.year, self.EVENT_SHORT_EXCEPTIONS.get(event.event_short,
event.event_short))
match_dicts, _ = self.parse(qual_match_sched_url, self.MATCH_SCHEDULE_PARSER)
for match_dict in match_dicts:
alliances = json.loads(match_dict['alliances_json'])
if (alliances['red']['score'] == -1 or alliances['blue']['score'] == -1 or
match_dict['comp_level'] in Match.ELIM_LEVELS):
break
else: # Only qual matches have been played and they have all been played
# If this is run when there are already elim matches in the DB, it will overwrite scores!
# Check to make sure event has no existing elim matches
if len(Match.query(Match.event == event.key, Match.comp_level.IN(Match.ELIM_LEVELS)).fetch(1, keys_only=True)) == 0:
logging.warning("No elim matches found for {}. Trying to parse elim match schedule.".format(event.key.id()))
elim_match_sched_url = self.MATCH_SCHEDULE_ELIMS_URL_PATTERN % (
event.year, self.EVENT_SHORT_EXCEPTIONS.get(event.event_short,
event.event_short))
elim_match_dicts, _ = self.parse(elim_match_sched_url, self.MATCH_SCHEDULE_PARSER)
match_dicts += elim_match_dicts
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match_dict.get("comp_level", None),
match_dict.get("set_number", 0),
match_dict.get("match_number", 0)),
event=event.key,
game=Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
set_number=match_dict.get("set_number", 0),
match_number=match_dict.get("match_number", 0),
comp_level=match_dict.get("comp_level", None),
team_key_names=match_dict.get("team_key_names", None),
time_string=match_dict.get("time_string", None),
alliances_json=match_dict.get("alliances_json", None)
)
for match_dict in match_dicts]
MatchHelper.add_match_times(event, matches)
return matches
示例14: matchDictToMatches
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def matchDictToMatches(self, match_dicts):
return [Match(id=Match.renderKeyName(self.event.key.id(),
match_dict.get("comp_level", None),
match_dict.get("set_number", 0),
match_dict.get("match_number", 0)),
event=self.event.key,
year=self.event.year,
set_number=match_dict.get("set_number", 0),
match_number=match_dict.get("match_number", 0),
comp_level=match_dict.get("comp_level", None),
team_key_names=match_dict.get("team_key_names", None),
time_string=match_dict.get("time_string", None),
alliances_json=match_dict.get("alliances_json", None))
for match_dict in match_dicts]
示例15: set_up_matches
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import renderKeyName [as 别名]
def set_up_matches(html, event):
with open(html, 'r') as f:
parsed_matches, _ = UsfirstMatchesParser.parse(f.read())
matches = [Match(id=Match.renderKeyName(event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
year=event.year,
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None))
for match in parsed_matches]
return matches