· 8 years ago · Feb 05, 2018, 04:46 PM
1# Tyler Hobson - Year 13
2# A2 Computer Science coursework final program
3# BASIC CAR TUNING SIMULATOR ---- COURSEWORK A2 COMPUTER SCIENCE
4
5# ------------------------
6
7# Imports tkinter module
8from tkinter import *
9from tkinter.font import Font
10from tkinter import messagebox
11
12# Imports pymysql for database
13import pymysql.cursors
14
15
16class Database():
17 db_hostname = 'localhost'
18 db_user = 'root'
19 db_port = 3306
20 db_password = 'f1lmstar'
21 db_name = 'Tuner_db'
22
23 def __init__(self, model):
24 self.model = model
25 self.create_db_and_table()
26 self.add_db_content()
27
28 def create_db_and_table(self):
29 # Create the database and tables
30 connection = pymysql.connect(host=Database.db_hostname,
31 user=Database.db_user,
32 port=Database.db_port,
33 password=Database.db_password)
34 try:
35 with connection.cursor() as cursor:
36 cursor.execute('CREATE DATABASE IF NOT EXISTS Tuner_db')
37 finally:
38 connection.close()
39
40 # Create a table
41 connection = pymysql.connect(host=Database.db_hostname,
42 user=Database.db_user,
43 port=Database.db_port,
44 password=Database.db_password,
45 db=Database.db_name,
46 cursorclass=pymysql.cursors.DictCursor
47 )
48 try:
49 with connection.cursor() as cursor:
50 sqlQuery = 'CREATE TABLE IF NOT EXISTS car_details(car_ID INT not null auto_increment, car_name VARCHAR(50) UNIQUE, gear1 INT(3), gear2 INT(3), gear3 INT(3), gear4 INT(3),gear5 INT(3), gear6 INT(3), gear_final INT(3), drag_length_selection INT(1), road_surface_selection INT(1), tyre_selection INT(1), drive_selection INT(1), kerb_weight INT(5), horsepower INT(5), width DECIMAL(18, 2), height DECIMAL(18, 2), primary key (car_ID))'
51 cursor.execute(sqlQuery)
52 finally:
53 connection.close()
54
55 def add_db_content(self):
56 # Set up the database content
57 cars_default = [self.model.default_settings_string, 50, 50, 50, 50, 50, 50, 50, 1, 1, 2, 1, 800, 2000, 1.9, 1.2], \
58 ['Alfa Romeo 4C Gr.3.', 50, 80, 50, 50, 50, 50, 50, 1, 2, 1, 2, 1043, 2000, 1.9, 1.2], \
59 ['Aston Martin Vulcan', 50, 50, 50, 80, 50, 50, 50, 1, 2, 1, 2, 800, 2000, 1.9, 1.2], \
60 ['Audi TT cup', 10, 20, 30, 40, 50, 60, 70, 1, 2, 1, 2, 1043, 2000, 1.9, 1.2], \
61 ['BMW i3', 80, 20, 80, 20, 80, 20, 80, 1, 2, 1, 2, 800, 2000, 1.9, 1.2], \
62 ['Citroen DS3 Racing', 50, 50, 50, 80, 50, 50, 50, 1, 2, 1, 4, 1500, 2000, 1.9, 1.2], \
63 ['Dodge Charger SRT Hellcat', 50, 80, 50, 50, 50, 50, 50, 1, 2, 1, 2, 1500, 2000, 1.9, 1.2], \
64 ['Ford Focus ST', 50, 50, 50, 50, 50, 50, 80, 1, 2, 1, 2, 1043, 2000, 1.9, 1.2]\
65
66 # Store values in table
67 connection = pymysql.connect(host=Database.db_hostname,
68 user=Database.db_user,
69 port=Database.db_port,
70 password=Database.db_password,
71 db=Database.db_name,
72 cursorclass=pymysql.cursors.DictCursor
73 )
74 try:
75 with connection.cursor() as cursor:
76 # check whether car name exists in database
77 sqlQueryCheck = 'SELECT car_ID FROM car_details WHERE car_name = %s'
78 sqlQueryDelete = 'DELETE FROM car_details WHERE car_ID = %s'
79 sqlQueryInsert = 'INSERT INTO car_details(`car_name`, `gear1`, `gear2`, `gear3`, `gear4`, `gear5`, `gear6`, `gear_final`, `drag_length_selection`, `road_surface_selection`, `tyre_selection`, `drive_selection`, `kerb_weight`, `horsepower`, `width`, `height`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
80
81
82 # UNCOMMENT TO DELETE ALL TABLES FROM DATABASE WHEN NEEDED
83 # sqlQueryDeleteAll = 'TRUNCATE TABLE car_details'
84 # cursor.execute(sqlQueryDeleteAll)
85
86 # iterate through car list and add to database if not already present
87 for row in cars_default:
88 # test whether all 16 details are in list for each car
89 if len(row) == 16:
90 cursor.execute(sqlQueryCheck, row[0])
91 result = cursor.fetchone()
92 if not result:
93 # if the car doesn't already exist in the database, add it
94 cursor.execute(sqlQueryInsert,
95 [row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8],
96 row[9], row[10], row[11], row[12], row[13], row[14], row[15]])
97 connection.commit()
98 else:
99 # if the car exists in the database, delete it and insert a new entry e.g. update data
100 cursor.execute(sqlQueryDelete, result['car_ID'])
101 cursor.execute(sqlQueryInsert,
102 [row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8],
103 row[9], row[10], row[11], row[12], row[13], row[14], row[15]])
104 connection.commit()
105 else:
106
107 print("details for car " + row[0] + " are incomplete - not added to database")
108
109 finally:
110 connection.close()
111
112 def get_simulation_details_for_car_query(self, car_name):
113 # get the simulation details for the car choice
114 connection = pymysql.connect(host=Database.db_hostname,
115 user=Database.db_user,
116 port=Database.db_port,
117 password=Database.db_password,
118 db=Database.db_name,
119 cursorclass=pymysql.cursors.DictCursor
120 )
121 try:
122 with connection.cursor() as cursor:
123 sqlQueryCheck = 'SELECT * FROM car_details WHERE car_name = %s'
124 cursor.execute(sqlQueryCheck, car_name)
125 result = cursor.fetchone()
126 if not result:
127 print("no car in database with name", car_name)
128 else:
129 print(car_name)
130 print(result)
131 finally:
132 connection.close()
133
134 def db_car_names_for_dropdown_query(self):
135 # get the names of the cars in the database
136
137 connection = pymysql.connect(host=Database.db_hostname,
138 user=Database.db_user,
139 port=Database.db_port,
140 password=Database.db_password,
141 db=Database.db_name,
142 cursorclass=pymysql.cursors.DictCursor
143 )
144 try:
145 with connection.cursor() as cursor:
146 sqlQueryCheck = 'SELECT car_name FROM car_details'
147 cursor.execute(sqlQueryCheck)
148 result = cursor.fetchall()
149 if not result:
150 print("no cars in the database")
151 else:
152 # create list to hold car names from database
153 car_list = []
154 for row in result:
155 car_list.append(row['car_name'])
156
157 self.model.car_dropdown_options = car_list.copy()
158
159 finally:
160 connection.close()
161
162
163
164 def load_sim_settings(self, selected_car_name):
165 # Get the "default car" details from the database and create a dictionary
166 connection = pymysql.connect(host=Database.db_hostname,
167 user=Database.db_user,
168 port=Database.db_port,
169 password=Database.db_password,
170 db=Database.db_name,
171 cursorclass=pymysql.cursors.DictCursor
172 )
173 try:
174 with connection.cursor() as cursor:
175 sqlQueryGetDefault = 'SELECT * FROM car_details WHERE car_name = %s'
176 default_settings_db_name = selected_car_name
177 print ("default_settings_db_name ", default_settings_db_name)
178 cursor.execute(sqlQueryGetDefault, default_settings_db_name)
179 result = cursor.fetchone()
180 if not result:
181 print("no DEFAULT SETTINGS in database with name")
182 exit()
183 else:
184 print(result)
185 finally:
186 connection.close()
187
188 sim_settings_dict = {'car_name': result['car_name'],
189 'gear1': result['gear1'],
190 'gear2': result['gear2'],
191 'gear3': result['gear3'],
192 'gear4': result['gear4'],
193 'gear5': result['gear5'],
194 'gear6': result['gear6'],
195 'gear_final': result['gear_final'],
196 'drag_length_selection': result['drag_length_selection'],
197 'road_surface_selection': result['road_surface_selection'],
198 'tyre_selection': result['tyre_selection'],
199 'drive_selection': result['drive_selection'],
200 'kerb_weight': result['kerb_weight'],
201 'horsepower': result['horsepower'],
202 'width': result['width'],
203 'height': result['height']
204 }
205 return sim_settings_dict
206
207
208class Model:
209 def __init__(self):
210 self.user = None
211 self.sim_settings_dict = {}
212 self.default_settings_string = "Default Settings"
213 self.results_dict = {'0_60': None,
214 '0_100': None,
215 'top_speed': None,
216 'final_speed': None
217 }
218 self.current_car = self.default_settings_string
219 self.car_dropdown_options = []
220 self.trace_variable = ""
221
222
223
224class Controller:
225 main_menu_needed = True
226 simulator_settings_first_run = True
227
228 def __init__(self, parent, model):
229 self.parent = parent
230 self.model = model
231 # run the database setup - create tables
232 self.database = Database(self.model)
233 # create the login frame
234 self.login_frame = LoginFrame(self, self.parent)
235 self.main_menu_frame = None
236 self.simulation_frame = None
237
238 def car_dropdown_option_changed(self, *args):
239 self.model.current_car = self.model.trace_variable.get()
240 print("the user chose the value ", self.model.current_car)
241 self.database.get_simulation_details_for_car_query(self.model.current_car)
242 self.create_simulator_settings_frame()
243
244
245 def login_successful(self):
246 self.login_frame.destroy()
247 if Controller.main_menu_needed:
248 self.main_menu_frame = MainMenuFrame(self, self.parent, self.model)
249 else:
250 self.create_simulator_settings_frame()
251
252 def save_username_password(self, username_entered, password_entered):
253 self.model.user = username_entered
254 # Save username and password to database / text file
255 print("Username to store", self.model.user)
256 print("Password to store", password_entered)
257
258 # Test whether username and password have been saved successfully
259 save_successful = 1
260 if save_successful == 1:
261 messagebox.showinfo("Info", "Username and password saved")
262 self.login_successful()
263 else:
264 messagebox.showerror("Error", "Cannot store username / password")
265
266 def check_username_password(self, username_entered, password_entered):
267 print("check username and password in database / text file")
268 # Check username and password to database / text file
269
270 # opens the textfile in which the username and password is stored
271 file = open("Username.txt", "r")
272 data = file.read().split(",")
273
274 # Reads the textfile and splits the data
275 username_stored, password_stored = data[0], data[1]
276 print("USERNAME:", username_stored)
277 print("PASSWORD", password_stored)
278 print(username_stored, password_stored)
279
280 # Checks of the user input matches the username and password in the text file
281 if username_entered == username_stored:
282 if password_entered == password_stored:
283 messagebox.showinfo("Login info", "Welcome " + username_entered)
284 self.model.user = username_entered
285 self.login_successful()
286 else:
287 messagebox.showerror("Login error", "Incorrect password")
288 else:
289 messagebox.showerror("Login error", "Incorrect username")
290
291 def login_btn_clicked(self, checkbox_state, entry_1, entry_2):
292 # Retrieves the variables name and password
293 username_entered = entry_1
294 password_entered = entry_2
295 checkbox_value = checkbox_state
296
297 print("USERNAME ENTERED:", username_entered)
298 print("PASSWORD ENTERED", password_entered)
299 print("CHECKBOX VALUE", checkbox_value)
300
301 if checkbox_state == 1:
302 # if new user
303 self.save_username_password(username_entered, password_entered)
304 else:
305 # if existing user
306 self.check_username_password(username_entered, password_entered)
307
308 def sim_settings_to_console(self):
309 print("gear ratio 1 is ", self.model.sim_settings_dict['gear1'])
310 print("gear ratio 2 is ", self.model.sim_settings_dict['gear2'])
311 print("gear ratio 3 is ", self.model.sim_settings_dict['gear3'])
312 print("gear ratio 4 is ", self.model.sim_settings_dict['gear4'])
313 print("gear ratio 5 is ", self.model.sim_settings_dict['gear5'])
314 print("gear ratio 6 is ", self.model.sim_settings_dict['gear6'])
315 print("gear ratio Final is ", self.model.sim_settings_dict['gear_final'])
316 print("drag_length_selection", self.model.sim_settings_dict['drag_length_selection'])
317 print("road_surface_selection", self.model.sim_settings_dict['road_surface_selection'])
318 print("tyre_selection", self.model.sim_settings_dict['tyre_selection'])
319 print("drive_selection", self.model.sim_settings_dict['drive_selection'])
320 print("kerb_weight", self.model.sim_settings_dict['kerb_weight'])
321 print("horsepower", self.model.sim_settings_dict['horsepower'])
322 print("width", self.model.sim_settings_dict['width'])
323 print("height", self.model.sim_settings_dict['height'])
324
325 def sim_results_to_console(self):
326 print("\nFinal results:")
327 print("Top speed = ", self.model.results_dict['top_speed'])
328 print("Final Car Speed = ", self.model.results_dict['final_speed'])
329 print('zeroToSixtyMPH = ', self.model.results_dict['0_60'])
330 print('zeroToOneHundredMPH = ', self.model.results_dict['0_100'])
331
332
333 def create_simulator_settings_frame(self):
334 if Controller.simulator_settings_first_run:
335 # create Simulator settings frame for the first time
336 Controller.simulator_settings_first_run = False
337 if Controller.main_menu_needed:
338 self.main_menu_frame.destroy()
339 # load the simulator settings into the model
340 self.model.current_car = self.model.default_settings_string
341 self.model.sim_settings_dict = self.database.load_sim_settings(self.model.current_car)
342 else:
343 # create Simulator settings frame with choice from the dropdown menu
344 self.simulation_frame.destroy()
345 # load the simulator settings into the model
346 print ("self.model.car_dropdown_variable is ", self.model.current_car)
347 self.model.sim_settings_dict = self.database.load_sim_settings(self.model.current_car)
348
349 # get the dropdown menu options for the simulator
350 self.database.db_car_names_for_dropdown_query()
351
352 # run the simulation frame with the model settings
353 self.simulation_frame = SimulationFrame(self, self.parent)
354
355
356
357 def start_simulation_btn_clicked(self):
358 # store the simulation settings in the model
359 self.model.sim_settings_dict['gear1'] = self.simulation_frame.sim_settings_frame.gear1RatioScale.get()
360 self.model.sim_settings_dict['gear2'] = self.simulation_frame.sim_settings_frame.gear2RatioScale.get()
361 self.model.sim_settings_dict['gear3'] = self.simulation_frame.sim_settings_frame.gear3RatioScale.get()
362 self.model.sim_settings_dict['gear4'] = self.simulation_frame.sim_settings_frame.gear4RatioScale.get()
363 self.model.sim_settings_dict['gear5'] = self.simulation_frame.sim_settings_frame.gear5RatioScale.get()
364 self.model.sim_settings_dict['gear6'] = self.simulation_frame.sim_settings_frame.gear6RatioScale.get()
365 self.model.sim_settings_dict['gear_final'] = self.simulation_frame.sim_settings_frame.gearFinalDriveScale.get()
366 self.model.sim_settings_dict['drag_length_selection'] = self.simulation_frame.sim_settings_frame.drag_length_selection.get()
367 self.model.sim_settings_dict['road_surface_selection'] = self.simulation_frame.sim_settings_frame.road_surface_selection.get()
368 self.model.sim_settings_dict['tyre_selection'] = self.simulation_frame.sim_settings_frame.tyre_selection.get()
369 self.model.sim_settings_dict['drive_selection'] = self.simulation_frame.sim_settings_frame.drive_selection.get()
370 self.model.sim_settings_dict['kerb_weight'] = self.simulation_frame.sim_settings_frame.kerbWeightEntry.get()
371 self.model.sim_settings_dict['horsepower'] = self.simulation_frame.sim_settings_frame.horsepowerEntry.get()
372 self.model.sim_settings_dict['width'] = self.simulation_frame.sim_settings_frame.widthEntry.get()
373 self.model.sim_settings_dict['height'] = self.simulation_frame.sim_settings_frame.heightEntry.get()
374
375 # Show settings in console
376 self.sim_settings_to_console()
377
378 # Run simulation
379 Simulator(self.model)
380
381 # Show results of simulation
382 self.sim_results_to_console()
383
384 self.simulation_frame.results_frame.show_results(self.model.results_dict['top_speed'], self.model.results_dict['final_speed'], self.model.results_dict['0_60'], self.model.results_dict['0_100'])
385
386
387
388 def load_statistics(self):
389 print("load statistics")
390
391 def create_car_upgrades_tuning(self):
392 print("load car upgrades")
393
394 def exit(self):
395 print("exit")
396
397
398class SimulationFrame(Frame):
399 def __init__(self, controller, parent):
400 Frame.__init__(self, parent)
401 self.parent = parent
402 self.controller = controller
403 self.sim_settings_frame = Frame
404 self.results_frame = Frame
405 self.grid()
406 self.make_widgets()
407
408 def make_widgets(self):
409 #left side
410 self.sim_settings_frame = SimSettingsFrame(self, self.controller, self.controller.model)
411 self.sim_settings_frame.grid(row=0, column=0)
412
413 #right side
414 self.results_frame = ResultsFrame(self)
415 self.results_frame.grid(row=0, column=1)
416
417
418class LoginFrame(Frame):
419 def __init__(self, controller, parent):
420 Frame.__init__(self, parent)
421 self.parent = parent
422 self.controller = controller
423 self.logbtn = Button(self)
424 self.grid(padx=(0, 100), pady=(20, 100))
425 self.make_widgets()
426
427 def make_widgets(self):
428 # Creates label displaying: "Car Simulator V_1.00"
429 Label(self, text="Car Simulator V_1.00", font=largeFont).grid(row=0, columnspan=2, pady=(10, 30))
430
431 # Creates label displaying: "Username"
432 Label(self, text="Username", font=mediumFont).grid(row=1, column=0, padx=100, pady=(0, 10))
433
434 # Creates entry box for the user to enter username
435 entry_1 = Entry(self, font=mediumFont)
436 entry_1.grid(row=1, column=1, sticky=W, pady=(0, 10))
437
438 # Creates label displaying: "Password"
439 Label(self, text="Password", font=mediumFont).grid(row=2, column=0, pady=(0, 10))
440
441 # Creates entry box for the user to enter password
442 entry_2 = Entry(self, show="*", font=mediumFont)
443 entry_2.grid(row=2, column=1, sticky=W, pady=(0, 10))
444
445 # creates tickbox for new users
446 checkbox_state = IntVar()
447 checkbox_state.set(0)
448 checkbox = Checkbutton(self, text="New User?", onvalue=1, offvalue=0, variable=checkbox_state, font=mediumFont)
449
450 checkbox.grid(pady=10, columnspan=2)
451
452 # Places button to log into the system
453 self.logbtn.configure(text="Login",
454 command=lambda: self.controller.login_btn_clicked(checkbox_state.get(), entry_1.get(), entry_2.get()), bg="light grey", font=mediumFont)
455 self.logbtn.grid(pady=(0, 10), columnspan=2)
456
457
458class MainMenuFrame(Frame):
459 def __init__(self, controller, parent, model):
460 Frame.__init__(self, parent)
461 self.parent = parent
462 self.model = model
463 self.controller = controller
464 self.grid()
465 self.make_widgets()
466
467 def make_widgets(self):
468 # Create label: "USERNAME"
469 Label(self, text="Welcome " + self.model.user, font=superSmallFont).grid(row=0, pady=20)
470
471 # Creates main title: "CAR SIMULATOR V_1.00"
472 Label(self, text="CAR SIMULATOR V_1.00", font=largeFont).grid(row=1, pady=(0,20), padx=100)
473
474 # Creates SubTitle: "MAIN - MENU"
475 Label(self, text="Main Menu", font=mediumFont).grid(row=2, pady=(0,20))
476
477 # Creates button that takes you to the simulation part of the program
478 btnSimulation = Button(self, bg="yellow", activebackground="yellow", text="Simulation", font=mediumFont, command=self.controller.create_simulator_settings_frame)
479 btnSimulation.grid(row=4, column=0)
480
481 # Creates button that takes you to the Load Simulation part of the program
482 btnLoad = Button(self, bg="green", activebackground="green", text="Load - Statistics", font=mediumFont, command=self.controller.load_statistics)
483 btnLoad.grid(row=5)
484
485 # Creates button that takes you to the Car Upgrades -- Tuning part of the program
486 btnUpgrades = Button(self, bg="turquoise1", activebackground="turquoise1", text="Car Upgrades -- Tuning", font=mediumFont, command=self.controller.create_car_upgrades_tuning)
487 btnUpgrades.grid(row=6, pady=(0, 50))
488
489 # Creates a button that close all parts of the program except the menu
490 btnExit = Button(self, bg="white", activebackground="white", text="Exit", font=mediumFont, command=self.controller.exit)
491 btnExit.grid(row=7, pady=(0, 50))
492
493
494class ResultsFrame(Frame):
495 def __init__(self, parent):
496 Frame.__init__(self, parent)
497 self.parent = parent
498 self.grid()
499 self.results_pane = None
500 self.results_contents_pane = None
501 self.make_widgets()
502
503 def make_widgets(self):
504 self.results_pane = Frame(self)
505 self.results_pane.grid(row=0, column=0)
506
507 Label(self.results_pane, text="Simulation Results", font=largeFont).grid(row=0, column=0, padx=60, sticky=W+N)
508
509 # creates frame for results to be displayed
510 self.results_contents_pane = Frame(self.results_pane)
511 self.results_contents_pane.grid(row=1, column=0)
512
513 # creates tooltip in results_contents_pane
514 Label(self.results_contents_pane, text="Set the simulation parameters on the left and press Start Simulation.", font=smallFont).grid(row=0, column=0, padx=65)
515
516 def show_results(self, top_speed, final_speed, to_sixty, to_hundred):
517 self.results_contents_pane.destroy()
518 self.results_contents_pane = Frame(self.results_pane)
519 self.results_contents_pane.grid(row=1, column=0, padx=60)
520
521 top_speed_label_text = "Top speed = " + str(top_speed) + "mph"
522 final_speed_label_text = "Final speed = " + str(final_speed) + "mph"
523 to_sixty_label_text = "0 - 60 = " + str(to_sixty) + " seconds"
524 to_hundred_label_text = "0 - 100 = " + str(to_hundred) + " seconds"
525
526 Label(self.results_contents_pane, text=top_speed_label_text, font=mediumFont).grid(sticky=W)
527 Label(self.results_contents_pane, text=final_speed_label_text, font=mediumFont).grid(sticky=W)
528 Label(self.results_contents_pane, text=to_sixty_label_text, font=mediumFont).grid(sticky=W)
529 Label(self.results_contents_pane, text=to_hundred_label_text, font=mediumFont).grid(sticky=W)
530
531class SimSettingsFrame(Frame):
532 def __init__(self, parent, controller, model):
533 Frame.__init__(self, parent)
534 self.parent = parent
535 self.model = model
536 self.controller = controller
537 self.grid()
538 self.gear1RatioScale = Scale
539 self.gear2RatioScale = Scale
540 self.gear3RatioScale = Scale
541 self.gear4RatioScale = Scale
542 self.gear5RatioScale = Scale
543 self.gear6RatioScale = Scale
544 self.gearFinalDriveScale = Scale
545 self.kerbWeightEntry = Entry
546 self.horsepowerEntry = Entry
547 self.widthEntry = Entry
548 self.heightEntry = Entry
549 self.drag_length_selection = StringVar
550 self.road_surface_selection = StringVar
551 self.drive_selection = StringVar
552 self.tyre_selection = StringVar
553 self.make_widgets()
554
555 def make_widgets(self):
556
557 # TOP LEFT FRAME
558 frame_left = Frame(self, highlightbackground="gray", highlightcolor="gray", highlightthickness=1)
559 frame_left.grid(row=1, column=0, sticky=W+E)
560
561 # creates title and subtitle
562 row0Frame=Frame(frame_left)
563 row0Frame.grid(row=0, column=0, sticky=W+E)
564 Label(row0Frame, text="Simulation Settings", font=largeFont).grid(row=0, column=0, sticky=W)
565 Label(row0Frame, text="Set Gear Ratios", font=mediumFont).grid(row=1, column=0, sticky=W)
566 Label(row0Frame, text="0 = Short gear change, 100 = Long gear change", font=smallFont).grid(row=2, column=0, sticky=W)
567
568 # creates Scale widgets
569 row1Frame = Frame(frame_left)
570 row1Frame.grid(row=1)
571
572 # creates "GEAR 1 : :", then creates a scale to choose gear ratio number
573 self.gear1RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300, tickinterval=25)
574 self.gear1RatioScale.set(self.model.sim_settings_dict['gear1'])
575 self.gear1RatioScale.grid(row=0, column=0, padx=15)
576
577 # creates "GEAR 2 : :", then creates a scale to choose gear ratio number
578 self.gear2RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
579 self.gear2RatioScale.set(self.model.sim_settings_dict['gear2'])
580 self.gear2RatioScale.grid(row=0, column=1, padx=15)
581
582 # creates "GEAR 3 : :", then creates a scale to choose gear ratio number
583 self.gear3RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL,font=superSmallFont, length=300)
584 self.gear3RatioScale.set(self.model.sim_settings_dict['gear3'])
585 self.gear3RatioScale.grid(row=0, column=2, padx=15)
586
587 # creates "GEAR 4 : :", then creates a scale to choose gear ratio number
588 self.gear4RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
589 self.gear4RatioScale.set(self.model.sim_settings_dict['gear4'])
590 self.gear4RatioScale.grid(row=0, column=3, padx=15)
591
592 # creates "GEAR 5 : :", then creates a scale to choose gear ratio number
593 self.gear5RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
594 self.gear5RatioScale.set(self.model.sim_settings_dict['gear5'])
595 self.gear5RatioScale.grid(row=0, column=4, padx=15)
596
597 # creates "GEAR 6 : :", then creates a scale to choose gear ratio number
598 self.gear6RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
599 self.gear6RatioScale.set(self.model.sim_settings_dict['gear6'])
600 self.gear6RatioScale.grid(row=0, column=5, padx=15)
601
602 # creates "FINAL DRIVE", then creates a scale to choose gear ratio number
603 self.gearFinalDriveScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300, tickinterval=25, width=30)
604 self.gearFinalDriveScale.set(self.model.sim_settings_dict['gear_final'])
605 self.gearFinalDriveScale.grid(row=0, column=6)
606
607 Label(row1Frame, text="Gear 1", font=smallFont).grid(row=1, column=0, padx=(10, 0))
608 Label(row1Frame, text="2", font=smallFont).grid(row=1, column=1, padx=(22, 0))
609 Label(row1Frame, text="3", font=smallFont).grid(row=1, column=2, padx=(22, 0))
610 Label(row1Frame, text="4", font=smallFont).grid(row=1, column=3, padx=(22, 0))
611 Label(row1Frame, text="5", font=smallFont).grid(row=1, column=4, padx=(22, 0))
612 Label(row1Frame, text="6", font=smallFont).grid(row=1, column=5, padx=(22, 0))
613 Label(row1Frame, text="FINAL DRIVE", font=smallFont).grid(row=1, column=6, padx=(22, 0))
614
615 # ROW 2 FRAME
616 row2Frame = Frame(frame_left, highlightbackground="gray", highlightcolor="gray", highlightthickness=1, width=750, height=100)
617 row2Frame.grid(row=2, column=0, stick=W+E)
618
619 row_count = 0
620 Label(row2Frame, text="Select Options", font=mediumFont).grid(row=row_count, column=0, sticky=W)
621
622 # DRAG STRIP LENGTH RADIO BUTTONS
623 # Creates a label to display options, then a text box to allow user to enter a selection
624 row_count += 1
625 Label(row2Frame, text="Drag Strip Length", font=smallFont).grid(row=row_count, column=0, sticky=W)
626
627 track_choices = {
628 "1/4 mile": 1,
629 "1/2 mile": 2,
630 "1 mile": 3
631 }
632 i = 1
633 self.drag_length_selection = StringVar()
634 for distance, val in track_choices.items():
635 print("val = ", val)
636 print("distance = ", distance)
637 radio_button = Radiobutton(row2Frame, variable=self.drag_length_selection, value=val, text=distance, command=lambda:self.ShowChoice(self.drag_length_selection.get()))
638 radio_button.grid(row=row_count, column=i, sticky=W)
639 i += 1
640 self.drag_length_selection.set(self.model.sim_settings_dict['drag_length_selection'])
641
642 # ROAD SURFACE RADIO BUTTONS
643 row_count += 1
644 # Creates a label to display options, then a text box to allow user to enter a selection
645 Label(row2Frame, text="Road Surface", font=smallFont).grid(row=row_count, column=0, sticky=W)
646
647 surface_choices = {
648 "Dirt Track": 1,
649 "Smooth": 2,
650 "Icy": 3,
651 "Grass & Turf": 4
652 }
653 i = 1
654 self.road_surface_selection = StringVar()
655 for surface, val in surface_choices.items():
656 print("val = ", val)
657 print("Surface = ", surface)
658 radio_button = Radiobutton(row2Frame, variable=self.road_surface_selection, value=val, text=surface, command=lambda:self.ShowChoice(self.road_surface_selection.get()))
659 radio_button.grid(row=row_count, column=i, sticky=W)
660 i += 1
661 self.road_surface_selection.set(self.model.sim_settings_dict['road_surface_selection'])
662 # TYRE CHOICE RADIO BUTTONS
663 row_count += 1
664 # Creates a label to display options, then a text box to allow user to enter a selection
665 Label(row2Frame, text="Tyre Selection", font=smallFont).grid(row=row_count, column=0, sticky=W)
666
667 tyre_choices = {
668 "Drag tyres": 1,
669 "Ultrasofts": 2,
670 "Road legal": 3,
671 "Offroad treads": 4,
672 "Chain tyres": 5
673 }
674 i = 1
675 self.tyre_selection = StringVar()
676 for tyre_choice, val in tyre_choices.items():
677 print("val = ", val)
678 print("Tyre choice = ", tyre_choice)
679 radio_button = Radiobutton(row2Frame, variable=self.tyre_selection, value=val, text=tyre_choice, command=lambda:self.ShowChoice(self.tyre_selection.get()))
680 radio_button.grid(row=row_count, column=i, sticky=W)
681 i += 1
682 self.tyre_selection.set(self.model.sim_settings_dict['tyre_selection'])
683
684 # DRIVE RADIO BUTTONS
685 row_count += 1
686 # Creates a label to display options, then a text box to allow user to enter a selection
687 Label(row2Frame, text="Drive Selection", font=smallFont).grid(row=row_count, column=0, sticky=W)
688
689 drive_choices = {
690 "Front wheel drive": 1,
691 "Rear wheel drive": 2,
692 "All wheel drive": 3
693 }
694 i = 1
695 self.drive_selection = StringVar()
696 for drive_choice, val in drive_choices.items():
697 radio_button = Radiobutton(row2Frame, variable=self.drive_selection, value=val, text=drive_choice, command=lambda:self.ShowChoice(self.drive_selection.get()))
698 radio_button.grid(row=row_count, column=i)
699 i += 1
700 self.drive_selection.set(self.model.sim_settings_dict['drive_selection'])
701
702 # ROW 3 FRAME
703 row_count = 0
704 row3Frame = Frame(frame_left, highlightbackground="gray", highlightcolor="gray", highlightthickness=1)
705 row3Frame.grid(row=3, column=0, stick=W+E)
706 Label(row3Frame, text="Car Details", font=mediumFont).grid(row=row_count, column=0, sticky=W, padx=(0, 20))
707
708 # creates a label for instructions on what to enter into the entry box
709 Label(row3Frame, text="Kerb Weight (Kg)",font=smallFont).grid(row=row_count, column=1, sticky=W)
710 self.kerbWeightEntry = Entry(row3Frame, font=smallFont)
711 self.kerbWeightEntry.insert(0, self.model.sim_settings_dict['kerb_weight'])
712 self.kerbWeightEntry.grid(row=0, column=2)
713
714 row_count += 1
715 # creates a label for instructions on what to enter into the entry box
716 Label(row3Frame, text="Horsepower (hp)", font=smallFont).grid(row=row_count, column=1, sticky=W)
717 self.horsepowerEntry = Entry(row3Frame, font=smallFont)
718 self.horsepowerEntry.insert(0, self.model.sim_settings_dict['horsepower'])
719 self.horsepowerEntry.grid(row=row_count, column=2)
720
721 row_count += 1
722 # creates a label for instructions on what to enter into the entry box
723 Label(row3Frame, text="Width (m)", font=smallFont).grid(row=row_count, column=1, sticky=W)
724 self.widthEntry = Entry(row3Frame, font=smallFont)
725 self.widthEntry.insert(0, self.model.sim_settings_dict['width'])
726 self.widthEntry.grid(row=row_count, column=2)
727
728 row_count += 1
729 # creates a label for instructions on what to enter into the entry box
730 Label(row3Frame, text="Height (m)",font=smallFont).grid(row=row_count, column=1, sticky=W)
731 self.heightEntry = Entry(row3Frame, font=smallFont)
732 self.heightEntry.insert(0, self.model.sim_settings_dict['height'])
733 self.heightEntry.grid(row=row_count, column=2)
734
735 # creates a button to submit all data to the system
736 submitButton = Button(row3Frame, text="Start Simulation", font=mediumFont,
737 command= self.controller.start_simulation_btn_clicked)
738 submitButton.grid(row=1, column=3, sticky=E+W, padx=20)
739
740 # Create dropdown and and check for change. Refresh of simulation settings
741 self.model.trace_variable = StringVar()
742 self.model.trace_variable.set(self.model.current_car)
743 print("self.model.current_car is ", self.model.current_car)
744 print("self.model.trace_variable is ", self.model.trace_variable.get())
745
746 self.model.trace_variable.trace("w", self.controller.car_dropdown_option_changed)
747
748 option_list = self.model.car_dropdown_options
749 w = OptionMenu(row3Frame, self.model.trace_variable, *option_list)
750
751 w.grid(row=2, column=3, sticky=E + W, padx=20)
752
753 def ShowChoice(self, track_dist_var):
754 print("")
755 # DO NOT DELETE THIS METHOD
756
757
758class Simulator:
759 def __init__(self, model):
760 self.model = model
761 self.startSimulation()
762
763 def startSimulation(self):
764 # get variables
765 drag_length = self.model.sim_settings_dict['drag_length_selection']
766 gear1RatioNumber = self.model.sim_settings_dict['gear1']
767 gear2RatioNumber = self.model.sim_settings_dict['gear2']
768 gear3RatioNumber = self.model.sim_settings_dict['gear3']
769 gear4RatioNumber = self.model.sim_settings_dict['gear4']
770 gear5RatioNumber = self.model.sim_settings_dict['gear5']
771 gear6RatioNumber = self.model.sim_settings_dict['gear6']
772 print('gear1RatioNumber ', gear1RatioNumber)
773 print('gear2RatioNumber ', gear2RatioNumber)
774 print('gear3RatioNumber ', gear3RatioNumber)
775 print('gear4RatioNumber ', gear4RatioNumber)
776 print('gear5RatioNumber ', gear5RatioNumber)
777 # Gets the gear ratios to use for further algorithms
778 gear_final_drive_number = (2 * self.model.sim_settings_dict['gear_final'])
779 print('gear_final_drive_number ', gear_final_drive_number)
780
781
782 TotalGears = (
783 gear1RatioNumber + gear2RatioNumber + gear3RatioNumber + gear4RatioNumber + gear5RatioNumber + gear6RatioNumber + gear_final_drive_number)
784 average_ratio = (TotalGears / 8)
785
786 # Calculates mean average of gear ratios
787 print("average_ratio = ", average_ratio)
788
789 # Creates integer value for drag length
790 drag_length = int(drag_length)
791 print("drag length = ", drag_length)
792
793 # runs if statement to determine which drag length the user has selected
794 if drag_length == 1:
795 # runs if statement to determine what the average gear ratio length the user has selected
796 if average_ratio < 20 and average_ratio > 0:
797 car_Speed = 10
798 print(car_Speed)
799 # determines the intial car speed to then be used in further algorithms
800 if average_ratio > 20 and average_ratio < 40:
801 car_Speed = 8
802 print(car_Speed)
803 # determines the intial car speed to then be used in further algorithms
804 if average_ratio > 40 and average_ratio < 60:
805 car_Speed = 5
806 print(car_Speed)
807 # determines the intial car speed to then be used in further algorithms
808 if average_ratio > 60 and average_ratio < 80:
809 car_Speed = 3
810 print(car_Speed)
811 # determines the intial car speed to then be used in further algorithms
812 if average_ratio > 80 and average_ratio < 100:
813 car_Speed = 2
814 print(car_Speed)
815 # determines the intial car speed to then be used in further algorithms
816 if drag_length == 2:
817 if average_ratio < 20 and average_ratio > 0:
818 car_Speed = 5
819 print(car_Speed)
820 # determines the intial car speed to then be used in further algorithms
821 if average_ratio > 20 and average_ratio < 40:
822 car_Speed = 10
823 print(car_Speed)
824 # determines the intial car speed to then be used in further algorithms
825 if average_ratio > 40 and average_ratio < 60:
826 car_Speed = 8
827 print(car_Speed)
828 # determines the intial car speed to then be used in further algorithms
829 if average_ratio > 60 and average_ratio < 80:
830 car_Speed = 3
831 print(car_Speed)
832 # determines the intial car speed to then be used in further algorithms
833 if average_ratio > 80 and average_ratio < 100:
834 car_Speed = 2
835 print(car_Speed)
836 # determines the intial car speed to then be used in further algorithms
837 if drag_length == 3:
838 if average_ratio < 20 and average_ratio > 0:
839 car_Speed = 2
840 print(car_Speed)
841 # determines the intial car speed to then be used in further algorithms
842 if average_ratio > 20 and average_ratio < 40:
843 car_Speed = 3
844 print(car_Speed)
845 # determines the intial car speed to then be used in further algorithms
846 if average_ratio > 40 and average_ratio < 60:
847 car_Speed = 8
848 print(car_Speed)
849 # determines the intial car speed to then be used in further algorithms
850 if average_ratio > 60 and average_ratio < 80:
851 car_Speed = 10
852 print(car_Speed)
853 # determines the intial car speed to then be used in further algorithms
854 if average_ratio > 80 and average_ratio < 100:
855 car_Speed = 5
856 print(car_Speed)
857 # determines the intial car speed to then be used in further algorithms
858
859 # converts the car speed into a string
860 car_speedPT1 = str(car_Speed)
861 print('car speed', car_speedPT1)
862
863 trackEntry_Number = self.model.sim_settings_dict['road_surface_selection']
864 print("Track = " + trackEntry_Number)
865 # retrieves and prints Track number
866 tyreEntry_Number = self.model.sim_settings_dict['tyre_selection']
867 print("Tyre = " + tyreEntry_Number)
868 # retrieves and prints Tyre number
869 driveEntry_Number = self.model.sim_settings_dict['drive_selection']
870 print("Drive = " + driveEntry_Number)
871 # retrieves and prints Drive number
872 car_Speed_Final1 = car_speedPT1
873 print("Speed = " + car_Speed_Final1)
874 # retrieves and prints Car Speed rack number
875
876 # Track change
877 # Track is Dirt Track
878 trackEntry_Number, tyreEntry_Number, driveEntry_Number, car_Speed_Final1 = int(
879 trackEntry_Number), int(tyreEntry_Number), int(driveEntry_Number), float(car_Speed_Final1)
880
881 kerbWeightEntryNumber = self.model.sim_settings_dict['kerb_weight']
882 print("Curb Weight = " + kerbWeightEntryNumber)
883 # retrieves and prints kerbWeight number
884
885 horsePowerEntryNumber = self.model.sim_settings_dict['horsepower']
886 print("Horsepower = " + horsePowerEntryNumber)
887 # retrieves and prints horsepower number
888
889 widthOfCar = self.model.sim_settings_dict['width']
890 print("Width = " + widthOfCar)
891 # retrieves and prints widthOfCar number
892
893 heightOfCar = self.model.sim_settings_dict['height']
894 print("Width = " + heightOfCar)
895 # retrieves and prints heightOfCar number
896
897 horsePowerEntryNumber, kerbWeightEntryNumber, widthOfCar, heightOfCar = float(horsePowerEntryNumber), float(
898 kerbWeightEntryNumber), float(widthOfCar), float(heightOfCar)
899
900 area = (widthOfCar / 1000) * (heightOfCar / 1000)
901 power = horsePowerEntryNumber * 745.7
902 speedMS = (2 * power / (0.35 * 1.25 * area)) ** (1 / 3)
903 topSpeedMPH = speedMS * 2.23694
904 topSpeedMPH = topSpeedMPH * 1.06680660592
905 topSpeedMPH = round(topSpeedMPH, 2)
906 topSpeedMPH = str(topSpeedMPH)
907
908 zeroToSixtyMPH = kerbWeightEntryNumber / horsePowerEntryNumber
909
910 # print("Top Speed = " + topSpeedMPH)
911 # print(zeroToSixtyMPH)
912
913 # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
914 car_Speed_Final3 = 0
915 if trackEntry_Number == 1 and tyreEntry_Number == 4:
916 car_Speed_Final2 = car_Speed_Final1 + 1
917 if driveEntry_Number == 1:
918 car_Speed_Final3 = car_Speed_Final2 - 2
919 print("Speed = ", car_Speed_Final3)
920 zeroToSixtyMPH = zeroToSixtyMPH * 1.8
921 # Puts original value checks the inputs then calculates final car speed
922 if driveEntry_Number == 2:
923 car_Speed_Final3 = car_Speed_Final2 - 1
924 print(car_Speed_Final3)
925 zeroToSixtyMPH = zeroToSixtyMPH * 1.8
926 # Puts original value checks the inputs then calculates final car speed
927 if driveEntry_Number == 3:
928 car_Speed_Final3 = car_Speed_Final2 + 2
929 print("Speed = ", car_Speed_Final3)
930 zeroToSixtyMPH = zeroToSixtyMPH * 1.3
931 # Puts original value checks the inputs then calculates final car speed
932 if trackEntry_Number == 1 and tyreEntry_Number == 1:
933 car_Speed_Final2 = car_Speed_Final1 - 1
934 if driveEntry_Number == 1:
935 car_Speed_Final3 = car_Speed_Final2 - 2
936 print("Speed = ", car_Speed_Final3)
937 zeroToSixtyMPH = zeroToSixtyMPH * 3
938 # Puts original value checks the inputs then calculates final car speed
939 if driveEntry_Number == 2:
940 car_Speed_Final3 = car_Speed_Final2 - 1
941 print("Speed = ", car_Speed_Final3)
942 zeroToSixtyMPH = zeroToSixtyMPH * 2.8
943 # Puts original value checks the inputs then calculates final car speed
944 if driveEntry_Number == 3:
945 car_Speed_Final3 = car_Speed_Final2 + 2
946 print("Speed = ", car_Speed_Final3)
947 zeroToSixtyMPH = zeroToSixtyMPH * 2
948 # Puts original value checks the inputs then calculates final car speed
949 if trackEntry_Number == 1 and tyreEntry_Number == 2:
950 car_Speed_Final2 = car_Speed_Final1 - 1
951 if driveEntry_Number == 1:
952 car_Speed_Final3 = car_Speed_Final2 - 2
953 print("Speed = ", car_Speed_Final3)
954 zeroToSixtyMPH = zeroToSixtyMPH * 2.8
955 # Puts original value checks the inputs then calculates final car speed
956 if driveEntry_Number == 2:
957 car_Speed_Final3 = car_Speed_Final2 - 1
958 print("Speed = ", car_Speed_Final3)
959 zeroToSixtyMPH = zeroToSixtyMPH * 2.6
960 # Puts original value checks the inputs then calculates final car speed
961 if driveEntry_Number == 3:
962 car_Speed_Final3 = car_Speed_Final2 + 2
963 print("Speed = ", car_Speed_Final3)
964 zeroToSixtyMPH = zeroToSixtyMPH * 1.8
965 # Puts original value checks the inputs then calculates final car speed
966 if trackEntry_Number == 1 and tyreEntry_Number == 3:
967 car_Speed_Final2 = car_Speed_Final1 - 1
968 if driveEntry_Number == 1:
969 car_Speed_Final3 = car_Speed_Final2 - 2
970 print("Speed = ", car_Speed_Final3)
971 zeroToSixtyMPH = zeroToSixtyMPH * 2
972 # Puts original value checks the inputs then calculates final car speed
973 if driveEntry_Number == 2:
974 car_Speed_Final3 = car_Speed_Final2 - 1
975 print("Speed = ", car_Speed_Final3)
976 zeroToSixtyMPH = zeroToSixtyMPH * 1.9
977 # Puts original value checks the inputs then calculates final car speed
978 if driveEntry_Number == 3:
979 car_Speed_Final3 = car_Speed_Final2 + 2
980 print("Speed = ", car_Speed_Final3)
981 zeroToSixtyMPH = zeroToSixtyMPH * 1.5
982 # Puts original value checks the inputs then calculates final car speed
983 if trackEntry_Number == 1 and tyreEntry_Number == 5:
984 car_Speed_Final2 = car_Speed_Final1 + 1
985 if driveEntry_Number == 1:
986 car_Speed_Final3 = car_Speed_Final2 - 2
987 print("Speed = ", car_Speed_Final3)
988 zeroToSixtyMPH = zeroToSixtyMPH * 2.2
989 # Puts original value checks the inputs then calculates final car speed
990 if driveEntry_Number == 2:
991 car_Speed_Final3 = car_Speed_Final2 - 1
992 print("Speed = ", car_Speed_Final3)
993 zeroToSixtyMPH = zeroToSixtyMPH * 2
994 # Puts original value checks the inputs then calculates final car speed
995 if driveEntry_Number == 3:
996 car_Speed_Final3 = car_Speed_Final2 + 2
997 print("Speed = ", car_Speed_Final3)
998 zeroToSixtyMPH = zeroToSixtyMPH * 1.6
999 # Puts original value checks the inputs then calculates final car speed
1000 # Track Changes
1001
1002 # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1003
1004 # Track is smooth tarmac
1005 if trackEntry_Number == 2 and tyreEntry_Number == 1:
1006 car_Speed_Final2 = car_Speed_Final1 + 5
1007 if driveEntry_Number == 1:
1008 car_Speed_Final3 = car_Speed_Final2 + 0
1009 print("Speed = ", car_Speed_Final3)
1010 zeroToSixtyMPH = zeroToSixtyMPH * 0.85
1011 # Puts original value checks the inputs then calculates final car speed
1012 if driveEntry_Number == 2:
1013 car_Speed_Final3 = car_Speed_Final2 + 2
1014 print("Speed = ", car_Speed_Final3)
1015 zeroToSixtyMPH = zeroToSixtyMPH * 0.75
1016 # Puts original value checks the inputs then calculates final car speed
1017 if driveEntry_Number == 3:
1018 car_Speed_Final3 = car_Speed_Final2 + 1
1019 print("Speed = ", car_Speed_Final3)
1020 zeroToSixtyMPH = zeroToSixtyMPH * 0.70
1021 # Puts original value checks the inputs then calculates final car speed
1022 if trackEntry_Number == 2 and tyreEntry_Number == 2:
1023 car_Speed_Final2 = car_Speed_Final1 + 4
1024 if driveEntry_Number == 1:
1025 car_Speed_Final3 = car_Speed_Final2 + 0
1026 print("Speed = ", car_Speed_Final3)
1027 zeroToSixtyMPH = zeroToSixtyMPH * 0.90
1028 # Puts original value checks the inputs then calculates final car speed
1029 if driveEntry_Number == 2:
1030 car_Speed_Final3 = car_Speed_Final2 + 2
1031 print("Speed = ", car_Speed_Final3)
1032 zeroToSixtyMPH = zeroToSixtyMPH * 0.80
1033 if driveEntry_Number == 3:
1034 car_Speed_Final3 = car_Speed_Final2 + 1
1035 print("Speed = ", car_Speed_Final3)
1036 zeroToSixtyMPH = zeroToSixtyMPH * 0.75
1037 # Puts original value checks the inputs then calculates final car speed
1038 if trackEntry_Number == 2 and tyreEntry_Number == 3:
1039 car_Speed_Final2 = car_Speed_Final1 + 2
1040 if driveEntry_Number == 1:
1041 car_Speed_Final3 = car_Speed_Final2 + 0
1042 print("Speed = ", car_Speed_Final3)
1043 zeroToSixtyMPH = zeroToSixtyMPH * 1
1044 # Puts original value checks the inputs then calculates final car speed
1045 if driveEntry_Number == 2:
1046 car_Speed_Final3 = car_Speed_Final2 + 2
1047 print("Speed = ", car_Speed_Final3)
1048 zeroToSixtyMPH = zeroToSixtyMPH * 0.9
1049 # Puts original value checks the inputs then calculates final car speed
1050 if driveEntry_Number == 3:
1051 car_Speed_Final3 = car_Speed_Final2 + 1
1052 print("Speed = ", car_Speed_Final3)
1053 zeroToSixtyMPH = zeroToSixtyMPH * 0.8
1054 # Puts original value checks the inputs then calculates final car speed
1055 if trackEntry_Number == 2 and tyreEntry_Number == 4:
1056 car_Speed_Final2 = car_Speed_Final1 + 0
1057 if driveEntry_Number == 1:
1058 car_Speed_Final3 = car_Speed_Final2 + 0
1059 print("Speed = ", car_Speed_Final3)
1060 zeroToSixtyMPH = zeroToSixtyMPH * 1.6
1061 # Puts original value checks the inputs then calculates final car speed
1062 if driveEntry_Number == 2:
1063 car_Speed_Final3 = car_Speed_Final2 + 2
1064 print("Speed = ", car_Speed_Final3)
1065 zeroToSixtyMPH = zeroToSixtyMPH * 1.5
1066 # Puts original value checks the inputs then calculates final car speed
1067 if driveEntry_Number == 3:
1068 car_Speed_Final3 = car_Speed_Final2 + 1
1069 print("Speed = ", car_Speed_Final3)
1070 zeroToSixtyMPH = zeroToSixtyMPH * 1.4
1071 # Puts original value checks the inputs then calculates final car speed
1072 if trackEntry_Number == 2 and tyreEntry_Number == 5:
1073 car_Speed_Final2 = car_Speed_Final1 - 4
1074 if driveEntry_Number == 1:
1075 car_Speed_Final3 = car_Speed_Final2 + 0
1076 print("Speed = ", car_Speed_Final3)
1077 zeroToSixtyMPH = zeroToSixtyMPH * 5
1078 # Puts original value checks the inputs then calculates final car speed
1079 if driveEntry_Number == 2:
1080 car_Speed_Final3 = car_Speed_Final2 + 2
1081 print("Speed = ", car_Speed_Final3)
1082 zeroToSixtyMPH = zeroToSixtyMPH * 5
1083 # Puts original value checks the inputs then calculates final car speed
1084 if driveEntry_Number == 3:
1085 car_Speed_Final3 = car_Speed_Final2 + 1
1086 print("Speed = ", car_Speed_Final3)
1087 zeroToSixtyMPH = zeroToSixtyMPH * 4.5
1088 # Puts original value checks the inputs then calculates final car speed
1089 # Track Change
1090
1091 # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1092
1093 # Track is icy road
1094 if trackEntry_Number == 3 and tyreEntry_Number == 5:
1095 car_Speed_Final2 = car_Speed_Final1 + 2
1096 if driveEntry_Number == 1:
1097 car_Speed_Final3 = car_Speed_Final2 - 3
1098 print("Speed = ", car_Speed_Final3)
1099 zeroToSixtyMPH = zeroToSixtyMPH * 3
1100 # Puts original value checks the inputs then calculates final car speed
1101 if driveEntry_Number == 2:
1102 car_Speed_Final3 = car_Speed_Final2 - 1
1103 print("Speed = ", car_Speed_Final3)
1104 zeroToSixtyMPH = zeroToSixtyMPH * 2.8
1105 # Puts original value checks the inputs then calculates final car speed
1106 if driveEntry_Number == 3:
1107 car_Speed_Final3 = car_Speed_Final2 + 2
1108 print("Speed = ", car_Speed_Final3)
1109 zeroToSixtyMPH = zeroToSixtyMPH * 2.5
1110 # Puts original value checks the inputs then calculates final car speed
1111 if trackEntry_Number == 3 and tyreEntry_Number == 1:
1112 car_Speed_Final2 = car_Speed_Final1 - 2
1113 if driveEntry_Number == 1:
1114 car_Speed_Final3 = car_Speed_Final2 - 3
1115 print("Speed = ", car_Speed_Final3)
1116 zeroToSixtyMPH = zeroToSixtyMPH * 7
1117 # Puts original value checks the inputs then calculates final car speed
1118 if driveEntry_Number == 2:
1119 car_Speed_Final3 = car_Speed_Final2 - 1
1120 print("Speed = ", car_Speed_Final3)
1121 zeroToSixtyMPH = zeroToSixtyMPH * 6
1122 # Puts original value checks the inputs then calculates final car speed
1123 if driveEntry_Number == 3:
1124 car_Speed_Final3 = car_Speed_Final2 + 2
1125 print("Speed = ", car_Speed_Final3)
1126 zeroToSixtyMPH = zeroToSixtyMPH * 5
1127 # Puts original value checks the inputs then calculates final car speed
1128 if trackEntry_Number == 3 and tyreEntry_Number == 2:
1129 car_Speed_Final2 = car_Speed_Final1 - 2
1130 if driveEntry_Number == 1:
1131 car_Speed_Final3 = car_Speed_Final2 - 3
1132 print("Speed = ", car_Speed_Final3)
1133 zeroToSixtyMPH = zeroToSixtyMPH * 6
1134 # Puts original value checks the inputs then calculates final car speed
1135 if driveEntry_Number == 2:
1136 car_Speed_Final3 = car_Speed_Final2 - 1
1137 print("Speed = ", car_Speed_Final3)
1138 zeroToSixtyMPH = zeroToSixtyMPH * 5
1139 # Puts original value checks the inputs then calculates final car speed
1140 if driveEntry_Number == 3:
1141 car_Speed_Final3 = car_Speed_Final2 + 2
1142 print("Speed = ", car_Speed_Final3)
1143 zeroToSixtyMPH = zeroToSixtyMPH * 4
1144 # Puts original value checks the inputs then calculates final car speed
1145 if trackEntry_Number == 3 and tyreEntry_Number == 3:
1146 car_Speed_Final2 = car_Speed_Final1 - 3
1147 if driveEntry_Number == 1:
1148 car_Speed_Final3 = car_Speed_Final2 - 3
1149 print("Speed = ", car_Speed_Final3)
1150 zeroToSixtyMPH = zeroToSixtyMPH * 5
1151 # Puts original value checks the inputs then calculates final car speed
1152 if driveEntry_Number == 2:
1153 car_Speed_Final3 = car_Speed_Final2 - 1
1154 print("Speed = ", car_Speed_Final3)
1155 zeroToSixtyMPH = zeroToSixtyMPH * 4
1156 # Puts original value checks the inputs then calculates final car speed
1157 if driveEntry_Number == 3:
1158 car_Speed_Final3 = car_Speed_Final2 + 2
1159 print("Speed = ", car_Speed_Final3)
1160 zeroToSixtyMPH = zeroToSixtyMPH * 3.2
1161 # Puts original value checks the inputs then calculates final car speed
1162 if trackEntry_Number == 3 and tyreEntry_Number == 4:
1163 car_Speed_Final2 = car_Speed_Final1 + 1
1164 if driveEntry_Number == 1:
1165 car_Speed_Final3 = car_Speed_Final2 - 3
1166 print("Speed = ", car_Speed_Final3)
1167 zeroToSixtyMPH = zeroToSixtyMPH * 4
1168 # Puts original value checks the inputs then calculates final car speed
1169 if driveEntry_Number == 2:
1170 car_Speed_Final3 = car_Speed_Final2 - 1
1171 print("Speed = ", car_Speed_Final3)
1172 zeroToSixtyMPH = zeroToSixtyMPH * 3.5
1173 # Puts original value checks the inputs then calculates final car speed
1174 if driveEntry_Number == 3:
1175 car_Speed_Final3 = car_Speed_Final2 + 2
1176 print("Speed = ", car_Speed_Final3)
1177 zeroToSixtyMPH = zeroToSixtyMPH * 3
1178 # Puts original value checks the inputs then calculates final car speed
1179 # Track Change
1180
1181 # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1182
1183 # Track Changes to Grass and Turf
1184 if trackEntry_Number == 4 and tyreEntry_Number == 4:
1185 car_Speed_Final2 = car_Speed_Final1 + 1
1186 if driveEntry_Number == 1:
1187 car_Speed_Final3 = car_Speed_Final2 - 3
1188 print("Speed = ", car_Speed_Final3)
1189 zeroToSixtyMPH = zeroToSixtyMPH * 2.2
1190 # Puts original value checks the inputs then calculates final car speed
1191 if driveEntry_Number == 2:
1192 car_Speed_Final3 = car_Speed_Final2 - 2
1193 print("Speed = ", car_Speed_Final3)
1194 zeroToSixtyMPH = zeroToSixtyMPH * 2.2
1195 # Puts original value checks the inputs then calculates final car speed
1196 if driveEntry_Number == 3:
1197 car_Speed_Final3 = car_Speed_Final2 + 3
1198 print("Speed = ", car_Speed_Final3)
1199 zeroToSixtyMPH = zeroToSixtyMPH * 1.6
1200 # Puts original value checks the inputs then calculates final car speed
1201 if trackEntry_Number == 4 and tyreEntry_Number == 1:
1202 car_Speed_Final2 = car_Speed_Final1 - 3
1203 if driveEntry_Number == 1:
1204 car_Speed_Final3 = car_Speed_Final2 - 3
1205 print("Speed = ", car_Speed_Final3)
1206 zeroToSixtyMPH = zeroToSixtyMPH * 3.2
1207 # Puts original value checks the inputs then calculates final car speed
1208 if driveEntry_Number == 2:
1209 car_Speed_Final3 = car_Speed_Final2 - 2
1210 print("Speed = ", car_Speed_Final3)
1211 zeroToSixtyMPH = zeroToSixtyMPH * 3
1212 # Puts original value checks the inputs then calculates final car speed
1213 if driveEntry_Number == 3:
1214 car_Speed_Final3 = car_Speed_Final2 + 3
1215 print("Speed = ", car_Speed_Final3)
1216 zeroToSixtyMPH = zeroToSixtyMPH * 2.4
1217 # Puts original value checks the inputs then calculates final car speed
1218 if trackEntry_Number == 4 and tyreEntry_Number == 2:
1219 car_Speed_Final2 = car_Speed_Final1 - 3
1220 if driveEntry_Number == 1:
1221 car_Speed_Final3 = car_Speed_Final2 - 3
1222 print("Speed = ", car_Speed_Final3)
1223 zeroToSixtyMPH = zeroToSixtyMPH * 3
1224 # Puts original value checks the inputs then calculates final car speed
1225 if driveEntry_Number == 2:
1226 car_Speed_Final3 = car_Speed_Final2 - 2
1227 print("Speed = ", car_Speed_Final3)
1228 zeroToSixtyMPH = zeroToSixtyMPH * 2.8
1229 # Puts original value checks the inputs then calculates final car speed
1230 if driveEntry_Number == 3:
1231 car_Speed_Final3 = car_Speed_Final2 + 3
1232 print("Speed = ", car_Speed_Final3)
1233 zeroToSixtyMPH = zeroToSixtyMPH * 1.9
1234 # Puts original value checks the inputs then calculates final car speed
1235 if trackEntry_Number == 4 and tyreEntry_Number == 3:
1236 car_Speed_Final2 = car_Speed_Final1 - 1
1237 if driveEntry_Number == 1:
1238 car_Speed_Final3 = car_Speed_Final2 - 3
1239 print("Speed = ", car_Speed_Final3)
1240 zeroToSixtyMPH = zeroToSixtyMPH * 2.2
1241 # Puts original value checks the inputs then calculates final car speed
1242 if driveEntry_Number == 2:
1243 car_Speed_Final3 = car_Speed_Final2 - 2
1244 print("Speed = ", car_Speed_Final3)
1245 zeroToSixtyMPH = zeroToSixtyMPH * 2.1
1246 # Puts original value checks the inputs then calculates final car speed
1247 if driveEntry_Number == 3:
1248 car_Speed_Final3 = car_Speed_Final2 + 3
1249 print("Speed = ", car_Speed_Final3)
1250 zeroToSixtyMPH = zeroToSixtyMPH * 1.7
1251 # Puts original value checks the inputs then calculates final car speed
1252 if trackEntry_Number == 4 and tyreEntry_Number == 5:
1253 car_Speed_Final2 = car_Speed_Final1 + 0
1254 if driveEntry_Number == 1:
1255 car_Speed_Final3 = car_Speed_Final2 - 3
1256 print("Speed = ", car_Speed_Final3)
1257 zeroToSixtyMPH = zeroToSixtyMPH * 2.4
1258 # Puts original value checks the inputs then calculates final car speed
1259 if driveEntry_Number == 2:
1260 car_Speed_Final3 = car_Speed_Final2 - 2
1261 print("Speed = ", car_Speed_Final3)
1262 zeroToSixtyMPH = zeroToSixtyMPH * 2.2
1263 # Puts original value checks the inputs then calculates final car speed
1264 if driveEntry_Number == 3:
1265 car_Speed_Final3 = car_Speed_Final2 + 3
1266 print("Speed = ", car_Speed_Final3)
1267 zeroToSixtyMPH = zeroToSixtyMPH * 1.8
1268 # Puts original value checks the inputs then calculates final car speed
1269
1270
1271
1272 zeroToOneHundredMPH = zeroToSixtyMPH * 2.435
1273 zeroToOneHundredMPH = round(zeroToOneHundredMPH, 2)
1274 zeroToOneHundredMPH = str(zeroToOneHundredMPH)
1275 zeroToSixtyMPH = round(zeroToSixtyMPH, 2)
1276 zeroToSixtyMPH = str(zeroToSixtyMPH)
1277
1278 self.model.results_dict['top_speed'] = topSpeedMPH
1279 self.model.results_dict['0_60'] = zeroToSixtyMPH
1280 self.model.results_dict['0_100'] = zeroToOneHundredMPH
1281 self.model.results_dict['final_speed'] = car_Speed_Final3
1282
1283 print("Top speed = ", topSpeedMPH)
1284 print("Final Car Speed = ", car_Speed_Final3)
1285 print ('zeroToSixtyMPH = ', zeroToSixtyMPH)
1286 print('zeroToOneHundredMPH = ', zeroToOneHundredMPH)
1287
1288
1289# -----------------------
1290root = Tk()
1291root.grid()
1292
1293# Set the font and size
1294text = Text(root)
1295superSmallFont = Font(family="Raleway", size=12)
1296smallFont = Font(family="Raleway", size=16)
1297mediumFont = Font(family="Raleway", size=20)
1298largeFont = Font(family="Raleway", size=30)
1299root.winfo_toplevel().title("CAR SIMULATOR V_1.00")
1300myModel = Model()
1301myApp = Controller(root, myModel)
1302root.mainloop()
1303
1304# To do
1305# Remove menu screen?
1306# Save car stats
1307# User login details to database