新增单独城市支持

This commit is contained in:
shenjian@fangjia.com
2022-11-17 15:34:09 +08:00
parent c059fc5c39
commit 958af45e79
2 changed files with 18 additions and 16 deletions
+15 -15
View File
@@ -3,7 +3,7 @@
"""
import logging
import pandas as pd
from goojia_utils import ElasticSearchClient, commutils, dateutils
from goojia_utils import ElasticSearchClient, commutils, dateutils, areautils
from elasticsearch import helpers
import numpy as np
from concurrent.futures import ThreadPoolExecutor
@@ -85,10 +85,12 @@ def update_status(new_df):
actions.clear()
def sync():
def sync(city=None):
log.info("开始同步消费数据...")
df = es206_client.scan_by_sql_to_data_frame(
"select id, city, tag, type, price from bd_poi where price > 0 and tag in('美食;中餐厅', '美食;外国餐厅')")
query_sql = "select id, city, tag, type, price from bd_poi where price > 0 and tag in('美食;中餐厅', '美食;外国餐厅') "
if pd.notna(city):
query_sql += " and city='" + areautils.get_city_display(city) + "'"
df = es206_client.scan_by_sql_to_data_frame(query_sql)
# 按百分位5-95筛选数据
cities = df['city'].unique()
@@ -103,6 +105,9 @@ def sync():
update_status(new_df)
seaweed_df = pd.read_csv(path + '/seaweed.csv', sep='@', encoding='UTF-8')
if pd.notna(city):
seaweed_df = seaweed_df[seaweed_df['city'] == city].copy()
seaweed_df = seaweed_df.reset_index(drop=True)
def find_around_price_item(index, item):
if 'lng' not in item:
@@ -125,23 +130,18 @@ def sync():
"_op_type": "update",
"_index": index_name,
"_id": item['_id'],
"doc": doc_info
"doc": doc_info,
"_retry_on_conflict": 5
}
actions.append(action)
if len(actions) == 5000:
try:
helpers.bulk(es206_client.elastic_client, actions)
count += len(actions)
log.info("更新:" + str(count))
except Exception as e:
log.error(e)
helpers.bulk(es206_client.elastic_client, actions)
count += len(actions)
log.info("更新:" + str(count))
actions.clear()
if len(actions) > 0:
try:
helpers.bulk(es206_client.elastic_client, actions)
except Exception as e:
log.error(e)
helpers.bulk(es206_client.elastic_client, actions)
actions.clear()
log.info("完成同步消费数据...")
@@ -99,7 +99,9 @@ def calc_consumption_rating(community_summary_df):
action = {'_op_type': 'update', # 操作 index update create delete
'_index': index_name, # index
'_id': _id, # 请勿忘记ID
'doc': row}
'doc': row,
"_retry_on_conflict": 5
}
actions.append(action)
if len(actions) == 5000:
helpers.bulk(client=es206_client.elastic_client, actions=actions)