Commit 34382578 authored by 路朝阳's avatar 路朝阳

新增vcc 贷中特征进行更改说明 0520

parent a0288067
This diff is collapsed.
...@@ -103,12 +103,7 @@ con_device_info = create_engine('mysql+pymysql://pengcheng_zhang:phBnseTGbmUd7cK ...@@ -103,12 +103,7 @@ con_device_info = create_engine('mysql+pymysql://pengcheng_zhang:phBnseTGbmUd7cK
con_vcc_device_info = create_engine('mysql+pymysql://bigdata_test:ieneue7ldondk03d@172.30.5.27:8066/acsdb?charset=utf8' con_vcc_device_info = create_engine('mysql+pymysql://bigdata_test:ieneue7ldondk03d@172.30.5.27:8066/acsdb?charset=utf8'
,echo=False) ,echo=False)
# vcc_talos信息: con_vcc_workflow = create_engine('mysql+pymysql://bigdata_test:ieneue7ldondk03d@172.30.5.27:8066/workflow?charset=utf8',echo=False)
# url: vcc-db.quantgroups.com:3306
# user: rc_slave_user_r con_vcc_score = create_engine('mysql+pymysql://bigdata_test:ieneue7ldondk03d@172.30.5.27:8066/vcc_model_score_recall?charset=utf8',echo=False)
# password: fiQFWvFIQV5vn1Ai
#
# vcc_quota信息:
# url: 172.18.4.12:3306
# user: rc_feature_user
# password: G5QcBud5eR7foGIU
\ No newline at end of file
# -*- coding:utf-8 -*-
from features.Base_Features import BaseFeatures as BF
from service.addresss_book_sql import *
import datetime
from service.Sql_cheat import *
import re
class __INIT__(BF):
def __init__(self):
time_now = datetime.datetime.strptime(datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
BF._apply_at = time_now
if self.orderId:
_df = getSql_Apply_quota_record(self.user_id,self.orderId)
if _df.empty == False:
BF._apply_at = datetime.datetime.strptime(_df['apply_time'].astype(str).values[0],'%Y-%m-%d %H:%M:%S')
class 新老客户标签():
"""新老客户标签 hfax_user_is_new"""
def feature(self):
_新老客户标签 = -9999999
get_apply_type_value = get_apply_type(self.uuid,self.orderId)
if get_apply_type_value ==0:
_新老客户标签 = 1
else:
_新老客户标签 = 0
self._result['新老客户标签']['value'] = _新老客户标签
return self._result
class 客户渠道来源标签():
"""客户渠道来源标签 hfax_user_apply_from#mappingCode"""
def feature(self):
_客户渠道来源标签 = -9999999
mapp_apply = {"渠道编号": [1, 195, 198, 214, 217, 263, 333, 445, 159407,
159561, 159583, 159731, 159753, 159843, 159845,
159849, 159860, 159861, 159862, 159881],
"对应渠道号": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]}
if self.orderId:
get_apply_type = chose_apply_from(self.orderId)
if get_apply_type.empty ==False:
mapp_df = pd.DataFrame(mapp_apply)
get_apply_type_value = mapp_df[mapp_df['渠道编号']==get_apply_type['apply_from'].values[0]]
if get_apply_type_value.empty == True:
_客户渠道来源标签 = -9999999
else:
_客户渠道来源标签 = get_apply_type_value['对应渠道号'].values[0]
self._result['客户渠道来源标签']['value'] = _客户渠道来源标签
return self._result
class 用户来源():
"""用户来源 hfax_user_apply_from#channelsSource"""
def feature(self):
_用户来源 = -9999999
inner_applyfrom = [198,1,217,214]
else_list = [1, 195, 198, 214, 217, 263, 333, 445, 159407,
159561, 159583, 159731, 159753, 159843, 159845,
159849, 159860, 159861, 159862, 159881]
if self.orderId:
get_apply_type = chose_apply_from(self.orderId)
if get_apply_type.empty ==False:
if get_apply_type['apply_from'].values[0] in else_list:
if get_apply_type['apply_from'].values[0] in inner_applyfrom:
_用户来源 = 1
else:
_用户来源 = 2
else:
_用户来源 = -9999999
self._result['用户来源']['value'] = _用户来源
return self._result
\ No newline at end of file
This diff is collapsed.
...@@ -745,4 +745,137 @@ def vcc_idcard_expires(uuid=None,order_no=None): ...@@ -745,4 +745,137 @@ def vcc_idcard_expires(uuid=None,order_no=None):
if (ll_idcard =='长期') or (ll_idcard =='长期有效'): if (ll_idcard =='长期') or (ll_idcard =='长期有效'):
return '20301230' return '20301230'
elif isinstance(ll_idcard.replace(".",""),str): elif isinstance(ll_idcard.replace(".",""),str):
return (ll_idcard.replace(".","")) return (ll_idcard.replace(".",""))
\ No newline at end of file
def quota_usage(uuid,applyTime):
"""额度使用"""
_sql = """select target_used_amount as transAmountNow, target_activated_amount as nowRealAmount
from user_quota_log where uuid = '{0}' and created_at < '{1}' order by created_at desc limit 1""".format(uuid,applyTime)
_df = pd.read_sql(_sql, con_vcc_quota)
return _df
def historical_overdue(user_id,applyTime):
"""vcc历史最大逾期"""
_sql = """select paid_off_date as paidOffDate, plan_date as planDate from acs_plan
where user_id = '{0}' and plan_status!='Refund' and plan_status!='Renew' and plan_date < '{1}'""".format(user_id,applyTime)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def time_credit(uuid,applyTime):
"""授信时间"""
_sql = """select created_at as creditAt from biz_audit_log where uuid = '{0}' and created_at < '{1}' order by created_at desc limit 1""".format(uuid,applyTime)
_df = pd.read_sql(_sql, con_vcc_workflow)
return _df
def time_credit_quta(uuid):
"""重新获取授信时间"""
_sql = """select apply_time from risk_record where apply_status =2 and uuid ='{0}' order by apply_time desc limit 1""".format(uuid)
_df = pd.read_sql(_sql,con=con_vcc_talos)
return _df
def time_credit_info(user_id,start_time,end_time):
_sql = """select * from acs_trans where user_id = '{0}' and trans_type IN ('Shop','Loan') and trans_status = 'Complete' and trans_time >= '{1}' and trans_time <= '{2}'""".format(user_id,start_time,end_time)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def view_activation(uuid,created_at):
"""查看激活额度"""
_sql = """select * from user_quota_log where uuid = '{0}' and created_at >= '{1}' order by created_at asc limit 1""".format(uuid,created_at)
_df = pd.read_sql(_sql, con_vcc_quota)
return _df
def first_transaction(user_id,applyTime):
"""首次交易时间"""
_sql = """select min(business_date) as fristBusinessDate from acs_trans
where user_id = '{0}' and trans_type IN ('Shop','Loan') AND trans_status = 'Complete' and trans_time < '{1}';""".format(user_id,applyTime)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def first_transaction_mount(user_id,fristBusinessDate):
"""首次交易当天的交易金额"""
_sql = """select sum(trans_amount) as today_amount from acs_trans
where user_id = '{0}' and trans_type IN ('Shop','Loan') AND trans_status = 'Complete' and business_date = '{1}';""".format(user_id,fristBusinessDate)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def trans_amount_info(user_id,start_time,end_time):
"""交易金额"""
_sql = """select * from acs_trans
where user_id = '{0}' and trans_type IN ('Shop','Loan') and trans_status = 'Complete' and trans_time >= '{1}' and trans_time <= '{2}' """.format(user_id,start_time,end_time)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def one_month_amount(user_id,start_time,end_time):
"""近一个月提前还款的金额"""
_sql = """select trans_amount from acs_trans where user_id = '{0}'
and trans_type = 'Repay' AND trans_status = 'Complete' and business_date<date(bill_no) and business_date >= '{1}' and business_date <= '{2}'""".format(user_id,start_time,end_time)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def one_month_term(user_id,start_time,end_time):
""""""
_sql = """select * from acs_trans where user_id = '{0}' and trans_type IN ( 'Shop', 'Loan' )
AND trans_status = 'Complete' and business_date >= '{1}' and business_date <= '{2}'""".format(user_id,start_time,end_time)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def all_month_term(user_id):
"""获取所有的交易笔数"""
_sql = """select * from acs_trans where user_id = '{0}' and trans_type IN ( 'Shop', 'Loan' )
AND trans_status = 'Complete' """.format(user_id)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def historical_trans_amount(user_id,applyTime):
"""历史交易金额"""
_sql = """SELECT * FROM acs_trans WHERE user_id = '{0}' and trans_type IN ( 'Shop', 'Loan' )
AND trans_status = 'Complete' and business_date <= '{1}';""".format(user_id,applyTime)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def history_fail_count(user_id,applyTime):
_sql = """SELECT count(*) as count FROM acs_trans WHERE user_id = '{0}'
and trans_type not in ('Shop','Loan') and trans_type='Deduct' AND trans_status != 'Complete' and business_date <= '{1}';""".format(user_id,applyTime)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def successful_active_month(user_id,start_time,end_time):
_sql = """SELECT count(*) as count FROM acs_trans WHERE user_id = '{0}' and trans_type NOT IN ( 'Shop', 'Loan' )
and trans_type = 'Repay' and trans_status = 'Complete' and business_date >= '{1}' and business_date <= '{2}';""".format(user_id,start_time,end_time)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def near_3loan_count(user_id,start_time,end_time):
"""近三天交易次数"""
_sql = """SELECT count(*) as count FROM acs_trans WHERE user_id = '{0}' and trans_type IN ('Shop','Loan')
AND trans_status = 'Complete' and business_date >= '{1}' and business_date <= '{2}';""".format(user_id,start_time,end_time)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def near_7loan_count(user_id,start_time,end_time):
""""""
_sql="""SELECT max(trans_amount) as maxTransAmount FROM acs_trans WHERE user_id = '{0}' and trans_type IN ('Shop','Loan')
AND trans_status = 'Complete' and business_date >= '{1}' and business_date <= '{2}';""".format(user_id,start_time,end_time)
_df = pd.read_sql(_sql, con_vcc_device_info)
return _df
def get_round(fnum,num):
"""使用mysql 函数四舍五入"""
_sql="""select ROUND({0}, {1}) as result ; """.format(fnum,num)
_value = pd.read_sql(_sql, con_vcc_device_info)['result'].values[0]
return _value
def feature_vcc_score(uuid):
_sql = """select model_score score from vcc_model_score_recall where uuid = '{0}' """.format(uuid)
_df = pd.read_sql(_sql, con_vcc_score)
return _df
...@@ -306,4 +306,33 @@ def getSql_userApplySubmit(user_id): ...@@ -306,4 +306,33 @@ def getSql_userApplySubmit(user_id):
WHERE u.id in {0} WHERE u.id in {0}
""".format(user_id) """.format(user_id)
_df = pd.read_sql(_sql,con_tuomin_xyqb) _df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df return _df
\ No newline at end of file
def get_apply_type(uuid=None, order_no=None):
"""新老客户标签"""
params = {'user_uuid': str(uuid), 'codes': 'user_loan_type_latest',
"order_id": str(order_no), "business_type": 0}
headers = {
'rc_auth_key': 'rc_offline',
'rc_auth_secret': "9d9}bc24!e1z1x3`(x~4r29d$+45n3)'zb696b$85e>_]p2&4f{,a3~8b3e_ldt^"
}
_response = None
try:
_url = "http://172.20.1.184:23010/calc/features"
_request = requests.get(_url, params=params, headers=headers)
if _request.status_code == 200:
_response = _request.json()
except Exception as e:
print(e.args)
if _response:
type_value = _response['data']['features']['user_loan_type_latest']['value']
return type_value
return None
def chose_apply_from(order_no):
"""选择渠道号"""
_sql = """SELECT apply_from FROM apply_quota_record WHERE order_no = '{0}'""".format(order_no)
_df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment