新增极值过滤

This commit is contained in:
shenjian@fangjia.com
2022-11-18 15:59:28 +08:00
parent cdffdd045e
commit 0baa286567
2 changed files with 17 additions and 1 deletions
@@ -13,7 +13,15 @@ log = logging.getLogger(__name__)
es206_client = ElasticSearchClient(host='192.168.0.206')
index_name = "community_summary"
path = "/opt/airflow/dags/repo/dags/business/business/community/data"
factor_df = pd.read_excel(path + '/财力评级极值设置.xlsx')
factor_dict = dict()
for index, item in factor_df.iterrows():
if pd.isna(item['min_total_price']):
continue
factor_dict[item['city']] = {'min_total_price': item['min_total_price'], 'max_total_price': item['max_total_price'], 'min_estate_charge': item['min_estate_charge'], 'max_estate_charge': item['max_estate_charge'], \
'min_avg_cost': item['min_avg_cost'], 'max_avg_cost': item['max_avg_cost']}
def calc_consumption_potential(city):
"""
@@ -24,6 +32,15 @@ def calc_consumption_potential(city):
sql += " where city='" + city + "'"
community_summary_df = es206_client.scan_by_sql_to_data_frame(sql)
# 户均总价计算时候改成万
### 极值设置
if city in factor_dict:
community_summary_df.loc[community_summary_df['total_price'] < factor_dict[city]['min_total_price'], 'total_price'] = factor_dict[city]['min_total_price']
community_summary_df.loc[community_summary_df['total_price'] > factor_dict[city]['max_total_price'], 'total_price'] = factor_dict[city]['max_total_price']
community_summary_df.loc[community_summary_df['estate_charge'] < factor_dict[city]['min_estate_charge'], 'estate_charge'] = factor_dict[city]['min_estate_charge']
community_summary_df.loc[community_summary_df['estate_charge'] > factor_dict[city]['max_estate_charge'], 'estate_charge'] = factor_dict[city]['max_estate_charge']
community_summary_df.loc[community_summary_df['avg_cost'] < factor_dict[city]['min_avg_cost'], 'avg_cost'] = factor_dict[city]['min_avg_cost']
community_summary_df.loc[community_summary_df['avg_cost'] > factor_dict[city]['max_avg_cost'], 'avg_cost'] = factor_dict[city]['max_avg_cost']
community_summary_df['total_price'] = community_summary_df['total_price'] / 10000
community_summary_df['total_price_mean'] = community_summary_df.groupby(by=['city'])['total_price'].transform(
@@ -119,5 +136,4 @@ def sync(city=None):
community_summary_df = calc_consumption_potential(city)
calc_consumption_rating(community_summary_df)
sync()