main.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import CBMSBatUniform
  2. #coding=utf-8
  3. import os
  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. from sqlalchemy.orm import sessionmaker
  10. import time, datetime
  11. from urllib import parse
  12. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
  13. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  14. dbManager = DBManager.DBManager()
  15. if __name__ == "__main__":
  16. # excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
  17. # SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  18. # SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  19. # SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  20. # SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  21. # SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  22. # SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  23. # SNnums_6060=SNdata_6060['SN号'].tolist()
  24. # SNnums_6040=SNdata_6040['SN号'].tolist()
  25. # SNnums_4840=SNdata_4840['SN号'].tolist()
  26. # SNnums_L7255=SNdata_L7255['SN号'].tolist()
  27. # SNnums_C7255=SNdata_C7255['SN号'].tolist()
  28. # SNnums_U7255=SNdata_U7255['SN号'].tolist()
  29. # SNnums= SNnums_6060 + SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255
  30. SNnums=['PK504B10100004342']
  31. # filepath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download'
  32. # files=os.listdir(filepath)
  33. # files=[files[5]]
  34. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  35. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  36. start_time=now_time-datetime.timedelta(days=20)
  37. end_time=str(now_time)
  38. start_time=str(start_time)
  39. start_time='2021-6-1 9:49:37'
  40. end_time='2021-6-15 19:49:37'
  41. #log信息配置
  42. mylog=log.Mylog('log_uniform.txt','error')
  43. mylog.logcfg()
  44. for sn in SNnums:
  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 'K504B' in sn:
  52. celltype=99 #60ah林磷酸铁锂电芯
  53. elif 'MGMLXN750' in sn:
  54. celltype=3 #力信50ah三元电芯
  55. elif ('MGMCLN750' or 'UD') in sn:
  56. celltype=4 #CATL 50ah三元电芯
  57. else:
  58. celltype=100
  59. print('SN:{},未找到对应电池类型!!!'.format(sn))
  60. # continue
  61. # sys.exit()
  62. # df_bms= pd.read_csv(filepath+'\\'+filesname,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\\'+'BMS_'+sn+'.csv',encoding='GB18030')
  70. #.........................................................................计算一致性..............................................................................
  71. if not df_bms.empty:
  72. BatUniform=CBMSBatUniform.BatUniform(sn,celltype,df_bms)
  73. df_res=BatUniform.batuniform()
  74. df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_Uniform'+sn+'.csv',encoding='GB18030')
  75. # print('done!!!')
  76. except IndexError as e:
  77. print(repr(e))
  78. mylog.logopt(sn,e)
  79. pass