This commit is contained in:
muliangshu
2024-07-22 17:13:59 +08:00
16 changed files with 579 additions and 56 deletions
+8 -2
View File
@@ -1,13 +1,18 @@
"""
价格异常检测脚本
"""
from goojia_utils import dateutils, pgsql
from goojia_utils import dateutils, pgsql, MAIN_MONGO_CLIENT, data_utils
import pandas as pd
import logging
import os
import sys
import requests
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
# 获取独家小区
exclusive_seaweed_df = pd.DataFrame(list(seaweed_conn.find({'cat': 'district', 'status': 0, 'mark_map.exclusive': '是'}, {'city': 1, 'region': 1, 'name': 1, 'mark_map.exclusive': 1}).batch_size(100000)))
exclusive_seaweed_df = data_utils.flatten_json(exclusive_seaweed_df, 'mark_map')
exclusive_seaweed_df = exclusive_seaweed_df.rename(columns={'name': 'commname', 'exclusive': '独家小区'})
def simple_calc(result_df):
"""
@@ -111,7 +116,7 @@ for key in six_map:
if abs(six_price - five_price) * 100 / five_price > 10:
actions.append({'city': info[0], 'region': info[1], 'commid': info[2], 'commname': info[3],
'five_price': five_price,'five_calc_type': five_map[key].split("|")[1],
'six_price': six_price,'six_calc_type': six_map[key].split("|")[1],
'six_price': six_price,'six_calc_type': six_map[key].split("|")[1], '差异值': abs(six_price - five_price) * 100 / five_price,
'涨跌幅': (six_price - five_price) * 100 / five_price, 'confidence': six_map[key].split("|")[2]})
if info[0] not in city_seaweed_dict:
city_seaweed_dict[info[0]] = 1
@@ -132,6 +137,7 @@ excel_writer = pd.ExcelWriter(aim_file_name)
if type == 'sample':
result_df = simple_calc(result_df)
result_df = pd.merge(result_df, exclusive_seaweed_df, on=['city', 'region', 'commname'], how='left')
result_df = result_df.drop_duplicates(subset=['commid'], keep='first')
result_df = result_df.rename(columns={'city': '城市', 'region': '区域', 'commid': '小区ID', 'commname': '小区名', 'five_price': '上一月价格',
'five_calc_type': '上一月计算方式', 'six_price': '当月价格', 'six_calc_type': '当月计算方式', 'confidence': '置信度'})