import numpy as np
import pandas as pd
from ACC_Trigger import ACC_Trigger
import warnings
warnings.filterwarnings("ignore", category=FutureWarning, module='pandas')
pd.set_option('future.no_silent_downcasting', True)

ICA_CONSTANT_SPEED = 3
ICA_FOLLOW_CAR = 4
ICA_y = 5

class ICA_Trigger():
    def __init__(self, df_vehState, df_ego, df_objstate):
        self.df_vehState = df_vehState
        self.df_ego = df_ego
        self.df_objstate = df_objstate

    def vehstate_recognize(self):
        ICA_start_end_time_dict = {}
        # 寻找ICA相应状态机下的simTime和set_cruise_speed数据
        constant_speed_time = self.df_vehState[self.df_vehState['ICA_status'] == ICA_CONSTANT_SPEED]['simTime'].tolist()

        follow_car_time = self.df_vehState[self.df_vehState['ICA_status'] == ICA_FOLLOW_CAR]['simTime'].tolist()

        y_time_list = self.df_vehState[self.df_vehState['ICA_status'] == ICA_y]['simTime'].tolist()

        ACC = ACC_Trigger(self.df_vehState, self.df_ego, self.df_objstate)
        ICA_speed_start_end_time_list = ACC.find_start_end_time(constant_speed_time)
        ICA_dist_start_end_time_list = ACC.find_start_end_time(follow_car_time)
        ICA_y_start_end_time_list = ACC.find_start_end_time(y_time_list)

        ICA_start_end_time_dict['ICA_cruise_time'] = ICA_speed_start_end_time_list
        ICA_start_end_time_dict['ICA_following_car_time'] = ICA_dist_start_end_time_list
        ICA_start_end_time_dict['ICA_vertical_time'] = ICA_y_start_end_time_list

        return ICA_start_end_time_dict

if __name__ == '__main__':
    df_vehState = pd.read_csv(r"D:\Cicv\Lantu\数据\VOYAH_ICA1\data\VehState.csv")
    df_ego = pd.read_csv(r"D:\Cicv\Lantu\数据\VOYAH_ICA1\data\EgoState.csv")
    df_objstate = pd.read_csv(r"D:\Cicv\Lantu\数据\VOYAH_ICA1\data\ObjState.csv")
    ICA = ICA_Trigger(df_vehState, df_ego, df_objstate)
    vehstate = ICA.vehstate_recognize()
    print(vehstate)
