-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
93 lines (69 loc) · 2.29 KB
/
stats.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
from itertools import islice
import sys
class Stats():
grossAvg = 0
maxGross = 0
highestFilm = ""
lowestFilm = ""
minGross = sys.maxsize
runAvg = 0
longestFilm = ""
shortestFilm = ""
maxRun = 0
minRun = sys.maxsize
def setStats(self, statList):
statsAsDict = {}
for i in islice(statList, 1, None):
if i not in statsAsDict:
statsAsDict[i] = 0
statsAsDict[i] += 1
return statsAsDict
def setGrossStats(self, grossList, titleList):
totalGross = 0
nonNA = 0
noFirst = list(islice(grossList, 1, None))
for i in range(len(noFirst)):
if noFirst[i] != "N/A":
valToInt = int(noFirst[i])
totalGross += valToInt
nonNA += 1
if valToInt > self.maxGross:
self.maxGross = valToInt
self.highestFilm = titleList[i + 1]
elif valToInt < self.minGross:
self.minGross = valToInt
self.lowestFilm = titleList[i + 1]
self.grossAvg = round(totalGross / nonNA, 2)
def getGrossAvg(self):
return self.grossAvg
def getMaxGross(self):
return self.maxGross
def getMinGross(self):
return self.minGross
def getHighestFilm(self):
return self.highestFilm
def getLowestFilm(self):
return self.lowestFilm
def setRunStats(self, runList, titleList):
totalRun = 0
noFirst = list(islice(runList, 1, None))
for i in range(len(noFirst)):
valToInt = int(noFirst[i])
totalRun += valToInt
if valToInt > self.maxRun:
self.maxRun = valToInt
self.longestFilm = titleList[i + 1]
elif valToInt < self.minRun:
self.minRun = valToInt
self.shortestFilm = titleList[i + 1]
self.runAvg = round(totalRun / len(noFirst), 2)
def getRunAvg(self):
return self.runAvg
def getMaxRun(self):
return self.maxRun
def getMinRun(self):
return self.minRun
def getLongestFilm(self):
return self.longestFilm
def getShortestFilm(self):
return self.shortestFilm