import pandas as pd from matplotlib import pyplot as plt from matplotlib.pyplot import MultipleLocator import os import numpy as np from LIB.BACKEND import DBManager import pymysql import datetime #数据库配置 # host='rm-uf6bt29r702r14jh4.mysql.rds.aliyuncs.com' # port=3306 # user='u_devlid' # password='EgL#EuQOlRqGml' # db='db_lidian' # mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db) # cursor = mysql.cursor() # param='vin,sn,pack_model_code,cell_battery_type' # sql = "select %s from %s" %(param,'vin_pack_cell_info') # cursor.execute(sql) # res = cursor.fetchall() # df_vin_pack_cell= pd.DataFrame(res,columns=param.split(',')) # df_vin_pack_cell=df_vin_pack_cell.set_index('vin') # vin='LUZAGAAA4KA003771' # param='time_st,time_sp,sn,method,short_current' # sql = "select %s from %s where sn='02YPEAG029603HA4D1302525 '" %(param,'algo_mid_intershort_result') # cursor.execute(sql) # res = cursor.fetchall() # df_short= pd.DataFrame(res,columns=param.split(',')) # df_short.to_excel(r'C:\Users\zldc\project\User\spf\hz-application-algo\USER\spf\100Result\safetywaring\\'+vin+'内短路结果.xlsx') # 内短路 filepath=r'D:\01WorkSpace\python\data_analyze_platform\USER\SPF\alibaba\99Result' files=os.listdir(filepath) # files=[vin+'内短路结果.xlsx'] for filename in files: if '内短路' in filename: vin=filename[:-4] # df_short= pd.read_csv(filepath+'\\'+filename,encoding='gb18030') # df_short['time_sp']=pd.to_datetime(df_short['time_sp'], format='%Y-%m-%d %H:%M:%S') # cellnums=len(eval(df_short.loc[0,'short_current'])) # cellvolt_name=['单体'+str(x) for x in range(1,cellnums+1)] # df=pd.DataFrame(columns=cellvolt_name) # for i in range(len(df_short)): # df.loc[i]=eval(df_short.loc[i,'short_current']) # plt.figure(figsize=(20,8)) # for i in range(df.shape[1]): # x=df_short['time_sp'] # y=df['单体'+str(i+1)] # plt.plot(x, y,marker='*',markersize=15) # plt.plot(x, [-20]*len(x),c='r') # plt.title(filename[0:17],fontsize=25) # plt.xlabel('时间', fontsize=20) # plt.ylabel('内短路电流', fontsize=20) # plt.xticks(fontsize=20,rotation=10) # plt.yticks(fontsize=20) # # plt.xlim(0,120) # plt.ylim(-25,30) # # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o') # # plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0) # plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 # plt.savefig(filepath+'\\'+vin+"内短路.png") # plt.show() # plt.close() df_short= pd.read_excel(filepath+'\\'+filename) cellnums=len(eval(df_short.loc[0,'short_current'])) cellvolt_name=['单体'+str(x) for x in range(1,cellnums+1)] plt.figure(figsize=(20,9)) for i in range(len(df_short)): x=list(range(1,cellnums+1)) y=eval(df_short.loc[i,'short_current']) y1=[-30]*cellnums plt.plot(x, y,marker='*',markersize=15) plt.plot(x, y1,color='r') plt.title(filename[0:17],fontsize=24) plt.xlabel('电芯序号', fontsize=20) plt.ylabel('内短路电流', fontsize=20) plt.xticks(fontsize=22) plt.yticks(fontsize=22) # plt.xlim(0,120) plt.ylim(-35,35) # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o') plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0) plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 plt.savefig(filepath+'\\'+vin+".png") plt.show() plt.close() # #离群度 # filepath=r'D:\01WorkSpace\项目\Alibaba\data\原始数据_2022-01-10_2022-02-10' # files=os.listdir(filepath) # for filename in files: # # if '内短路' in filename: # vin=filename[:-4] # df_bms= pd.read_csv(filepath+'\\'+filename,encoding='gb18030') # df_bms=df_bms.replace('', np.nan) # # df_bms.sort_values(by="time" , inplace=True, ascending=True) # df_bms['time']=pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S') # now_time='2022-4-3 14:00:00' # now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S') # start_time='2022-1-25 00:00:00' # end_time='2022-2-1 00:00:00' # start_time=datetime.datetime.strptime(start_time,'%Y-%m-%d %H:%M:%S') # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d %H:%M:%S') # df_bms=df_bms[(df_bms['time']>start_time) & (df_bms['time']2) &(df_volt<4.5)] # # df_volt=df_volt['2022-1-26 00:00:00':'2022-1-29 18:00:00'] # plt.figure(figsize=(16,9)) # for i in cellvolt_name[50:61]: # x=df_volt.index # y=df_volt[i] # plt.plot(x, y,label=i) # plt.title(vin,fontsize=18) # plt.xlabel('时间', fontsize=15) # plt.ylabel('电压', fontsize=15) # plt.xticks(fontsize=15) # plt.yticks(fontsize=15) # # plt.xlim(0,120) # # plt.ylim(-20,20) # # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o') # plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0) # plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 # plt.savefig(filepath+'\\'+vin+"离群度.png") # plt.show() # plt.close()