def drop_out_check(self): race_time = calc_millisec(self.race_time) total_time = calc_millisec(self.total_time) if race_time - total_time > 20 * 60 * 1000: # 20 min return True else: return False
def test_time_parser(self): self.assertEqual(1, calc_millisec("00:00:00.001")) self.assertEqual(2, calc_millisec("00:00:00.002")) self.assertEqual(3, calc_millisec("00:00:00.003")) self.assertEqual(1100, calc_millisec("00:00:01.100")) self.assertEqual(61000, calc_millisec("00:01:01.000"))
def gen_last_pit_time(file_name): if file_name != 'N/A': with open(file_name, 'r') as passings_csv: passings_obj = csv.reader(passings_csv) passings_dict = {} for passing in passings_obj: try: if 'P' in passing[3]: if passing[1] in passings_dict: if passings_dict[passing[1]] < calc_millisec( passing[7]): passings_dict[passing[1]] = calc_millisec( passing[7]) elif passing[1] != '': passings_dict[passing[1]] = calc_millisec( passing[7]) except IndexError: time.sleep(1) return gen_last_pit_time(file_name) return passings_dict else: log_print( 'Fatal Error: attempting to generate last pit time with no passings file name given' ) log_print('Ending program')
def normal_lap_check(self): if self.last_time != 'IN PIT' and self.last_time != '': abs_lap_diff = abs( calc_millisec(self.last_time) - calc_millisec(self.best_lap_time)) if abs_lap_diff < 30 * 1000 and (not self.drop_out_triggered): return True else: return False else: return True # if last time is not a times stamp then it is considered a normal lap
def __init__(self, reg_num, init_stint_info): self.reg_num = reg_num self.initial_stint_info = init_stint_info self.car_num = self.initial_stint_info[reg_num]['car_number'] self.pit_time = calc_millisec( self.initial_stint_info[reg_num]['total_time']) self.last_time_line = self.initial_stint_info[reg_num][ 'last_time_line'] self.pit_msg_sent = False self.over_stint_triggered = False
def check_time(self, last_time): self.flag = get_race_data()['flag'] # refresh to current flag status not_triggered = (not self.msg_triggered) and ( not self.drop_out_triggered) if self.flag == 'green': # ignore abnormal laps when not green self.refresh_info() not_out_lap = self.laps_since_pit > 1 # only checks laps after pit out lap if not_out_lap: best_time_ms = calc_millisec(self.best_lap_time) abnormal_short = best_time_ms + (60 * 1000) <= last_time < ( best_time_ms * 2) over_double = ( best_time_ms * 2) <= last_time < (best_time_ms * 2) + (30 * 1000) abnormal_long = (best_time_ms * 2) + ( 30 * 1000) <= last_time < (20 * 60 * 1000) - last_time if abnormal_short and not_triggered: self.message_trigger() log_print( 'Car {carnum} is 1 min over their avg laptime at {time}' .format(carnum=self.car_num, time=self.total_time)) elif over_double and not_triggered: self.message_trigger() log_print( 'Car {carnum} has a lap twice their avg at {time}'. format(carnum=self.car_num, time=self.total_time)) elif abnormal_long and not_triggered: self.message_trigger() log_print( 'Car {carnum} has an abnormally long lap at: {time}'. format(carnum=self.car_num, time=self.total_time)) elif self.normal_lap_check(): self.normal_lap() if self.drop_out_check() and not_triggered: self.drop_out() log_print( 'Car {carnum} has not hit for 20 mins, last crossing at {time}' .format(carnum=self.car_num, time=self.total_time))
def start_abnormal_lap_check(team_obj_dict): leader_board = get_leader_board() if len(team_obj_dict) < len(leader_board): new_driver = add_driver(team_obj_dict, leader_board) team_obj_dict[new_driver.reg_num] = new_driver log_print('{carnum} added to Lap-Checker'.format( carnum=team_obj_dict[new_driver.car_num])) for driver_key in team_obj_dict: driver = team_obj_dict[driver_key] if driver.reg_num not in leader_board: instantiate_team_lap_check() log_print('Reinstantiating TeamLapCheck') break driver_last_time = leader_board[driver.reg_num]['last_time'] if (driver_last_time != '') and (driver_last_time != 'IN PIT'): new_lap_time = calc_millisec(driver_last_time) driver.check_time(new_lap_time) time.sleep(refreshrate)
def start_driver_stint_check(driver_stint_dict): stint_info = get_stint_info() if len(driver_stint_dict) < len(stint_info): new_driver = add_driver(driver_stint_dict, stint_info) driver_stint_dict[new_driver.reg_num] = new_driver log_print('{carnum} added to Stint-Checker'.format( carnum=new_driver.car_num)) for driver_key in driver_stint_dict: driver = driver_stint_dict[driver_key] if driver.reg_num not in stint_info: log_print( 'Car {carnum} is missing from the scoreboard feed and is no longer being monitored!' .format(carnum=driver.car_num)) driver_stint_dict.pop(driver_key) # this needs testing break new_driver_info = stint_info[driver.reg_num] driver.last_time_line = new_driver_info['last_time_line'] new_lap_time = calc_millisec(new_driver_info['total_time']) if driver.last_time_line == "Start/Finish": driver.pit_msg_sent = False if driver.stint_check( new_lap_time) and not driver.over_stint_triggered: driver.over_stint() current_time_stamp = fix_time( stint_info[driver.reg_num]['total_time']) log_print( '{carnum} is nearing their 2 hour driver stint at {time}'. format(carnum=driver.car_num, time=current_time_stamp)) else: driver.pit_stop(new_driver_info['last_time_line'], new_lap_time) if not driver.pit_msg_sent: log_only('Pit Stop: {carnum} at {time}'.format( carnum=driver.car_num, time=new_driver_info['total_time'])) driver.pit_msg_sent = True time.sleep(refresh_rate)