main.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import datetime
  2. import pandas as pd
  3. import numpy as np
  4. import datetime
  5. from USER.SPF.alibaba.Common import DBDownload
  6. from USER.SPF.alibaba.Common import log
  7. import CBMSBatSoh
  8. if __name__ == "__main__":
  9. SNnums= ['LS002']
  10. end_time=datetime.datetime.now()-datetime.timedelta(seconds=10)
  11. start_time=end_time-datetime.timedelta(seconds=12000)
  12. start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
  13. end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
  14. #log信息配置............................................................................................................................................................................
  15. mylog=log.Mylog('log_soh.txt','error')
  16. mylog.logcfg()
  17. for sn in SNnums:
  18. try:
  19. # if 'PK500' in sn:
  20. # celltype=1 #6040三元电芯
  21. # elif 'PK502' in sn:
  22. # celltype=2 #4840三元电芯
  23. # elif 'PK504' in sn:
  24. # celltype=99 #60ah林磷酸铁锂电芯
  25. # elif 'MGMLXN750' in sn:
  26. # celltype=3 #力信50ah三元电芯
  27. # elif 'MGMCLN750' in sn:
  28. # celltype=4 #CATL 50ah三元电芯
  29. # else:
  30. # print('未找到对应电池编号!!!\n',sn)
  31. # # sys.exit()
  32. celltype=99
  33. #............................................................读取原始数据库数据...........................................................................
  34. df_bms= pd.read_excel(r'D:\01WorkSpace\项目\Alibaba\data\原始数据_2022-01-10_2022-02-10\力神_LS002.xlsx')
  35. cellvolt_name=['CellVolt'+str(x) for x in range(1,73)]
  36. celltemp_name=['CellTemp'+str(x) for x in range(1,33)]
  37. df_volt=pd.DataFrame([x[0].split(",") for x in np.array(df_bms[['cell_volt']])])
  38. df_volt.columns = cellvolt_name
  39. df_volt=df_volt.astype('float')
  40. df_temp=pd.DataFrame([x[0].split(",") for x in np.array(df_bms[['cell_temp']])])
  41. df_temp.columns = celltemp_name
  42. df_temp=df_temp.astype('float')
  43. df_bms=pd.concat([df_bms,df_volt,df_temp],axis=1)
  44. df_bms.dropna(axis=0, inplace=True)
  45. df_bms=df_bms.reset_index(drop=True)
  46. #............................................................读取结果数据库数据.........................................................................
  47. # host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  48. # port=3306
  49. # db='qx_cas'
  50. # user='qx_read'
  51. # password='Qx@123456'
  52. # mode=1
  53. # tablename='cellstateestimation_soh'
  54. # DBRead=DBDownload.DBDownload(host, port, db, user, password, mode)
  55. # with DBRead as DBRead:
  56. # df_soh=DBRead.getdata(param='time_st,time_sp,sn,method,soh,cellsoh,packsoh', tablename=tablename, sn=sn, timename='time_sp', st=start_time, sp=end_time)
  57. df_soh=pd.DataFrame()
  58. # print(df_soh)
  59. #.................................................................计算soh...................................................................................
  60. BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_soh)
  61. df_res=BatSoh.batsoh()
  62. df_res.to_excel(r'D:\01WorkSpace\python\data_analyze_platform\USER\SPF\alibaba\99Result\\'+'CBMS_SOH_'+sn+'.xlsx')
  63. # print('done!!!')
  64. except Exception as e:
  65. print(repr(e))
  66. mylog.logopt(sn,e)
  67. pass