Skip to content

Commit

Permalink
V0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
domhnallmorr committed Mar 9, 2024
1 parent ed977df commit c2a70a0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
customtkinter.set_default_color_theme("blue") # Themes: blue (default), dark-blue, green

app = customtkinter.CTk() # create CTk window like you do with the Tk window
app.title("Race Engine V0.0.2")
app.title("Race Engine V0.0.3")
controller = race_engine_controller.RaceEngineController(app)

app.after(0, lambda:app.state("zoomed"))
Expand Down
9 changes: 8 additions & 1 deletion src/race_engine_model/commentary.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@ def gen_retirement_message(driver):
f"{driver} walks away from the car, retiring from the race.",
]

return random.choice(messages)
return random.choice(messages)

def gen_lead_after_turn1_message(driver):
messages = [
f"{driver} leads the field out of turn 1!"
]

return random.choice(messages)
4 changes: 4 additions & 0 deletions src/race_engine_model/race_engine_circuit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ def __init__(self, name, number_of_laps, base_laptime):

self.pit_stop_loss = 20_000 #20s loss coming through pits

self.dist_to_turn1 = 615 # distance from pole to turn 1 in meters



28 changes: 26 additions & 2 deletions src/race_engine_model/race_engine_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def run_race(self):
def advance(self):

if self.status == "pre_race":
self.calculate_start()
self.commentary_to_process.append(commentary.gen_race_start_message())
self.calculate_start()
self.status = "running"

else:
Expand Down Expand Up @@ -210,8 +210,14 @@ def calculate_lap(self):
participant.complete_lap()

def calculate_start(self):
# Calculate Turn 1
order_after_turn1 = self.calculate_run_to_turn1()

# redefine particpants based on turn1 order
self.participants = [o[1] for o in order_after_turn1]

'''
just spread field out in starting order as first attempt
just spread field out after turn1
'''
for idx, p in enumerate(self.participants):
p.laptime = self.circuit_model.base_laptime + 6_000 + (idx * 1_000) + random.randint(100, 1500)
Expand All @@ -226,6 +232,24 @@ def calculate_start(self):

self.current_lap += 1

def calculate_run_to_turn1(self):
dist_to_turn1 = self.circuit_model.dist_to_turn1
average_speed = 47.0 #m/s

order_after_turn1 = []
for idx, p in enumerate(self.participants):
random_factor = random.randint(-2000, 2000)/1000
time_to_turn1 = round(dist_to_turn1 / (average_speed + random_factor), 3)
order_after_turn1.append([time_to_turn1, p])

dist_to_turn1 += 5 # add 5 meters per grid slot

order_after_turn1 = sorted(order_after_turn1, key=lambda x: x[0], reverse=False)

self.commentary_to_process.append(commentary.gen_lead_after_turn1_message(order_after_turn1[0][1].name))

return order_after_turn1

def update_standings(self):
for driver in self.standings_df["Driver"]:
particpant_model = self.get_particpant_model_by_name(driver)
Expand Down
9 changes: 7 additions & 2 deletions src/race_engine_view/timing_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def setup_labels(self):
self.driver1_fuel_label = customtkinter.CTkLabel(self.driver1_frame, text="0.0kg")
self.driver1_fuel_label.grid(row=2, column=1, sticky="EW")

# LABELS FOR LAPTIMES PLOTS
customtkinter.CTkLabel(self.laptimes_frame, text="Driver 1", anchor=W).grid(row=0, column=1, sticky="EW", padx=self.view.padx, pady=self.view.pady)
customtkinter.CTkLabel(self.laptimes_frame, text="Driver 2 (Optional)", anchor=W).grid(row=0, column=3, sticky="EW", padx=self.view.padx, pady=self.view.pady)

def setup_buttons(self):
self.timing_button = customtkinter.CTkButton(self.button_frame, text="Timing", command=lambda window="timing": self.show_window(window), image=self.view.timing_icon2, compound=LEFT, anchor="w")
self.timing_button.grid(row=0, column=0, sticky="EW", padx=self.view.padx, pady=self.view.pady)
Expand All @@ -109,16 +113,17 @@ def setup_widgets(self):
self.table = timing_screen_table.TimingScreenTable(self.timing_frame, self.view)
self.table.pack(expand=True, fill=BOTH, side=LEFT)

combo_width = 300
# LAP TIMES COMBOS
self.driver1_laptime_combo = customtkinter.CTkComboBox(self.laptimes_frame, values=self.view.driver_names, command=self.update_laptimes_plot)
self.driver1_laptime_combo = customtkinter.CTkComboBox(self.laptimes_frame, values=self.view.driver_names, command=self.update_laptimes_plot, width=combo_width)
self.driver1_laptime_combo.grid(row=1, column=1, sticky="EW", padx=self.view.padx, pady=self.view.pady)
self.driver1_laptime_combo.set("Nico Rosberg")

self.driver2_laptime_var = customtkinter.StringVar(value="on")
self.driver2_laptime_checkbox = customtkinter.CTkCheckBox(self.laptimes_frame, text="", variable=self.driver2_laptime_var, onvalue="on", offvalue="off", width=10, command=self.update_laptimes_plot)
self.driver2_laptime_checkbox.grid(row=1, column=2, sticky="E", padx=(120, 5), pady=self.view.pady)

self.driver2_laptime_combo = customtkinter.CTkComboBox(self.laptimes_frame, values=self.view.driver_names, command=self.update_laptimes_plot)
self.driver2_laptime_combo = customtkinter.CTkComboBox(self.laptimes_frame, values=self.view.driver_names, command=self.update_laptimes_plot, width=combo_width)
self.driver2_laptime_combo.grid(row=1, column=3, sticky="EW", padx=(5, 5), pady=self.view.pady)
self.driver2_laptime_combo.set("Michael Schumacher")

Expand Down

0 comments on commit c2a70a0

Please sign in to comment.