123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import CBMSBatBehave
- import pandas as pd
- import time, datetime
- from matplotlib import pyplot as plt
- from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
- #...............................................主函数..........................................................................................................
- if __name__ == "__main__":
-
- excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
- SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
- SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
- SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
- SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
- SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
- SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
- SNdata_ZKHD=pd.read_excel(excelpath, sheet_name='重卡换电')
- SNnums_6060=SNdata_6060['SN号'].tolist()
- SNnums_6040=SNdata_6040['SN号'].tolist()
- SNnums_4840=SNdata_4840['SN号'].tolist()
- SNnums_L7255=SNdata_L7255['SN号'].tolist()
- SNnums_C7255=SNdata_C7255['SN号'].tolist()
- SNnums_U7255=SNdata_U7255['SN号'].tolist()
- SNnums_ZKHD=SNdata_ZKHD['SN号'].tolist()
- SNnums=[SNnums_L7255 + SNnums_C7255 + SNnums_U7255 + SNnums_4840, SNnums_6040 + SNnums_6060]
- SNnums=SNnums_ZKHD
- df_res=pd.read_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_'+'行为分析'+'.xlsx',index_col=0)
- df_res['time_st']=pd.to_datetime(df_res['time_st'], format='%Y-%m-%d %H:%M:%S')
-
- ax=plt.figure()
- for sn in SNnums:
- if 'PK500' in sn:
- celltype=1 #6040三元电芯
- elif 'PK502' in sn:
- celltype=2 #4840三元电芯
- elif 'K504B' in sn:
- celltype=99 #60ah林磷酸铁锂电芯
- elif 'MGMLXN750' in sn:
- celltype=3 #力信50ah三元电芯
- elif ('MGMCLN750' or 'UD') in sn:
- celltype=4 #CATL 50ah三元电芯
- elif 'TJMCL' in sn:
- celltype=100 #金茂重卡换电
- else:
- print('SN:{},未找到对应电池类型!!!'.format(sn))
- continue
- # sys.exit()
- #统计每个电池包每天的换电次数.......................................................................................................................................................
- df_res_sn=df_res[df_res['sn']==sn]
- if not df_res_sn.empty:
- df= df_res_sn.set_index('time_st')
- df['sum']=1
- df=df.resample('D').sum()
- x=df.index.tolist()
- y=df['sum'].tolist()
-
- plt.plot(x, y,label=sn,marker='*',markersize=15)
- plt.title('每个电池包日换电次数',fontsize=18)
- plt.xlabel('日期', fontsize=15)
- plt.ylabel('换电次数', fontsize=15)
- plt.xticks(pd.date_range(x[0],x[-1],freq='3d'),fontsize=13,rotation=45)
- plt.yticks(fontsize=13)
- # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
- plt.legend()
- plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
- plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
- # ax.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\每个电池包日换电次数.png')
- plt.show()
- #统计所有电池包每天的换电次数........................................................................................................................................
- df1= df_res.set_index('time_st')
- df1['sum']=1
- df1=df1.resample('D').sum()
- x=df1.index.tolist()
- y=df1['sum'].tolist()
-
- ax1=plt.figure()
- plt.bar(x,y)
- plt.title('所有电池包日换电次数',fontsize=18)
- plt.xlabel('日期', fontsize=15)
- plt.ylabel('换电次数', fontsize=15)
- plt.xticks(pd.date_range(x[0],x[-1],freq='3d'),fontsize=13,rotation=45)
- plt.yticks(fontsize=13)
- # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
- plt.legend(bbox_to_anchor=(1, 0), loc=3, fontsize=16)
- plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
- plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
- for a,b in zip(x,y):
- plt.text(a, b+0.05, '%.0f' % b, ha='center', va= 'bottom',fontsize=12)
- # ax1.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\所有电池包日换电次数.png')
- plt.show()
- #统计所有电池包每周的平均换电次数........................................................................................................................................
- df1= df_res.set_index('time_st')
- df1['sum']=1
- df1=df1.resample('D').sum()
- x=df1.index.tolist()
- y=(df1['sum']/8).tolist()
-
- ax1=plt.figure()
- plt.plot(x,y,marker='*',markersize=15)
- plt.title('每个电池包日平均换电次数',fontsize=18)
- plt.xlabel('日期', fontsize=15)
- plt.ylabel('换电次数', fontsize=15)
- plt.xticks(pd.date_range(x[0],x[-1],freq='3d'),fontsize=13,rotation=45)
- plt.yticks(fontsize=13)
- # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
- plt.legend(bbox_to_anchor=(1, 0), loc=3, fontsize=16)
- plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
- plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
- for a,b in zip(x,y):
- plt.text(a, b+0.05, '%.1f' % b, ha='center', va= 'bottom',fontsize=12)
- # ax1.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\每个电池包日平均换电次数.png')
- plt.show()
- #统计每天的换电时间段...........................................................................................................................
- df_res['time_st']=df_res['time_st'].map(lambda x:x.strftime('%H:%M:%S'))
- # df_res['time_st']=pd.to_datetime(df_res['time_st'], format='%H:%M:%S')
- df_res['time_st']=df_res['time_st'].map(lambda x:datetime.datetime.strptime(x,'%H:%M:%S'))
- df1= df_res.set_index('time_st')
- df1['sum']=1
- df1=df1.resample('H').sum()
- x=range(len(df1))
- y=(df1['sum']).tolist()
-
- ax1=plt.figure()
- plt.bar(x,y)
- plt.plot(x,y,marker='*',markersize=13,color='r')
- plt.title('电池包换电时间段',fontsize=18)
- plt.xlabel('时间', fontsize=15)
- plt.ylabel('换电次数', fontsize=15)
- plt.xticks(range(0,len(df1),1),fontsize=15)
- plt.yticks(fontsize=15)
- # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
- plt.legend(bbox_to_anchor=(1, 0), loc=3, fontsize=16)
- plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
- plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
- for a,b in zip(x,y):
- plt.text(a, b+0.05, '%.1f' % b, ha='center', va= 'bottom',fontsize=15)
- # ax1.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\电池包换电时间段.png')
- plt.show()
|