Пример #1
0
 def testCtorFiltersByQueue(self):
     self.matchlist = MatchList(self.gameinfo,
                                'l am eternal',
                                maxMatches=10,
                                queue="SOLODUO")
     for match in self.matchlist.matches:
         self.assertEquals(QueueType.RANKED_SOLODUO.value,
                           match.matchDto['queueId'])
Пример #2
0
 def testCtorFiltersBySeason(self):
     self.matchlist = MatchList(self.gameinfo, 'l am eternal', 100,
                                SeasonId.SEASON_2016)
     for match in self.matchlist.matches:
         self.assertEquals(SeasonId.SEASON_2016.value,
                           match.matchDto['seasonId'])
     self.assertTrue(
         len(self.matchlist.matches) > 0,
         'bad test; got no games. Try increasing maxMatches to search for,'
         +
         ' probable cause season comes earlier in time than the latest match searched for by this number of maxMatches'
     )
Пример #3
0
    def testCtorReturnsListOfMatchObjects(self):
        self.matchlist = MatchList(self.gameinfo, 'l am eternal')
        msg = 'matches in MatchList object not MatchDtos as described by RGAPI'
        #this isn't an exhuastive list of the things that make something a MatchDto

        for match in self.matchlist.matches:
            self.assertTrue(isinstance(match, Match), 'match not a Matchobj')
            self.assertIn('seasonId', match.matchDto.keys(), msg)
            self.assertIn('gameId', match.matchDto.keys(), msg)
            self.assertIn('teams', match.matchDto.keys(), msg)
            self.assertIn('participants', match.matchDto.keys(), msg)
            self.assertIn('frames', match.timeline.keys(), msg)
            self.assertIn('frameInterval', match.timeline.keys(), msg)
        self.assertTrue(
            len(self.matchlist.matches) > 0, 'no matches in this matchlist')
Пример #4
0
            d[k] = (100 * d[k][0] / numGames / 2,
                    timedelta(milliseconds=sum(d[k][1]) / len(d[k][1])))
        else:
            d[k] = (100 * d[k][0] / numGames,
                    timedelta(milliseconds=sum(d[k][1]) / len(d[k][1])))


def printDict(d):
    for k, v in d.items():
        print('\t\tself.assertEqual(result[' + str(k) + '][1].seconds,' +
              str(v[1].seconds) + ')')
        print('\t\tself.assertEqual(result[' + str(k) + '][0],' + str(v[0]) +
              ')')


ml = MatchList(MockInfoGetter(), 'l am eternal', 5)

wins = 0
losses = 0
towers = [('OUTER_TURRET', 'MID_LANE'), ('OUTER_TURRET', 'BOT_LANE'),
          ('OUTER_TURRET', 'TOP_LANE'), ('INNER_TURRET', 'MID_LANE'),
          ('INNER_TURRET', 'BOT_LANE'), ('INNER_TURRET', 'TOP_LANE'),
          ('BASE_TURRET', 'MID_LANE'), ('BASE_TURRET', 'BOT_LANE'),
          ('BASE_TURRET', 'TOP_LANE'), ('NEXUS_TURRET', 'MID_LANE')]

towerKillWinDict = dict()
towerDestroyedWinDict = dict()
towerKillLossDict = dict()
towerDestroyedLossDict = dict()
for match in ml.matches:
    if match.isWin():
Пример #5
0
 def setUp(self):
     gameinfo = getInfoGetter(True)
     self.matchlist = MatchList(gameinfo, 'l am eternal', queue="SOLODUO")
Пример #6
0
 def setUp(self):
     self.matchlist = MatchList(getInfoGetter(True), 'l am eternal', 5)
Пример #7
0
def search(request, name):
    '''gameinfo = getInfoGetter(True)
    print('creating MatchList')
    ml = MatchList(gameinfo, 'l am eternal')
    print("Searching for " + name)
    id = gameinfo.getSummonerByName(name)['accountId']
    matchtimes = []
    allmatches = []
    matchdetails = []
    for i in range(0,HUNDREDS_OF_MATCHES):
        matches = gameinfo.getMatchlistBySummonerId(id, i*100, 50) 
            
        for match in matches['matches']:
            allmatches.append(match)
            matchdetails.append(gameinfo.getMatchById(match['gameId']))
    i = 0
    winrateByTime = [[0 for x in range(2)] for y in range(4)]
    for match in allmatches:
        if match['queue'] == 420:
            #NA: match['timestamp']/1000 IS PST OF BEGINNING OF MATCH
            #VERIFIED 
            utctime = datetime.fromtimestamp(match['timestamp']/1000)
            offset = timedelta(hours=0)
            time = utctime - offset
            matchtimes.append(str(time) + ' timestamp: ' +str(match['timestamp']) + '   '+ str(match['gameId']) + '    ' + str(matchdetails[i]['queueId']) + ' ' + str(win(name, matchdetails[i])))
            
            if win(name, matchdetails[i]):
                if time.hour >= 18:
                    winrateByTime[3][1]+=1
                    winrateByTime[3][0]+=1
                elif time.hour >= 12:
                    winrateByTime[2][1]+=1
                    winrateByTime[2][0]+=1
                elif time.hour >= 6:
                    winrateByTime[1][1]+=1
                    winrateByTime[1][0]+=1
                else: #0-6
                    winrateByTime[0][1]+=1
                    winrateByTime[0][0]+=1
            else:
                if time.hour >= 18:
                    winrateByTime[3][0]+=1
                elif time.hour >= 12:
                    winrateByTime[2][0]+=1
                elif time.hour >= 6:
                    winrateByTime[1][0]+=1
                else: #0-6
                    winrateByTime[0][0]+=1
        i+=1
        
            #print("not a ranked game.")
    onPlayersTeam = dict()
    vsPlayersTeam = dict()
    for match in matchdetails:
        if match['queueId'] == 420:
            thisSummonersTeam = []
            enemyTeam = []
            thisSummonerWon = win(name, match)
            thisSummonerId = 0
            
            thisSummonersTeamId = 0
            for player in match['participantIdentities']:
                if player['player']['summonerName'].lower() == name:
                    thisSummonerId = player['participantId']
                    break
            for participant in match['participants']:
                
                if participant['participantId'] == thisSummonerId:
                    thisSummonersTeamId = participant['teamId']
                    break
            
            participantIds = dict()
            for player in match['participantIdentities']:
                participantIds[player['participantId']] = player['player']['summonerName']
            
            for participant in match['participants']:
                if participant['teamId'] == thisSummonersTeamId:
                    thisSummonersTeam.append(participant['participantId'])
                else:
                    enemyTeam.append(participant['participantId'])
            if thisSummonerWon:
                for particId in thisSummonersTeam:
                    if participantIds[particId] in onPlayersTeam:
                        wg = onPlayersTeam[participantIds[particId]]
                        onPlayersTeam[participantIds[particId]] = (wg[0]+1, wg[1]+1)
                    else:
                        onPlayersTeam[participantIds[particId]] = (1,1)
                for particId in enemyTeam:
                    if participantIds[particId] in vsPlayersTeam:
                        wg = vsPlayersTeam[participantIds[particId]]
                        vsPlayersTeam[participantIds[particId]] = (wg[0], wg[1]+1)
                    else:
                        vsPlayersTeam[participantIds[particId]] = (0,1)
            else:
                for particId in thisSummonersTeam:
                    if participantIds[particId] in onPlayersTeam:
                        wg = onPlayersTeam[participantIds[particId]]
                        onPlayersTeam[participantIds[particId]] = (wg[0], wg[1]+1)
                    else:
                        onPlayersTeam[participantIds[particId]] = (0,1)
                for particId in enemyTeam:
                    if participantIds[particId] in vsPlayersTeam:
                        wg = vsPlayersTeam[participantIds[particId]]
                        vsPlayersTeam[participantIds[particId]] = (wg[0]+1, wg[1]+1)
                    else:
                        vsPlayersTeam[participantIds[particId]] = (1,1)
    onPlayersTeamList = []
    for item in onPlayersTeam.items():
        if item[1][1] > 1:
            onPlayersTeamList.append(item)
    onPlayersTeamList.sort(key=lambda x: x[1][1], reverse=True)

    vsPlayersTeamList = []
    for item in vsPlayersTeam.items():
        if item[1][1] > 1:
            vsPlayersTeamList.append(item)
    vsPlayersTeamList.sort(key=lambda x: x[1][1], reverse=True)
    
    print(onPlayersTeamList)
    print(vsPlayersTeamList)
    
    winratesByTime = []
    if winrateByTime[3][0] != 0:
        winratesByTime.append('18:00-24:00: ' + str(winrateByTime[3][1]/winrateByTime[3][0]*100) + '% of ' + str(winrateByTime[3][0]) + ' games.')
    else:
        winratesByTime.append('18:00-24:00: no games')
    if winrateByTime[2][0] != 0:
        winratesByTime.append('12:00-18:00: ' + str(winrateByTime[2][1]/winrateByTime[2][0]*100) + '% of ' + str(winrateByTime[2][0]) + ' games.')
    else:
        winratesByTime.append('12:00-18:00: no games')
    if winrateByTime[1][0] != 0:
        winratesByTime.append('6:00-12:00: ' + str(winrateByTime[1][1]/winrateByTime[1][0]*100) + '% of ' + str(winrateByTime[1][0]) + ' games.')
    else:
        winratesByTime.append('6:00-12:00: no games')
    if winrateByTime[0][0] != 0:
        winratesByTime.append('0:00-6:00: ' + str(winrateByTime[0][1]/winrateByTime[0][0]*100) + '% of ' + str(winrateByTime[0][0]) + ' games.')
    else: 
        winratesByTime.append('0:00-6:00: no games')
    
    
    print(winratesByTime)
    return render(request, 'search/search.html', {
        'name'           : name             ,  
        'matchtimes'     : matchtimes       , 
        'winratesByTime' : winratesByTime   ,
        'onPlayersTeam'  : onPlayersTeamList,
        'vsPlayersTeam'  : vsPlayersTeamList,
    })
    '''
    maxMatches = int(request.session['numMatches'])
    champions = request.session['champions']
    role = request.session['role']
    queue = request.session['queue']
    if champions == "":
        champions = None
    if role == "":
        role = None
    if queue == "":
        queue = None
    try:
        matchList = MatchList(getInfoGetter(), name, maxMatches, None, queue,
                              champions, role)
    except RuntimeError as e:
        return HttpResponse("Error: " + str(e))
    #remember that you wrote the text 'in PST only' into search.html
    if matchList.size() == 0:
        return HttpResponse(
            'no matches found with those parameters. Try a different search or include more matches.'
        )

    return render(
        request,
        'search/search.html',
        {
            'name':
            name,
            'overview':
            str(matchList),
            'numMatches':
            maxMatches,
            'matchIds':
            matchList.matchIdList(),
            'summonerId':
            matchList.id,

            #By time
            'wrByTime':
            matchList.winrateByTime(),

            #OtherSummoners:
            'otherSummonersWr':
            matchList.winrateByOtherSummoners(),

            #Dragons:
            'pctElementals':
            matchList.pctAllElemental(),
            'pctElders':
            matchList.pctAllElders(),
            'pctOfEachType':
            matchList.pctDragonsKilledByType(),
            'pctOfTotalByType':
            matchList.pctEachDragonType(),
            'pctEleByOrder':
            matchList.pctElementalKilledByOrder(),
            'pctElderByOrder':
            matchList.pctElderKilledByOrder(),

            #Dragon time info:
            'firstDragTime':
            matchList.firstElementalDragonTime(),
            'enemyContDragInfo':
            matchList.timePercentEnemyContestedElementalDragons(),
            'enemyB2BDragInfo':
            matchList.timePercentEnemyBackToBackElementalDragons(),
            'contDragInfo':
            matchList.timePercentContestedElementalDragons(),
            'b2BDragInfo':
            matchList.timePercentBackToBackElementalDragons(),

            #Barons:
            'avgBarons':
            matchList.avgBarons(),

            #Towers:
            'winTowersKilled':
            matchList.towersKilledInWins(),
            'lossTowersKilled':
            matchList.towersKilledInLosses(),
            'winTowersLost':
            matchList.towersLostInWins(),
            'lossTowersLost':
            matchList.towersLostInLosses(),

            #kills:
            'championKills':
            matchList.compileKillLists()
        })