maincopycopycopy.py 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import CBMSBatChrgcopy
  2. import log
  3. #coding=utf-8
  4. import datetime
  5. import pandas as pd
  6. from LIB.BACKEND import DBManager, Log
  7. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
  8. # from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  9. from sqlalchemy import create_engine
  10. import time, datetime
  11. import os
  12. import numpy as np
  13. from apscheduler.schedulers.blocking import BlockingScheduler
  14. import QX_BatteryParam
  15. import pymysql
  16. import matplotlib.pyplot as plt
  17. #...............................................主函数.......................................................................................................................
  18. if __name__ == "__main__":
  19. excelpath=r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\sn.csv'
  20. SNdata_didi_trw = pd.read_csv(excelpath, encoding='gbk')
  21. SNnums_didi_trw = SNdata_didi_trw['device_id'].tolist()
  22. SNnums = SNnums_didi_trw
  23. mylog=log.Mylog('log_diag.txt','error')
  24. mylog.logcfg()
  25. #print('---------------计算中-------------------------')
  26. start=time.time()
  27. for sn in SNnums:
  28. #读取结果数据库数据........................................................................................................................................................
  29. host='47.97.96.242'
  30. port=3306
  31. db='didi'
  32. user='root'
  33. password='qx123456'
  34. tablename='didi_data'
  35. param='date,device_id,bat_model,position,current,soc,celltemp,cellvolt_2,cellvolt_3,cellvolt_4,cellvolt_5,cellvolt_6,cellvolt_7,cellvolt_8,cellvolt_9'
  36. mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db)
  37. cursor = mysql.cursor()
  38. sql = "select %s from %s where device_id='%s'" %(param,tablename,sn)
  39. cursor.execute(sql)
  40. res = cursor.fetchall()
  41. df_bms= pd.DataFrame(res,columns=param.split(','))
  42. cursor.close()
  43. mysql.close()
  44. #电压排序................................................................................................................................................................
  45. df_temp_crnt = df_bms[df_bms['current']>1]#筛选充电数据
  46. df_temp = df_temp_crnt[df_temp_crnt['position']==2]#筛选充电数据
  47. df_chrgr = df_temp.reset_index(drop=True)
  48. df_chrgr_cellvolt = df_chrgr[['cellvolt_2','cellvolt_3','cellvolt_4','cellvolt_5','cellvolt_6','cellvolt_7','cellvolt_8','cellvolt_9']]
  49. df_chrgr_cellvolt_change = np.array(df_chrgr_cellvolt)#转数组
  50. df_chrgr_cellvolt_sort = np.argsort(df_chrgr_cellvolt_change)#取排序号
  51. df_cellvolt_sort_dif = np.diff(df_chrgr_cellvolt_sort,axis=0)#一次微分
  52. df_cellvolt_sort_dif_confir = np.nonzero(df_cellvolt_sort_dif)#取非0值
  53. Cell_num = set(df_cellvolt_sort_dif_confir[1])#寻找哪号电芯序号异常np.unique
  54. X_col=np.size(df_chrgr_cellvolt,0) #计算 X 的列数
  55. #df_cellvolt_sort_difdif = np.diff(df_cellvolt_sort_dif)#二次微分
  56. problem_data = pd.DataFrame()
  57. temp_list = []
  58. for item in Cell_num:
  59. temp_list.append(np.sum(df_cellvolt_sort_dif_confir[1]==item) > X_col/20)
  60. if any(temp_list):#序号变化的电芯
  61. data_temp = pd.DataFrame(df_chrgr_cellvolt_sort)
  62. #problem_data = pd.concat([df_chrgr,data_temp], axis = 1)
  63. problem_data = data_temp
  64. sn=sn.replace('/','')
  65. if not problem_data.empty:
  66. problem_data.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'CBMS_diag_'+sn+'.csv',encoding='gbk')
  67. #print(problem_data)
  68. # ax=problem_data.plot(marker='*',markersize=15, figsize=(16,9))
  69. # plt.xlabel('时间', fontsize=20)
  70. # plt.ylabel('排序变化', fontsize=20)
  71. # plt.xticks(fontsize=15)
  72. # plt.yticks(fontsize=15)
  73. # # plt.ylim(-30,30)
  74. # plt.title(str(sn),fontsize=25)
  75. # plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  76. # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  77. # plt.legend(bbox_to_anchor=(1, 0), loc=3, fontsize=14)
  78. # plt.show()
  79. # fig = ax.get_figure()
  80. # fig.savefig(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+str(sn)+'电压排序.png')
  81. end=time.time()
  82. print('--------------计算时间:------------')
  83. print(end-start)
  84. # print(df_soh)