优化
This commit is contained in:
@@ -192,7 +192,8 @@ def sync(city=None):
|
||||
"_op_type": "index",
|
||||
"_index": index_name,
|
||||
"_id": item['_id'],
|
||||
"_source": doc_info
|
||||
"_source": doc_info,
|
||||
"_retry_on_conflict": 5
|
||||
}
|
||||
|
||||
actions.append(action)
|
||||
|
||||
@@ -59,15 +59,16 @@ def calc_percentile(city=None):
|
||||
|
||||
for city_now in cities:
|
||||
df = consumption_aim_df[consumption_aim_df['city'] == city_now].copy()
|
||||
percents_now_df = percents_df[percents_df['city'] == city_now].copy()
|
||||
for i in range(1, 101):
|
||||
if i == 1:
|
||||
df.loc[(df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i
|
||||
df.loc[(df['avg_price'] <= percents_now_df[(percents_now_df['type'] == 'avg_price') & (percents_now_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i
|
||||
|
||||
df.loc[(df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i
|
||||
df.loc[(df['total_price'] <= percents_now_df[(percents_now_df['type'] == 'total_price') & (percents_now_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i
|
||||
else:
|
||||
df.loc[(df['avg_price'] > percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i - 1)].iloc[0]['price']) & (df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i
|
||||
df.loc[(df['avg_price'] > percents_now_df[(percents_now_df['type'] == 'avg_price') & (percents_now_df['percent'] == i - 1)].iloc[0]['price']) & (df['avg_price'] <= percents_now_df[(percents_now_df['type'] == 'avg_price') & (percents_now_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i
|
||||
|
||||
df.loc[(df['total_price'] > percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i - 1)].iloc[0]['price']) & (df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i
|
||||
df.loc[(df['total_price'] > percents_now_df[(percents_now_df['type'] == 'total_price') & (percents_now_df['percent'] == i - 1)].iloc[0]['price']) & (df['total_price'] <= percents_now_df[(percents_now_df['type'] == 'total_price') & (percents_now_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i
|
||||
|
||||
# 批量更新
|
||||
for index, item in df.iterrows():
|
||||
@@ -81,7 +82,9 @@ def calc_percentile(city=None):
|
||||
action = {'_op_type': 'update',
|
||||
'_index': index_name,
|
||||
'_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)
|
||||
|
||||
Reference in New Issue
Block a user