Exemplo n.º 1
0
def GetBuildStatsforChamp(sumnames,cname,numgames=50,jungle=False):

	# Get Summoner Objects and summoner ids
	if len([sumnames])>1:
		summoners = cass.get_summoners_by_name(sumnames)
		sumids = list(map(lambda x: x.id,summoners))
	else:
		summoners = cass.get_summoner_by_name(sumnames)
		sumids = [summoners.id]

	champ = cass.get_champion_by_name(cname)
	matchlist = []
	itemlist = []

	for s in sumids:

		# Get Match History for specific champion for Solo Ranked this season. We can update to expand to other queues or past seasons
		matches = base.get_match_list(s,num_matches=numgames,champion_ids = champ.id,ranked_queues='RANKED_SOLO_5x5',seasons='PRESEASON2016').matches
		matchlist = matchlist + matches

	# Put in check that summoner for participant id matches summoner id
	for m in matchlist:

		# For each match, find participant object matching the champion and get item set
		match = cass.get_match(m.matchId)
		c = list(map(lambda x: x.champion.id,match.participants))
		player = match.participants[c.index(champ.id)]
		its = list(map(lambda x: x.id,filter(None,player.stats.items)))
		itemlist = itemlist + its

	
	# Format Item set and calculate percentages
	itcounts = pd.DataFrame(list(Counter(itemlist).items()),columns=['id','perc'])
	itcounts = pd.merge(itcounts,Loading.items[Loading.items['id'].isin(itemlist)],on=['id'])
	itcounts['perc'] = itcounts['perc']/itcounts['perc'].sum()

	print('numgames=' + str(len(matchlist)))

	return itcounts.sort(columns=['perc'])
Exemplo n.º 2
0
def test_summoners_by_name():
    int_test_handler.test_result(
        riotapi.get_summoners_by_name([int_test_handler.summoner_name]))
Exemplo n.º 3
0
def test_summoners_by_name():
    int_test_handler.test_result(riotapi.get_summoners_by_name([int_test_handler.summoner_name]))
Exemplo n.º 4
0
def addMatch(request):
	if request.POST:
		newgame = Game()
		posted = request.POST
		print(posted.get('team1name'))
		newgame.team1 = Team.objects.get(teamName__iexact=posted.get('team1name')).teamID
		newgame.team2 = Team.objects.get(teamName__iexact=posted.get('team2name')).teamID
		newgame.winner = Team.objects.get(teamName__iexact=posted.get('winner')).teamID
		print (Game.objects.all().aggregate(Max('Number')))
		try:
			newgame.Number = Game.objects.all().aggregate(Max('Number'))['Number__max'] + 1
		except TypeError:
			newgame.Number = 0
		riotapi.set_region("NA")
		m = riotapi.get_match(posted.get('match'))
		if newgame.team2 == newgame.winner:
			loser = Team.objects.get(teamName__iexact=posted.get('team1name'))
			position = 2
		else:
			loser = Team.objects.get(teamName__iexact=posted.get('team2name'))
			position = 1
		addPoints(Team.objects.get(teamName__iexact=posted.get('winner')), loser, position)
		print(posted.get('P2'))
		namelist= []
		namelist.append(posted.get('P1'))
		namelist.append(posted.get('P2'))
		namelist.append(posted.get('P3'))
		namelist.append(posted.get('P4'))
		namelist.append(posted.get('P5'))
		namelist.append(posted.get('2P1'))
		namelist.append(posted.get('2P2'))
		namelist.append(posted.get('2P3'))
		namelist.append(posted.get('2P4'))
		namelist.append(posted.get('2P5'))
		summoners = riotapi.get_summoners_by_name(namelist)
		print(dir(summoners[0]))
		print(summoners[0].id)
		newgame.team1Player1 = summoners[0].id
		newgame.team1Player2 = summoners[1].id
		newgame.team1Player3 = summoners[2].id
		newgame.team1Player4 = summoners[3].id
		newgame.team1Player5 = summoners[4].id
		newgame.team2Player1 = summoners[5].id
		newgame.team2Player2 = summoners[6].id
		newgame.team2Player3 = summoners[7].id
		newgame.team2Player4 = summoners[8].id
		newgame.team2Player5 = summoners[9].id
		newgame.matchID = posted.get('match')
		i = 0
		for player in m.participants:
			try:
				st = Stats.objects.get(PlayerID=summoners[i].id)
			except:
				st = Stats()
				st.PlayerID = summoners[i].id
			i= i+ 1
			st.Kills = st.Kills + player.stats.kills
			st.Deaths = st.Deaths + player.stats.deaths
			st.Assists = st.Assists + player.stats.assists
			st.GoldTotal = st.GoldTotal + player.stats.gold_earned
			st.GamesPlayed = st.GamesPlayed + 1
			if player.stats.largest_critical_strike > st.LargestCrit:
				st.LargestCrit = player.stats.largest_critical_strike
			st.Creeps = st.Creeps + player.stats.minion_kills + player.stats.monster_kills
			st.SecondsPlayed = st.SecondsPlayed + m.duration.total_seconds()
			st.DamageDealt = st.DamageDealt + player.stats.damage_dealt_to_champions
			st.DamageReceived = st.DamageReceived + player.stats.damage_taken
			if i <= 5:
				st.TeamKillTotal =  st.TeamKillTotal + m.participants[0].stats.kills  + m.participants[1].stats.kills  + m.participants[2].stats.kills  + m.participants[3].stats.kills  + m.participants[4].stats.kills
			else:
				st.TeamKillTotal =  st.TeamKillTotal + m.participants[5].stats.kills  + m.participants[6].stats.kills  + m.participants[7].stats.kills  + m.participants[8].stats.kills  + m.participants[9].stats.kills
			st.DoubleKills =  st.DoubleKills + player.stats.double_kills
			st.TripleKills = st.TripleKills + player.stats.triple_kills
			st.QuadraKills = st.QuadraKills + player.stats.quadra_kills
			st.PentaKills = st.PentaKills + player.stats.penta_kills
			st.save()
		with open('olsrunner/matches/' + str(newgame.Number) + '.pk', 'wb') as outfile:
			pickle.dump( m , outfile)
		newgame.filename = 'olsrunner/matches/' + str(newgame.Number) + '.pk'
		newgame.save()
		return HttpResponse("match added")
	else:
		teamNames = []
		teams = Team.objects.all().values('teamName')
		for t in teams:
			teamNames.append(t['teamName'])
		
		return HttpResponse(render(request, 'addMatch.html', {'teams' :teamNames}))