新增单独城市支持
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from goojia_utils import ElasticSearchClient, commutils, dateutils
|
from goojia_utils import ElasticSearchClient, commutils, dateutils, areautils
|
||||||
from elasticsearch import helpers
|
from elasticsearch import helpers
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
@@ -85,10 +85,12 @@ def update_status(new_df):
|
|||||||
actions.clear()
|
actions.clear()
|
||||||
|
|
||||||
|
|
||||||
def sync():
|
def sync(city=None):
|
||||||
log.info("开始同步消费数据...")
|
log.info("开始同步消费数据...")
|
||||||
df = es206_client.scan_by_sql_to_data_frame(
|
query_sql = "select id, city, tag, type, price from bd_poi where price > 0 and tag in('美食;中餐厅', '美食;外国餐厅') "
|
||||||
"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筛选数据
|
# 按百分位5-95筛选数据
|
||||||
cities = df['city'].unique()
|
cities = df['city'].unique()
|
||||||
@@ -103,6 +105,9 @@ def sync():
|
|||||||
update_status(new_df)
|
update_status(new_df)
|
||||||
|
|
||||||
seaweed_df = pd.read_csv(path + '/seaweed.csv', sep='@', encoding='UTF-8')
|
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):
|
def find_around_price_item(index, item):
|
||||||
if 'lng' not in item:
|
if 'lng' not in item:
|
||||||
@@ -125,23 +130,18 @@ def sync():
|
|||||||
"_op_type": "update",
|
"_op_type": "update",
|
||||||
"_index": index_name,
|
"_index": index_name,
|
||||||
"_id": item['_id'],
|
"_id": item['_id'],
|
||||||
"doc": doc_info
|
"doc": doc_info,
|
||||||
|
"_retry_on_conflict": 5
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.append(action)
|
actions.append(action)
|
||||||
if len(actions) == 5000:
|
if len(actions) == 5000:
|
||||||
try:
|
helpers.bulk(es206_client.elastic_client, actions)
|
||||||
helpers.bulk(es206_client.elastic_client, actions)
|
count += len(actions)
|
||||||
count += len(actions)
|
log.info("更新:" + str(count))
|
||||||
log.info("更新:" + str(count))
|
|
||||||
except Exception as e:
|
|
||||||
log.error(e)
|
|
||||||
actions.clear()
|
actions.clear()
|
||||||
if len(actions) > 0:
|
if len(actions) > 0:
|
||||||
try:
|
helpers.bulk(es206_client.elastic_client, actions)
|
||||||
helpers.bulk(es206_client.elastic_client, actions)
|
|
||||||
except Exception as e:
|
|
||||||
log.error(e)
|
|
||||||
actions.clear()
|
actions.clear()
|
||||||
|
|
||||||
log.info("完成同步消费数据...")
|
log.info("完成同步消费数据...")
|
||||||
|
|||||||
@@ -99,7 +99,9 @@ def calc_consumption_rating(community_summary_df):
|
|||||||
action = {'_op_type': 'update', # 操作 index update create delete
|
action = {'_op_type': 'update', # 操作 index update create delete
|
||||||
'_index': index_name, # index
|
'_index': index_name, # index
|
||||||
'_id': _id, # 请勿忘记ID
|
'_id': _id, # 请勿忘记ID
|
||||||
'doc': row}
|
'doc': row,
|
||||||
|
"_retry_on_conflict": 5
|
||||||
|
}
|
||||||
actions.append(action)
|
actions.append(action)
|
||||||
if len(actions) == 5000:
|
if len(actions) == 5000:
|
||||||
helpers.bulk(client=es206_client.elastic_client, actions=actions)
|
helpers.bulk(client=es206_client.elastic_client, actions=actions)
|
||||||
|
|||||||
Reference in New Issue
Block a user