From 4c55387790988d8c13994fd44513bfcec4c1f063 Mon Sep 17 00:00:00 2001 From: wangwenyan Date: Fri, 16 Aug 2024 10:33:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=88=90=E4=BA=A4=E6=8C=82?= =?UTF-8?q?=E7=89=8C=E4=BB=B7=E7=B3=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/business/business/evaluate_ratio.py | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/dags/business/business/evaluate_ratio.py b/dags/business/business/evaluate_ratio.py index 1ee1180..a9ab4fb 100644 --- a/dags/business/business/evaluate_ratio.py +++ b/dags/business/business/evaluate_ratio.py @@ -1,9 +1,8 @@ -from goojia_utils import MAIN_MONGO_CLIENT,dateutils -from datetime import datetime,date +from goojia_utils import MAIN_MONGO_CLIENT, dateutils +from datetime import datetime, date import pandas as pd from dateutil.relativedelta import relativedelta - deal_price_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'deal_price') district_sell_stat_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_stat', 'district_sell_stat') evaluate_ratio_conn = MAIN_MONGO_CLIENT.get_collection('business', 'evaluate_ratio') @@ -21,6 +20,7 @@ year = datetimeNow.year month = datetimeNow.month day = datetimeNow.day + def sync(): # 查询2年内成交价格 dear_price_r = deal_price_conn.find({ @@ -28,14 +28,15 @@ def sync(): { "$gte": datetime(ago_year, ago_month, ago_day, 0, 0), "$lt": datetime(year, month, day, 0, 0) - }, - 'area': {"$gt": 20}, - 'type': {'$ne': '车位'}, - 'match_id': {'$exists': 'true'}, - 'avg_price': {'$lte': 500000} - }, {'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'area': 1, 'trade_date': 1, 'match_id': 1}) + } + }, {'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'area': 1, 'trade_date': 1, 'match_id': 1, + 'type': 1}).batch_size(10000) df1 = pd.DataFrame(list(dear_price_r)) + df1 = df1[df1.type != "车位"] + df1 = df1[df1.area > 20] + df1 = df1[df1.avg_price > 500000] + df1 = df1[~df1.match_id.isna()] if df1.empty: return # 去重 @@ -64,7 +65,7 @@ def sync(): "$gte": 202106, "$lt": 202306 } - },{'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'date': 1}) + }, {'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'date': 1}) df2 = pd.DataFrame(list(district_stat_r)) @@ -91,7 +92,7 @@ def sync(): df = pd.merge(deal_price_city_avgprice, district_stat_city_avgprice, how='inner', on=['city']) df['ratio'] = round((df['avg_price_x'] - df['avg_price_y']) / df['avg_price_y'], 2) - #df.to_excel('data/city_ratio.xlsx', index=False) + # df.to_excel('data/city_ratio.xlsx', index=False) for index in df.index: city = df['city'].get(index) @@ -143,4 +144,5 @@ def sync(): "$set": {"ratio": ratio, "m_date": m_date}} update_result = evaluate_ratio_conn.update_one(query, update, upsert=True) -sync() \ No newline at end of file + +sync()