from LIB.BACKEND import DBManager
from LIB.MIDDLE.CellStateEstimation.Common import log
import datetime
import pandas as pd   

dbManager = DBManager.DBManager()

#log信息配置
mylog=log.Mylog('log.txt','error')
mylog.logcfg()

dataSOH = pd.read_excel('sn-20210903.xlsx',sheet_name='MGMC')
fileNames = dataSOH['sn']
fileNames = list(fileNames)

data_GMGC=pd.DataFrame()
for k in range(len(fileNames)):
    try:    
        sn = fileNames[k]
        df_data = dbManager.get_data(sn=sn, start_time='2021-07-01 00:00:00', end_time='2021-11-01 00:00:00', data_groups=['bms','gps'])
        data_bms = df_data['bms']
        data_gps = df_data['gps']
        df_merge=pd.merge(data_bms, data_gps,how='outer',sort=True)
        df_merge['sn']=sn
        data_GMGC=data_GMGC.append(df_merge)
    except Exception as e:
        print(repr(e))
        mylog.logopt(sn,e)
        pass
        
