123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #coding=utf-8
- import os
- import datetime
- import pandas as pd
- from LIB.BACKEND import DBManager, Log
- from LIB.MIDDLE import SignalMonitor
- from sqlalchemy import create_engine
- from sqlalchemy.orm import sessionmaker
- import time, datetime
- import traceback
- from LIB.MIDDLE.DrivingRange import UpdtFct
- import pymysql
- from urllib import parse
- dbManager = DBManager.DBManager()
- if __name__ == "__main__":
- #建立引擎
- db_engine = create_engine(str(r"mysql+pymysql://%s:" + '%s' + "@%s/%s") % ('root', 'pengmin', 'localhost', 'qixiangdb'))
- #连接到qx数据库
- db_qx = pymysql.connect(
- host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com',
- user='qx_read',
- password='Qx@123456',#Qx@123456
- database='qx_cas',
- charset='utf8'
- )
- #连接到本地数据库,输出物
- db_local = pymysql.connect(
- host='localhost',
- user='root',
- password='pengmin',
- database='qixiangdb',
- charset='utf8'
- )
- #调度周期:每天运行一次。
- #更新所有sn,连读多日的factor,如果start_date和end_date相隔一天,代表更新start_date的factor。
- start_date="2021-07-23"
- end_date="2021-07-28"
- UpdtFct.updtAllSnFct(start_date,end_date, db_engine, db_local, db_qx)
- df_newest = UpdtFct.updtNewestFctTb(db_local, db_engine)
- #按照日期排序,只保留最近的一天,输出factor_unique_df,方法为replace。
- #本函数,每天需要运行一次,用于更新factor。
- df_newest.to_sql("tb_sn_factor_newest",con=db_engine,chunksize=10000,\
- if_exists='replace',index=False)
- #调度周期:程序每5分钟运行一次
- #更新剩余里程,每5min一次,几秒钟运行结束。
- test_time=datetime.datetime.now()#当前系统时间
- input_time=datetime.datetime.strftime(test_time,'%Y-%m-%d %H:%M:%S')
- # input_time='2021-07-29 11:59:00'#手动设定一个时间
- #函数每5min调度一次,input_time为当前时间,更新tb_sn_factor_soc_range表格
- df_range = UpdtFct.updtVehElecRng(db_qx, db_local, db_engine, input_time)
- df_range.to_sql("tb_sn_factor_soc_range",con=db_engine,chunksize=10000,\
- if_exists='replace',index=False)
|