diff --git a/project_evaluation_analysis/generate_task_static_history.py b/project_evaluation_analysis/generate_task_static_history.py new file mode 100644 index 0000000..074b8c0 --- /dev/null +++ b/project_evaluation_analysis/generate_task_static_history.py @@ -0,0 +1,116 @@ +import sys +import os + +import config + +curPath = os.path.abspath(os.path.dirname(__file__)) +rootPath = os.path.split(curPath)[0] +sys.path.append(rootPath) + +import warnings +from datetime import datetime,timedelta +from utils import get_conn, get_month_date +warnings.filterwarnings("ignore") + +def execute_sql(sql:str): + conn = get_conn() + curs = conn.cursor() + curs.execute(sql) + conn.commit() + conn.close() +def record_task_history(): + #每次调用此函数,默认记录当前日期的里程碑数据,然后回顾最近2个月的数据,若2个月之前的数据不存在,则以随机数的方式生成填充,并在is_test字段标记为true + + # 查看当前历史表中已经有的数据 + now = datetime.now() + today_str=now.strftime('%Y-%m-%d') + today=datetime.strptime(today_str,'%Y-%m-%d') + delta = timedelta(days=60) + begin_date=now-delta + begin_date_str=begin_date.strftime('%Y-%m-%d') + # 取出数据库中已有的最后一天的日期 + last_date_sql=f'''SELECT max(date) as last_date from ( +SELECT date from ai_task_static_history where date>'{begin_date_str}' GROUP BY date order by date +) as a''' + + conn = get_conn() + curs = conn.cursor() + curs.execute(last_date_sql) + last_date=curs.fetchone()[0] + last_date_str="" + if last_date is None: + last_date_str=(today-timedelta(days=60)).strftime('%Y-%m-%d') + else: + last_date_str=last_date.strftime('%Y-%m-%d') + #last_date_str='2023-02-01' + if last_date_str==today_str: + config.logger.info("当前日期的task数据已存在,跳过生成") + return + + last_date=datetime.strptime(last_date_str,'%Y-%m-%d') + + delta=timedelta(days=1) + generate_day=last_date+delta + config.logger.info(f"开始生成{generate_day}到{today}的数据") + while generate_day