import pandas as pd import numpy as np from datetime import datetime import datetime from tqdm import tqdm from scipy.interpolate import interp1d from ZlwlAlgosCommon.utils.ProUtils import * from ZlwlAlgosCommon.service.iotp.IotpAlgoService import IotpAlgoService from ZlwlAlgosCommon.service.iotp.Beans import DataField from ZlwlAlgosCommon.orm.models import * from Data_Cleaning_oop_thr import DataCleaning input_file_list = '/home/limingze/zlwl-algos/USER/limingze/Inconsistency/algo_soh_zk.csv' output_path = '/home/limingze/zlwl-algos/USER/limingze/Inconsistency/Data/' t_device_path = '/home/limingze/zlwl-algos/USER/limingze/Inconsistency/t_device_zk.csv' pack_param_path = '/home/limingze/zlwl-algos/USER/limingze/Inconsistency/algo_pack_param.csv' history_file = '/home/limingze/zlwl-algos/USER/limingze/Inconsistency/Data/update.csv' df_in_list = pd.read_csv(input_file_list) t_device = pd.read_csv(t_device_path) pack_param = pd.read_csv(pack_param_path) history_df = pd.read_csv(history_file) CellVoltNums_list = [] for a in tqdm(range(len(df_in_list))): sn = df_in_list['sn'][a] pack_model_a = t_device.loc[t_device['sn'] == sn, 'pack_model'].values[0] pack_param_a = pack_param.loc[pack_param['pack_code'] == pack_model_a, 'param'].values[0] CellVoltNums_a = eval(json.loads(pack_param_a)['CellVoltTotalCount']) CellVoltNums_list.append(CellVoltNums_a) CellVoltNums = max(CellVoltNums_list) cell_soc_seg_begin_chr_name = ['cell_soc_begin_chr'+str(x) for x in range(1, CellVoltNums+1)] cell_soc_seg_stop_chr_name = ['cell_soc_stop_chr'+str(x) for x in range(1, CellVoltNums+1)] cell_soc_seg_begin_dis_name = ['cell_soc_begin_dis'+str(x) for x in range(1, CellVoltNums+1)] cell_soc_seg_stop_dis_name = ['cell_soc_stop_dis'+str(x) for x in range(1, CellVoltNums+1)] pack_soc_seg_name = ['pack_soc_begin_chr','pack_soc_stop_chr','pack_soc_begin_dis','pack_soc_stop_dis'] cell_soc_mmm_name = ['cell_soc_begin_chr_max','cell_soc_begin_chr_min','cell_soc_begin_chr_diff','cell_soc_begin_chr_mean', 'cell_soc_begin_dis_max','cell_soc_begin_dis_min','cell_soc_begin_dis_diff','cell_soc_begin_dis_mean'] soc_name = cell_soc_seg_begin_chr_name + cell_soc_seg_stop_chr_name + cell_soc_seg_begin_dis_name + cell_soc_seg_stop_dis_name + pack_soc_seg_name + cell_soc_mmm_name soc_name.append('dod') df_soc_seg = pd.DataFrame(columns=soc_name, index=df_in_list.index) cell_delta_energy_chr_name = ['cell_delta_energy_chr'+str(x) for x in range(1, CellVoltNums+1)] cell_delta_energy_dis_name = ['cell_delta_energy_dis'+str(x) for x in range(1, CellVoltNums+1)] delta_energy_name = cell_delta_energy_chr_name + cell_delta_energy_dis_name + ['pack_delta_energy_chr'] + ['pack_delta_energy_dis'] df_energy = pd.DataFrame(columns=delta_energy_name, index=df_in_list.index) cell_res_name = ['cell_res'+str(x) for x in range(1, CellVoltNums+1)] res_name = cell_res_name + ['cell_res_mean'] + ['cell_res_diff'] df_res = pd.DataFrame(columns=res_name, index=df_in_list.index) sn = 'PJXCLL532S234M001' start_time = datetime.datetime.strptime('2023-5-10 04:56:00'.split()[0] + " 00:00:00", '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') end_time = datetime.datetime.strptime('2023-5-14 06:18:00'.split()[0] + " 23:59:59", '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') cur_env = 'dev' # 设置运行环境 app_path = "/home/limingze/zlwl-algos/" # 设置app绝对路径 sysUtils = SysUtils(cur_env, app_path) hbase_params = sysUtils.get_cf_param('hbase-datafactory') iotp_service = IotpAlgoService(hbase_params=hbase_params) columns = [ DataField.time, DataField.sn, DataField.pack_crnt, DataField.pack_volt, DataField.pack_soc, DataField.cell_voltage, DataField.cell_temp, DataField.bms_sta, DataField.cell_voltage_count] df_data = iotp_service.get_data(sn_list=[sn], columns=columns, start_time=start_time, end_time=end_time) data_clean = DataCleaning(df_data) data_clean = data_clean.revise_status_codes() data_clean['time'] = pd.to_datetime(data_clean['time']) data_clean.to_csv(output_path + str(sn) + '_' + str(start_time).split()[0] + '_' + str(end_time).split()[0] + '_ceshi.csv', encoding="utf_8_sig", index=False)