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

dbManager = DBManager.DBManager()

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

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

month='202110'

for k in range(l):
    try:
        sn = fileNames[k]

        df_data = dbManager.get_data(sn=sn, start_time='2021-12-01 00:00:00', end_time='2022-01-01 00:00:00', data_groups=['bms','gps'])
        data_bms = df_data['bms']
        data_gps = df_data['gps']
        if sn[:4] in ['MGMC','UDO2']:
            data_bms['总电流[A]'] = -data_bms['总电流[A]']

        #...............每日累积里程............................................................................
        if len(data_bms['时间戳'])>0 and len(data_gps['时间戳'])>0:
            df_res = calcul_mileage.calcul_mileage(sn,data_bms,data_gps)
            df_res.to_csv('Mileage_'+sn+'_'+month+'.csv')
        
    except Exception as e:
        print(repr(e))
        mylog.logopt(sn,e)
        pass
