示例#1
0
def addReportInfo(d,pData): 
    #could be a more efficient method if updated to take in both recent and aggregate at the same time
    champ = dbcalls.translateChamp(pData["championId"])
    stats = pData["stats"]
    win = 1 if stats["win"] else 0
    
    #champion info
    if champ in d:
        d[champ]["matches"] += 1
        d[champ]["wins"] += win
    else:
        d[champ] = {"matches":1,"wins":win,"items":{},"lanes":{},"runes":{},"runeSets":[]}
    
    #items info (per champion)
    for num in range(0,7):
        itemNum = stats["item"+(str)(num)]
        item = dbcalls.translateItem(itemNum)
        if(not item == "0"): #ensures we don't add empty inventory slots to the items dict, or outdated items
            items = d[champ]["items"]
            if item in items:
                items[item] += 1
            else:
                items[item] = 1
                
    #lane info (per champion)
    lane = pData["timeline"]["lane"]
    lanes = d[champ]["lanes"]
    overallLanes = d["lanes"]
    if lane in lanes:
        lanes[lane] += 1
    else:
        lanes[lane] = 1
    if lane in overallLanes:
        overallLanes[lane] += 1
    else:
        overallLanes[lane] = 1
        
    #rune info (per champion)
    runeSet = {"keystone":"","primaryTree":"","secondaryTree":"",
               "perk1":"","perk2":"","perk3":"","perk4":"","perk5":""}
    
    runeSet["primaryTree"] = dbcalls.translateRune(stats["perkPrimaryStyle"])
    runeSet["secondaryTree"] = dbcalls.translateRune(stats["perkSubStyle"])
    for num in range(0,6):
        perkNum = "perk"+(str)(num)
        runeNum = stats[perkNum]
        rune = dbcalls.translateRune(runeNum)
        runes = d[champ]["runes"]
        if(perkNum in runeSet): #all perks other than 0 (keystone) are in the runeSet dictionary
            runeSet[perkNum] = rune
        else:
            runeSet["keystone"] = rune
        if(not rune == ""): #ensures we don't add outdated runes that will cause an error
            if rune in runes:
                runes[rune] += 1
            else:
                runes[rune] = 1
    d[champ]["runeSets"].append(runeSet)
示例#2
0
def getFingerprint(name):
    fingerprint = {"flash":[0,0],
                   "numMatches":0,
                   "itemMatrix":{}
                   }
    
    account = riotapicalls.getAccountByName(name)
    assert "id" in account, "Invalid name given, no account found for: " + name
    summId = account["id"]
    #matches = riotapicalls.getAllRankedMatchesByAccount(account)
    matches = dbcalls.fetchMatchesByAccount(account)
    
    fingerprint["numMatches"] = len(matches)
    for match in matches:
        pId = findParticipantId(match,summId)
        p = match["participants"][pId-1]    #the info for the participant
            
        #check which key flash is typically on
        if(p["spell1Id"] == 4):  #4 is the id for flash
            fingerprint["flash"][0] += 1
        elif(p["spell2Id"] == 4):    #else statement because may not have flash
            fingerprint["flash"][1] += 1
            
        #gather item data for all the items in the inventory
        inventory = []
        for slot in range(0,7):
            itemNum = p["stats"]["item"+(str)(slot)]
            item = dbcalls.translateItem(itemNum) #if invalid item, it is an empty string
            if(not item == "" and item in ACTIVE_ITEMS):
                inventory.append(item)
                if(item not in fingerprint["itemMatrix"]):
                    fingerprint["itemMatrix"][item] = [0,0,0,0,0,0,0,0]
                fingerprint["itemMatrix"][item][slot] += 1
                fingerprint["itemMatrix"][item][7] += 1 #this is the total count of the item
    print("Done with " + name + " matches.")
        
    fingerprint = handleInventory(fingerprint)
    
    return fingerprint