Skip to content

Commit 362ffd1

Browse files
committed
move out old code
1 parent d7a75b5 commit 362ffd1

15 files changed

+64
-58
lines changed

telemetry/management/commands/pitcrew.py

+22-20
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,34 @@ def handle(self, *args, **options):
3636
# If the environment variable is set, it overrides the --coach option
3737
coach_name = options["coach"] if options["coach"] else env_coach
3838

39-
if options["kube_crew"]:
40-
cmd = options["kube_crew"]
41-
kube_crew = KubeCrew()
42-
if cmd == "start":
43-
kube_crew.start_coach(coach_name)
44-
elif cmd == "stop":
45-
kube_crew.stop_coach(coach_name)
39+
# if options["kube_crew"]:
40+
# cmd = options["kube_crew"]
41+
# kube_crew = KubeCrew()
42+
# if cmd == "start":
43+
# kube_crew.start_coach(coach_name)
44+
# elif cmd == "stop":
45+
# kube_crew.stop_coach(coach_name)
4646

47-
sys.exit(0)
47+
# sys.exit(0)
4848

4949
if coach_name:
50+
# Start the coach for the specified driver
5051
driver, created = Driver.objects.get_or_create(name=coach_name)
5152
coach, created = Coach.objects.get_or_create(driver=driver)
52-
if driver.name == "durandom":
53-
crew.coach_watcher.start_coach_no_history(driver.name, coach, debug=True)
54-
else:
55-
crew.coach_watcher.start_coach(driver.name, coach, debug=True)
56-
57-
elif options["session_saver"]:
58-
t = threading.Thread(target=crew.firehose.run)
59-
t.name = "firehose"
60-
t.start()
61-
t = threading.Thread(target=crew.session_saver.run)
62-
t.name = "session_saver"
63-
t.start()
53+
crew.coach_watcher.start_coach_no_history(driver.name, coach, debug=True)
54+
# if driver.name == "durandom":
55+
# else:
56+
# crew.coach_watcher.start_coach(driver.name, coach, debug=True)
57+
58+
# elif options["session_saver"]:
59+
# t = threading.Thread(target=crew.firehose.run)
60+
# t.name = "firehose"
61+
# t.start()
62+
# t = threading.Thread(target=crew.session_saver.run)
63+
# t.name = "session_saver"
64+
# t.start()
6465
else:
66+
# Start the coach watcher, which will start the coach for each driver
6567
if not crew.replay and not options["no_save"]:
6668

6769
def start_flask():

telemetry/models/session.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def analyze_rbr(self, telemetry, now):
152152
if distance > self.current_lap.length:
153153
self.current_lap.length = distance
154154
self.current_lap.time = lap_time
155+
self.current_lap.end = now
155156

156157
# self.current_lap.touch(now)
157158
# at the end of the session, lap_time stops, but distance keeps increasing
@@ -175,7 +176,7 @@ def analyze_rbr(self, telemetry, now):
175176
def analyze_other(self, telemetry, now) -> None:
176177
try:
177178
distance = telemetry["DistanceRoundTrack"]
178-
current_lap = telemetry["CurrentLap"]
179+
current_lap = int(telemetry["CurrentLap"])
179180
lap_time = telemetry["CurrentLapTime"]
180181
lap_time_previous = telemetry["LapTimePrevious"]
181182
lap_is_valid = telemetry["CurrentLapIsValid"]
File renamed without changes.
File renamed without changes.
File renamed without changes.

telemetry/pitcrew/coach_watcher.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
# from .coach import Coach as PitCrewCoach
1010
# from .coach_app import CoachApp
11-
from .coach_copilots import CoachCopilots
11+
# from .coach_copilots import CoachCopilots
1212
from .coach_copilots_no_history import CoachCopilotsNoHistory
13-
from .history import History
13+
# from .history import History
1414
from .kube_crew import KubeCrew
1515
from .mqtt import Mqtt
1616

@@ -51,40 +51,40 @@ def watch_coaches(self):
5151
self.kube_crew.sync_deployments()
5252
self.firehose.do_clear_sessions = True
5353

54-
def start_coach(self, driver_name, coach_model, debug=False):
55-
history = History()
56-
# if coach_model.mode == Coach.MODE_TRACK_GUIDE_APP or coach_model.mode == Coach.MODE_DEBUG_APP:
57-
# coach = CoachApp(history, coach_model, debug=debug)
58-
# if coach_model.mode == Coach.MODE_COPILOTS:
59-
# coach = CoachCopilots(history, coach_model, debug=debug)
60-
# else:
61-
# coach = PitCrewCoach(history, coach_model, debug=debug)
62-
coach = CoachCopilots(history, coach_model, debug=debug)
63-
64-
topic = f"crewchief/{driver_name}/#"
65-
mqtt = Mqtt(coach, topic, replay=self.replay, debug=debug)
66-
67-
def history_thread():
68-
logging.info(f"History thread starting for {driver_name}")
69-
history.run()
70-
logging.info(f"History thread stopped for {driver_name}")
71-
72-
h = threading.Thread(target=history_thread)
73-
h.name = f"history-{driver_name}"
74-
75-
def mqtt_thread():
76-
logging.info(f"MQTT thread starting for {driver_name}")
77-
mqtt.run()
78-
logging.info(f"MQTT thread stopped for {driver_name}")
79-
80-
c = threading.Thread(target=mqtt_thread)
81-
c.name = f"mqtt-{driver_name}"
82-
83-
threads = list()
84-
threads.append(h)
85-
threads.append(c)
86-
c.start()
87-
h.start()
54+
# def start_coach(self, driver_name, coach_model, debug=False):
55+
# history = History()
56+
# # if coach_model.mode == Coach.MODE_TRACK_GUIDE_APP or coach_model.mode == Coach.MODE_DEBUG_APP:
57+
# # coach = CoachApp(history, coach_model, debug=debug)
58+
# # if coach_model.mode == Coach.MODE_COPILOTS:
59+
# # coach = CoachCopilots(history, coach_model, debug=debug)
60+
# # else:
61+
# # coach = PitCrewCoach(history, coach_model, debug=debug)
62+
# coach = CoachCopilots(history, coach_model, debug=debug)
63+
64+
# topic = f"crewchief/{driver_name}/#"
65+
# mqtt = Mqtt(coach, topic, replay=self.replay, debug=debug)
66+
67+
# def history_thread():
68+
# logging.info(f"History thread starting for {driver_name}")
69+
# history.run()
70+
# logging.info(f"History thread stopped for {driver_name}")
71+
72+
# h = threading.Thread(target=history_thread)
73+
# h.name = f"history-{driver_name}"
74+
75+
# def mqtt_thread():
76+
# logging.info(f"MQTT thread starting for {driver_name}")
77+
# mqtt.run()
78+
# logging.info(f"MQTT thread stopped for {driver_name}")
79+
80+
# c = threading.Thread(target=mqtt_thread)
81+
# c.name = f"mqtt-{driver_name}"
82+
83+
# threads = list()
84+
# threads.append(h)
85+
# threads.append(c)
86+
# c.start()
87+
# h.start()
8888

8989
def start_coach_no_history(self, driver_name, coach_model, debug=False):
9090
coach = CoachCopilotsNoHistory(coach_model, debug=debug)

telemetry/pitcrew/history.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# FIXME: this is also used in b4mad_racing_website/fastlap_app.py
12
import time
23

34
import numpy as np
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

telemetry/pitcrew/persister_db.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, driver: Driver, debug=False):
1515
self.clear_interval = 60 * 60 * 5 # ticks. telemetry is sent at 60hz, so 60*60*5 = 5 minutes
1616
self.save_ticks = 0
1717
self.save_interval = 60 * 60 * 1 # ticks. telemetry is sent at 60hz, so 60*60*1 = 1 minute
18+
self.save_interval = 60
1819

1920
def notify(self, topic, payload, now=None):
2021
now = now or django.utils.timezone.now()
@@ -54,7 +55,7 @@ def notify(self, topic, payload, now=None):
5455
session = self.sessions[topic]
5556
if session:
5657
session.signal(payload, now)
57-
# self.save_sessions(now)
58+
self.save_sessions(now)
5859

5960
def get_session(self, session_id, game, track, car, session_type, car_class) -> Optional[Session]:
6061
try:

telemetry/pitcrew/segment.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# FIXME: this is also used in b4mad_racing_website/fastlap_app.py
12
import statistics
23

34
import pandas as pd

0 commit comments

Comments
 (0)