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

dbManager = DBManager.DBManager()

#now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')   #type: str
now_time='2021-12-27 00:00:00'
now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')     #type: datetime
start_time=now_time-datetime.timedelta(days=1)
end_time=str(now_time)
start_time=str(start_time)

sn='MGMCLN750N215N180'
df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, 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+'.csv')
