diff --git a/dags/business/business/community/consumption_stat.py b/dags/business/business/community/consumption_stat.py index ce3dca6..84a7ae5 100644 --- a/dags/business/business/community/consumption_stat.py +++ b/dags/business/business/community/consumption_stat.py @@ -1,7 +1,8 @@ """ 财力评级统计 """ -from goojia_utils import ElasticSearchClient, dateutils, nextcloudutils, dingutils +from elasticsearch import helpers +from goojia_utils import ElasticSearchClient, dateutils, nextcloudutils, dingutils, data_utils import pandas as pd import numpy as np import logging @@ -23,22 +24,60 @@ nextcloud_aim_file_path = '财力评级/财力评级/财力评级统计报表' def stat(): pass + def detail(city): """ 计算消费潜力 """ - sql = "select id, city, region, name, total_price, estate_charge, estate_charge_fix, relative_price_ranking, avg_cost, consumption_rating, price_rating, consumption_score from community_summary " - if city is not None: - sql += " where city = '" + city + "'" - community_summary_df = es206_client.scan_by_sql_to_data_frame(sql) + community_summary_df = es206_client.scan_to_data_frame(query={"query": { + "bool": { + "must": [ + { + "term": { + "city": { + "value": city + } + } + } + ] + } + }}, source=[ + "id", + "city", + "region", + "name", + "avg_price", + "total_price", + "credit_detail.total_price_score", + "estate_charge", + "estate_charge_fix", + "estate_charge_flag", + "main_house_area", + "relative_price_ranking", + "avg_cost", + "consumption_rating", + "price_rating", + "consumption_score", + "sub_factor.total_price_rating" + ], index="community_summary") + community_summary_df = data_utils.flatten_json(community_summary_df, 'sub_factor') + community_summary_df = data_utils.flatten_json(community_summary_df, 'credit_detail') community_summary_df['diff'] = np.abs(community_summary_df['consumption_rating'] - community_summary_df['price_rating']) - maybe_wrong_community = community_summary_df[community_summary_df['diff'] > 2] - maybe_wrong_community = maybe_wrong_community.rename(columns={'id': '小区ID', 'city': '城市', 'region': '区域', - 'name': '小区名称', 'total_price': '户均总价', 'estate_charge': '物业费', 'estate_charge_fix': '物业费(修正后)', - 'relative_price_ranking': '相对价格排名', 'avg_cost': '人均消费', 'consumption_rating': '财力评级', 'price_rating': '价格评级', - 'consumption_score': '财力分数', 'diff': '差值'}) + community_summary_df['total_price_diff'] = np.abs(community_summary_df['consumption_rating'] - community_summary_df['total_price_rating']) + community_summary_df['estate_charge_type'] = np.where(community_summary_df['estate_charge_flag'] == 1,'周边','自有') + + community_summary_df['credit'] = np.where(community_summary_df['total_price_diff'] == 0, '高', np.where(community_summary_df['total_price_diff'] == 1, '中', np.where(community_summary_df['total_price_diff'] >= 2, '低', '-'))) + community_summary_df = community_summary_df.rename(columns={'city': '城市', 'region': '区域', 'name': '小区名称', 'consumption_score': '财力分数', 'consumption_rating': '财力评级', + 'total_price_rating': '户均总价评级', 'total_price_diff': '差值', + 'total_price': '户均总价', 'avg_price': '小区均价', 'main_house_area': '典型面积', 'relative_price_ranking': '相对价格排名', + 'avg_cost': '人均消费', 'estate_charge': '物业费', 'estate_charge_fix': '物业费修正', 'price_rating': '价格评级', 'estate_charge_type': '物业费获取方式', + 'credit': '置信度' + }) + community_summary_df['计算方式'] = None + community_summary_df['获取方式'] = np.where(community_summary_df['total_price_score'] <= 6,'周边','自有') aim_file = dateutils.format_date(dateutils.localize()) + '财力评级结果.csv' - maybe_wrong_community.to_csv(save_png_path + '/' + aim_file, index=False, columns=["城市", "区域", "小区名称", "财力评级", "价格评级", "财力分数", "差值", "户均总价", "相对价格排名", "人均消费", "物业费", "物业费(修正后)"]) + community_summary_df.to_csv(save_png_path + '/' + aim_file, index=False, columns=["城市", "区域", "小区名称", "财力分数", "财力评级", "户均总价评级", "差值", "户均总价", "小区均价", "计算方式", "典型面积", + "获取方式", "相对价格排名", "人均消费", "物业费", "物业费获取方式", '置信度']) nextcloudutils.up_to_nextcloud(save_png_path + "/" + aim_file, nextcloud_aim_file_path + "/" + aim_file) dingutils.send_text("【统计】财力评级统计完毕,请点击 https://nextcloud.fangjia.com/s/nMbzk6ZKJDimapf 查看", "32400b949005817550937f82a82c064fe5be65c23204306442c15e8b485d7ef2")