Skip to content

Commit

Permalink
move out old code
Browse files Browse the repository at this point in the history
  • Loading branch information
durandom committed Nov 12, 2024
1 parent d7a75b5 commit 362ffd1
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 58 deletions.
42 changes: 22 additions & 20 deletions telemetry/management/commands/pitcrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,34 @@ def handle(self, *args, **options):
# If the environment variable is set, it overrides the --coach option
coach_name = options["coach"] if options["coach"] else env_coach

if options["kube_crew"]:
cmd = options["kube_crew"]
kube_crew = KubeCrew()
if cmd == "start":
kube_crew.start_coach(coach_name)
elif cmd == "stop":
kube_crew.stop_coach(coach_name)
# if options["kube_crew"]:
# cmd = options["kube_crew"]
# kube_crew = KubeCrew()
# if cmd == "start":
# kube_crew.start_coach(coach_name)
# elif cmd == "stop":
# kube_crew.stop_coach(coach_name)

sys.exit(0)
# sys.exit(0)

if coach_name:
# Start the coach for the specified driver
driver, created = Driver.objects.get_or_create(name=coach_name)
coach, created = Coach.objects.get_or_create(driver=driver)
if driver.name == "durandom":
crew.coach_watcher.start_coach_no_history(driver.name, coach, debug=True)
else:
crew.coach_watcher.start_coach(driver.name, coach, debug=True)

elif options["session_saver"]:
t = threading.Thread(target=crew.firehose.run)
t.name = "firehose"
t.start()
t = threading.Thread(target=crew.session_saver.run)
t.name = "session_saver"
t.start()
crew.coach_watcher.start_coach_no_history(driver.name, coach, debug=True)
# if driver.name == "durandom":
# else:
# crew.coach_watcher.start_coach(driver.name, coach, debug=True)

# elif options["session_saver"]:
# t = threading.Thread(target=crew.firehose.run)
# t.name = "firehose"
# t.start()
# t = threading.Thread(target=crew.session_saver.run)
# t.name = "session_saver"
# t.start()
else:
# Start the coach watcher, which will start the coach for each driver
if not crew.replay and not options["no_save"]:

def start_flask():
Expand Down
3 changes: 2 additions & 1 deletion telemetry/models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def analyze_rbr(self, telemetry, now):
if distance > self.current_lap.length:
self.current_lap.length = distance
self.current_lap.time = lap_time
self.current_lap.end = now

# self.current_lap.touch(now)
# at the end of the session, lap_time stops, but distance keeps increasing
Expand All @@ -175,7 +176,7 @@ def analyze_rbr(self, telemetry, now):
def analyze_other(self, telemetry, now) -> None:
try:
distance = telemetry["DistanceRoundTrack"]
current_lap = telemetry["CurrentLap"]
current_lap = int(telemetry["CurrentLap"])
lap_time = telemetry["CurrentLapTime"]
lap_time_previous = telemetry["LapTimePrevious"]
lap_is_valid = telemetry["CurrentLapIsValid"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
72 changes: 36 additions & 36 deletions telemetry/pitcrew/coach_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

# from .coach import Coach as PitCrewCoach
# from .coach_app import CoachApp
from .coach_copilots import CoachCopilots
# from .coach_copilots import CoachCopilots
from .coach_copilots_no_history import CoachCopilotsNoHistory
from .history import History
# from .history import History
from .kube_crew import KubeCrew
from .mqtt import Mqtt

Expand Down Expand Up @@ -51,40 +51,40 @@ def watch_coaches(self):
self.kube_crew.sync_deployments()
self.firehose.do_clear_sessions = True

def start_coach(self, driver_name, coach_model, debug=False):
history = History()
# if coach_model.mode == Coach.MODE_TRACK_GUIDE_APP or coach_model.mode == Coach.MODE_DEBUG_APP:
# coach = CoachApp(history, coach_model, debug=debug)
# if coach_model.mode == Coach.MODE_COPILOTS:
# coach = CoachCopilots(history, coach_model, debug=debug)
# else:
# coach = PitCrewCoach(history, coach_model, debug=debug)
coach = CoachCopilots(history, coach_model, debug=debug)

topic = f"crewchief/{driver_name}/#"
mqtt = Mqtt(coach, topic, replay=self.replay, debug=debug)

def history_thread():
logging.info(f"History thread starting for {driver_name}")
history.run()
logging.info(f"History thread stopped for {driver_name}")

h = threading.Thread(target=history_thread)
h.name = f"history-{driver_name}"

def mqtt_thread():
logging.info(f"MQTT thread starting for {driver_name}")
mqtt.run()
logging.info(f"MQTT thread stopped for {driver_name}")

c = threading.Thread(target=mqtt_thread)
c.name = f"mqtt-{driver_name}"

threads = list()
threads.append(h)
threads.append(c)
c.start()
h.start()
# def start_coach(self, driver_name, coach_model, debug=False):
# history = History()
# # if coach_model.mode == Coach.MODE_TRACK_GUIDE_APP or coach_model.mode == Coach.MODE_DEBUG_APP:
# # coach = CoachApp(history, coach_model, debug=debug)
# # if coach_model.mode == Coach.MODE_COPILOTS:
# # coach = CoachCopilots(history, coach_model, debug=debug)
# # else:
# # coach = PitCrewCoach(history, coach_model, debug=debug)
# coach = CoachCopilots(history, coach_model, debug=debug)

# topic = f"crewchief/{driver_name}/#"
# mqtt = Mqtt(coach, topic, replay=self.replay, debug=debug)

# def history_thread():
# logging.info(f"History thread starting for {driver_name}")
# history.run()
# logging.info(f"History thread stopped for {driver_name}")

# h = threading.Thread(target=history_thread)
# h.name = f"history-{driver_name}"

# def mqtt_thread():
# logging.info(f"MQTT thread starting for {driver_name}")
# mqtt.run()
# logging.info(f"MQTT thread stopped for {driver_name}")

# c = threading.Thread(target=mqtt_thread)
# c.name = f"mqtt-{driver_name}"

# threads = list()
# threads.append(h)
# threads.append(c)
# c.start()
# h.start()

def start_coach_no_history(self, driver_name, coach_model, debug=False):
coach = CoachCopilotsNoHistory(coach_model, debug=debug)
Expand Down
1 change: 1 addition & 0 deletions telemetry/pitcrew/history.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# FIXME: this is also used in b4mad_racing_website/fastlap_app.py
import time

import numpy as np
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion telemetry/pitcrew/persister_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, driver: Driver, debug=False):
self.clear_interval = 60 * 60 * 5 # ticks. telemetry is sent at 60hz, so 60*60*5 = 5 minutes
self.save_ticks = 0
self.save_interval = 60 * 60 * 1 # ticks. telemetry is sent at 60hz, so 60*60*1 = 1 minute
self.save_interval = 60

def notify(self, topic, payload, now=None):
now = now or django.utils.timezone.now()
Expand Down Expand Up @@ -54,7 +55,7 @@ def notify(self, topic, payload, now=None):
session = self.sessions[topic]
if session:
session.signal(payload, now)
# self.save_sessions(now)
self.save_sessions(now)

def get_session(self, session_id, game, track, car, session_type, car_class) -> Optional[Session]:
try:
Expand Down
1 change: 1 addition & 0 deletions telemetry/pitcrew/segment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# FIXME: this is also used in b4mad_racing_website/fastlap_app.py
import statistics

import pandas as pd
Expand Down

0 comments on commit 362ffd1

Please sign in to comment.