From 4f9fe0dce966ee1356307b4c25c07122b4649252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Thu, 20 Mar 2025 14:51:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=9F=E9=87=91BUG=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/office/rent/base_price.py | 56 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/dags/office/rent/base_price.py b/dags/office/rent/base_price.py index eb95970..bb689f2 100644 --- a/dags/office/rent/base_price.py +++ b/dags/office/rent/base_price.py @@ -276,33 +276,37 @@ def calc(city, year_month): diff_df = combined.drop_duplicates(subset=['city', 'region', 'name'], keep=False) actions.clear() for index, item in diff_df.iterrows(): - location = { - "type": "Point", - "coordinates": [item['lng'] / math.pow(10, 10), item['lat'] / math.pow(10, 10)] - } - city = item['city'] - region = item['region'] - name = item['name'] - estate_type2 = item['estate_type2'] - bed_kind = item['bed_kind'] - ret = office_rent_stat_conn.aggregate([ - { - '$geoNear': { - 'near': location, - 'distanceField': "distance", - 'maxDistance': 3000, - 'spherical': True - } - }, - { - '$match': { - 'date': year_month - } - }, - { - '$limit': 5 + try: + location = { + "type": "Point", + "coordinates": [item['lng'] / math.pow(10, 10), item['lat'] / math.pow(10, 10)] } - ]); + city = item['city'] + region = item['region'] + name = item['name'] + estate_type2 = item['estate_type2'] if pd.notna(item['estate_type2']) else None + bed_kind = item['bed_kind'] + ret = office_rent_stat_conn.aggregate([ + { + '$geoNear': { + 'near': location, + 'distanceField': "distance", + 'maxDistance': 3000, + 'spherical': True + } + }, + { + '$match': { + 'date': year_month + } + }, + { + '$limit': 5 + } + ]); + except Exception as e: + print("Error occurred:", str(e)) + print(item) # 提取 avg_price 的值 avg_prices = [doc["avg_price"] for doc in ret] # 计算平均值