main.py 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import CBMSBatSoh
  2. import log
  3. #coding=utf-8
  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 import DBDownload
  10. dbManager = DBManager.DBManager()
  11. if __name__ == "__main__":
  12. excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\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. SNnums_6060=SNdata_6060['SN号'].tolist()
  20. SNnums_6040=SNdata_6040['SN号'].tolist()
  21. SNnums_4840=SNdata_4840['SN号'].tolist()
  22. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  23. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  24. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  25. SNnums= SNnums_6060 + SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255
  26. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  27. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  28. start_time=now_time-datetime.timedelta(days=30)
  29. end_time=str(now_time)
  30. start_time=str(start_time)
  31. #log信息配置
  32. mylog=log.Mylog('log.txt','error')
  33. mylog.logcfg()
  34. for sn in SNnums:
  35. try:
  36. if 'PK500' in sn:
  37. celltype=1 #6040三元电芯
  38. elif 'PK502' in sn:
  39. celltype=2 #4840三元电芯
  40. elif 'PK504' in sn:
  41. celltype=99 #60ah林磷酸铁锂电芯
  42. elif 'MGMLXN750' in sn:
  43. celltype=3 #力信50ah三元电芯
  44. elif 'MGMCLN750' in sn:
  45. celltype=4 #CATL 50ah三元电芯
  46. else:
  47. print('未找到对应电池编号!!!\n',sn)
  48. # sys.exit()
  49. sn='PK504B10100004353'
  50. celltype=99
  51. start_time='2021-04-01 19:12:26'
  52. end_time='2021-06-02 19:12:26'
  53. # df_bms= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_'+sn+'.csv',encoding='GB18030')
  54. # df_accum= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_accum_'+sn+'.csv',encoding='GB18030')
  55. #..........................................................................读取原始数据库数据...........................................................................
  56. dbManager = DBManager.DBManager()
  57. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms','accum'])
  58. df_bms = df_data['bms']
  59. df_accum=df_data['accum']
  60. # df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_'+sn+'.csv',encoding='GB18030')
  61. # df_accum.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_accum_'+sn+'.csv',encoding='GB18030')
  62. #..........................................................................读取结果数据库数据.........................................................................
  63. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  64. port=3306
  65. db='qx_cas'
  66. user='qx_read'
  67. password='Qx@123456'
  68. tablename='cellstateestimation_soh'
  69. DBRead=DBDownload.DBDownload(host, port, db, user, password)
  70. with DBRead as DBRead:
  71. df_soh=DBRead.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename=tablename, sn=sn)
  72. #..............................................................................计算soh...................................................................................
  73. BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_accum,df_soh)
  74. df_res=BatSoh.batsoh()
  75. df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\'+'CBMS_SOH'+sn+'_1.csv',encoding='GB18030')
  76. # print('done!!!')
  77. except IndexError as e:
  78. print(repr(e))
  79. mylog.logopt(sn,e)
  80. pass