main.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import CBMSBatSoh
  2. #coding=utf-8
  3. import datetime
  4. import pandas as pd
  5. from LIB.BACKEND import DBManager, Log
  6. import time, datetime
  7. import os
  8. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
  9. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  10. dbManager = DBManager.DBManager()
  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_ZKHD
  28. SNdata_6040 = pd.read_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\CBMS_SOH_26040.xlsx')
  29. SNnums=SNdata_6040['sn'].tolist()
  30. SNnums=['PK50001A100000545']
  31. # filepath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download'
  32. # files=os.listdir(filepath)
  33. # files=[files[5]]
  34. end_time=datetime.datetime.now()-datetime.timedelta(seconds=10)
  35. start_time=end_time-datetime.timedelta(seconds=1200)
  36. start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
  37. end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
  38. start_time='2020-10-31 00:49:37'
  39. end_time='2021-12-31 19:49:37'
  40. #log信息配置............................................................................................................................................................................
  41. mylog=log.Mylog('log_soh.txt','error')
  42. mylog.logcfg()
  43. for sn in SNnums:
  44. # sn=filesname[:-4]
  45. print(sn)
  46. try:
  47. if 'PK500' in sn:
  48. celltype=1 #6040三元电芯
  49. elif 'PK502' in sn:
  50. celltype=2 #4840三元电芯
  51. elif 'PK504' in sn:
  52. celltype=99 #60ah林磷酸铁锂电芯
  53. elif 'MGMLXN750' in sn:
  54. celltype=3 #力信50ah三元电芯
  55. elif 'MGMCLN750' in sn:
  56. celltype=4 #CATL 50ah三元电芯
  57. else:
  58. celltype=100
  59. print('未找到对应电池编号!!!\n',sn)
  60. # sys.exit()
  61. # df_bms= pd.read_csv(filepath+'\\'+filesname,encoding='GB18030')
  62. # df_accum= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download\\'+'BMS_accum_'+sn+'.csv',encoding='GB18030')
  63. #..........................................................................读取原始数据库数据...........................................................................
  64. dbManager = DBManager.DBManager()
  65. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  66. df_bms = df_data['bms']
  67. df_bms=df_bms.dropna(subset=['总电流[A]'])
  68. df_bms.reset_index(inplace=True,drop=True) #重置索引
  69. df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download\\'+sn+'.csv',encoding='GB18030')
  70. df_accum=pd.DataFrame()
  71. #..........................................................................读取结果数据库数据.........................................................................
  72. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  73. port=3306
  74. db='qx_cas'
  75. user='qx_read'
  76. password='Qx@123456'
  77. mode=1
  78. tablename='cellstateestimation_soh'
  79. DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
  80. with DBRead as DBRead:
  81. df_soh=DBRead.getdata(param='time_st,time_sp,sn,method,soh,cellsoh', tablename=tablename, sn=sn, timename='time_sp', st=start_time, sp=end_time)
  82. # print(df_soh)
  83. # df_soh=pd.DataFrame()
  84. #..............................................................................计算soh...................................................................................
  85. BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_accum,df_soh)
  86. df_res=BatSoh.batsoh()
  87. df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_SOH'+sn+'.csv',encoding='GB18030')
  88. # print('done!!!')
  89. except Exception as e:
  90. print(repr(e))
  91. mylog.logopt(sn,e)
  92. pass