class Report(Player): def __init__(self, playerId): self.wb = Workbook() self.ws = self.wb.active self.ws.title = "Full" self.player = Player(playerId) self.headers = """matchCreation winner championId champLevel kills assists deaths kda minionsKilled goldEarned lane matchDuration totalDamageDealtToChampions totalDamageTaken wardsPlaced wardsKilled visionWardsBoughtInGame csDiffPerMin@10 csDiffPerMin@20 csDiffPerMinAverage goldPerMin@10 goldPerMin@20 goldPerMinAverage xpDiffPerMin@10 xpDiffPerMin@20 xpDiffPerMinAverage creepsPerMin@10 creepsPerMin@20 creepsPerMinAverage xpPerMin@10 xpPerMin@20 xpPerMinAverage damageTakenDiffPerMin@10 damageTakenDiffPerMin@20 damageTakenDiffPerMinAverage damageTakenPerMin@10 damageTakenPerMin@20 damageTakenPerMinAverage item0 item1 item2 item3 item4 item5 item6 matchHistoryUri""" def _createCell(self, column, row, value, BOLD=False, WRAP=False): self.ws.cell(column=column, row=row).font = Font(bold=BOLD) self.ws.cell(column=column, row=row, value=value) self.ws.cell(column=column, row=row).alignment = Alignment(wrap_text=WRAP) def _createHeaders(self): for i, header in enumerate(self.headers.splitlines()): self._createCell(i + 1, 1, header.strip(), BOLD=True, WRAP=True) def _createFullRow(self, row, match): stats = match.stats for col, header in enumerate(self.headers.splitlines()): if header.strip() == "matchCreation": date = datetime.fromtimestamp(stats[header.strip()] / 1000) self._createCell(col + 1, row, date) elif header.strip() == "winner": if stats[header.strip()] == 1: self._createCell(col + 1, row, "WIN") else: self._createCell(col + 1, row, "LOSS") elif header.strip() == "championId": champion = match.champion() self._createCell(col + 1, row, champion) elif header.strip() == "matchDuration": self._createCell(col + 1, row, round(stats[header.strip()] / 60.0, 2)) elif header.strip() == "kda": self._createCell(col + 1, row, match.kda()) else: try: self._createCell(col + 1, row, stats[header.strip()]) except: if "Average" in header.strip(): deltas = [] deltas.append(stats[header.strip().replace("Average", "_zeroToTen")]) deltas.append(stats[header.strip().replace("Average", "_tenToTwenty")]) deltas.append(stats[header.strip().replace("Average", "_twentyToThirty")]) deltas.append(stats[header.strip().replace("Average", "_thirtyToEnd")]) average = 0 i = 0 for v in deltas: if v: i += 1 average += v try: average = average / i except: average = 0 self._createCell(col + 1, row, round(average, 2)) else: delta = stats[header.strip().replace("@10", "_zeroToTen").replace("@20", "_tenToTwenty")] if type(delta) is float: delta = round(delta, 2) self._createCell(col + 1, row, delta) def create(self): self._createHeaders() matches = self.player.getMatches() for i, match in enumerate(matches): self._createFullRow(i + 2, match) column = {} for c in self.ws.rows: for i in c: column[i.column] = 0 break for a, c in enumerate(self.ws.rows): if a > 0: for b, i in enumerate(c): if b > 0: v = len(str(i.value)) * 2 if v > column[i.column]: column[i.column] = v self.ws.column_dimensions[i.column].width = v else: self.ws.column_dimensions[i.column].width = 18 else: self.ws.row_dimensions[c[1].row].height = 30 dest_filename = "LoLReport_{}.xlsx".format(self.player.playerId) self.wb.save(filename=dest_filename)
def __init__(self, playerId): self.wb = Workbook() self.ws = self.wb.active self.ws.title = "Full" self.player = Player(playerId) self.headers = """matchCreation
import LoL from LoLRequest import Request from LoLPlayer import Player from LoLDB import Database as DB from time import time,sleep UPDATE_INTERVAL = 60 try: DB().createDatabase() except: pass while True: for id in LoL.PLAYERIDS: player = Player(id) if not player.hasRecord(): print "[CREATE] {}".format(id), matches = player.retrieveMatches(newPlayer=True) if matches != 0: print '...', matches, 'matches added.' elif ((time()-player.lastUpdated())/60) >= UPDATE_INTERVAL: matches = player.retrieveMatches() if matches != 0: print "[UPDATE] {} ...".format(id), matches, 'matches added.'