-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_components.py
112 lines (74 loc) · 3.15 KB
/
output_components.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import copy
import xlsxwriter
import components as cp
# def CalculateAverageMatchStatlines(statlines : cp.MatchDataOut):
# statlines = []
# for match in matches:
# for statline in match.statlines:
# if statline.gamertag not in
def CalculateAverageSeriesStatlines(series: cp.SeriesOut):
averages = {}
seriesStatlines = GetStatlinesFromSeries(series)
for statline in seriesStatlines:
toAdd = statline
gamertag = statline.gamertag
if GamertagInStatlinesDict(gamertag, averages):
toAdd.AddStatline(averages[gamertag])
averages[gamertag] = toAdd
for player in averages.keys():
averages[player].CalculateAverages()
return averages
def GamertagInStatlinesArray(gamertag, statlines: [cp.MatchDataOut]):
return gamertag in GetGamertagsInStatlines(statlines)
def GamertagInStatlinesDict(gamertag, statlinesDict):
return statlinesDict.get(gamertag) is not None
def GetGamertagsInStatlines(statlines: [cp.MatchDataOut]):
return [statline.gamertag for statline in statlines]
def GetStatlinesFromSeries(series: cp.SeriesOut):
return [statline for match in copy.deepcopy(series.matches) for statline in match.statlines]
def GetStatlinesDataFromMatch(match: cp.MatchOut):
return [statline.getDataDict().values() for statline in match.statlines.copy()]
""" CSV OUTPUT FUNCTIONS """
def GenerateSeriesReport(series: cp.SeriesOut):
sheetname = series.GetSheetName()
workbook = xlsxwriter.Workbook(sheetname)
worksheet = workbook.add_worksheet()
writeToSheet(worksheet, series.GetHeaders(), 0)
writeToSheet(worksheet, STAT_HEADERS, 2)
for matchNo, match in enumerate(series.matches):
writeToSheet(worksheet, GetGameNumber(matchNo + 1), 18 + 20 * matchNo)
writeToSheet(worksheet, match.GetHeaders(), 19 + 20 * matchNo)
writeToSheet(worksheet, STAT_HEADERS, 20 + 20 * matchNo)
writeRowsToSheet(worksheet, GetStatlinesDataFromMatch(match), 21 + 20 * matchNo)
# avgData = CalculateAverageSeriesStatlines(series)
# for j, key in enumerate(avgData.keys()):
# writeToSheet(worksheet, avgData[key].getDataDict().values(), 3+j)
workbook.close()
print(f"Generated {sheetname}")
def writeToSheet(sheet, data, row):
for col, dp in enumerate(data):
sheet.write_column(row, col, [dp])
def writeRowsToSheet(sheet, data, startRow):
for row in range(startRow, startRow + len(data)):
for col, dp in enumerate(data[row - startRow]):
sheet.write_column(row, col, [dp])
def GetGameNumber(gameNumber):
return [
"Game " + str(gameNumber)
]
STAT_HEADERS = [
"Gamertag", "K", "D", "A", "KD", "dmgD"
, "dmgT", "Acc", "Fired", "Landed"
, "Perf", "dmg%", "dmgD/K", "dmgD/D"
, "dmgD/Min", "dmgT/K", "dmgT/D"
, "dmgT/Min", "Land/D", "KA/D"
, "dmg[+/-]", "[+/-]"
]
series = cp.SeriesOut(7)
# CalculateAverageSeriesStatlines(series)
GenerateSeriesReport(series)
# data = CalculateAverageStatlines(series)
# big data
# https://leafapp.co/scrims/228/players
# https://leafapp.co/scrims/234/players
# https://leafapp.co/scrims/236/players