-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.py
More file actions
138 lines (112 loc) · 4.59 KB
/
statistics.py
File metadata and controls
138 lines (112 loc) · 4.59 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from collections import OrderedDict
from classes.sessionresult import SessionResult
from typing import List
import matplotlib.pyplot as plt
import numpy as np
from hashlib import sha256
import random
from os.path import join
def getHotLaps(results: List[SessionResult]):
tracks = OrderedDict()
for result in results:
if result.getHash() not in tracks:
tracks[result.getHash()] = OrderedDict()
for driver in result.Drivers:
hotlapTime = driver.BestLapTime
if driver.getHash() in tracks[result.getHash()]:
existingHotLap = tracks[result.getHash()][driver.getHash()]["BestLapTime"]
if existingHotLap > hotlapTime and hotlapTime > 0.0:
tracks[result.getHash()][driver.getHash()]["BestLapTime"] = hotlapTime
tracks[result.getHash()][driver.getHash()]["ResultFile"] = result.getPageFilename()
tracks[result.getHash()][driver.getHash()]["LapCount"] = tracks[result.getHash()][driver.getHash()]["LapCount"] + driver.getTimedLaps()
tracks[result.getHash()][driver.getHash()]["AllLapCount"] = tracks[result.getHash()][driver.getHash()]["AllLapCount"] + len(driver.Laps)
else:
if driver.BestLapTime != 0.0:
tracks[result.getHash()][driver.getHash()] = {
"Name": driver.Name,
"Vehicle": driver.VehName,
"CarType": driver.CarType,
"BestLapTime": driver.BestLapTime,
"LapCount": driver.getTimedLaps(),
"AllLapCount": len(driver.Laps),
"Track": result.TrackEvent,
"ResultFile": result.getPageFilename()
}
return tracks
def calculateGaps(result: SessionResult):
gaps= OrderedDict()
for lapCount in range(0, result.MostLapsCompleted ):
leadingTime = 0.0
for driver in result.Drivers:
if driver.Name not in gaps:
gaps[driver.Name] = []
# get the currently leading car
if lapCount < len(driver.Laps):
if driver.Laps[lapCount].Position == 1:
leadingTime = driver.Laps[lapCount].Et
for driver in result.Drivers:
if lapCount < len(driver.Laps):
ownTime = driver.Laps[lapCount].Et
delta = ownTime - leadingTime
# negative delta?
gaps[driver.Name].append(delta)
return gaps
def plotGaps(result: SessionResult, targetDirectory):
plt.clf()
plt.cla()
plt.close()
gaps = calculateGaps(result)
for driver in gaps:
y = gaps[driver]
x = []
for i in range(0, len(y) ):
x.append(i)
plt.plot(x,y,label=driver,color=(np.random.uniform(0, 1), np.random.uniform(0, 1), np.random.uniform(0, 1)))
plt.xlim(left=0,right=result.MostLapsCompleted -1)
plt.xticks(np.arange(0, result.MostLapsCompleted , 1.0))
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.savefig(join(targetDirectory,"{0}{1}{2}_gaps.png".format(result.getHash(),result.DateTime,result.Session)), bbox_inches='tight')
def getPositions(result: SessionResult):
results = OrderedDict()
for driver in result.Drivers:
results[driver.Name] = [driver.ClassGridPos]
for lap in driver.Laps:
results[driver.Name].append(lap.Position)
return results
def plotPositionGraph(result: SessionResult, targetDirectory):
plt.clf()
plt.cla()
plt.close()
results = getPositions(result)
yticks = []
sortedDrivers = sorted(result.Drivers, key=lambda x: x.ClassGridPos, reverse=False)
for driver in sortedDrivers:
yticks.append(driver.Name)
for name in results:
x = []
y = results[name]
for i in range(0, len(y) ):
x.append(i)
plt.plot(x,y,label=name)
plt.xlim(left=1,right=result.MostLapsCompleted)
plt.ylim(bottom=len(result.Drivers), top=0)
plt.yticks(np.arange(1,len(result.Drivers) +1),yticks)
plt.xticks(np.arange(0, result.MostLapsCompleted +1, 1.0))
plt.savefig(join(targetDirectory,"{0}{1}{2}_positions.png".format(result.getHash(),result.DateTime,result.Session)), bbox_inches='tight')
def plotStandardDeviation(result:SessionResult, targetDirectory):
x = []
y = []
for driver in result.Drivers:
x.append(driver.Name)
y.append(driver.getStandardDeviation())
plt.clf()
plt.cla()
plt.close()
objects = x
y_pos = np.arange(len(x))
performance = [10,8,6,4,2,1]
plt.bar(y_pos, y, align='center', alpha=0.5)
plt.xticks(y_pos, x)
plt.ylabel('Deviation in seconds')
plt.xticks(rotation=90)
plt.savefig(join(targetDirectory,"{0}{1}{2}_deviations.png".format(result.getHash(),result.DateTime,result.Session)), bbox_inches='tight')