新增置信度
This commit is contained in:
@@ -17,35 +17,41 @@ m_date = dateutils.iso_format()
|
||||
avg_price_map = dict()
|
||||
|
||||
|
||||
def build_doc(item):
|
||||
doc_dict = dict()
|
||||
if 'total_price' in item and pd.notna(item['total_price']):
|
||||
doc_dict['total_price'] = int(item['total_price'])
|
||||
return doc_dict
|
||||
|
||||
|
||||
def sync(city=None):
|
||||
log.info(f"开始置信度打分 {index_name}")
|
||||
|
||||
# 加载库中均价数据
|
||||
query_sql = "SELECT city, region, name, credit_detail FROM community_summary WHERE consumption_rating>0 "
|
||||
query_filter = [{"range": {"consumption_rating": {"gt": 0}}}]
|
||||
if pd.notna(city):
|
||||
query_sql += " AND city='" + city + "' "
|
||||
community_summary_df = es206_client.scan_by_sql_to_data_frame(query_sql)
|
||||
query_filter.append({"term": {"city": city}})
|
||||
|
||||
query = {
|
||||
"_source": ["city", "region", "credit_detail"],
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": query_filter
|
||||
}
|
||||
}
|
||||
}
|
||||
community_summary_df = es206_client.scan_to_data_frame("community_summary", query)
|
||||
community_summary_df = data_utils.flatten_json(community_summary_df, 'credit_detail')
|
||||
community_summary_df['total_price_score'].fillna(0, inplace=True)
|
||||
community_summary_df['relative_price_ranking_score'].fillna(0, inplace=True)
|
||||
community_summary_df['estate_charge_score'].fillna(0, inplace=True)
|
||||
|
||||
community_summary_df['total_score'] = 0.6 * community_summary_df['total_price_score'] + 0.2 * community_summary_df['relative_price_ranking_score'] + 0.2 * community_summary_df['estate_charge_score']
|
||||
community_summary_df['total_score'] = round(0.6 * community_summary_df['total_price_score'] + 0.2 * community_summary_df['relative_price_ranking_score'] + 0.2 * community_summary_df['estate_charge_score'])
|
||||
community_summary_df['credit'] = round(community_summary_df['total_score'] / 10, 2)
|
||||
|
||||
actions = list()
|
||||
count = 0
|
||||
|
||||
for index, item in community_summary_df.iterrows():
|
||||
doc_info = build_doc(item)
|
||||
for index, item in community_summary_df[community_summary_df['total_score'].notna()].iterrows():
|
||||
doc_info = {
|
||||
'credit': item['credit'],
|
||||
'credit_detail': {
|
||||
'total_score': item['total_score']
|
||||
}
|
||||
}
|
||||
|
||||
action = {
|
||||
"_op_type": "update",
|
||||
@@ -62,6 +68,8 @@ def sync(city=None):
|
||||
actions.clear()
|
||||
if len(actions) > 0:
|
||||
helpers.bulk(es206_client.elastic_client, actions)
|
||||
count += len(actions)
|
||||
logging.info("已更新:" + str(count))
|
||||
actions.clear()
|
||||
log.info(f"完成置信度打分 {index_name}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user