新增户均总价补全功能
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,6 @@ import logging
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from goojia_utils import ElasticSearchClient, commutils, dateutils
|
from goojia_utils import ElasticSearchClient, commutils, dateutils
|
||||||
from elasticsearch import helpers
|
from elasticsearch import helpers
|
||||||
import numpy as np
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from goojia_utils import MAIN_MONGO_CLIENT, ElasticSearchClient, commutils, dateutils, areautils
|
from goojia_utils import MAIN_MONGO_CLIENT, ElasticSearchClient, commutils, dateutils
|
||||||
from elasticsearch import helpers
|
from elasticsearch import helpers
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
import re
|
import re
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
"""
|
||||||
|
户均总价根据房源面积补充至206
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
import pandas as pd
|
||||||
|
from goojia_utils import ElasticSearchClient, dateutils
|
||||||
|
from elasticsearch import helpers
|
||||||
|
|
||||||
|
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"
|
||||||
|
m_date = dateutils.iso_format()
|
||||||
|
|
||||||
|
|
||||||
|
def build_doc(item):
|
||||||
|
doc_dict = dict()
|
||||||
|
if 'total_price' in item and pd.notna(item['total_price']):
|
||||||
|
doc_dict['total_price'] = int(item['total_price'])
|
||||||
|
return doc_dict
|
||||||
|
|
||||||
|
|
||||||
|
def sync():
|
||||||
|
log.info(f"开始补全户均总价信息至206 {index_name}")
|
||||||
|
|
||||||
|
factor_df = pd.read_csv(path + '/小区户均总价面积因子已去极值.csv', sep='@', encoding='UTF-8')
|
||||||
|
community_df = es206_client.scan_by_sql_to_data_frame("select city, region, name, avg_price from community_summary where avg_price is not null and total_price is null")
|
||||||
|
|
||||||
|
community_factor_df = pd.merge(community_df, factor_df, how='left', on=['_id', 'city', 'region', 'name'])
|
||||||
|
community_factor_df['total_price'] = community_factor_df['avg_price'] * community_factor_df['factor']
|
||||||
|
community_factor_df = community_factor_df[community_factor_df['total_price'].notna()]
|
||||||
|
community_factor_df['total_price'] = community_factor_df['total_price'].astype(int)
|
||||||
|
|
||||||
|
actions = list()
|
||||||
|
count = 0
|
||||||
|
for index, item in community_factor_df.iterrows():
|
||||||
|
doc_info = build_doc(item)
|
||||||
|
|
||||||
|
action = {
|
||||||
|
"_op_type": "update",
|
||||||
|
"_index": index_name,
|
||||||
|
"_id": item['_id'],
|
||||||
|
"doc": doc_info
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.append(action)
|
||||||
|
if len(actions) == 5000:
|
||||||
|
try:
|
||||||
|
helpers.bulk(es206_client.elastic_client, actions)
|
||||||
|
count += len(actions)
|
||||||
|
logging.info("已补全:" + str(count))
|
||||||
|
except Exception as e:
|
||||||
|
log.error(e)
|
||||||
|
actions.clear()
|
||||||
|
if len(actions) > 0:
|
||||||
|
try:
|
||||||
|
helpers.bulk(es206_client.elastic_client, actions)
|
||||||
|
except Exception as e:
|
||||||
|
log.error(e)
|
||||||
|
actions.clear()
|
||||||
|
log.info(f"完成补全户均总价信息至206 {index_name}")
|
||||||
|
|
||||||
|
|
||||||
|
sync()
|
||||||
@@ -34,6 +34,11 @@ with DAG(
|
|||||||
# task_id='total_price_dag',
|
# task_id='total_price_dag',
|
||||||
# bash_command='python /opt/airflow/dags/repo/dags/business/business/community/total_price.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
# bash_command='python /opt/airflow/dags/repo/dags/business/business/community/total_price.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
||||||
# )
|
# )
|
||||||
|
t6_1 = BashOperator(
|
||||||
|
task_id='total_price_complete_dag',
|
||||||
|
bash_command='python /opt/airflow/dags/repo/dags/business/business/community/total_price_complete.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
||||||
|
)
|
||||||
|
t6_1
|
||||||
# t7 = BashOperator(
|
# t7 = BashOperator(
|
||||||
# task_id='traffic_dag',
|
# task_id='traffic_dag',
|
||||||
# bash_command='python /opt/airflow/dags/repo/dags/business/business/community/traffic.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
# bash_command='python /opt/airflow/dags/repo/dags/business/business/community/traffic.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
||||||
@@ -58,9 +63,8 @@ with DAG(
|
|||||||
# task_id='price_rating_dag',
|
# task_id='price_rating_dag',
|
||||||
# bash_command='python /opt/airflow/dags/repo/dags/business/business/community/price_rating.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
# bash_command='python /opt/airflow/dags/repo/dags/business/business/community/price_rating.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
||||||
# )
|
# )
|
||||||
t13 = BashOperator(
|
# t13 = BashOperator(
|
||||||
task_id='education_dag',
|
# task_id='education_dag',
|
||||||
bash_command='python /opt/airflow/dags/repo/dags/business/business/community/education.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
# bash_command='python /opt/airflow/dags/repo/dags/business/business/community/education.py {{dag_run.conf["type"] if "type" in dag_run.conf}}',
|
||||||
)
|
# )
|
||||||
t13
|
|
||||||
# t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7 >> t8 >> t9 >> t10 >> t11 >> t12 >> T13
|
# t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7 >> t8 >> t9 >> t10 >> t11 >> t12 >> T13
|
||||||
|
|||||||
Reference in New Issue
Block a user