#coding=utf-8 import sys import datetime import pandas as pd from LIB.BACKEND import DBManager, Log from sqlalchemy import create_engine import time, datetime from apscheduler.schedulers.blocking import BlockingScheduler from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log #...................................SOC计算函数...................................................................................................................... def soc_cal(): import CBMSBatSoc global SNnums global df_ram start=time.time() end_time=datetime.datetime.now()-datetime.timedelta(seconds=10) start_time=end_time-datetime.timedelta(seconds=70) 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() # sn='PK504B10100003033' # 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') #读取原始数据库数据........................................................................................................................................................ dbManager = DBManager.DBManager() df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms']) df_bms = df_data['bms'] # df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\''BMS_'+sn+'.csv',encoding='GB18030') #读取结果数据库数据........................................................................................................................................................ 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==99: 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] if df_ram_sn.empty: with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\04BatSoc\\'+'soc_'+str(sn)+'.txt','a') as file: file.write(str(tuple(df_ram_sn.columns))+'\n') 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) #重置索引 # print(df_res) # print(df_ram) if not df_ram_sn.empty: with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\04BatSoc\\'+'soc_'+str(sn)+'.txt','a') as file: file.write(str(tuple(df_ram_sn.iloc[-1]))+'\n') end=time.time() print(end-start) #...............................................主函数....................................................................................................................... if __name__ == "__main__": excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx' SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060') SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040') SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840') SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255') SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255') SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255') SNnums_6060=SNdata_6060['SN号'].tolist() SNnums_6040=SNdata_6040['SN号'].tolist() SNnums_4840=SNdata_4840['SN号'].tolist() SNnums_L7255=SNdata_L7255['SN号'].tolist() SNnums_C7255=SNdata_C7255['SN号'].tolist() SNnums_U7255=SNdata_U7255['SN号'].tolist() SNnums= SNnums_6060 + SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255 SNnums=['UD02030118B4C0046','MGMCLN750N215I005','PK504B10100004327','PK504B10100003032','PK504B00100004172','PK504B10100003033','PK50001A100000222'] # #log信息配置 mylog=log.Mylog('log_soc.txt','error') mylog.logcfg() #参数初始化......................................................................................................................................................................... column_name=['time', 'sn', 'bms_soc', 'soc','cellsocmin','cellsocmax','standingtime','rampackcrnt','ramcellvoltmin','ramcellvoltmax','kocellvoltmin','kocellvoltmax','ocvweight','as_accum','socstep'] df_ram=pd.DataFrame(columns=column_name) scheduler = BlockingScheduler() scheduler.add_job(soc_cal, 'interval', seconds=60, id='soc_job') try: scheduler.start() except Exception as e: scheduler.shutdown() print(repr(e)) mylog.logopt(e)