test.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\python\data_analyze_platform\USER\SPF\alibaba\99Result'
  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=(20,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. y1=[-30]*cellnums
  72. plt.plot(x, y,marker='*',markersize=15)
  73. plt.plot(x, y1,color='r')
  74. plt.title(filename[0:17],fontsize=24)
  75. plt.xlabel('电芯序号', fontsize=20)
  76. plt.ylabel('内短路电流', fontsize=20)
  77. plt.xticks(fontsize=22)
  78. plt.yticks(fontsize=22)
  79. # plt.xlim(0,120)
  80. plt.ylim(-35,35)
  81. # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  82. plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0)
  83. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  84. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  85. plt.savefig(filepath+'\\'+vin+".png")
  86. plt.show()
  87. plt.close()
  88. # #离群度
  89. # filepath=r'D:\01WorkSpace\项目\Alibaba\data\原始数据_2022-01-10_2022-02-10'
  90. # files=os.listdir(filepath)
  91. # for filename in files:
  92. # # if '内短路' in filename:
  93. # vin=filename[:-4]
  94. # df_bms= pd.read_csv(filepath+'\\'+filename,encoding='gb18030')
  95. # df_bms=df_bms.replace('', np.nan)
  96. # # df_bms.sort_values(by="time" , inplace=True, ascending=True)
  97. # df_bms['time']=pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S')
  98. # now_time='2022-4-3 14:00:00'
  99. # now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  100. # start_time='2022-1-25 00:00:00'
  101. # end_time='2022-2-1 00:00:00'
  102. # start_time=datetime.datetime.strptime(start_time,'%Y-%m-%d %H:%M:%S')
  103. # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d %H:%M:%S')
  104. # df_bms=df_bms[(df_bms['time']>start_time) & (df_bms['time']<end_time)]
  105. # CellVoltNums = len((df_bms.iloc[0]['cell_volt']).split(',')) # 找出电芯数量出现最多的次数
  106. # cellvolt_name=['CellVoltage'+str(x) for x in range(1,CellVoltNums+1)]
  107. # df_volt=pd.DataFrame(df_bms['cell_volt'].str.split(',').tolist()).iloc[:,list(range(CellVoltNums))]
  108. # df_volt.columns = cellvolt_name
  109. # df_volt=df_volt.astype('float')
  110. # df_volt.index=df_bms['time']
  111. # # df_volt=df_volt[(df_volt>2) &(df_volt<4.5)]
  112. # # df_volt=df_volt['2022-1-26 00:00:00':'2022-1-29 18:00:00']
  113. # plt.figure(figsize=(16,9))
  114. # for i in cellvolt_name[50:61]:
  115. # x=df_volt.index
  116. # y=df_volt[i]
  117. # plt.plot(x, y,label=i)
  118. # plt.title(vin,fontsize=18)
  119. # plt.xlabel('时间', fontsize=15)
  120. # plt.ylabel('电压', fontsize=15)
  121. # plt.xticks(fontsize=15)
  122. # plt.yticks(fontsize=15)
  123. # # plt.xlim(0,120)
  124. # # plt.ylim(-20,20)
  125. # # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
  126. # plt.legend(bbox_to_anchor=(1, 0), loc=3, borderaxespad=0)
  127. # plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  128. # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  129. # plt.savefig(filepath+'\\'+vin+"离群度.png")
  130. # plt.show()
  131. # plt.close()