main.py 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import CBMSBatInterShort
  2. import log
  3. #coding=utf-8
  4. import sys
  5. import datetime
  6. import pandas as pd
  7. from LIB.BACKEND import DBManager, Log
  8. from sqlalchemy import create_engine
  9. import time, datetime
  10. from LIB.MIDDLE.CellStateEstimation.Common import DBDownload
  11. dbManager = DBManager.DBManager()
  12. if __name__ == "__main__":
  13. excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\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. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  28. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  29. start_time=now_time-datetime.timedelta(days=30)
  30. end_time=str(now_time)
  31. start_time=str(start_time)
  32. #log信息配置
  33. mylog=log.Mylog('log.txt','error')
  34. mylog.logcfg()
  35. for sn in SNnums:
  36. try:
  37. if 'PK500' in sn:
  38. celltype=1 #6040三元电芯
  39. elif 'PK502' in sn:
  40. celltype=2 #4840三元电芯
  41. elif 'K504B' in sn:
  42. celltype=99 #60ah林磷酸铁锂电芯
  43. elif 'MGMLXN750' in sn:
  44. celltype=3 #力信50ah三元电芯
  45. elif 'MGMCLN750' or 'UD' in sn:
  46. celltype=4 #CATL 50ah三元电芯
  47. else:
  48. print('SN:{},未找到对应电池类型!!!'.format(sn))
  49. continue
  50. # sys.exit()
  51. sn='PK50201A000002039'
  52. celltype=2
  53. start_time='2021-05-02 09:12:26'
  54. end_time='2021-06-03 19:12:26'
  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.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\''BMS_'+sn+'.csv',encoding='GB18030')
  61. #.....................................................................读取结果数据库数据.............................................................................
  62. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  63. port=3306
  64. db='qx_cas'
  65. user='qx_read'
  66. password='Qx@123456'
  67. tablename='cellstateestimation_soh'
  68. DBRead=DBDownload.DBDownload(host, port, db, user, password)
  69. with DBRead as DBRead:
  70. df_soh=DBRead.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename=tablename, sn=sn)
  71. #...........................................................................计算漏电流............................................................................
  72. BatInterShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,df_soh)
  73. df_res=BatInterShort.intershort()
  74. df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\'+'CBMS_Short_'+sn+'_1.csv',encoding='GB18030')
  75. # print('done!!!')
  76. except Exception as e:
  77. print(repr(e))
  78. mylog.logopt(sn,e)
  79. pass