优化户均总价

This commit is contained in:
shenjian@fangjia.com
2022-11-17 17:25:23 +08:00
parent 958af45e79
commit 5e3f9d6001
+15 -14
View File
@@ -25,9 +25,9 @@ def build_doc(item):
return doc_dict
def avg_price_map_deal(x):
avg_price_map[x['city'] + x['region'] + x['name']] = x['avg_price']
return x
# def avg_price_map_deal(x):
# avg_price_map[x['city'] + x['region'] + x['name']] = x['avg_price']
# return x
def deal(seaweed_df, index, item):
@@ -45,14 +45,14 @@ def deal(seaweed_df, index, item):
names.append(alias_item)
# 户均总价
if (curr_city + curr_region + curr_name) in avg_price_map:
avg_price = avg_price_map[curr_city + curr_region + curr_name]
if pd.notna(avg_price):
# if (curr_city + curr_region + curr_name) in avg_price_map:
# avg_price = avg_price_map[curr_city + curr_region + curr_name]
# if pd.notna(avg_price):
# 由于覆盖率较低,暂不过滤
# min_avg_price = 0.8 * avg_price
# max_avg_rice = 1.2 * avg_price
total_price = commutils.get_total_price(curr_city, curr_region, names, day_before=366)
seaweed_df.loc[index, 'total_price'] = total_price
total_price = commutils.get_total_price(curr_city, curr_region, names, day_before=366)
seaweed_df.loc[index, 'total_price'] = total_price
def sync(city=None):
@@ -64,12 +64,12 @@ def sync(city=None):
seaweed_df = seaweed_df.reset_index(drop=True)
# 加载库中均价数据
query_sql = "SELECT city, region, name, avg_price FROM community_summary "
if pd.notna(city):
query_sql += " WHERE city='" + city + "' "
community_summary_df = es206_client.scan_by_sql_to_data_frame(query_sql)
# query_sql = "SELECT city, region, name, avg_price FROM community_summary "
# if pd.notna(city):
# query_sql += " WHERE city='" + city + "' "
# community_summary_df = es206_client.scan_by_sql_to_data_frame(query_sql)
community_summary_df.apply(lambda x: avg_price_map_deal(x), axis=1)
# community_summary_df.apply(lambda x: avg_price_map_deal(x), axis=1)
with ThreadPoolExecutor(30) as pool:
for index, item in seaweed_df.iterrows():
@@ -84,7 +84,8 @@ def sync(city=None):
"_op_type": "update",
"_index": index_name,
"_id": item['_id'],
"doc": doc_info
"doc": doc_info,
"_retry_on_conflict": 5
}
actions.append(action)