main.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import CBMSBatBehave
  2. import pymysql
  3. import datetime
  4. import pandas as pd
  5. import multiprocessing
  6. from LIB.BACKEND import DBManager, Log
  7. import time, datetime
  8. from apscheduler.schedulers.blocking import BlockingScheduler
  9. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  10. #...............................................主函数..........................................................................................................
  11. if __name__ == "__main__":
  12. excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
  13. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  14. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  15. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  16. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  17. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  18. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  19. SNdata_ZKHD=pd.read_excel(excelpath, sheet_name='重卡换电')
  20. SNnums_6060=SNdata_6060['SN号'].tolist()
  21. SNnums_6040=SNdata_6040['SN号'].tolist()
  22. SNnums_4840=SNdata_4840['SN号'].tolist()
  23. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  24. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  25. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  26. SNnums_ZKHD=SNdata_ZKHD['SN号'].tolist()
  27. SNnums=[SNnums_L7255 + SNnums_C7255 + SNnums_U7255 + SNnums_4840, SNnums_6040 + SNnums_6060]
  28. SNnums=SNnums_ZKHD
  29. mylog=log.Mylog('log_diag.txt','error')
  30. mylog.logcfg()
  31. start=time.time()
  32. now_time=datetime.datetime.now() #-datetime.timedelta(seconds=3600*24+3600*14.6)
  33. start_time=now_time-datetime.timedelta(seconds=70)
  34. start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
  35. end_time=now_time.strftime('%Y-%m-%d %H:%M:%S')
  36. start_time='2021-12-1 00:00:00'
  37. end_time='2021-12-30 23:59:59'
  38. for sn in SNnums:
  39. try:
  40. if 'PK500' in sn:
  41. celltype=1 #6040三元电芯
  42. elif 'PK502' in sn:
  43. celltype=2 #4840三元电芯
  44. elif 'K504B' in sn:
  45. celltype=99 #60ah林磷酸铁锂电芯
  46. elif 'MGMLXN750' in sn:
  47. celltype=3 #力信50ah三元电芯
  48. elif ('MGMCLN750' or 'UD') in sn:
  49. celltype=4 #CATL 50ah三元电芯
  50. elif 'TJMCL' in sn:
  51. celltype=100 #金茂重卡换电
  52. else:
  53. print('SN:{},未找到对应电池类型!!!'.format(sn))
  54. continue
  55. # sys.exit()
  56. #读取原始数据库数据........................................................................................................................................................
  57. dbManager = DBManager.DBManager()
  58. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  59. df_bms = df_data['bms']
  60. df_bms=df_bms.dropna(axis=0,subset=['总电流[A]','SOH[%]','SOC[%]']) #去除有空值的行
  61. df_bms.reset_index(inplace=True,drop=True) #重置索引
  62. df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download\\'+sn+'_BMS_'+'.csv',encoding='GB18030')
  63. # print(df_bms)
  64. #用户行为分析................................................................................................................................................................
  65. if not df_bms.empty:
  66. BatBehave=CBMSBatBehave.BatBehave(sn,celltype,df_bms)
  67. df_res=BatBehave.behave()
  68. #当前热失控故障写入数据库
  69. if not df_res.empty:
  70. #读取老的excel结果
  71. try:
  72. df_res_old= pd.read_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_'+'行为分析1'+'.xlsx',index_col=0)
  73. except:
  74. df_res_old=pd.DataFrame()
  75. #新的结果与老结果合并
  76. if df_res_old.empty:
  77. df_res=df_res
  78. else:
  79. df_res=df_res.append(df_res_old)
  80. #合并后的结果存入excel文件
  81. if not df_res.empty:
  82. df_res.to_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_'+'行为分析1'+'.xlsx')
  83. # print('done!!!')
  84. end=time.time()
  85. print(end-start)
  86. except Exception as e:
  87. print(repr(e))
  88. mylog.logopt(e)