From 2773927a240dc406881a5ee1aa6055152f68175f Mon Sep 17 00:00:00 2001 From: lusiyi Date: Wed, 22 Feb 2023 18:12:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0milestone=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generate_milestone_history_data.py | 134 ++++++++++++++++++ sql/01_2022-08-09.sql | 29 ++++ 2 files changed, 163 insertions(+) create mode 100644 project_evaluation_analysis/generate_milestone_history_data.py diff --git a/project_evaluation_analysis/generate_milestone_history_data.py b/project_evaluation_analysis/generate_milestone_history_data.py new file mode 100644 index 0000000..3908def --- /dev/null +++ b/project_evaluation_analysis/generate_milestone_history_data.py @@ -0,0 +1,134 @@ +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_milestone_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_milestone_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("当前日期的milestone数据已存在,跳过生成") + 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