本文整理汇总了Python中models.Match.winner方法的典型用法代码示例。如果您正苦于以下问题:Python Match.winner方法的具体用法?Python Match.winner怎么用?Python Match.winner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.winner方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_match
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import winner [as 别名]
def get_match(request, region=None, match_id=None):
region = 'na' if region is None else region
api_key = request.body if request.body else API_KEY
proceed = update_rate_limits(api_key, region)
if not proceed:
return HttpResponse("Rate limit exceeded. Try again in a few seconds.", status=429)
if match_id is not None:
try:
match = Match.objects.filter(match_id=match_id)[0]
except:
match = Match(match_id=match_id, region=region)
match.save()
else:
try:
match_priorities = MatchList.objects.filter(match_used=False, region=region).values('match_id').annotate(priority_sum=Sum('match_priority')).order_by('-priority_sum')[0]
# if summoners have a higher priority than matches, then input a summoner's champion mastery and matchlist
if Summoners.objects.filter(summoner_used=False, region=region).exists():
if Summoners.objects.filter(summoner_used=False, region=region).order_by('-summoner_priority')[0].summoner_priority > 2 *match_priorities['priority_sum']:
return get_matchlist_and_champion_mastery(request, region, None)
match = Match.objects.get(pk=match_priorities['match_id'])
match_id = match.match_id
except:
return get_matchlist_and_champion_mastery(request, region, None)
url = urllib2.Request("https://{0}.api.pvp.net/api/lol/{0}/v2.2/match/{1}?api_key={2}".format(region, match_id, api_key))
try:
response = urllib2.urlopen(url)
except urllib2.HTTPError as e:
if e.code == 429:
num_seconds = 5
if "Retry-After" in e.headers:
num_seconds = int(e.headers.get("Retry-After"))
timers = RateLimitTimer.objects.filter(region=region)
try:
timer = timers[0]
except:
timer=RateLimitTimer(region=region)
timer.next_check_time = datetime.utcnow() + timedelta(seconds=num_seconds)
timer.save()
return HttpResponse("Rate limit exceeded. Try again in " + num_seconds + " seconds.", status=429)
elif e.code == 404: #not sure why it gets this sometimes (perhaps match is too recent?)
matchlists = MatchList.objects.filter(match_id=match, region=region)
for matchlist in matchlists:
matchlist.match_used = True
matchlist.save()
return get_matchlist_and_champion_mastery(request, region, None)
else:
return HttpResponse(status=e.code)
except urllib2.URLError:
return HttpResponse("Error connecting to the Riot API. Try again soon.", status=504)
data = json.load(response)
matchlist_tuples = {}
for i, participant in enumerate(data['participants']):
index = i % 5
if participant.get('teamId', 'N/A') == 200:
index += 5
matchlist_tuples[participant.get('participantId', 'N/A')] = (index, MatchList(match_id=match, region=region, match_used=1, champion_id=participant.get('championId', 'N/A'), lane=participant.get('timeline', 'N/A').get('lane', 'N/A'), role=participant.get('timeline', 'N/A').get('role', 'N/A'), queue=data.get('queueType', 'N/A')))
summoners = []
num_summoners_used = 0
for participant in data['participantIdentities']:
participant_id = participant.get('participantId', 'N/A')
try:
summoner_id = participant.get('player', 'N/A').get('summonerId', 'N/A')
except:
continue
if not Summoners.objects.filter(summoner_id=summoner_id, region=region).exists():
summoner = Summoners(summoner_id=summoner_id, region=region, summoner_priority=0)
summoner.save()
summoners.append(summoner)
else:
summoner = Summoners.objects.filter(summoner_id=summoner_id, region=region)[0]
if not summoner.summoner_used:
summoners.append(summoner)
else:
num_summoners_used += 1
matchlist_tuples[participant_id][1].summoner_id = summoner
try:
matchlist = MatchList.objects.filter(summoner_id=summoner, match_id=match, region=region)[0]
matchlist.match_used = True
except:
matchlist = matchlist_tuples[participant_id][1]
matchlist.save()
setattr(match, 'summoner_'+str(matchlist_tuples[participant_id][0]), summoner)
for summoner in summoners:
summoner.summoner_priority += num_summoners_used
summoner.save()
for team in data['teams']:
if team.get('teamId', 'N/A') == 200:
match.winner = team.get('winner', 'N/A')
match.save()
return redirect('home')