def collectItemUsage(): matchesList = collectMatches() # Start by creating dictionaries of every spell, item, rune, and champion names try: itemUsage = { champion.name: [{ spell.name: 0 for spell in kass.get_summoner_spells(region="NA") }, {item.name: 0 for item in kass.get_items(region="NA")}, {rune.name: 0 for rune in kass.get_runes(region="NA")}] for champion in kass.get_champions(region="NA") } except Warning as err: print(err) for match in matchesList: for player in match.participants: currWin = player.stats.win if (currWin): # Only care if there was a win for the champion currChamp = player.champion.name if player.summoner_spell_d.name in itemUsage[currChamp][0]: itemUsage[currChamp][0][player.summoner_spell_d.name] += 1 if player.summoner_spell_f.name in itemUsage[currChamp][0]: itemUsage[currChamp][0][player.summoner_spell_f.name] += 1 for item in player.stats.items: if item is not None and item.name in itemUsage[currChamp][ 1]: itemUsage[currChamp][1][item.name] += 1 for rune in player.runes: if rune is not None and rune.name in itemUsage[currChamp][ 2]: itemUsage[currChamp][2][rune.name] += 1 return itemUsage
def _init_runes(all_runes=None): if not all_runes: all_runes = {rune.id: rune for rune in cass.get_runes()} RunePage._runes_by_id = {id_: Rune(data) for id_, data in all_runes.items()} else: RunePage._runes_by_id = all_runes RunePage._runes_by_name = {rune.name: rune for _, rune in RunePage._runes_by_id.items()}
def rune_from_desc() -> Question: rune: Rune = random.choice(riotapi.get_runes()) desc: str = censor_name(util.SANITIZER.handle(rune.long_description), *rune.name.split()) return Question("What's the name of this rune?", desc, rune.name, extra=f" ({rune.path.value} Tree)")
def load_all(self, refresh: bool = False): # Save refresh variable so we don't have to pass it into every method self.refresh = refresh if refresh: cassiopeia.configuration.settings.clear_sinks() cassiopeia.configuration.settings.expire_sinks() # Open the download popup, start downloading data and updating the # progress bar as we go progress_popup = hinter.ui.progress.Progress( 0, 'Downloading and processing: Champions') cassiopeia.get_champions() progress_popup.update(70, 'Downloading and processing: Items') cassiopeia.get_items() progress_popup.update(80, 'Downloading and processing: Maps') cassiopeia.get_maps() progress_popup.update(81, 'Downloading and processing: Spells') cassiopeia.get_summoner_spells() progress_popup.update(82, 'Downloading and processing: Runes') cassiopeia.get_runes() progress_popup.update(85, 'Downloading and processing: Rank icons') self.load_rank_icons(refresh) # Inform user data refresh completed, wait, then close the popup progress_popup.update(100, 'Data refresh complete! Window will close') time.sleep(3) progress_popup.close() # Do not update again until this is called, refresh data loaded checks self.refresh = False
def test_runes(): for rune in cass.get_runes(region="NA").keystones: rune.name, rune.id, rune.path, rune.tier assert rune.is_keystone
def tree_from_rune() -> Question: rune: Rune = random.choice(riotapi.get_runes()) return Question(f"What tree is {rune.name} from?", None, rune.path.value)
def storeMatches(): try: conn = pymysql.connect(user=config.dbUsername, password=config.dbPassword, host=config.dbIP, database=config.dbName) cursor = conn.cursor() except pymysql.Error as err: print(err) # Dict of tables TABLES = {} TABLES['champions'] = ''' CREATE TABLE champions ( champID int NOT NULL, champName varchar(25) NOT NULL, item1 varchar(50), item2 varchar(50), item3 varchar(50), item4 varchar(50), item5 varchar(50), item6 varchar(50), item7 varchar(50), rune1 varchar(35), rune2 varchar(35), rune3 varchar(35), rune4 varchar(35), rune5 varchar(35), rune6 varchar(35), rune7 varchar(35), spell1 varchar(40), spell2 varchar(40), PRIMARY KEY(champName) )''' TABLES['items'] = ''' CREATE TABLE items ( itemID int NOT NULL, itemName varchar(50) NOT NULL, PRIMARY KEY(itemName) )''' TABLES['runes'] = ''' CREATE TABLE runes ( runeID int NOT NULL, runeName varchar(35) NOT NULL, PRIMARY KEY(runeName) )''' TABLES['spells'] = ''' CREATE TABLE spells ( spellID int NOT NULL, spellName varchar(40) NOT NULL, PRIMARY KEY(spellName) )''' # Create the tables from the dict of tables above for name, ddl in TABLES.items(): try: print("Creating table {}: ".format(name), end='') cursor.execute(ddl) conn.commit() except pymysql.Error as err: print(err) else: print("OK") # Fill tables with all champions, items, spells, and runes allChamps = {champion.id: champion.name for champion in kass.get_champions(region="NA")} allItems = {item.id: item.name for item in kass.get_items(region="NA")} allRunes = {rune.id: rune.name for rune in kass.get_runes(region="NA")} allSpells = {spell.id: spell.name for spell in kass.get_summoner_spells(region="NA")} addChamp = ('''INSERT INTO champions (champID, champName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE champName=champName''') addItem = ('''INSERT INTO items (itemID, itemName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE itemName=itemName''') addRune = ('''INSERT INTO runes (runeID, runeName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE runeName=runeName''') addSpell = ('''INSERT INTO spells (spellID, spellName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE spellName=spellName''') try: for champ, name in allChamps.items(): dataChamp = (champ, name) cursor.execute(addChamp, dataChamp) conn.commit() for item, name in allItems.items(): dataItem = (item, name) cursor.execute(addItem, dataItem) conn.commit() for rune, name in allRunes.items(): dataRune = (rune, name) cursor.execute(addRune, dataRune) conn.commit() for spell, name in allSpells.items(): dataSpell = (spell, name) cursor.execute(addSpell, dataSpell) conn.commit() except pymysql.Error as err: print(err) else: print("Tables populated with default data") if conn.open: conn.close() cursor.close()
def print_t3_runes(): for rune in cass.get_runes(): if rune.tier == 3: print(rune.name)
def print_keystone_runes(): for rune in cass.get_runes(region="NA").keystones: print(rune.name)
def print_keystone_runes(): for rune in cass.get_runes(region="NA").keystones: print(rune.name)
def test_runes(): for rune in cass.get_runes(region="NA").keystones: rune.name, rune.id, rune.path, rune.tier assert rune.is_keystone
def get_static_data(request, region): region = normalize_region(region) response = {} try: response['version'] = cass.get_version(region=region) items_response = {} items = cass.get_items(region=region) for item in items: item_response = {} item_response['name'] = item.name item_response['totalGold'] = item.gold.total item_response['sellGold'] = item.gold.sell item_response['description'] = item.description item_response['plaintext'] = item.plaintext item_response['from'] = [it.id for it in item.builds_from] items_response[str(item.id)] = item_response runes_response = {} runes = cass.get_runes(region=region) for rune in runes: rune_response = {} rune_response['name'] = rune.name rune_response['path'] = rune.path.name rune_response['shortDescription'] = rune._data[cass.core.staticdata.rune.RuneData].shortDescription #rune.short_description rune_response['isKeystone'] = rune.is_keystone runes_response[str(rune.id)] = rune_response skills_response = {} champion_response = {} champions = cass.get_champions(region=region) for champion in champions: ch = {} ch['name'] = champion.name ch['title'] = champion.title ch['img'] = champion.image.full champion_response[str(champion.id)] = ch skills = ['q', 'w', 'e', 'r'] skill_response = { 'p': {}, 'q': {}, 'w': {}, 'e': {}, 'r': {} } skill_response['p']['img'] = champion.passive.image_info.full skill_response['p']['name'] = champion.passive.name skill_response['p']['description'] = champion.passive.sanitized_description for i, skill in enumerate(skills): skill_response[skill]['img'] = champion.spells[i].image_info.full skill_response[skill]['name'] = champion.spells[i].name skill_response[skill]['description'] = champion.spells[i].sanitized_description skill_response[skill]['cooldowns'] = champion.spells[i].cooldowns skill_response[skill]['costs'] = champion.spells[i].costs skills_response[str(champion.id)] = skill_response response['items'] = items_response response['runes'] = runes_response response['championSkills'] = skills_response response['champions'] = champion_response except Exception as e: log.warn("failed to get static data", e, stack_info=True) return HttpResponse(status=500) return JsonResponse(response)