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] # 计算平均值