人均消费价格选取策略修改
This commit is contained in:
@@ -17,45 +17,48 @@ m_date = dateutils.iso_format()
|
||||
path = "/home/airflow/data/community"
|
||||
|
||||
|
||||
def find_around_price(lng, lat):
|
||||
def find_around_price(city_now, lng, lat):
|
||||
"""
|
||||
查找周边均价
|
||||
返回取值为10~300,为所有有价格的1-99百分位
|
||||
"""
|
||||
if pd.isna(lng):
|
||||
return None
|
||||
ret_es = es206_client.elastic_client.search({
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{
|
||||
filter = []
|
||||
if pd.notna(city_now):
|
||||
filter.append({
|
||||
"term": {
|
||||
"status": {
|
||||
"value": 0
|
||||
"city": {
|
||||
"value": city_now
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"range": {
|
||||
"price": {
|
||||
"gt": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
})
|
||||
filter.append({
|
||||
"terms": {
|
||||
"tag": [
|
||||
"美食;中餐厅",
|
||||
"美食;外国餐厅"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
})
|
||||
filter.append({
|
||||
"range": {
|
||||
"price": {
|
||||
"gte": 10,
|
||||
"lte": 300
|
||||
}
|
||||
}
|
||||
})
|
||||
filter.append({
|
||||
"geo_distance": {
|
||||
"distance": 1000,
|
||||
"location": [lng, lat]
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
ret_es = es206_client.elastic_client.search({
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": filter
|
||||
}
|
||||
},
|
||||
"size": 0,
|
||||
@@ -74,7 +77,7 @@ def build_doc(item):
|
||||
doc_dict = dict()
|
||||
if 'avg_cost' in item:
|
||||
if pd.notna(item['avg_cost']):
|
||||
doc_dict['avg_cost'] = item['avg_cost']
|
||||
doc_dict['avg_cost'] = int(item['avg_cost'])
|
||||
else:
|
||||
doc_dict['avg_cost'] = None
|
||||
return doc_dict
|
||||
@@ -104,7 +107,7 @@ def update_status(new_df):
|
||||
|
||||
def sync(city=None):
|
||||
log.info("开始同步消费数据...")
|
||||
# 暂时注释
|
||||
# 【过期,无需状态】
|
||||
# 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) + "'"
|
||||
@@ -121,6 +124,7 @@ def sync(city=None):
|
||||
#
|
||||
# # 按最新的百分位更新库中价格状态
|
||||
# update_status(new_df)
|
||||
### 人均消费大于500的,按500
|
||||
|
||||
seaweed_df = pd.read_csv(path + '/seaweed.csv', sep='@', encoding='UTF-8')
|
||||
if pd.notna(city):
|
||||
@@ -134,7 +138,8 @@ def sync(city=None):
|
||||
return
|
||||
lng = commutils.format_lat_lng(item['lng'])
|
||||
lat = commutils.format_lat_lng(item['lat'])
|
||||
price = find_around_price(lng, lat)
|
||||
city_now = areautils.get_city_display(item['city'])
|
||||
price = find_around_price(city_now, lng, lat)
|
||||
if pd.notna(price):
|
||||
seaweed_df.loc[index, 'avg_cost'] = price
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user