49 lines
2.7 KiB
Python
49 lines
2.7 KiB
Python
"""
|
|
财力评级统计
|
|
"""
|
|
from goojia_utils import ElasticSearchClient, dateutils, nextcloudutils, dingutils
|
|
import pandas as pd
|
|
import numpy as np
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
es206_client = ElasticSearchClient(host='192.168.0.89', username='elastic', password='elasticsearch')
|
|
index_name = "community_summary"
|
|
|
|
save_path_prefix = "/home/airflow/data/community"
|
|
|
|
save_png_path = save_path_prefix + "/consumption_rating"
|
|
if not os.path.exists(save_png_path):
|
|
os.makedirs(save_png_path)
|
|
nextcloud_aim_file_path = '财力评级/财力评级/财力评级统计报表'
|
|
|
|
def stat(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['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': '差值'})
|
|
aim_file = dateutils.format_date(dateutils.localize()) + '财力评级结果.csv'
|
|
maybe_wrong_community.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")
|
|
|
|
sys_city = sys.argv[1] if len(sys.argv) > 1 else None
|
|
if pd.notna(sys_city) and "," in sys_city:
|
|
cities = sys_city.split(",")
|
|
for city in cities:
|
|
stat(city)
|
|
else:
|
|
stat(sys_city) |