123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- from ctypes import Structure
- import pandas as pd
- import numpy as np
- import datetime
- import time, datetime
- import matplotlib.pyplot as plt
- from pylab import*
- import math
- import os
- import log
- path = r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\02析锂分析\各项目析锂情况_211130\增加波峰高度与峰谷比计算结果'
- mylog=log.Mylog('log_diag.txt','error')
- mylog.logcfg()
- def get_file(): #创建一个空列表
- files =os.listdir(path)
- files.sort() #排序
- file_list= []
- for file in files:
- if not os.path.isdir(path +file): #判断该文件是否是一个文件夹
- f_name = str(file)
- # print(f_name)
- tr = '\\' #多增加一个斜杠
- filename = path + tr + f_name
- file_list.append(filename)
- return file_list
- file_list = get_file()
- for file in file_list:
- df_lipltd_level = pd.DataFrame(columns=['sn','total_num','total_amount','liplt_num','liplated_amount','liplated_level','warnning_level'])
- data = pd.read_csv(file,encoding='GB18030')
- #----------------------------------------筛选充电后静置数据------------------------------------------------------------
- # MGMCLN_name = list(filter(lambda x: 'MGMCLN' in x, data['sn']))
- # df_MGMCLN7255 = data.loc[data['sn'].isin(MGMCLN_name)]
- df_MGMCLN7255_del = data.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)#去除重复值
- MGMCLN_list = np.unique(df_MGMCLN7255_del['sn'], return_index = False, return_inverse = False, return_counts = False)#
- temperature = [15, 20, 22, 21, 17, 6, 4, -0.5]#5~11月平均气温
- temperatuer = list(map(lambda x: x + 273.15, temperature))
- for item in MGMCLN_list:
- df_liamount = pd.DataFrame()
- df_amount_temp = pd.DataFrame()
- df_num = pd.DataFrame()
- df_Num_temp = pd.DataFrame()
- df_data_temp = df_MGMCLN7255_del.loc[df_MGMCLN7255_del['sn'] == item]
- df_data_temp.reset_index(drop = True,inplace=True)
- df_month_temp = pd.to_datetime(df_data_temp['time'])
- df_month = df_month_temp.dt.month
- df_month = list(map(lambda x: x - 5, df_month))#月份对应的温度位置
- for i in range(0,len(df_data_temp)):#len(df_data_temp)
- df_Num_temp = pd.DataFrame(eval(df_data_temp.iloc[i]['liplated']))#统计析锂次数
- df_num = pd.concat([df_num,df_Num_temp], axis = 1)#统计总次数
- df_lipltamount_temp = eval(df_data_temp.iloc[i]['liplated_amount'])#解析原数据列表
- df_lipltamount_corrt = 4e-17*math.exp(0.1289*temperatuer[df_month[i]])#析锂量的温度系数
- df_amount_temp = pd.DataFrame(list(map(lambda x: x*df_lipltamount_corrt, df_lipltamount_temp)))
- df_liamount = pd.concat([df_liamount,df_amount_temp], axis = 1)#按列拼接各个该sn不同时刻的析锂量,每一行为一个电芯
- df_sn_liamount = np.sum(df_liamount, axis = 1)#对该sn中每个电芯的析锂量求和
- df_total_amount = np.sum(df_sn_liamount)#所有的析锂量
- df_sn_num = np.sum(df_num, axis = 1)#对该sn中每个电芯析锂次数的求和
- df_total_num = np.sum(df_sn_num)#所有的析锂次数
- df_level_temp = df_sn_liamount.tolist()[:]
- df_temp_level = np.array(df_level_temp)
- df_temp_level[df_temp_level < 30] = 0
- df_temp_level[(df_temp_level >= 30) & (df_temp_level < 60)] = 1
- df_temp_level[(df_temp_level >= 60) & (df_temp_level < 90)] = 2
- df_temp_level[(df_temp_level >= 90) & (df_temp_level < 120)] = 3
- df_temp_level[(df_temp_level >= 120) & (df_temp_level < 180)] = 4
- df_temp_level[(df_temp_level >= 180) & (df_temp_level <240)] = 5
- df_temp_level[df_temp_level >= 240] = 6
- df_level = np.sum(df_temp_level)#电池包析锂量评级
- df_liplt_num = df_sn_num.tolist()
- df_liamount_list = df_sn_liamount.tolist()
- df_liplated_level = df_temp_level.tolist()
- df_warnning_level = df_level.tolist()
- 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)]})
- df_lipltd_level = df_lipltd_level.append(df_lipltd_confir_level)
- df_lipltd_level = df_lipltd_level.reset_index(drop = True)
- df_lipltd_level.sort_values(by = ['total_amount'], ascending=False,inplace=True)#对故障信息按照时间进行排序
- temp = file.split('\\')
- sn_name = temp[-1].split('.')[0]
- title = sn_name
- 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')
-
-
- # df_li_amount = df_data_temp['liplated_amount']
- # #--------------------------------------------------------确认是否析锂----------------------------------------------------------------------------
- # # df_lipltd_data = pd.DataFrame(columns=['sn','date','liplated'])
- # for item in range(0,k):
- # lipltd_confirm = []
- # lipltd_amount = []
- # df_check_liplated_temp = df_rest_volt_diffdt.loc[df_rest_volt_diffdt['chrgr_rest'] == item].reset_index(drop = True)
- # df_lipltd_volt_temp = df_check_liplated_temp[cellvolt_list]
- # df_lipltd_volt_len = len(df_lipltd_volt_temp)
- # df_data_temp_add = df_lipltd_volt_temp.iloc[df_lipltd_volt_len-4:df_lipltd_volt_len-1]
- # df_lipltd_volt_temp_add = df_lipltd_volt_temp.append(df_data_temp_add)
- # df_lipltd_volt_temp_dif = np.diff(df_lipltd_volt_temp_add,axis=0)#电压一次微分,计算dv/dt
- # df_lipltd_volt_temp_dif = pd.DataFrame(df_lipltd_volt_temp_dif)
- # df_lipltd_volt_temp_dif.columns = cellvolt_list
- # df_lipltd_volt_temp_difdif = np.diff(df_lipltd_volt_temp_dif,axis=0)#电压二次微分,判断升降
- # df_lipltd_volt_temp_difdif = pd.DataFrame(df_lipltd_volt_temp_difdif)
- # df_lipltd_volt_temp_difdif.columns = cellvolt_list
- # df_lipltd_volt_temp_difdif_temp = df_lipltd_volt_temp_difdif
- # df_lipltd_volt_temp_difdif_temp[df_lipltd_volt_temp_difdif_temp >= 0] = 1
- # df_lipltd_volt_temp_difdif_temp[df_lipltd_volt_temp_difdif_temp < 0] = -1
- # df_lipltd_volt_temp_difdifdif = np.diff(df_lipltd_volt_temp_difdif_temp,axis=0)#三次微分,利用-2,2判断波分和波谷
- # df_lipltd_volt_difdifdif = pd.DataFrame(df_lipltd_volt_temp_difdifdif)
- # df_lipltd_volt_difdifdif.columns = cellvolt_list
- # df_lipltd_volt_difdifdif['chrgr_rest'] = k
- # df_lipltd_volt_difdifdif['时间戳'] = list(df_check_liplated_temp['时间戳'])
- # df_lipltd_volt_difdifdif = df_lipltd_volt_difdifdif.reset_index(drop = True)
- # df_lipltd_data_temp = df_lipltd_volt_difdifdif.loc[df_lipltd_volt_difdifdif['时间戳'] < (df_check_liplated_temp['时间戳'][0] + datetime.timedelta(minutes=90))]
- # for cell_name in cellvolt_list:#对每个电芯判断
- # df_check_plated_data = df_lipltd_data_temp[cell_name]
- # peak_pos = np.where(df_check_plated_data == -2)
- # bot_pos = np.where(df_check_plated_data == 2)
- # if len(peak_pos[0]) & len(bot_pos[0]):
- # if (peak_pos[0][0] > bot_pos[0][0]) & (df_lipltd_volt_temp_dif[cell_name][peak_pos[0][0] + 1] < 0):
- # lipltd_confirm.append(1)#1为析锂,0为非析锂
- # lipltd_amount.append((df_check_liplated_temp['时间戳'][bot_pos[0][0] + 2] - df_check_liplated_temp['时间戳'][0])/pd.Timedelta(1, 'min'))
- # else:
- # lipltd_confirm.append(0)
- # lipltd_amount.append(0)
- # else:
- # lipltd_confirm.append(0)
- # lipltd_amount.append(0)
- # if any(lipltd_confirm) & (max(lipltd_amount) > 5):
- # df_lipltd_confir_temp = pd.DataFrame({"sn":['sn'], "time":[df_check_liplated_temp['时间戳'][0]], "liplated":[str(lipltd_confirm)], "liplated_amount":[str(lipltd_amount)]})
- # df_lipltd_data = df_lipltd_data.append(df_lipltd_confir_temp)
- # df_lipltd_data = df_lipltd_data.reset_index(drop = True)
- # df_lipltd_data.sort_values(by = ['time'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
- # df_lipltd_data.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\MGMCLN750N215N049\析锂检测.csv',index=False,encoding='GB18030')
-
- # # for i in range(1,k):
- # # # fig = plt.figure(figsize=(20,10))
- # # df_fig = df_rest_volt_diffdt.loc[df_rest_volt_diffdt['chrgr_rest'] == i]
- # # df_fig = df_fig.reset_index(drop=True)
- # # length = len(df_fig)
- # # for volt_num in cellvolt_name[5:6]:
- # # # plt.scatter([x for x in range(0, length)], df_fig[volt_num][0:length], label=volt_num)
- # # plt.plot(df_fig['时间戳'], df_fig[volt_num],linewidth = 2, linestyle = '-', marker = 's',label=volt_num)
- # # plt.rcParams['font.family']=['SimHei']
- # # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
- # # plt.legend()
- # # temp = file.split('\\')
- # # sn_name = temp[9].split('.')[0]
- # # title = sn_name + '-' + df_fig['时间戳'][0].strftime('%y-%m-%d')#df_fig['device_id'][0] + '-' +
- # # print(type(title))
- # # plt.xlabel('时间', fontsize=14)
- # # plt.ylabel('电压的时间微分(mv/min)', fontsize=14)
- # # plt.xlim(df_fig['时间戳'][0]-datetime.timedelta(minutes=5),df_fig['时间戳'][0] + datetime.timedelta(hours=3))
- # # # plt.ylim(-2.5,0.5)
- # # plt.title(title)
- # # plt.savefig(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\MGMCLN750N215N049\\'+title+'.png', dpi=300)
- # # # plt.show()
- # fig = plt.figure(figsize=(20,10))
- # for i in range(3,4):#0,k
- # # fig = plt.figure(figsize=(20,10))
- # df_fig = df_rest_volt_diffdt.loc[df_rest_volt_diffdt['chrgr_rest'] == i]
- # df_fig = df_fig.reset_index(drop=True)
- # length = len(df_fig)
- # temp = file.split('\\')
- # sn_name = temp[9].split('.')[0]
- # title = sn_name + '-' + df_fig['时间戳'][0].strftime('%y-%m-%d')#df_fig['device_id'][0] + '-' +
- # plt_data_len = len(df_fig)
- # # for volt_num in cellvolt_name[5:6]:
- # # plt.scatter([x for x in range(0, length)], df_fig[volt_num][0:length], label=volt_num)
- # # plt.plot([x for x in range(0, plt_data_len)], df_fig[cellvolt_name[5]],linewidth = 2, linestyle = '-', marker = 's',label = title)
- # # plt.plot([x for x in range(0, plt_data_len)], df_fig[cellvolt_name[2]],linewidth = 2, linestyle = '-', marker = 's',label = title)
- # plt.plot(df_fig['时间戳'], df_fig[cellvolt_name[5]],linewidth = 2, linestyle = '-', marker = 's',label = cellvolt_name[5])
- # mpl.rcParams['font.sans-serif']=['SimHei']
- # mpl.rcParams['axes.unicode_minus']=False #用来正常显示负号
- # plt.legend()
- # plt.xlabel('采样点', fontsize=14)
- # plt.ylabel('电压的时间微分(mv/min)', fontsize=14)
- # plt.xlim(df_fig['时间戳'][0]-datetime.timedelta(minutes=5),df_fig['时间戳'][0] + datetime.timedelta(hours=5))
- # # plt.xlim(0, 60)
- # # plt.ylim(-2.5,0.5)
- # plt.title('6#电芯不同时间电压微分曲线')
- # plt.savefig(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\MGMCLN750N215N049\\'+'6#电芯析锂'+'.png', dpi=300)
- # # plt.show()
-
|