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