main.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import datetime
  2. import pandas as pd
  3. from LIB.BACKEND import DBManager, Log
  4. from sqlalchemy import create_engine
  5. import time, datetime
  6. from apscheduler.schedulers.blocking import BlockingScheduler
  7. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload as DBDownload
  8. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  9. from pandas.core.frame import DataFrame
  10. import datacompy
  11. from LIB.MIDDLE.SaftyCenter.Common import QX_BatteryParam
  12. from LIB.MIDDLE.SaftyCenter.Common import DBDownload as DBDw
  13. from LIB.MIDDLE.SaftyCenter.Low_Soc_Alarm.low_soc_alarm import Low_soc_alarm
  14. def Low_Soc_Alarm():
  15. end_time=datetime.datetime.now()
  16. start_time=end_time-datetime.timedelta(days=1)
  17. start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
  18. end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
  19. #-------------------------读取数据-------------------------------------------------------------------
  20. excelpath=r'D:\ZLWORK\code\data_analyze_platform\USER\eric\SaftyCenter_CODE_V1\sn-20210903.xlsx'
  21. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  22. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  23. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  24. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  25. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  26. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  27. SNnums_6060=SNdata_6060['SN号'].tolist()
  28. SNnums_6040=SNdata_6040['SN号'].tolist()
  29. SNnums_4840=SNdata_4840['SN号'].tolist()
  30. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  31. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  32. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  33. SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
  34. #SNnums=['MGMCLN750N215I009']
  35. #-------------------------执行循环----------------------------------------------------------------------
  36. low_soc_bat_list=DataFrame(columns=['sn','time','level'])
  37. for sn in SNnums:#SN遍历
  38. print(sn)
  39. if 'PK500' in sn:
  40. celltype=1 #6040三元电芯
  41. elif 'PK502' in sn:
  42. celltype=2 #4840三元电芯
  43. elif 'K504B' in sn:
  44. celltype=99 #60ah林磷酸铁锂电芯
  45. elif 'MGMLXN750' in sn:
  46. celltype=3 #力信50ah三元电芯
  47. elif 'MGMCLN750' or 'UD' in sn:
  48. celltype=4 #CATL 50ah三元电芯
  49. else:
  50. print('SN:{},未找到对应电池类型!!!'.format(sn))
  51. continue
  52. # sys.exit()
  53. param=QX_BatteryParam.BatteryInfo(celltype)
  54. #读取原始数据库数据.....................................................................................
  55. dbManager = DBManager.DBManager()
  56. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  57. df_bms = df_data['bms']
  58. #读取电池当前运营状态.....................................................................................................................................................
  59. host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
  60. port=3306
  61. db='qixiang_manage'
  62. user='qx_query'
  63. password='@Qx_query'
  64. mode=4
  65. tablename1='py_battery'
  66. DBRead=DBDw.DBDownload(host, port, db, user, password,mode)
  67. with DBRead as DBRead:
  68. df_OprtnSta=DBRead.getdata('qrcode','status', tablename=tablename1, sn=sn, timename='', st='', sp='',factory='')#取最后一条运营状态
  69. #执行主程序-------------------------------------------------------------------------------------------
  70. low_soc_bat_list=Low_soc_alarm.low_soc_alarm(param,df_bms,low_soc_bat_list,sn,df_OprtnSta)
  71. return low_soc_bat_list
  72. mylog=log.Mylog('log_diag.txt','error')
  73. mylog.logcfg()
  74. scheduler = BlockingScheduler()
  75. low_soc_bat_list=Low_Soc_Alarm()
  76. low_soc_bat_list.to_excel('Low_Soc_Alarm.xlsx')
  77. #------------------------------------定时执行程序-----------------------------------------------------------
  78. scheduler.add_job(Low_Soc_Alarm, 'interval',days=1, start_date='2021-11-12 00:00:00', id='low_soc_alarm')
  79. try:
  80. scheduler.start()
  81. except Exception as e:
  82. scheduler.shutdown()
  83. print(repr(e))
  84. mylog.logopt(e)