优化pgsql
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
"""
|
||||
价格异常检测脚本
|
||||
"""
|
||||
from goojia_utils import dateutils, oracle
|
||||
from goojia_utils import dateutils, pgsql
|
||||
import pandas as pd
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import requests
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
os.environ["ORACLE_HOME"] = "/home/airflow/instantclient_21_7"
|
||||
engine = create_engine("postgresql+psycopg2://postgres:postgres@192.168.0.236:5432/warehouse", echo=False)
|
||||
|
||||
def simple_calc(result_df):
|
||||
"""
|
||||
新增是否有样本列
|
||||
@@ -26,9 +24,9 @@ def simple_calc(result_df):
|
||||
if len(actions) == 800:
|
||||
ins = "','".join(actions)
|
||||
ins = "'" + ins + "'"
|
||||
simple_temp_df = pd.read_sql(
|
||||
simple_temp_df = pgsql.scan_by_sql_to_data_frame(
|
||||
"select distinct gujia_comm_id as commid from base.t0831_bigdata_forsale_gj_h where " +
|
||||
" anc_tm> TO_DATE('" + month_before + "','YYYY-MM-DD') and gujia_comm_id in (" + ins + ")", con=engine)
|
||||
" anc_tm> TO_DATE('" + month_before + "','YYYY-MM-DD') and gujia_comm_id in (" + ins + ")")
|
||||
|
||||
simple_df = pd.concat([simple_df, simple_temp_df])
|
||||
actions.clear()
|
||||
@@ -36,9 +34,9 @@ def simple_calc(result_df):
|
||||
if len(actions) > 0:
|
||||
ins = "','".join(actions)
|
||||
ins = "'" + ins + "'"
|
||||
simple_temp_df = pd.read_sql(
|
||||
simple_temp_df = pgsql.scan_by_sql_to_data_frame(
|
||||
"select distinct gujia_comm_id as commid from base.t0831_bigdata_forsale_gj_h where " +
|
||||
" anc_tm> TO_DATE('" + month_before + "','YYYY-MM-DD') and gujia_comm_id in (" + ins + ")", con=engine)
|
||||
" anc_tm> TO_DATE('" + month_before + "','YYYY-MM-DD') and gujia_comm_id in (" + ins + ")")
|
||||
simple_df = pd.concat([simple_df, simple_temp_df])
|
||||
actions.clear()
|
||||
simple_df['has_sample'] = 1
|
||||
@@ -88,8 +86,8 @@ if type == month_last:
|
||||
month_now = month_last
|
||||
month_last = month_before
|
||||
|
||||
df = pd.read_sql("SELECT gujia_bss_prc_id as id, urbn_nm as cityname, gujia_admndiv_nm as distname, gujia_bds_id as commid, comm_nm as commname, gujia_bds_clmtd as calc_type, gujia_bds_cfdc_dgr as confidence, gujia_comm_basic_prc as avg_price, gujiabds_clc_yrmo_val as year_month FROM t_app_p9pha_plda.avm_community_base_price_gj_h WHERE gujiabds_clc_yrmo_val IN('"+month_now+"', '"+month_last+"') " +
|
||||
" ORDER BY urbn_nm, gujia_admndiv_nm, gujia_bds_id, comm_nm, gujia_bds_clmtd", con=engine)
|
||||
df = pgsql.scan_by_sql_to_data_frame("SELECT gujia_bss_prc_id as id, urbn_nm as cityname, gujia_admndiv_nm as distname, gujia_bds_id as commid, comm_nm as commname, gujia_bds_clmtd as calc_type, gujia_bds_cfdc_dgr as confidence, gujia_comm_basic_prc as avg_price, gujiabds_clc_yrmo_val as year_month FROM t_app_p9pha_plda.avm_community_base_price_gj_h WHERE gujiabds_clc_yrmo_val IN('"+month_now+"', '"+month_last+"') " +
|
||||
" ORDER BY urbn_nm, gujia_admndiv_nm, gujia_bds_id, comm_nm, gujia_bds_clmtd")
|
||||
|
||||
six_map = dict()
|
||||
five_map = dict()
|
||||
|
||||
Reference in New Issue
Block a user