新增美团数据
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
每个小区近一年成交统计
|
||||
"""
|
||||
from goojia_utils import MAIN_MONGO_CLIENT, dateutils, ElasticSearchClient
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
|
||||
es45_client = ElasticSearchClient(host='192.168.0.45')
|
||||
deal_price_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'deal_price')
|
||||
district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_facilitys')
|
||||
|
||||
city_df = pd.read_excel('/opt/airflow/dags/repo/dags/mt/supply/data/美团19城市列表.xlsx')
|
||||
cities = city_df['城市列表'].values.tolist()
|
||||
|
||||
# 1. 获取「今天」
|
||||
today = datetime.date.today()
|
||||
# 2. 获取当前月的第一天
|
||||
first = today.replace(day=1)
|
||||
# 3. 减一天,得到上个月的最后一天
|
||||
last_month = first - datetime.timedelta(days=1)
|
||||
|
||||
month_start = last_month.strftime("%Y%m") + '01'
|
||||
curr_month_start = dateutils.format_date(datetime.datetime.now(), '%Y%m') + '01'
|
||||
logging.info(month_start + ' ' + curr_month_start)
|
||||
|
||||
month_start_date = dateutils.parse_date(month_start, '%Y%m%d')
|
||||
curr_month_start_date = dateutils.parse_date(curr_month_start, '%Y%m%d')
|
||||
path = "/home/airflow/data/mt"
|
||||
|
||||
result_df = pd.read_csv(path + '/FJW_COMM_' + dateutils.format_date(datetime.datetime.now(), '%Y%m') + '.csv', sep='@', encoding='utf-8')
|
||||
|
||||
"""
|
||||
MONGO城市成交数据
|
||||
"""
|
||||
deal_num_df = pd.DataFrame(list(deal_price_conn.aggregate([
|
||||
{'$match': {'match_id': {'$exists': True}, 'area': {'$gte': 20}, 'avg_price': {'$gt': 0},
|
||||
'trade_date': {'$gte': dateutils.add_months(curr_month_start_date, months=-12),
|
||||
'$lt': curr_month_start_date}}},
|
||||
{'$group': {'_id': '$match_id', 'deal_num': {'$sum': 1}}}
|
||||
])))
|
||||
|
||||
deal_num_df = deal_num_df.rename(columns={'_id': 'id'})
|
||||
result_df = pd.merge(result_df, deal_num_df, how='left', on='id')
|
||||
|
||||
"""
|
||||
ES上海成交数据
|
||||
"""
|
||||
deal_es_num_df = es45_client.scan_to_data_frame('esf_deal_price_lansi', {
|
||||
"_source": ["fjCity", "fjRegion", "fjName"],
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"exists": {"field": "fjName"}
|
||||
},
|
||||
{
|
||||
"range": {
|
||||
"contractTime": {
|
||||
"gte": dateutils.add_months(curr_month_start_date, months=-12),
|
||||
"lt": curr_month_start_date
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
deal_es_num_df = deal_es_num_df.rename(columns={'fjCity': 'city', 'fjRegion': 'region', 'fjName': 'name'})
|
||||
deal_es_num_df = deal_es_num_df.drop(columns={'_id'})
|
||||
deal_es_num_df['es_num'] = 0
|
||||
deal_es_num_df['es_num'] = deal_es_num_df.groupby(by=['city', 'region', 'name'])['es_num'].transform('count')
|
||||
deal_es_num_df = deal_es_num_df.drop_duplicates(subset=['city', 'region', 'name'], keep='first')
|
||||
|
||||
result_df['deal_num'].fillna(0, inplace=True)
|
||||
result_df = pd.merge(result_df, deal_es_num_df, how='left', on=['city', 'region', 'name'])
|
||||
result_df['deal_num'] += result_df['es_num']
|
||||
result_df = result_df.drop(columns={'es_num'})
|
||||
|
||||
|
||||
columns = ['id', 'city', 'region', 'name', 'alias', 'address', 'addr_alias', 'avg_price', 'rent_price', 'lng', 'lat',
|
||||
'block', 'loop_line_info', 'business_quarter', 'households', 'property_fee', 'car_site_count',
|
||||
'property_life', 'house_property',
|
||||
'all_area', 'build_area', 'plot_ratio', 'landscaping_ratio', 'property_type', 'build_type',
|
||||
'build_structure', 'finish_building_date',
|
||||
'developer', 'house_type', 'house_area', 'deal_num', 'district_facilitys', 'school', 'market', 'subway',
|
||||
'bank', 'hospital']
|
||||
result_df.to_csv(path + '/FJW_COMM_' + dateutils.format_date(datetime.datetime.now(), '%Y%m') + '.csv', sep='@',
|
||||
encoding='utf-8', index=False, columns=columns)
|
||||
Reference in New Issue
Block a user