123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import datetime
- import pandas as pd
- import time
- from apscheduler.schedulers.blocking import BlockingScheduler
- from USER.alibaba.Common import DBDownload
- from USER.alibaba.Common import log
- import CBMSBatSoc
- #...................................SOC计算函数......................................................................................................................
- def soc_cal():
- global start_time
- global df_ram
- global df_bms
- SNnums= ['HUATING01']
- start=time.time()
- # end_time=datetime.datetime.now()-datetime.timedelta(seconds=10)
- # start_time=end_time-datetime.timedelta(seconds=11)
-
- start_time=start_time+datetime.timedelta(seconds=10)
- end_time=start_time+datetime.timedelta(seconds=11)
- # start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
- # end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
- for sn in SNnums:
- # if 'PK500' in sn:
- # celltype=1 #6040三元电芯
- # elif 'PK502' in sn:
- # celltype=2 #4840三元电芯
- # elif 'K504B' in sn:
- # celltype=99 #60ah林磷酸铁锂电芯
- # elif 'MGMLXN750' in sn:
- # celltype=3 #力信50ah三元电芯
- # elif 'MGMCLN750' or 'UD' in sn:
- # celltype=4 #CATL 50ah三元电芯
- # else:
- # print('SN:{},未找到对应电池类型!!!'.format(sn))
- # continue
- # sys.exit()
- celltype=2
- # start_time='2021-05-02 09:12:26'
- # end_time='2021-06-03 19:12:26'
- # # df_bms= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download\\'+'BMS_'+sn+'.csv',encoding='GB18030')
- #读取原始数据库数据........................................................................................................................................................
- # df_bms= pd.read_excel(r'D:\00WorkSpace\01Python\data_analyze_platform\USER\alibaba\98Download\18650-SOH原始数据.xlsx')
- # df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\''BMS_'+sn+'.csv',encoding='GB18030')
- # df_bms['time']=pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S')
- df_bms1=df_bms[(df_bms['time'] > start_time) & (df_bms['time'] < end_time)]
- df_bms1.reset_index(inplace=True,drop=True)
- # print(df_bms1)
- #读取结果数据库数据........................................................................................................................................................
- # host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
- # port=3306
- # db='qx_cas'
- # user='qx_read'
- # password='Qx@123456'
- # mode=1
- # tablename='cellstateestimation_soh'
- # DBRead=DBDownload.DBDownload(host, port, db, user, password, mode)
- # with DBRead as DBRead:
- # df_soh=DBRead.getdata(param='time_st,sn,soh', tablename=tablename, sn=sn, timename='time_sp', st=start_time, sp=end_time)
- df_soh=pd.DataFrame({'time_st':[1],'sn':[sn],'soh':[100]})
- if celltype>50:
- # tablename='cellstateestimation_uniform_socvoltdiff'
- # with DBRead as DBRead:
- # df_socdiff=DBRead.getdata(param='time,sn,cellsoc_diff', tablename=tablename, sn=sn, timename='time', st=start_time, sp=end_time)
- df_socdiff=pd.DataFrame({'time':[1],'sn':[sn],'cellsoc_diff':[1.2]})
- else:
- df_socdiff=pd.DataFrame()
- # print(df_bms)
- # print(df_soh)
-
- #socram存储...............................................................................................................................................................
- if not df_bms1.empty:
- df_ram_sn=df_ram[df_ram['sn']==sn]
- if df_ram_sn.empty:
- with open(r'D:\00WorkSpace\01Python\data_analyze_platform\USER\alibaba\04BatSoc\\'+'soc_'+sn+'.txt','a') as file:
- file.write(str(tuple(df_ram_sn.columns))+'\n')
-
- BatSoc=CBMSBatSoc.BatSoc(sn,celltype,df_bms1,df_soh,df_ram_sn,df_socdiff)
- df_res, df_ram_sn=BatSoc.batsoc()
- if not df_ram_sn.empty:
- sn_index=df_ram.loc[df_ram['sn']==sn].index
- df_ram=df_ram.drop(index=sn_index)
- df_ram=df_ram.append(df_ram_sn)
- df_ram.reset_index(inplace=True,drop=True) #重置索引
-
- # print(df_res)
- # print(df_ram)
- if not df_ram_sn.empty:
- with open(r'D:\00WorkSpace\01Python\data_analyze_platform\USER\alibaba\04BatSoc\\'+'soc_'+sn+'.txt','a') as file:
- file.write(str(tuple(df_ram_sn.iloc[-1]))+'\n')
-
-
- end=time.time()
- print(end-start)
-
- #...............................................主函数.......................................................................................................................
- if __name__ == "__main__":
- #log信息配置
- mylog=log.Mylog('log_soc.txt','error')
- mylog.logcfg()
- #参数初始化.........................................................................................................................................................................
- column_name=['time', 'sn', 'bms_soc', 'soc','cellsoc','standingtime','rampackcrnt','ramcellvolt','kocellvoltmin','kocellvoltmax','ocvweight','as_accum','socstep']
- df_ram=pd.DataFrame(columns=column_name)
- start_time=datetime.datetime.strptime('2021-10-22 14:59:00','%Y-%m-%d %H:%M:%S')
- df_bms= pd.read_excel(r'D:\00WorkSpace\01Python\data_analyze_platform\USER\alibaba\98Download\18650-SOC原始数据.xlsx')
- df_bms['time']=pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S')
- scheduler = BlockingScheduler()
- scheduler.add_job(soc_cal, 'interval', seconds=0.05, id='soc_job')
-
- try:
- scheduler.start()
- except Exception as e:
- scheduler.shutdown()
- print(repr(e))
- mylog.logopt(e)
|