123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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 df_ram
- global SNnums
- end_time=datetime.datetime.now()
- start_time=end_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()
- #读取原始数据库数据........................................................................................................................................................
- df_bms= pd.read_excel(r'D:\00WorkSpace\01Python\data_analyze_platform\USER\alibaba\98Download\力神40Ah-SOC原始数据.xlsx')
- #读取结果数据库数据........................................................................................................................................................
- 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)
- 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)
- else:
- df_socdiff=pd.DataFrame()
- # print(df_bms)
- # print(df_soh)
-
- #socram...............................................................................................................................................................
- if not df_bms.empty:
- df_ram_sn=df_ram[df_ram['sn']==sn]
-
- BatSoc=CBMSBatSoc.BatSoc(sn,celltype,df_bms,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) #重置索引
-
- #结果存入数据库...........................................................
- if not df_res.empty:
- pass
- #...............................................主函数.......................................................................................................................
- if __name__ == "__main__":
- #所有SN号
- SNnums= ['LISHEN01']
- #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)
- 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)
|