# 获取数据
import pandas as pd
from LIB.BACKEND import DataPreProcess


def status_sta(df_bms, df_gps, start_time, charge_count, drive_count, stand_count, factory='骑享'):
    dataPrePro = DataPreProcess.DataPreProcess()
    if not df_bms.empty:
        if factory == '骑享':
        # 时间完全相同的数据仅保留一行
            df_bms_pro, df_gps_pro = dataPrePro.time_filter(df_bms, df_gps)

            # bms数据按照电流和状态分段, 然后在状态分段内部，根据时间跳变继续分段（解决段内数据丢失）

            df_bms_pro = dataPrePro.data_split_by_status(df_bms_pro)
            df_bms_pro = dataPrePro.data_split_by_time(df_bms_pro)

            if 'charge' in df_bms_pro['data_status'].tolist():
                charge_count = charge_count + 1
            elif 'drive' in df_bms_pro['data_status'].tolist():
                drive_count = drive_count + 1
            else:
                stand_count = stand_count + 1
        elif factory == '金茂':
            if 4 in df_bms['充电状态'].tolist():
                charge_count = charge_count + 1
            elif 3 in df_bms['充电状态'].tolist() or 5 in df_bms['充电状态'].tolist():
                drive_count = drive_count + 1
            else:
                stand_count = stand_count + 1
    else:
        stand_count = stand_count + 1
                

    return charge_count, drive_count, stand_count
    
    