liplated_range.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. from ctypes import Structure
  2. import pandas as pd
  3. import numpy as np
  4. import datetime
  5. import time, datetime
  6. import matplotlib.pyplot as plt
  7. from pylab import*
  8. import math
  9. import os
  10. import log
  11. path = r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\02析锂分析\各项目析锂情况_211130\增加波峰高度与峰谷比计算结果'
  12. mylog=log.Mylog('log_diag.txt','error')
  13. mylog.logcfg()
  14. def get_file(): #创建一个空列表
  15. files =os.listdir(path)
  16. files.sort() #排序
  17. file_list= []
  18. for file in files:
  19. if not os.path.isdir(path +file): #判断该文件是否是一个文件夹
  20. f_name = str(file)
  21. # print(f_name)
  22. tr = '\\' #多增加一个斜杠
  23. filename = path + tr + f_name
  24. file_list.append(filename)
  25. return file_list
  26. file_list = get_file()
  27. for file in file_list:
  28. df_lipltd_level = pd.DataFrame(columns=['sn','total_num','total_amount','liplt_num','liplated_amount','liplated_level','warnning_level'])
  29. data = pd.read_csv(file,encoding='GB18030')
  30. #----------------------------------------筛选充电后静置数据------------------------------------------------------------
  31. # MGMCLN_name = list(filter(lambda x: 'MGMCLN' in x, data['sn']))
  32. # df_MGMCLN7255 = data.loc[data['sn'].isin(MGMCLN_name)]
  33. df_MGMCLN7255_del = data.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)#去除重复值
  34. MGMCLN_list = np.unique(df_MGMCLN7255_del['sn'], return_index = False, return_inverse = False, return_counts = False)#
  35. temperature = [15, 20, 22, 21, 17, 6, 4, -0.5]#5~11月平均气温
  36. temperatuer = list(map(lambda x: x + 273.15, temperature))
  37. for item in MGMCLN_list:
  38. df_liamount = pd.DataFrame()
  39. df_amount_temp = pd.DataFrame()
  40. df_num = pd.DataFrame()
  41. df_Num_temp = pd.DataFrame()
  42. df_data_temp = df_MGMCLN7255_del.loc[df_MGMCLN7255_del['sn'] == item]
  43. df_data_temp.reset_index(drop = True,inplace=True)
  44. df_month_temp = pd.to_datetime(df_data_temp['time'])
  45. df_month = df_month_temp.dt.month
  46. df_month = list(map(lambda x: x - 5, df_month))#月份对应的温度位置
  47. for i in range(0,len(df_data_temp)):#len(df_data_temp)
  48. df_Num_temp = pd.DataFrame(eval(df_data_temp.iloc[i]['liplated']))#统计析锂次数
  49. df_num = pd.concat([df_num,df_Num_temp], axis = 1)#统计总次数
  50. df_lipltamount_temp = eval(df_data_temp.iloc[i]['liplated_amount'])#解析原数据列表
  51. df_lipltamount_corrt = 4e-17*math.exp(0.1289*temperatuer[df_month[i]])#析锂量的温度系数
  52. df_amount_temp = pd.DataFrame(list(map(lambda x: x*df_lipltamount_corrt, df_lipltamount_temp)))
  53. df_liamount = pd.concat([df_liamount,df_amount_temp], axis = 1)#按列拼接各个该sn不同时刻的析锂量,每一行为一个电芯
  54. df_sn_liamount = np.sum(df_liamount, axis = 1)#对该sn中每个电芯的析锂量求和
  55. df_total_amount = np.sum(df_sn_liamount)#所有的析锂量
  56. df_sn_num = np.sum(df_num, axis = 1)#对该sn中每个电芯析锂次数的求和
  57. df_total_num = np.sum(df_sn_num)#所有的析锂次数
  58. df_level_temp = df_sn_liamount.tolist()[:]
  59. df_temp_level = np.array(df_level_temp)
  60. df_temp_level[df_temp_level < 30] = 0
  61. df_temp_level[(df_temp_level >= 30) & (df_temp_level < 60)] = 1
  62. df_temp_level[(df_temp_level >= 60) & (df_temp_level < 90)] = 2
  63. df_temp_level[(df_temp_level >= 90) & (df_temp_level < 120)] = 3
  64. df_temp_level[(df_temp_level >= 120) & (df_temp_level < 180)] = 4
  65. df_temp_level[(df_temp_level >= 180) & (df_temp_level <240)] = 5
  66. df_temp_level[df_temp_level >= 240] = 6
  67. df_level = np.sum(df_temp_level)#电池包析锂量评级
  68. df_liplt_num = df_sn_num.tolist()
  69. df_liamount_list = df_sn_liamount.tolist()
  70. df_liplated_level = df_temp_level.tolist()
  71. df_warnning_level = df_level.tolist()
  72. df_lipltd_confir_level = pd.DataFrame({"sn":[item],"total_num":[df_total_num],"total_amount":[df_total_amount],"liplt_num":[str(df_liplt_num)], "liplated_amount":[str(df_liamount_list)], "liplated_level":[str(df_liplated_level)],"warnning_level":[str(df_warnning_level)]})
  73. df_lipltd_level = df_lipltd_level.append(df_lipltd_confir_level)
  74. df_lipltd_level = df_lipltd_level.reset_index(drop = True)
  75. df_lipltd_level.sort_values(by = ['total_amount'], ascending=False,inplace=True)#对故障信息按照时间进行排序
  76. temp = file.split('\\')
  77. sn_name = temp[-1].split('.')[0]
  78. title = sn_name
  79. df_lipltd_level.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\02析锂分析\各项目析锂情况_211130\增加波峰高度与峰谷比计算结果\\'+ sn_name + '析锂排序.csv',index=False,encoding='GB18030')
  80. # df_li_amount = df_data_temp['liplated_amount']
  81. # #--------------------------------------------------------确认是否析锂----------------------------------------------------------------------------
  82. # # df_lipltd_data = pd.DataFrame(columns=['sn','date','liplated'])
  83. # for item in range(0,k):
  84. # lipltd_confirm = []
  85. # lipltd_amount = []
  86. # df_check_liplated_temp = df_rest_volt_diffdt.loc[df_rest_volt_diffdt['chrgr_rest'] == item].reset_index(drop = True)
  87. # df_lipltd_volt_temp = df_check_liplated_temp[cellvolt_list]
  88. # df_lipltd_volt_len = len(df_lipltd_volt_temp)
  89. # df_data_temp_add = df_lipltd_volt_temp.iloc[df_lipltd_volt_len-4:df_lipltd_volt_len-1]
  90. # df_lipltd_volt_temp_add = df_lipltd_volt_temp.append(df_data_temp_add)
  91. # df_lipltd_volt_temp_dif = np.diff(df_lipltd_volt_temp_add,axis=0)#电压一次微分,计算dv/dt
  92. # df_lipltd_volt_temp_dif = pd.DataFrame(df_lipltd_volt_temp_dif)
  93. # df_lipltd_volt_temp_dif.columns = cellvolt_list
  94. # df_lipltd_volt_temp_difdif = np.diff(df_lipltd_volt_temp_dif,axis=0)#电压二次微分,判断升降
  95. # df_lipltd_volt_temp_difdif = pd.DataFrame(df_lipltd_volt_temp_difdif)
  96. # df_lipltd_volt_temp_difdif.columns = cellvolt_list
  97. # df_lipltd_volt_temp_difdif_temp = df_lipltd_volt_temp_difdif
  98. # df_lipltd_volt_temp_difdif_temp[df_lipltd_volt_temp_difdif_temp >= 0] = 1
  99. # df_lipltd_volt_temp_difdif_temp[df_lipltd_volt_temp_difdif_temp < 0] = -1
  100. # df_lipltd_volt_temp_difdifdif = np.diff(df_lipltd_volt_temp_difdif_temp,axis=0)#三次微分,利用-2,2判断波分和波谷
  101. # df_lipltd_volt_difdifdif = pd.DataFrame(df_lipltd_volt_temp_difdifdif)
  102. # df_lipltd_volt_difdifdif.columns = cellvolt_list
  103. # df_lipltd_volt_difdifdif['chrgr_rest'] = k
  104. # df_lipltd_volt_difdifdif['时间戳'] = list(df_check_liplated_temp['时间戳'])
  105. # df_lipltd_volt_difdifdif = df_lipltd_volt_difdifdif.reset_index(drop = True)
  106. # df_lipltd_data_temp = df_lipltd_volt_difdifdif.loc[df_lipltd_volt_difdifdif['时间戳'] < (df_check_liplated_temp['时间戳'][0] + datetime.timedelta(minutes=90))]
  107. # for cell_name in cellvolt_list:#对每个电芯判断
  108. # df_check_plated_data = df_lipltd_data_temp[cell_name]
  109. # peak_pos = np.where(df_check_plated_data == -2)
  110. # bot_pos = np.where(df_check_plated_data == 2)
  111. # if len(peak_pos[0]) & len(bot_pos[0]):
  112. # if (peak_pos[0][0] > bot_pos[0][0]) & (df_lipltd_volt_temp_dif[cell_name][peak_pos[0][0] + 1] < 0):
  113. # lipltd_confirm.append(1)#1为析锂,0为非析锂
  114. # lipltd_amount.append((df_check_liplated_temp['时间戳'][bot_pos[0][0] + 2] - df_check_liplated_temp['时间戳'][0])/pd.Timedelta(1, 'min'))
  115. # else:
  116. # lipltd_confirm.append(0)
  117. # lipltd_amount.append(0)
  118. # else:
  119. # lipltd_confirm.append(0)
  120. # lipltd_amount.append(0)
  121. # if any(lipltd_confirm) & (max(lipltd_amount) > 5):
  122. # df_lipltd_confir_temp = pd.DataFrame({"sn":['sn'], "time":[df_check_liplated_temp['时间戳'][0]], "liplated":[str(lipltd_confirm)], "liplated_amount":[str(lipltd_amount)]})
  123. # df_lipltd_data = df_lipltd_data.append(df_lipltd_confir_temp)
  124. # df_lipltd_data = df_lipltd_data.reset_index(drop = True)
  125. # df_lipltd_data.sort_values(by = ['time'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  126. # df_lipltd_data.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\MGMCLN750N215N049\析锂检测.csv',index=False,encoding='GB18030')
  127. # # for i in range(1,k):
  128. # # # fig = plt.figure(figsize=(20,10))
  129. # # df_fig = df_rest_volt_diffdt.loc[df_rest_volt_diffdt['chrgr_rest'] == i]
  130. # # df_fig = df_fig.reset_index(drop=True)
  131. # # length = len(df_fig)
  132. # # for volt_num in cellvolt_name[5:6]:
  133. # # # plt.scatter([x for x in range(0, length)], df_fig[volt_num][0:length], label=volt_num)
  134. # # plt.plot(df_fig['时间戳'], df_fig[volt_num],linewidth = 2, linestyle = '-', marker = 's',label=volt_num)
  135. # # plt.rcParams['font.family']=['SimHei']
  136. # # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  137. # # plt.legend()
  138. # # temp = file.split('\\')
  139. # # sn_name = temp[9].split('.')[0]
  140. # # title = sn_name + '-' + df_fig['时间戳'][0].strftime('%y-%m-%d')#df_fig['device_id'][0] + '-' +
  141. # # print(type(title))
  142. # # plt.xlabel('时间', fontsize=14)
  143. # # plt.ylabel('电压的时间微分(mv/min)', fontsize=14)
  144. # # plt.xlim(df_fig['时间戳'][0]-datetime.timedelta(minutes=5),df_fig['时间戳'][0] + datetime.timedelta(hours=3))
  145. # # # plt.ylim(-2.5,0.5)
  146. # # plt.title(title)
  147. # # plt.savefig(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\MGMCLN750N215N049\\'+title+'.png', dpi=300)
  148. # # # plt.show()
  149. # fig = plt.figure(figsize=(20,10))
  150. # for i in range(3,4):#0,k
  151. # # fig = plt.figure(figsize=(20,10))
  152. # df_fig = df_rest_volt_diffdt.loc[df_rest_volt_diffdt['chrgr_rest'] == i]
  153. # df_fig = df_fig.reset_index(drop=True)
  154. # length = len(df_fig)
  155. # temp = file.split('\\')
  156. # sn_name = temp[9].split('.')[0]
  157. # title = sn_name + '-' + df_fig['时间戳'][0].strftime('%y-%m-%d')#df_fig['device_id'][0] + '-' +
  158. # plt_data_len = len(df_fig)
  159. # # for volt_num in cellvolt_name[5:6]:
  160. # # plt.scatter([x for x in range(0, length)], df_fig[volt_num][0:length], label=volt_num)
  161. # # plt.plot([x for x in range(0, plt_data_len)], df_fig[cellvolt_name[5]],linewidth = 2, linestyle = '-', marker = 's',label = title)
  162. # # plt.plot([x for x in range(0, plt_data_len)], df_fig[cellvolt_name[2]],linewidth = 2, linestyle = '-', marker = 's',label = title)
  163. # plt.plot(df_fig['时间戳'], df_fig[cellvolt_name[5]],linewidth = 2, linestyle = '-', marker = 's',label = cellvolt_name[5])
  164. # mpl.rcParams['font.sans-serif']=['SimHei']
  165. # mpl.rcParams['axes.unicode_minus']=False #用来正常显示负号
  166. # plt.legend()
  167. # plt.xlabel('采样点', fontsize=14)
  168. # plt.ylabel('电压的时间微分(mv/min)', fontsize=14)
  169. # plt.xlim(df_fig['时间戳'][0]-datetime.timedelta(minutes=5),df_fig['时间戳'][0] + datetime.timedelta(hours=5))
  170. # # plt.xlim(0, 60)
  171. # # plt.ylim(-2.5,0.5)
  172. # plt.title('6#电芯不同时间电压微分曲线')
  173. # plt.savefig(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\MGMCLN750N215N049\\'+'6#电芯析锂'+'.png', dpi=300)
  174. # # plt.show()