main.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 low_soc_alarm import Low_soc_alarm
  14. import pymysql
  15. def Low_Soc_Alarm():
  16. end_time=datetime.datetime.now()
  17. start_time=end_time-datetime.timedelta(days=1)
  18. start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
  19. end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
  20. #-------------------------读取数据-------------------------------------------------------------------
  21. host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
  22. port=3306
  23. db='qixiang_oss'
  24. user='qixiang_oss'
  25. password='Qixiang2021'
  26. conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
  27. cursor = conn.cursor()
  28. cursor.execute("select sn from app_device")
  29. res = cursor.fetchall()
  30. df_sn = pd.DataFrame(res, columns=['sn'])
  31. df_sn = df_sn.reset_index(drop=True)
  32. conn.close();
  33. # excelpath=r'D:\ZLWORK\code\data_analyze_platform\USER\eric\SaftyCenter_CODE_V1\sn-20210903.xlsx'
  34. # SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  35. # SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  36. # SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  37. # SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  38. # SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  39. # SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  40. # SNnums_6060=SNdata_6060['SN号'].tolist()
  41. # SNnums_6040=SNdata_6040['SN号'].tolist()
  42. # SNnums_4840=SNdata_4840['SN号'].tolist()
  43. # SNnums_L7255=SNdata_L7255['SN号'].tolist()
  44. # SNnums_C7255=SNdata_C7255['SN号'].tolist()
  45. # SNnums_U7255=SNdata_U7255['SN号'].tolist()
  46. # SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
  47. #SNnums=['MGMCLN750N215I009']
  48. #SNnums=df_sn
  49. #-------------------------执行循环----------------------------------------------------------------------
  50. low_soc_bat_list=DataFrame(columns=['sn','time','level'])
  51. for sn in df_sn['sn']:#SN遍历
  52. print(sn)
  53. if 'PK500' in sn:
  54. celltype=1 #6040三元电芯
  55. elif 'PK502' in sn:
  56. celltype=2 #4840三元电芯
  57. elif 'K504B' in sn:
  58. celltype=99 #60ah林磷酸铁锂电芯
  59. elif 'MGMLXN750' in sn:
  60. celltype=3 #力信50ah三元电芯
  61. elif 'MGMCLN750' or 'UD' in sn:
  62. celltype=4 #CATL 50ah三元电芯
  63. elif 'BT1048020' in sn:
  64. celltype=101 #20ah林磷酸铁锂电芯
  65. else:
  66. print('SN:{},未找到对应电池类型!!!'.format(sn))
  67. continue
  68. # sys.exit()
  69. param=QX_BatteryParam.BatteryInfo(celltype)
  70. #读取原始数据库数据.....................................................................................
  71. dbManager = DBManager.DBManager()
  72. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  73. df_bms = df_data['bms']
  74. #读取电池当前运营状态.....................................................................................................................................................
  75. host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
  76. port=3306
  77. db='qixiang_manage'
  78. user='qx_query'
  79. password='@Qx_query'
  80. mode=4
  81. tablename1='py_battery'
  82. DBRead=DBDw.DBDownload(host, port, db, user, password,mode)
  83. with DBRead as DBRead:
  84. df_OprtnSta=DBRead.getdata('qrcode','status', tablename=tablename1, sn=sn, timename='', st='', sp='',factory='')#取最后一条运营状态
  85. #执行主程序-------------------------------------------------------------------------------------------
  86. low_soc_bat_list=Low_soc_alarm.low_soc_alarm(param,df_bms,low_soc_bat_list,sn,df_OprtnSta)
  87. if len(low_soc_bat_list):
  88. print(low_soc_bat_list)
  89. return low_soc_bat_list
  90. # mylog=log.Mylog('log_diag.txt','error')
  91. # mylog.logcfg()
  92. try:
  93. low_soc_bat_list=Low_Soc_Alarm()
  94. low_soc_bat_list.to_excel('low_soc_bat_list.xlsx')
  95. except Exception as e:
  96. print(repr(e))
  97. # mylog.logopt(e)