main.py 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import CBMSBatInterShort
  2. #coding=utf-8
  3. import sys
  4. import datetime
  5. import pandas as pd
  6. from LIB.BACKEND import DBManager, Log
  7. from sqlalchemy import create_engine
  8. import time, datetime
  9. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
  10. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  11. dbManager = DBManager.DBManager()
  12. if __name__ == "__main__":
  13. excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
  14. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  15. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  16. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  17. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  18. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  19. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  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= SNnums_6060 + SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255
  27. SNnums=['TJMCL120502305038','TJMCL120502305032','TJMCL120502305022','TJMCL120502305026','TJMCL120502305032','TJMCL120502305044','TJMCL120502305048','TJMCL120502305012','TJMCL120502305010']
  28. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  29. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  30. start_time=now_time-datetime.timedelta(days=30)
  31. end_time=str(now_time)
  32. start_time=str(start_time)
  33. start_time='2021-11-17 00:00:00'
  34. end_time='2021-11-23 00:00:00'
  35. #log信息配置
  36. mylog=log.Mylog('log_short.txt','error')
  37. mylog.logcfg()
  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. else:
  51. celltype=100
  52. print('SN:{},未找到对应电池类型!!!'.format(sn))
  53. # continue
  54. # sys.exit()
  55. # df_bms= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_'+sn+'.csv',encoding='GB18030')
  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(subset=['总电流[A]'])
  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\\'+'BMS_'+sn+'.csv',encoding='GB18030')
  63. #.....................................................................读取结果数据库数据.............................................................................
  64. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  65. port=3306
  66. db='qx_cas'
  67. user='qx_read'
  68. password='Qx@123456'
  69. mode=1
  70. tablename='cellstateestimation_soh'
  71. DBRead=DBDownload.DBDownload(host, port, db, user, password, mode)
  72. with DBRead as DBRead:
  73. 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)
  74. #...........................................................................计算漏电流............................................................................
  75. BatInterShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,df_soh)
  76. df_res=BatInterShort.intershort()
  77. df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_Short_1_'+sn+'.csv',encoding='GB18030')
  78. # print('done!!!')
  79. except Exception as e:
  80. print(repr(e))
  81. mylog.logopt(sn,e)
  82. pass