Skip to content

Commit

Permalink
V0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
domhnallmorr committed Apr 14, 2024
1 parent 457c9cd commit 6e01f23
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 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.7")
app.title("Race Engine V0.0.8")
controller = race_engine_controller.RaceEngineController(app)

app.after(0, lambda:app.state("zoomed"))
Expand Down
21 changes: 15 additions & 6 deletions src/race_engine_model/race_engine_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self):
]
)

self.setup_standings()
# self.setup_standings()

self.current_lap = 1
self.time_left = None
Expand Down Expand Up @@ -116,6 +116,10 @@ def setup_standings(self):

self.standings_df = pd.DataFrame(columns=columns, data=data)

# SETUP STARTING GRID FOR RACE
if "Q1" in self.results.keys():
self.standings_df["Driver"] = self.results["Q1"]["results"]["Driver"]

def run_race(self):
self.calculate_start()

Expand All @@ -133,7 +137,7 @@ def run_race(self):
def advance(self):
if self.session == "race":
self.advance_race()
elif self.session in ["FP1"]:
elif self.session in ["FP1", "Q1"]:
self.advance_practice()

def advance_race(self):
Expand Down Expand Up @@ -324,7 +328,7 @@ def calculate_run_to_turn1(self):
average_speed = 47.0 #m/s

order_after_turn1 = []
for idx, p in enumerate(self.participants):
for idx, p in enumerate([self.get_particpant_model_by_name(n) for n in self.standings_df["Driver"].values.tolist()]):
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])
Expand Down Expand Up @@ -420,16 +424,20 @@ def update_player_drivers_strategy(self, driver1_data, driver2_data):

def setup_session(self, session):
self.session = session
self.status = "pre_session"

self.setup_standings()

if session in ["FP1"]:
self.time_left = 120 * 60 # 2 hours in seconds
if session in ["FP1", "Q1"]:
if session == "FP1":
self.time_left = 120 * 60 # 2 hours in seconds
elif session == "Q1":
self.time_left = 60 * 60 # 1hr qualy session

for participant in self.participants:
participant.setup_session()
if participant not in [self.player_driver1, self.player_driver2]:
participant.generate_practice_runs(self.time_left)
participant.generate_practice_runs(self.time_left, session)
participant.status = "in_pits"

# SET STAUS COLUMN TO "PIT"
Expand All @@ -447,6 +455,7 @@ def end_session(self, session):
self.results[session] = {}
self.results[session]["p1"] = fastest_driver
self.results[session]["fastest lap"] = fastest_laptime
self.results[session]["results"] = self.standings_df.copy(deep=True)

def simulate_session(self, session):
self.setup_session(session)
Expand Down
15 changes: 10 additions & 5 deletions src/race_engine_model/race_engine_particpant_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,20 @@ def setup_session(self):
self.practice_laps_completed = 0
self.practice_runs = [] # [[time_left, fuel, number_laps]]

def generate_practice_runs(self, session_time):
def generate_practice_runs(self, session_time, session):

time_left = session_time

while time_left > 0:
leave_time = random.randint(time_left - (20*60), time_left)
number_laps = random.randint(3, 10)
min_fuel_load = int(self.circuit_model.fuel_consumption * number_laps) + 1
fuel_load = random.randint(min_fuel_load, 155)
if session != "Q1": # practice run
leave_time = random.randint(time_left - (20*60), time_left)
number_laps = random.randint(3, 10)
min_fuel_load = int(self.circuit_model.fuel_consumption * number_laps) + 1
fuel_load = random.randint(min_fuel_load, 155)
else: # qualy run
leave_time = random.randint(time_left - (10*60), time_left)
number_laps = 3
fuel_load = 3

self.practice_runs.append([leave_time, fuel_load, number_laps])

Expand Down
2 changes: 1 addition & 1 deletion src/race_engine_view/custom_widgets/strategy_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, parent, view, driver_name, start_col, start_row, session):

row = start_row + 1

if self.session in ["FP1"]:
if self.session in ["FP1", "Q1"]:
self.setup_practice_edit_widgets(row)
self.change_fuel_event(change=None)
self.change_laps_to_run_event(change=None)
Expand Down
3 changes: 3 additions & 0 deletions src/race_engine_view/race_weekend_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def setup_widgets(self):
image=self.view.sunny_icon2, compound=RIGHT)
self.qualy_forecast_label.grid(row=2, column=0, padx=(self.view.padx_large, self.view.padx), pady=self.view.pady, sticky="W")

self.go_to_qualy_btn = customtkinter.CTkButton(self.qualifying_frame, text="Go To Qualifying", command=lambda session="Q1": self.view.controller.go_to_session(session))
self.go_to_qualy_btn.grid(row=10, column=0, padx=self.view.padx_large, pady=self.view.pady, sticky="NW")

# WARMUP ------------------------------
customtkinter.CTkLabel(self.warmup_frame, text="Warmup", font=self.view.header1_font).grid(row=1,
column=0, padx=self.view.padx, pady=self.view.pady, sticky="NW")
Expand Down
2 changes: 2 additions & 0 deletions src/race_engine_view/timing_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def setup_labels(self):
self.title_label.grid(row=0, column=0, padx=self.view.padx, pady=self.view.pady, sticky="NW")
if self.session == "FP1":
self.title_label.configure(text="Friday Practice")
elif self.session == "Q1":
self.title_label.configure(text="Qualifying")

self.lap_label = customtkinter.CTkLabel(self.top_frame, text="PRE-RACE", width=100, anchor=W)
self.lap_label.grid(row=1, column=0, padx=self.view.padx, pady=self.view.pady, sticky="NW")
Expand Down

0 comments on commit 6e01f23

Please sign in to comment.