12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import pandas as pd
- from sqlalchemy import create_engine
- import numpy as np
- def cellVolt_rang(sn,df_bms):
- #电压排序................................................................................................................................................................
- print('--------计算中----------')
- sn_choose1 = []
- # sn_choose2 = []
- # sn_choose3 = []
- # sn_choose4 = []
- temp1 = pd.DataFrame()
- # temp2 = pd.DataFrame()
- # temp3 = pd.DataFrame()
- # temp4 = pd.DataFrame()
- df_temp_crnt = df_bms[df_bms['current']>1]#筛选充电数据
- df_temp = df_temp_crnt[df_temp_crnt['position']==2]#筛选充电数据
- if not df_temp.empty:
- df_chrgr = df_temp.reset_index(drop=True)
- df_chrgr_cellvolt = df_chrgr[['cellvolt_2','cellvolt_3','cellvolt_4','cellvolt_5','cellvolt_6','cellvolt_7','cellvolt_8','cellvolt_9']]
- df_chrgr_cellvolt_change = np.array(df_chrgr_cellvolt)#转数组
- df_chrgr_cellvolt_sort = np.argsort(df_chrgr_cellvolt_change)#取排序号
- df_sort_change = pd.DataFrame(df_chrgr_cellvolt_sort)
- df_sort_set = df_sort_change.apply(pd.value_counts)#计算各列出现排列序号的次数
- df_sort_set.fillna(0, inplace=True)#Na值填充0
- df_sort_set_change = np.array(df_sort_set)
- df_sort_set_change_sort = np.sort(df_sort_set_change, axis = 0)#计算各电芯出现排列序号的次数
- X_col=np.size(df_chrgr_cellvolt,0) #计算 X 的列数
- if X_col > 0:
- temp_list1 = df_sort_set_change_sort[:,7] > 0.5*X_col
- temp_list2 = df_sort_set_change_sort[:,6] > 0.4*X_col
- # temp_list1 = np.max(df_sort_set,axis=0)
- # temp_list = temp_list1 < X_col/2
- # for i in range(0,8):
- # temp_list1 = (max(df_sort_set[i]) < 2*X_col/3)
- # temp_list = temp_list1.append(temp_list1)
- if np.count_nonzero(temp_list1 & temp_list2) >= 2:#序号变化的电芯
- # data_temp = pd.DataFrame(df_chrgr_cellvolt_sort)
- # problem_data = pd.concat([df_chrgr,data_temp], axis = 1)
- sn_choose1.append(sn)
- temp1 = pd.DataFrame(sn_choose1)
- # if any(temp_list2):
- # sn_choose2.append(sn)
- # temp2 = pd.DataFrame(sn_choose2)
- # if any(temp_list1 & temp_list2):
- # sn_choose3.append(sn)
- # temp3 = pd.DataFrame(sn_choose3)
- # if any(temp_list3):
- # sn_choose4.append(sn)
- # temp4 = pd.DataFrame(sn_choose4)
-
- #df_chrgr_cellvolt_sort.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'CBMS_diag_'+sn+'.csv',encoding='gbk')
- #保存数据这个位置改为保存sn号
- #end=time.time()
- # print('--------------计算时间:------------')
- # print(end-start)
- # print(df_soh)
- return temp1#,temp2,temp3,temp4
|