示例#1
0
def third_main():
    #np.set_printoptions(threshold=np.inf)
    api = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2')
    api_euw = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                      Consts.REGIONS['europe_west'])
    api_eune = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                       Consts.REGIONS['europe_nordic_and_east'])
    api_kr = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                     Consts.REGIONS['korea'])
    #loading the NA match ids
    #data = json.loads(open('./BILGEWATER/EUW.json').read())
    #data += json.loads(open('./BILGEWATER/EUW.json').read())
    data = json.loads(open('./BILGEWATER/NA.json').read())
    pop_spells = make_spells_dict()
    match_num = 1
    for matchid in data:
        if match_num > 700:
            break
        print("On match number " + str(match_num))
        #if match_num <= 10000:
        #print(matchid)
        #match = api_euw.get_match_info(matchid, {'includeTimeline': True})
        #else:
        match = api.get_match_info(matchid, {'includeTimeline': True})
        if match is False or match['matchDuration'] < 1000:
            print("Broken Match")
            continue
        for champ in match['participants']:
            #get champ id and name
            championID = champ['championId']
            champ_name = champion_cache.find(championID)
            if champ_name is False:
                champ_name = api.get_champ_by_id(championID)['key']
            champion_cache.place(championID, champ_name)
            #combination so it does not matter which order summoner spells are chosen
            spell1id = champ['spell2Id'] + champ['spell1Id']
            spell2id = champ['spell1Id'] * champ['spell2Id']
            if champ['spell2Id'] in pop_spells[champ_name]:
                pop_spells[champ_name][champ['spell2Id']] += 1
            else:
                pop_spells[champ_name][champ['spell2Id']] = 1
            if champ['spell1Id'] in pop_spells[champ_name]:
                pop_spells[champ_name][champ['spell1Id']] += 1
            else:
                pop_spells[champ_name][champ['spell1Id']] = 1
            #print(pop_spells)
            #add to team list
        match_num += 1
    with open('spell_dict.json', 'w') as fp:
        json.dump(pop_spells, fp)
示例#2
0
def third_main():
	#np.set_printoptions(threshold=np.inf)
	api = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2')
	api_euw = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['europe_west'])
	api_eune = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['europe_nordic_and_east'])
	api_kr = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['korea'])
	#loading the NA match ids
	#data = json.loads(open('./BILGEWATER/EUW.json').read())
	#data += json.loads(open('./BILGEWATER/EUW.json').read())
	data = json.loads(open('./BILGEWATER/NA.json').read())
	pop_spells = make_spells_dict()
	match_num = 1
	for matchid in data:
		if match_num > 700:
			break
		print("On match number " + str(match_num))
		#if match_num <= 10000:
			#print(matchid)
			#match = api_euw.get_match_info(matchid, {'includeTimeline': True})
		#else: 
		match = api.get_match_info(matchid, {'includeTimeline': True})
		if match is False or match['matchDuration'] < 1000:
			print("Broken Match")
			continue
		for champ in match['participants']:
			#get champ id and name
			championID = champ['championId']
			champ_name = champion_cache.find(championID)
			if champ_name is False:
				champ_name = api.get_champ_by_id(championID)['key']
			champion_cache.place(championID, champ_name)
			#combination so it does not matter which order summoner spells are chosen
			spell1id = champ['spell2Id'] + champ['spell1Id']
			spell2id = champ['spell1Id'] * champ['spell2Id']
			if champ['spell2Id'] in pop_spells[champ_name]:
				pop_spells[champ_name][champ['spell2Id']] += 1
			else:
				pop_spells[champ_name][champ['spell2Id']] = 1
			if champ['spell1Id'] in pop_spells[champ_name]:
				pop_spells[champ_name][champ['spell1Id']] += 1
			else:
				pop_spells[champ_name][champ['spell1Id']] = 1
			#print(pop_spells)
			#add to team list
		match_num+=1
	with open('spell_dict.json', 'w') as fp:
		json.dump(pop_spells, fp)
示例#3
0
def main():
	#np.set_printoptions(threshold=np.inf)
	api = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2')
	api_euw = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['europe_west'])
	api_eune = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['europe_nordic_and_east'])
	api_kr = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['korea'])
	#loading the NA match ids
	data = json.loads(open('./BILGEWATER/EUW.json').read())
	#data += json.loads(open('./BILGEWATER/EUNE.json').read())
	#data += json.loads(open('./BILGEWATER/KR.json').read())
	data += json.loads(open('./BILGEWATER/NA.json').read())
	csv_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	pop_items = make_items_dict()
	pop_spells = make_spells_dict()
	team_comps = {}
	data_col_base = len(Consts.STAT_TO_MATRIX)
	_fill_champ_id_range(csv_data, data_col_base)
	match_num = 1
	for matchid in data:
		print("On match number " + str(match_num))
		if match_num <= 10000:
			#print(matchid)
			match = api_euw.get_match_info(matchid, {'includeTimeline': True})
		else: 
			match = api.get_match_info(matchid, {'includeTimeline': True})
		win_team = []
		lose_team = []
		if match is False or match['matchDuration'] < 1000:
			print("Broken Match")
			continue
		for champ in match['participants']:
			#get champ id and name
			championID = champ['championId']
			champ_name = champion_cache.find(championID)
			if champ_name is False:
				champ_name = api.get_champ_by_id(championID)['key']
			champion_cache.place(championID, champ_name)
			chmp_mtrx_index = CHAMP_TO_MATRIX[champ_name]
			#these methods return values which must then be input into the matrix
			offense, defense, utility = _parse_masteries(champ.get('masteries', []))
			kills, deaths, assists, phys_dmg, mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, win = _parse_stats(champ['stats'], championID)
			cs_min, gold_min = _parse_timeline(champ['timeline'])
			#combination so it does not matter which order summoner spells are chosen
			spell1id = champ['spell2Id'] + champ['spell1Id']
			spell2id = champ['spell1Id'] * champ['spell2Id']
			if champ['spell2Id'] in pop_spells[champ_name]:
				pop_spells[champ_name][champ['spell2Id']] += 1
			else:
				pop_spells[champ_name][champ['spell2Id']] = 1
			if champ['spell1Id'] in pop_spells[champ_name]:
				pop_spells[champ_name][champ['spell1Id']] += 1
			else:
				pop_spells[champ_name][champ['spell1Id']] = 1
			#print(pop_spells)
			#place data into matrix
			#attack range not changed because data is normalized anyway
			csv_data_delta = np.array([offense, defense, utility, kills, deaths, assists, phys_dmg, mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, 
				0, cs_min, gold_min, spell1id, spell2id, win])
			csv_data[chmp_mtrx_index, data_col_base + 1:data_col_base + len(Consts.VARIABLE_TO_MATRIX) + 1] += csv_data_delta
			#these methods input data directly into matrix
			csv_data = _parse_runes(champ.get('runes', []), csv_data, chmp_mtrx_index)
			csv_data = _parse_items(champ['stats'], csv_data, chmp_mtrx_index, pop_items, True)
			
			#add 1 to champion counter	 
			csv_data[chmp_mtrx_index, Consts.BLACK_MARKET_FEATURES-1]+=1

			#add to team list
			if win == 1:
				win_team.append(champ_name)
			else:
				lose_team.append(champ_name)
		if SHOW_MATRIX:
			print(csv_data)
		win_team = tuple(sorted(win_team))
		#print(win_team)
		lose_team = tuple(sorted(lose_team))
		#print(lose_team)
		team_comps = add_to_team_comps(win_team, lose_team, team_comps)
		#print(team_comps)
		match_num+=1
	np.savetxt('data.csv', csv_data, delimiter= ",", comments = "")
	with open('item_dict.json', 'w') as fp:
		json.dump(pop_items, fp)
	with open('team_dict.json', 'w') as fp:
		json.dump(team_comps, fp)
	with open('spell_dict.json', 'w') as fp:
		json.dump(pop_spells, fp)
示例#4
0
def second_main():
	#np.set_printoptions(threshold=np.inf)
	api = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2')
	api_euw = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['europe_west'])
	api_eune = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['europe_nordic_and_east'])
	api_kr = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2', Consts.REGIONS['korea'])
	#loading the NA match ids
	data = json.loads(open('./BILGEWATER/EUW.json').read())
	data += json.loads(open('./BILGEWATER/KR.json').read())
	data += json.loads(open('./BILGEWATER/NA.json').read())
	data_col_base = len(Consts.STAT_TO_MATRIX)
	#initialize different arrays
	marksman_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	support_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	mage_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	tank_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	phys_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	mgc_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	jgler_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	ass_data = np.zeros(shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
	data_list = {'Magical Bruiser': mgc_data, 'Assassin': ass_data, 'Jungler': jgler_data, 'Marksman': marksman_data, 'Support': support_data, 'Mage': mage_data, 'Tank': tank_data, 'Physical Bruiser': phys_data}
	for role in data_list:
		_fill_champ_id_range(data_list[role], data_col_base)
	#initialize k-cluster
	kmean, scaler = KLearn.get_k_learn()
	match_num = 1
	for matchid in data:
		print("On match number " + str(match_num))
		if match_num <= 10000:
			#print(matchid)
			match = api_euw.get_match_info(matchid, {'includeTimeline': True})
		elif match_num <= 20000:
			match = api_kr.get_match_info(matchhid, {'includeTimeline': True})
		else: 
			match = api.get_match_info(matchhid, {'includeTimeline': True})
		if match['matchDuration'] < 1000:
			print("Broken Match")
			continue
		for champ in match['participants']:
			champ_data = np.zeros(shape=[1, Consts.BLACK_MARKET_FEATURES])
			#get champ id and name
			championID = champ['championId']
			champ_name = champion_cache.find(championID)
			if champ_name is False:
				champ_name = api.get_champ_by_id(championID)['key']
			champion_cache.place(championID, champ_name)
			chmp_mtrx_index = CHAMP_TO_MATRIX[champ_name]
			#these methods return values which must then be input into the matrix
			offense, defense, utility = _parse_masteries(champ.get('masteries', []))
			kills, deaths, assists, phys_dmg, mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, win = _parse_stats(champ['stats'], championID)
			cs_min, gold_min = _parse_timeline(champ['timeline'])	
			#combination so it does not matter which order summoner spells are chosen
			spell1id = champ['spell2Id'] + champ['spell1Id']
			spell2id = champ['spell1Id'] * champ['spell2Id']
			#place data into matrix
			#attack range not changed because data is normalized anyway
			data_delta = np.array([offense, defense, utility, kills, deaths, assists, phys_dmg, mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, 
				0, cs_min, gold_min, spell1id, spell2id, win])
			champ_data[0, data_col_base + 1:data_col_base + len(Consts.VARIABLE_TO_MATRIX) + 1] += data_delta
			#these methods input data directly into matrix
			champ_data = _parse_runes(champ.get('runes', []), champ_data, 0)
			champ_data = _parse_items(champ['stats'], champ_data, 0, {}, False)
			#add 1 to champion counter	 
			champ_data[0, Consts.BLACK_MARKET_FEATURES-1]+=1
			cluster_num = find_cluster(kmean, scaler, champ_data)
			data_list[KLearn.roles[cluster_num]][chmp_mtrx_index] += champ_data.flatten()
		match_num+=1
	for role in data_list:
		np.savetxt('role_data' + role + '.csv', data_list[role], delimiter= ",", comments = "")
示例#5
0
def main():
    #np.set_printoptions(threshold=np.inf)
    api = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2')
    api_euw = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                      Consts.REGIONS['europe_west'])
    api_eune = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                       Consts.REGIONS['europe_nordic_and_east'])
    api_kr = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                     Consts.REGIONS['korea'])
    #loading the NA match ids
    data = json.loads(open('./BILGEWATER/EUW.json').read())
    #data += json.loads(open('./BILGEWATER/EUNE.json').read())
    #data += json.loads(open('./BILGEWATER/KR.json').read())
    data += json.loads(open('./BILGEWATER/NA.json').read())
    csv_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    pop_items = make_items_dict()
    pop_spells = make_spells_dict()
    team_comps = {}
    data_col_base = len(Consts.STAT_TO_MATRIX)
    _fill_champ_id_range(csv_data, data_col_base)
    match_num = 1
    for matchid in data:
        print("On match number " + str(match_num))
        if match_num <= 10000:
            #print(matchid)
            match = api_euw.get_match_info(matchid, {'includeTimeline': True})
        else:
            match = api.get_match_info(matchid, {'includeTimeline': True})
        win_team = []
        lose_team = []
        if match is False or match['matchDuration'] < 1000:
            print("Broken Match")
            continue
        for champ in match['participants']:
            #get champ id and name
            championID = champ['championId']
            champ_name = champion_cache.find(championID)
            if champ_name is False:
                champ_name = api.get_champ_by_id(championID)['key']
            champion_cache.place(championID, champ_name)
            chmp_mtrx_index = CHAMP_TO_MATRIX[champ_name]
            #these methods return values which must then be input into the matrix
            offense, defense, utility = _parse_masteries(
                champ.get('masteries', []))
            kills, deaths, assists, phys_dmg, mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, win = _parse_stats(
                champ['stats'], championID)
            cs_min, gold_min = _parse_timeline(champ['timeline'])
            #combination so it does not matter which order summoner spells are chosen
            spell1id = champ['spell2Id'] + champ['spell1Id']
            spell2id = champ['spell1Id'] * champ['spell2Id']
            if champ['spell2Id'] in pop_spells[champ_name]:
                pop_spells[champ_name][champ['spell2Id']] += 1
            else:
                pop_spells[champ_name][champ['spell2Id']] = 1
            if champ['spell1Id'] in pop_spells[champ_name]:
                pop_spells[champ_name][champ['spell1Id']] += 1
            else:
                pop_spells[champ_name][champ['spell1Id']] = 1
            #print(pop_spells)
            #place data into matrix
            #attack range not changed because data is normalized anyway
            csv_data_delta = np.array([
                offense, defense, utility, kills, deaths, assists, phys_dmg,
                mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, 0, cs_min,
                gold_min, spell1id, spell2id, win
            ])
            csv_data[chmp_mtrx_index, data_col_base + 1:data_col_base +
                     len(Consts.VARIABLE_TO_MATRIX) + 1] += csv_data_delta
            #these methods input data directly into matrix
            csv_data = _parse_runes(champ.get('runes', []), csv_data,
                                    chmp_mtrx_index)
            csv_data = _parse_items(champ['stats'], csv_data, chmp_mtrx_index,
                                    pop_items, True)

            #add 1 to champion counter
            csv_data[chmp_mtrx_index, Consts.BLACK_MARKET_FEATURES - 1] += 1

            #add to team list
            if win == 1:
                win_team.append(champ_name)
            else:
                lose_team.append(champ_name)
        if SHOW_MATRIX:
            print(csv_data)
        win_team = tuple(sorted(win_team))
        #print(win_team)
        lose_team = tuple(sorted(lose_team))
        #print(lose_team)
        team_comps = add_to_team_comps(win_team, lose_team, team_comps)
        #print(team_comps)
        match_num += 1
    np.savetxt('data.csv', csv_data, delimiter=",", comments="")
    with open('item_dict.json', 'w') as fp:
        json.dump(pop_items, fp)
    with open('team_dict.json', 'w') as fp:
        json.dump(team_comps, fp)
    with open('spell_dict.json', 'w') as fp:
        json.dump(pop_spells, fp)
示例#6
0
def second_main():
    #np.set_printoptions(threshold=np.inf)
    api = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2')
    api_euw = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                      Consts.REGIONS['europe_west'])
    api_eune = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                       Consts.REGIONS['europe_nordic_and_east'])
    api_kr = RiotAPI('be8ccf5f-5d08-453f-84f2-ec89ddd7cea2',
                     Consts.REGIONS['korea'])
    #loading the NA match ids
    data = json.loads(open('./BILGEWATER/EUW.json').read())
    data += json.loads(open('./BILGEWATER/KR.json').read())
    data += json.loads(open('./BILGEWATER/NA.json').read())
    data_col_base = len(Consts.STAT_TO_MATRIX)
    #initialize different arrays
    marksman_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    support_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    mage_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    tank_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    phys_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    mgc_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    jgler_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    ass_data = np.zeros(
        shape=[Consts.BLACK_MARKET_CHAMPIONS, Consts.BLACK_MARKET_FEATURES])
    data_list = {
        'Magical Bruiser': mgc_data,
        'Assassin': ass_data,
        'Jungler': jgler_data,
        'Marksman': marksman_data,
        'Support': support_data,
        'Mage': mage_data,
        'Tank': tank_data,
        'Physical Bruiser': phys_data
    }
    for role in data_list:
        _fill_champ_id_range(data_list[role], data_col_base)
    #initialize k-cluster
    kmean, scaler = KLearn.get_k_learn()
    match_num = 1
    for matchid in data:
        print("On match number " + str(match_num))
        if match_num <= 10000:
            #print(matchid)
            match = api_euw.get_match_info(matchid, {'includeTimeline': True})
        elif match_num <= 20000:
            match = api_kr.get_match_info(matchhid, {'includeTimeline': True})
        else:
            match = api.get_match_info(matchhid, {'includeTimeline': True})
        if match['matchDuration'] < 1000:
            print("Broken Match")
            continue
        for champ in match['participants']:
            champ_data = np.zeros(shape=[1, Consts.BLACK_MARKET_FEATURES])
            #get champ id and name
            championID = champ['championId']
            champ_name = champion_cache.find(championID)
            if champ_name is False:
                champ_name = api.get_champ_by_id(championID)['key']
            champion_cache.place(championID, champ_name)
            chmp_mtrx_index = CHAMP_TO_MATRIX[champ_name]
            #these methods return values which must then be input into the matrix
            offense, defense, utility = _parse_masteries(
                champ.get('masteries', []))
            kills, deaths, assists, phys_dmg, mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, win = _parse_stats(
                champ['stats'], championID)
            cs_min, gold_min = _parse_timeline(champ['timeline'])
            #combination so it does not matter which order summoner spells are chosen
            spell1id = champ['spell2Id'] + champ['spell1Id']
            spell2id = champ['spell1Id'] * champ['spell2Id']
            #place data into matrix
            #attack range not changed because data is normalized anyway
            data_delta = np.array([
                offense, defense, utility, kills, deaths, assists, phys_dmg,
                mgc_dmg, true_dmg, dmg_taken, team_jgl, enemy_jgl, 0, cs_min,
                gold_min, spell1id, spell2id, win
            ])
            champ_data[0, data_col_base + 1:data_col_base +
                       len(Consts.VARIABLE_TO_MATRIX) + 1] += data_delta
            #these methods input data directly into matrix
            champ_data = _parse_runes(champ.get('runes', []), champ_data, 0)
            champ_data = _parse_items(champ['stats'], champ_data, 0, {}, False)
            #add 1 to champion counter
            champ_data[0, Consts.BLACK_MARKET_FEATURES - 1] += 1
            cluster_num = find_cluster(kmean, scaler, champ_data)
            data_list[KLearn.roles[cluster_num]][
                chmp_mtrx_index] += champ_data.flatten()
        match_num += 1
    for role in data_list:
        np.savetxt('role_data' + role + '.csv',
                   data_list[role],
                   delimiter=",",
                   comments="")