Skip to content

Commit

Permalink
add car class (b4mad#379)
Browse files Browse the repository at this point in the history
* Add car class

* fix tests
  • Loading branch information
durandom authored Aug 17, 2023
1 parent bac355e commit 5af8e95
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 145 deletions.
2 changes: 1 addition & 1 deletion components/paddock/scripts/dumpdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x
cd "$(dirname "$0")/.."

models="game car track sessiontype session driver coach fastlap fastlapsegment lap"
models="fastlapsegment lap"
models="car"
for o in $models; do
pipenv run ./manage.py dumpdata --indent 2 telemetry.$o > telemetry/fixtures.all/$o.json
done
21 changes: 19 additions & 2 deletions components/paddock/telemetry/fixtures/car.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@
"model": "telemetry.car",
"pk": 9,
"fields": {
"created": "2023-07-04T16:27:23.109Z",
"modified": "2023-07-04T16:27:23.124Z",
"name": "Ferrari 488 GT3 Evo 2020",
"game": 1
"game": 1,
"car_class": null
}
},
{
"model": "telemetry.car",
"pk": 351,
"fields": {
"created": "2023-07-04T16:27:23.109Z",
"modified": "2023-07-04T16:27:23.124Z",
"name": "Reynard 95i Ford-Cosworth",
"game": 5
"game": 5,
"car_class": null
}
},
{
"model": "telemetry.car",
"pk": 1280,
"fields": {
"created": "2023-07-04T16:27:23.109Z",
"modified": "2023-07-04T16:27:23.124Z",
"name": "Ligier JS P320",
"game": 1,
"car_class": null
}
}
]
10 changes: 6 additions & 4 deletions components/paddock/telemetry/fixtures/coach.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"model": "telemetry.coach",
"pk": 10,
"fields": {
"error": "",
"status": "start coaching for a lap time of 1 minute 45.50 seconds ",
"created": "2023-07-04T16:27:23.139Z",
"modified": "2023-08-14T17:33:03.225Z",
"error": "no data found for game Automobilista 2 on track Cascavel4:Cascavel2 in car Porsche Cayman GT4 Clubsport MR",
"status": "start coaching for a lap time of 2 minutes 0.44 seconds lets get some laps in debugging mode",
"enabled": true,
"mode": "default",
"fast_lap": 15
"fast_lap": 1808,
"mode": "debug"
}
}
]
29 changes: 25 additions & 4 deletions components/paddock/telemetry/fixtures/fastlap.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions components/paddock/telemetry/fixtures/filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ set -x
cd $(dirname $0)
jq '[.[] | select(.pk == 1 or .pk == 5)]' ../fixtures.all/game.json > game.json
# jq '[.[] | select(.fields.game == 1 or .fields.game == 5)]' ../fixtures.all/car.json > car.json
jq '[.[] | select(.pk == 9 or .pk == 351)]' ../fixtures.all/car.json > car.json
jq '[.[] | select(.pk == 409 or .pk == 83 or .pk == 1040 or .pk == 193)]' ../fixtures.all/track.json > track.json
jq '[.[] | select(.pk == 9 or .pk == 351 or .pk == 1280)]' ../fixtures.all/car.json > car.json
jq '[.[] | select(.pk == 409 or .pk == 83 or .pk == 1040 or .pk == 193 or .pk == 37)]' ../fixtures.all/track.json > track.json
jq '[.[] | select(.pk == 10 )]' ../fixtures.all/coach.json > coach.json
jq '[.[] | select(.pk == 10 or .pk == 1)]' ../fixtures.all/driver.json > driver.json
jq '[.[] | select(.pk == 703 or .pk == 157 or .pk == 1237 or .pk == 15)]' ../fixtures.all/fastlap.json > fastlap.json
jq '[.[] | select(.pk == 703 or .pk == 157 or .pk == 1237 or .pk == 15 or .pk == 1808)]' ../fixtures.all/fastlap.json > fastlap.json
jq '[.[] | select(.fields.fast_lap == 703 or .fields.fast_lap == 157 or .fields.fast_lap == 1237)]' ../fixtures.all/fastlapsegment.json > fastlapsegment.json
jq '[.[] | select(.fields.fast_lap == 703 or .fields.fast_lap == 157 or .fields.fast_lap == 1237)]' ../fixtures.all/lap.json > lap.json
jq '[.[] | select(.pk == 24222 or .pk == 26684 or .pk == 57153 or .pk == 17096 or .pk == 17360 or .pk == 57010 or .pk == 57975 or .pk == 58151 or .pk == 58155)]' ../fixtures.all/session.json > session.json
Expand Down
19 changes: 19 additions & 0 deletions components/paddock/telemetry/fixtures/track.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
[
{
"model": "telemetry.track",
"pk": 37,
"fields": {
"created": "2023-07-04T16:27:23.319Z",
"modified": "2023-07-04T16:27:23.330Z",
"name": "roadamerica full",
"length": 6410,
"game": 1
}
},
{
"model": "telemetry.track",
"pk": 83,
"fields": {
"created": "2023-07-04T16:27:23.319Z",
"modified": "2023-07-04T16:27:23.330Z",
"name": "Road_America:Road_America_RC",
"length": 6441,
"game": 5
Expand All @@ -12,6 +25,8 @@
"model": "telemetry.track",
"pk": 193,
"fields": {
"created": "2023-07-04T16:27:23.319Z",
"modified": "2023-07-04T16:27:23.330Z",
"name": "virginia 2022 full",
"length": 5220,
"game": 1
Expand All @@ -21,6 +36,8 @@
"model": "telemetry.track",
"pk": 409,
"fields": {
"created": "2023-07-04T16:27:23.319Z",
"modified": "2023-07-04T16:27:23.330Z",
"name": "fuji nochicane",
"length": 4460,
"game": 1
Expand All @@ -30,6 +47,8 @@
"model": "telemetry.track",
"pk": 1040,
"fields": {
"created": "2023-07-04T16:27:23.319Z",
"modified": "2023-07-04T16:27:23.330Z",
"name": "oschersleben gp",
"length": 3610,
"game": 1
Expand Down
26 changes: 26 additions & 0 deletions components/paddock/telemetry/migrations/0013_alter_coach_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.3 on 2023-08-17 07:32

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("telemetry", "0012_alter_coach_mode"),
]

operations = [
migrations.AlterField(
model_name="coach",
name="mode",
field=models.CharField(
choices=[
("default", "Default"),
("debug", "Debug"),
("only_brake", "Only Brakepoints"),
("only_brake_debug", "Only Brakepoints (Debug))"),
],
default="default",
max_length=64,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Generated by Django 4.2.3 on 2023-08-17 08:19

import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("telemetry", "0013_alter_coach_mode"),
]

operations = [
migrations.CreateModel(
name="CarClass",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"created",
model_utils.fields.AutoCreatedField(
default=django.utils.timezone.now, editable=False, verbose_name="created"
),
),
(
"modified",
model_utils.fields.AutoLastModifiedField(
default=django.utils.timezone.now, editable=False, verbose_name="modified"
),
),
("name", models.CharField(max_length=200)),
(
"game",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="car_classes", to="telemetry.game"
),
),
],
options={
"ordering": ["name"],
},
),
migrations.AddField(
model_name="car",
name="car_class",
field=models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, related_name="cars", to="telemetry.carclass"
),
),
]
15 changes: 15 additions & 0 deletions components/paddock/telemetry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ class Meta:
name = models.CharField(max_length=200)

game = models.ForeignKey(Game, on_delete=models.CASCADE, related_name="cars")
car_class = models.ForeignKey("CarClass", on_delete=models.CASCADE, related_name="cars", null=True)

def __str__(self):
return self.name


class CarClass(TimeStampedModel):
class Meta:
ordering = [
"name",
]

name = models.CharField(max_length=200)

game = models.ForeignKey(Game, on_delete=models.CASCADE, related_name="car_classes")

def __str__(self):
return self.name
Expand Down
1 change: 1 addition & 0 deletions components/paddock/telemetry/pitcrew/firehose.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def notify(self, topic, payload, now=None):
session.game_name = game
session.track = track
session.car = car
session.car_class = payload.get("CarClass", "")
session.session_type = session_type
self.sessions[topic] = session

Expand Down
1 change: 1 addition & 0 deletions components/paddock/telemetry/pitcrew/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, id, start=None):
self.game_name = ""
self.track = ""
self.car = ""
self.car_class = ""
self.session_type = ""
self.record = None

Expand Down
1 change: 1 addition & 0 deletions components/paddock/telemetry/pitcrew/session_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def save_sessions(self):
created,
) = SessionType.objects.get_or_create(type=session.session_type)
session.car, created = session.game.cars.get_or_create(name=session.car)
session.car.car_class, created = session.game.car_classes.get_or_create(name=session.car_class)
session.track, created = session.game.tracks.get_or_create(name=session.track)
(
session.record,
Expand Down
Loading

0 comments on commit 5af8e95

Please sign in to comment.