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 = []
- # 使用enumerate来跟踪分组的顺序(模拟全局索引的奇偶性)
- for idx, (name, group) in enumerate(LKA_left_groups, start=1):
- result_time = []
- # 获取片段的simTime值
- sim_times = group['simTime'].tolist()
- # 根据分组的奇偶性(即这里的idx)选择simTime
- # if idx % 2 == 0:
- # 偶数组,选择第一个
- 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)
|