BehaveStatistics.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import CBMSBatBehave
  2. import pandas as pd
  3. import time, datetime
  4. from matplotlib import pyplot as plt
  5. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  6. #...............................................主函数..........................................................................................................
  7. if __name__ == "__main__":
  8. excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
  9. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  10. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  11. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  12. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  13. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  14. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  15. SNdata_ZKHD=pd.read_excel(excelpath, sheet_name='重卡换电')
  16. SNnums_6060=SNdata_6060['SN号'].tolist()
  17. SNnums_6040=SNdata_6040['SN号'].tolist()
  18. SNnums_4840=SNdata_4840['SN号'].tolist()
  19. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  20. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  21. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  22. SNnums_ZKHD=SNdata_ZKHD['SN号'].tolist()
  23. SNnums=[SNnums_L7255 + SNnums_C7255 + SNnums_U7255 + SNnums_4840, SNnums_6040 + SNnums_6060]
  24. SNnums=SNnums_ZKHD
  25. df_res=pd.read_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_'+'行为分析'+'.xlsx',index_col=0)
  26. df_res['time_st']=pd.to_datetime(df_res['time_st'], format='%Y-%m-%d %H:%M:%S')
  27. ax=plt.figure()
  28. for sn in SNnums:
  29. if 'PK500' in sn:
  30. celltype=1 #6040三元电芯
  31. elif 'PK502' in sn:
  32. celltype=2 #4840三元电芯
  33. elif 'K504B' in sn:
  34. celltype=99 #60ah林磷酸铁锂电芯
  35. elif 'MGMLXN750' in sn:
  36. celltype=3 #力信50ah三元电芯
  37. elif ('MGMCLN750' or 'UD') in sn:
  38. celltype=4 #CATL 50ah三元电芯
  39. elif 'TJMCL' in sn:
  40. celltype=100 #金茂重卡换电
  41. else:
  42. print('SN:{},未找到对应电池类型!!!'.format(sn))
  43. continue
  44. # sys.exit()
  45. #统计每个电池包每天的换电次数.......................................................................................................................................................
  46. df_res_sn=df_res[df_res['sn']==sn]
  47. if not df_res_sn.empty:
  48. df= df_res_sn.set_index('time_st')
  49. df['sum']=1
  50. df=df.resample('D').sum()
  51. x=df.index.tolist()
  52. y=df['sum'].tolist()
  53. plt.plot(x, y,label=sn,marker='*',markersize=15)
  54. plt.title('每个电池包日换电次数',fontsize=18)
  55. plt.xlabel('日期', fontsize=15)
  56. plt.ylabel('换电次数', fontsize=15)
  57. plt.xticks(pd.date_range(x[0],x[-1],freq='3d'),fontsize=13,rotation=45)
  58. plt.yticks(fontsize=13)
  59. # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  60. plt.legend()
  61. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  62. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  63. # ax.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\每个电池包日换电次数.png')
  64. plt.show()
  65. #统计所有电池包每天的换电次数........................................................................................................................................
  66. df1= df_res.set_index('time_st')
  67. df1['sum']=1
  68. df1=df1.resample('D').sum()
  69. x=df1.index.tolist()
  70. y=df1['sum'].tolist()
  71. ax1=plt.figure()
  72. plt.bar(x,y)
  73. plt.title('所有电池包日换电次数',fontsize=18)
  74. plt.xlabel('日期', fontsize=15)
  75. plt.ylabel('换电次数', fontsize=15)
  76. plt.xticks(pd.date_range(x[0],x[-1],freq='3d'),fontsize=13,rotation=45)
  77. plt.yticks(fontsize=13)
  78. # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  79. plt.legend(bbox_to_anchor=(1, 0), loc=3, fontsize=16)
  80. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  81. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  82. for a,b in zip(x,y):
  83. plt.text(a, b+0.05, '%.0f' % b, ha='center', va= 'bottom',fontsize=12)
  84. # ax1.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\所有电池包日换电次数.png')
  85. plt.show()
  86. #统计所有电池包每周的平均换电次数........................................................................................................................................
  87. df1= df_res.set_index('time_st')
  88. df1['sum']=1
  89. df1=df1.resample('D').sum()
  90. x=df1.index.tolist()
  91. y=(df1['sum']/8).tolist()
  92. ax1=plt.figure()
  93. plt.plot(x,y,marker='*',markersize=15)
  94. plt.title('每个电池包日平均换电次数',fontsize=18)
  95. plt.xlabel('日期', fontsize=15)
  96. plt.ylabel('换电次数', fontsize=15)
  97. plt.xticks(pd.date_range(x[0],x[-1],freq='3d'),fontsize=13,rotation=45)
  98. plt.yticks(fontsize=13)
  99. # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  100. plt.legend(bbox_to_anchor=(1, 0), loc=3, fontsize=16)
  101. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  102. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  103. for a,b in zip(x,y):
  104. plt.text(a, b+0.05, '%.1f' % b, ha='center', va= 'bottom',fontsize=12)
  105. # ax1.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\每个电池包日平均换电次数.png')
  106. plt.show()
  107. #统计每天的换电时间段...........................................................................................................................
  108. df_res['time_st']=df_res['time_st'].map(lambda x:x.strftime('%H:%M:%S'))
  109. # df_res['time_st']=pd.to_datetime(df_res['time_st'], format='%H:%M:%S')
  110. df_res['time_st']=df_res['time_st'].map(lambda x:datetime.datetime.strptime(x,'%H:%M:%S'))
  111. df1= df_res.set_index('time_st')
  112. df1['sum']=1
  113. df1=df1.resample('H').sum()
  114. x=range(len(df1))
  115. y=(df1['sum']).tolist()
  116. ax1=plt.figure()
  117. plt.bar(x,y)
  118. plt.plot(x,y,marker='*',markersize=13,color='r')
  119. plt.title('电池包换电时间段',fontsize=18)
  120. plt.xlabel('时间', fontsize=15)
  121. plt.ylabel('换电次数', fontsize=15)
  122. plt.xticks(range(0,len(df1),1),fontsize=15)
  123. plt.yticks(fontsize=15)
  124. # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  125. plt.legend(bbox_to_anchor=(1, 0), loc=3, fontsize=16)
  126. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  127. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  128. for a,b in zip(x,y):
  129. plt.text(a, b+0.05, '%.1f' % b, ha='center', va= 'bottom',fontsize=15)
  130. # ax1.savefig(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\电池包换电时间段.png')
  131. plt.show()