Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
F1 Overtake Analyser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lennard Geese
F1 Overtake Analyser
Commits
d74335cb
Commit
d74335cb
authored
3 weeks ago
by
Lennard Geese
Browse files
Options
Downloads
Patches
Plain Diff
Implement painting graph background for weather change window
parent
f9c4c34c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
DataPlotter.py
+62
-13
62 additions, 13 deletions
DataPlotter.py
Todos.md
+1
-1
1 addition, 1 deletion
Todos.md
main.py
+12
-6
12 additions, 6 deletions
main.py
with
75 additions
and
20 deletions
DataPlotter.py
+
62
−
13
View file @
d74335cb
import
random
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
from
matplotlib
import
cm
import
matplotlib
as
mpl
import
numpy
as
np
from
D
at
aHandler
import
DataHandler
from
m
at
plotlib.colors
import
ListedColormap
from
DataHandler
import
DataHandler
# TODO: Adjust input parameters for multiple weather change windows
class
DataPlotter
(
DataHandler
):
def
plotOvertakesWithTireChangeWindow
(
self
,
overtakesPerLap
:
list
[
int
],
earliestTireChange
:
int
,
latestTireChange
:
int
,
raceName
:
str
):
def
plotOvertakesWithTireChangeWindow
(
self
,
overtakesPerLap
:
list
[
int
],
firstTireChange
:
int
,
lastTireChange
:
int
,
raceName
:
str
):
# TODO: Account for cases where no tire changes (meaning values of 0 or -1)
# TODO: Let visualization start at 0, but graph at 1
# Adjust values
#overtakesPerLap.insert(0, 0) # Insert 0th lap, which cannot have overtakes
firstTireChange
-=
1
lastTireChange
+=
1
overtakesPerLap
.
insert
(
0
,
0
)
# Insert 0th lap, which cannot have overtakes
laps
:
int
=
len
(
overtakesPerLap
)
plt
.
xlim
(
0
,
laps
+
1
)
# set x-range of plot
figure
,
axis
=
plt
.
subplots
(
figsize
=
(
8.0
,
4.9
))
# Define data range
x_values
=
np
.
arange
(
1
,
laps
+
1
)
plt
.
plot
(
x_values
,
overtakesPerLap
)
axis
.
plot
(
overtakesPerLap
)
axis
=
plt
.
gca
()
# Label stuff
axis
.
set_xlabel
(
'
Lap
'
)
axis
.
set_ylabel
(
'
Position changes in lap
'
)
axis
.
set_title
(
raceName
)
major_ticks_laps
=
np
.
arange
(
0
,
laps
,
5
)
# Set ticks on axis
major_ticks_laps
=
np
.
arange
(
0
,
laps
+
1
,
5
)
major_ticks_overtakes
=
np
.
arange
(
0
,
max
(
overtakesPerLap
)
+
1
,
5
)
minor_ticks_laps
=
np
.
arange
(
0
,
laps
,
1
)
minor_ticks_laps
=
np
.
arange
(
0
,
laps
+
1
,
1
)
minor_ticks_overtakes
=
np
.
arange
(
0
,
max
(
overtakesPerLap
)
+
1
,
1
)
axis
.
set_xticks
(
major_ticks_laps
)
axis
.
set_xticks
(
minor_ticks_laps
,
minor
=
True
)
axis
.
set_yticks
(
major_ticks_overtakes
)
axis
.
set_yticks
(
minor_ticks_overtakes
,
minor
=
True
)
# A
nd a corresponding
grid
# A
dd
grid
axis
.
grid
(
which
=
'
both
'
)
# Or if you want different settings for the grids:
axis
.
grid
(
which
=
'
minor
'
,
alpha
=
0.2
)
axis
.
grid
(
which
=
'
major
'
,
alpha
=
0.5
)
# Add legend
axis
.
legend
(
bbox_to_anchor
=
(
1.0
,
1.02
))
# Paint background between the first and last tire change
axis
.
axvspan
(
firstTireChange
,
lastTireChange
,
color
=
'
blue
'
,
alpha
=
0.3
)
plt
.
tight_layout
()
plt
.
show
()
\ No newline at end of file
plt
.
show
()
def
plotBackgroundPaintTest
(
self
):
laps
:
int
=
50
overtakesPerLap
:
list
[
int
]
=
[
random
.
randint
(
0
,
10
)
for
_
in
range
(
laps
)]
firstTireChange
:
int
=
random
.
randint
(
10
,
20
)
lastTireChange
:
int
=
random
.
randint
(
30
,
40
)
isWeatherChanging
:
list
[
bool
]
=
[
False
]
*
laps
for
lap
in
range
(
laps
):
if
firstTireChange
<=
lap
<=
lastTireChange
:
isWeatherChanging
[
lap
]
=
True
colormap
=
mpl
.
colors
.
ListedColormap
([
'
white
'
,
'
blue
'
])
dataFrame
=
pd
.
DataFrame
(
overtakesPerLap
)
dataFrame
[
1
]
=
isWeatherChanging
axis
=
dataFrame
[
0
].
plot
()
axis
.
pcolorfast
(
axis
.
get_xlim
(),
axis
.
get_ylim
(),
dataFrame
[
1
].
values
[
np
.
newaxis
],
cmap
=
colormap
,
alpha
=
0.3
)
plt
.
show
()
This diff is collapsed.
Click to expand it.
Todos.md
+
1
−
1
View file @
d74335cb
...
...
@@ -2,7 +2,7 @@
-
[x] Automatically title graph by race name (no more hardcoding the graph name)
-
[x] Adjust for pitstop discrepancies
-
[x] Fetch rain races via API, not Reddit
-
[
] Paint back of graph for weather change window
-
[
x
] Paint back of graph for weather change window
-
[ ] Adjust for position changes caused by crashes (keep out of calculation similarly to PCs due to pitstops ?)
-
[ ] Include safety car periods & driver crashes
-
[ ] Automatically determine if race is DWR or SWR
...
...
This diff is collapsed.
Click to expand it.
main.py
+
12
−
6
View file @
d74335cb
...
...
@@ -18,12 +18,10 @@ class Main:
def
main
(
self
):
dataHandler
:
Main
.
DataHandlingPackage
=
Main
.
DataHandlingPackage
()
year
:
int
=
2015
rainRaces
:
list
[
Session
]
=
dataHandler
.
importer
.
getRainRacesSince
(
year
)
print
(
f
"
Rain races since
{
max
(
year
,
2018
)
}
"
)
for
rainRace
in
rainRaces
:
print
(
rainRace
)
#dataHandler = Main.DataHandlingPackage()
#dataHandler.plotter.plotBackgroundPaintTest()
# self.printRainRaces()
racesToAnalyse
=
[
SessionIdentifier
(
2022
,
"
Imola
"
,
"
R
"
),
# Imola 2022 (DWR)
...
...
@@ -34,6 +32,14 @@ class Main:
self
.
overtakeAnalysis
(
racesToAnalyse
)
def
printRainRaces
(
self
):
dataHandler
:
Main
.
DataHandlingPackage
=
Main
.
DataHandlingPackage
()
year
:
int
=
2015
rainRaces
:
list
[
Session
]
=
dataHandler
.
importer
.
getRainRacesSince
(
year
)
print
(
f
"
Rain races since
{
max
(
year
,
2018
)
}
"
)
for
rainRace
in
rainRaces
:
print
(
rainRace
)
def
overtakeAnalysis
(
self
,
raceSessionIdentifiers
:
list
[
SessionIdentifier
]):
dataHandler
:
Main
.
DataHandlingPackage
=
self
.
DataHandlingPackage
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment