1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import numpy as np
- import pandas as pd
- import datetime
- import pymysql
- from apscheduler.schedulers.blocking import BlockingScheduler
- from USER.SPF.alibaba.Common import log
- import CBMSBatCtrl
- #...................................SOC计算函数......................................................................................................................
- def ctrl_cal():
- global df_ram_rlyctrl
- global df_ram_statectrl
- global now_time
- global df_bms
- end_time=now_time+datetime.timedelta(seconds=3)
- start_time=now_time
- now_time=now_time+datetime.timedelta(seconds=3)
- host='120.25.223.1'
- port=4901
- user='root'
- password='123456'
- db='ali'
- mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db)
- #log信息配置............................................................................................................................................................................
- mylog=log.Mylog('log_ctrl.txt','error')
- mylog.logcfg()
- sn_list=['KPD001','KPD002','KPD003']
- try:
- #读取所有康普盾电池包原始数据库最后一条数据...........................................................................
-
- df_bms= df_bms[(df_bms['time']>=start_time) & (df_bms['time']<end_time)]
- df_bms=df_bms.reset_index(drop=True)
- cellvolt_name=['CellVolt'+str(x) for x in range(1,121)]
- df_volt=pd.DataFrame([x[0].split(",") for x in np.array(df_bms[['cell_volt']])]).iloc[:,list(range(120))]
- df_volt.columns = cellvolt_name
- df_volt=df_volt.astype('float')
- df_bms=pd.concat([df_bms,df_volt],axis=1)
- df_bms.dropna(axis=0, inplace=True)
- #读取所有未结束故障......................................................
- df_diag=pd.DataFrame({'sn':['KPD001','KPD002','KPD003'],'fault_code':[100,100,100]})
- #下行控制...................................................................................
- host1='120.25.223.1'
- port1=4902
- BatCrtl=CBMSBatCtrl.BatCrtl(host1,port1,df_ram_statectrl,df_ram_rlyctrl,df_diag,df_bms,sn_list)
- df_ram_rlyctrl, df_ram_statectrl=BatCrtl.bat_crtl()
- # print('done!!!')
-
- except Exception as e:
- print(repr(e))
- mylog.logopt(e)
- pass
- #...............................................主函数.......................................................................................................................
- if __name__ == "__main__":
- #log信息配置
- mylog=log.Mylog('log_ctrl.txt','error')
- mylog.logcfg()
- #参数初始化.........................................................................................................................................................................
- df_ram_rlyctrl=pd.DataFrame(columns=['time','sn','batrlyctrl'])
- df_ram_statectrl=pd.DataFrame(columns=['time','sn','batstatectrl','done_flg'])
- df_bms= pd.read_excel(r'D:\01WorkSpace\项目\Alibaba\data\原始数据_2022-01-10_2022-02-10\data(1)(1).xlsx')
- now_time=datetime.datetime.strptime('2022-4-27 20:28:01','%Y-%m-%d %H:%M:%S')
- scheduler = BlockingScheduler()
- scheduler.add_job(ctrl_cal, 'interval', seconds=0.05, id='crtl_job')
-
- try:
- scheduler.start()
- except Exception as e:
- scheduler.shutdown()
- print(repr(e))
- mylog.logopt(e)
|