voltrange.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import pandas as pd
  2. from sqlalchemy import create_engine
  3. import numpy as np
  4. def cellVolt_rang(sn,df_bms):
  5. #电压排序................................................................................................................................................................
  6. print('--------计算中----------')
  7. sn_choose1 = []
  8. # sn_choose2 = []
  9. # sn_choose3 = []
  10. # sn_choose4 = []
  11. temp1 = pd.DataFrame()
  12. # temp2 = pd.DataFrame()
  13. # temp3 = pd.DataFrame()
  14. # temp4 = pd.DataFrame()
  15. df_temp_crnt = df_bms[df_bms['current']>1]#筛选充电数据
  16. df_temp = df_temp_crnt[df_temp_crnt['position']==2]#筛选充电数据
  17. if not df_temp.empty:
  18. df_chrgr = df_temp.reset_index(drop=True)
  19. df_chrgr_cellvolt = df_chrgr[['cellvolt_2','cellvolt_3','cellvolt_4','cellvolt_5','cellvolt_6','cellvolt_7','cellvolt_8','cellvolt_9']]
  20. df_chrgr_cellvolt_change = np.array(df_chrgr_cellvolt)#转数组
  21. df_chrgr_cellvolt_sort = np.argsort(df_chrgr_cellvolt_change)#取排序号
  22. df_sort_change = pd.DataFrame(df_chrgr_cellvolt_sort)
  23. df_sort_set = df_sort_change.apply(pd.value_counts)#计算各列出现排列序号的次数
  24. df_sort_set.fillna(0, inplace=True)#Na值填充0
  25. df_sort_set_change = np.array(df_sort_set)
  26. df_sort_set_change_sort = np.sort(df_sort_set_change, axis = 0)#计算各电芯出现排列序号的次数
  27. X_col=np.size(df_chrgr_cellvolt,0) #计算 X 的列数
  28. if X_col > 0:
  29. temp_list1 = df_sort_set_change_sort[:,7] > 0.5*X_col
  30. temp_list2 = df_sort_set_change_sort[:,6] > 0.4*X_col
  31. # temp_list1 = np.max(df_sort_set,axis=0)
  32. # temp_list = temp_list1 < X_col/2
  33. # for i in range(0,8):
  34. # temp_list1 = (max(df_sort_set[i]) < 2*X_col/3)
  35. # temp_list = temp_list1.append(temp_list1)
  36. if np.count_nonzero(temp_list1 & temp_list2) >= 2:#序号变化的电芯
  37. # data_temp = pd.DataFrame(df_chrgr_cellvolt_sort)
  38. # problem_data = pd.concat([df_chrgr,data_temp], axis = 1)
  39. sn_choose1.append(sn)
  40. temp1 = pd.DataFrame(sn_choose1)
  41. # if any(temp_list2):
  42. # sn_choose2.append(sn)
  43. # temp2 = pd.DataFrame(sn_choose2)
  44. # if any(temp_list1 & temp_list2):
  45. # sn_choose3.append(sn)
  46. # temp3 = pd.DataFrame(sn_choose3)
  47. # if any(temp_list3):
  48. # sn_choose4.append(sn)
  49. # temp4 = pd.DataFrame(sn_choose4)
  50. #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')
  51. #保存数据这个位置改为保存sn号
  52. #end=time.time()
  53. # print('--------------计算时间:------------')
  54. # print(end-start)
  55. # print(df_soh)
  56. return temp1#,temp2,temp3,temp4