test.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import pandas as pd
  2. from matplotlib import pyplot as plt
  3. from matplotlib.pyplot import MultipleLocator
  4. import os
  5. import numpy as np
  6. from LIB.BACKEND import DBManager
  7. import pymysql
  8. import datetime
  9. #数据库配置
  10. # host='rm-uf6bt29r702r14jh4.mysql.rds.aliyuncs.com'
  11. # port=3306
  12. # user='u_devlid'
  13. # password='EgL#EuQOlRqGml'
  14. # db='db_lidian'
  15. # mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db)
  16. # cursor = mysql.cursor()
  17. # param='vin,sn,pack_model_code,cell_battery_type'
  18. # sql = "select %s from %s" %(param,'vin_pack_cell_info')
  19. # cursor.execute(sql)
  20. # res = cursor.fetchall()
  21. # df_vin_pack_cell= pd.DataFrame(res,columns=param.split(','))
  22. # df_vin_pack_cell=df_vin_pack_cell.set_index('vin')
  23. # vin='LUZAGAAA4KA003771'
  24. # param='time_st,time_sp,sn,method,short_current'
  25. # sql = "select %s from %s where sn='02YPEAG029603HA4D1302525 '" %(param,'algo_mid_intershort_result')
  26. # cursor.execute(sql)
  27. # res = cursor.fetchall()
  28. # df_short= pd.DataFrame(res,columns=param.split(','))
  29. # df_short.to_excel(r'C:\Users\zldc\project\User\spf\hz-application-algo\USER\spf\100Result\safetywaring\\'+vin+'内短路结果.xlsx')
  30. # 内短路
  31. filepath=r'D:\01WorkSpace\项目\Alibaba\data\内短路数据_2022-01-10_2022-02-10'
  32. files=os.listdir(filepath)
  33. # files=[vin+'内短路结果.xlsx']
  34. for filename in files:
  35. # if '内短路' in filename:
  36. vin=filename[:-4]
  37. df_short= pd.read_csv(filepath+'\\'+filename,encoding='gb18030')
  38. df_short['time_sp']=pd.to_datetime(df_short['time_sp'], format='%Y-%m-%d %H:%M:%S')
  39. cellnums=len(eval(df_short.loc[0,'short_current']))
  40. cellvolt_name=['单体'+str(x) for x in range(1,cellnums+1)]
  41. df=pd.DataFrame(columns=cellvolt_name)
  42. for i in range(len(df_short)):
  43. df.loc[i]=eval(df_short.loc[i,'short_current'])
  44. plt.figure(figsize=(20,8))
  45. for i in range(df.shape[1]):
  46. x=df_short['time_sp']
  47. y=df['单体'+str(i+1)]
  48. plt.plot(x, y,marker='*',markersize=15)
  49. plt.plot(x, [-20]*len(x),c='r')
  50. plt.title(filename[0:17],fontsize=25)
  51. plt.xlabel('时间', fontsize=20)
  52. plt.ylabel('内短路电流', fontsize=20)
  53. plt.xticks(fontsize=20,rotation=10)
  54. plt.yticks(fontsize=20)
  55. # plt.xlim(0,120)
  56. plt.ylim(-25,30)
  57. # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  58. # plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0)
  59. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  60. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  61. plt.savefig(filepath+'\\'+vin+"内短路.png")
  62. plt.show()
  63. plt.close()
  64. # df_short= pd.read_excel(filepath+'\\'+filename)
  65. # cellnums=len(eval(df_short.loc[0,'short_current']))
  66. # cellvolt_name=['单体'+str(x) for x in range(1,cellnums+1)]
  67. # plt.figure(figsize=(16,9))
  68. # for i in range(len(df_short)):
  69. # x=list(range(1,cellnums+1))
  70. # y=eval(df_short.loc[i,'short_current'])
  71. # plt.plot(x, y,label=df_short.loc[i,'time_st'],marker='*',markersize=15)
  72. # plt.title(filename[0:17],fontsize=18)
  73. # plt.xlabel('电芯序号', fontsize=15)
  74. # plt.ylabel('内短路电流', fontsize=15)
  75. # plt.xticks(fontsize=15)
  76. # plt.yticks(fontsize=15)
  77. # # plt.xlim(0,120)
  78. # # plt.ylim(-20,20)
  79. # # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  80. # plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0)
  81. # plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  82. # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  83. # plt.savefig(filepath+'\\'+filename[0:17]+".png")
  84. # plt.show()
  85. # plt.close()
  86. # #离群度
  87. # filepath=r'D:\01WorkSpace\项目\Alibaba\data\原始数据_2022-01-10_2022-02-10'
  88. # files=os.listdir(filepath)
  89. # for filename in files:
  90. # # if '内短路' in filename:
  91. # vin=filename[:-4]
  92. # df_bms= pd.read_csv(filepath+'\\'+filename,encoding='gb18030')
  93. # df_bms=df_bms.replace('', np.nan)
  94. # # df_bms.sort_values(by="time" , inplace=True, ascending=True)
  95. # df_bms['time']=pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S')
  96. # now_time='2022-4-3 14:00:00'
  97. # now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  98. # start_time='2022-1-25 00:00:00'
  99. # end_time='2022-2-1 00:00:00'
  100. # start_time=datetime.datetime.strptime(start_time,'%Y-%m-%d %H:%M:%S')
  101. # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d %H:%M:%S')
  102. # df_bms=df_bms[(df_bms['time']>start_time) & (df_bms['time']<end_time)]
  103. # CellVoltNums = len((df_bms.iloc[0]['cell_volt']).split(',')) # 找出电芯数量出现最多的次数
  104. # cellvolt_name=['CellVoltage'+str(x) for x in range(1,CellVoltNums+1)]
  105. # df_volt=pd.DataFrame(df_bms['cell_volt'].str.split(',').tolist()).iloc[:,list(range(CellVoltNums))]
  106. # df_volt.columns = cellvolt_name
  107. # df_volt=df_volt.astype('float')
  108. # df_volt.index=df_bms['time']
  109. # # df_volt=df_volt[(df_volt>2) &(df_volt<4.5)]
  110. # # df_volt=df_volt['2022-1-26 00:00:00':'2022-1-29 18:00:00']
  111. # plt.figure(figsize=(16,9))
  112. # for i in cellvolt_name[50:61]:
  113. # x=df_volt.index
  114. # y=df_volt[i]
  115. # plt.plot(x, y,label=i)
  116. # plt.title(vin,fontsize=18)
  117. # plt.xlabel('时间', fontsize=15)
  118. # plt.ylabel('电压', fontsize=15)
  119. # plt.xticks(fontsize=15)
  120. # plt.yticks(fontsize=15)
  121. # # plt.xlim(0,120)
  122. # # plt.ylim(-20,20)
  123. # # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  124. # plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0)
  125. # plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  126. # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  127. # plt.savefig(filepath+'\\'+vin+"离群度.png")
  128. # plt.show()
  129. # plt.close()