12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import numpy as np
- import pandas as pd
- STANDBY = 0
- RIGHT_WARNING = 2
- class LKA_Trigger():
- def __init__(self, df_vehState):
- self.df_vehState = df_vehState
- def lane_keep_warning_status(self, left_or_right):
- '''
- :return:
- start_vehstate: 状态机开始的时间,以列表形式存储
- close_vehstate:状态机结束的时间,以列表形式存储
- '''
- groups = (self.df_vehState['LKA_status'] != self.df_vehState['LKA_status'].shift()).cumsum()
- LKA_left_groups = self.df_vehState[self.df_vehState['LKA_status'] == left_or_right].groupby(groups)
-
- result_times = []
-
- for idx, (name, group) in enumerate(LKA_left_groups, start=1):
- result_time = []
-
- sim_times = group['simTime'].tolist()
-
-
-
- if sim_times:
- result_time.append(sim_times[-1])
- result_time.append(sim_times[-1])
- result_times.append(result_time)
- return result_times
- def LKA_warning_active_time_statistics(self):
- warning_status_time_dict = {}
- left_warning = 1
- right_warning = 2
- LKA_left_vehstate = self.lane_keep_warning_status(left_warning)
- LKA_right_vehstate = self.lane_keep_warning_status(right_warning)
- warning_status_time_dict['LKA_left_active_time'] = LKA_left_vehstate
- warning_status_time_dict['LKA_right_active_time'] = LKA_right_vehstate
- return warning_status_time_dict
- if __name__ == '__main__':
- df_vehState = pd.read_csv(r"D:\Cicv\Lantu\数据\LKA_data2\data\VehState.csv")
- LKA = LKA_Trigger(df_vehState)
- vehstate = LKA.LKA_warning_active_time_statistics()
- print(vehstate)
|