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

新增设备信息特征6个

parent 66cd185b
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -98,6 +98,11 @@ con_vcc_transfer = create_engine('mysql+pymysql://real_data_test:qpRBSarm$Tv*YO!
con_vcc_transfer_pay = create_engine('mysql+pymysql://real_data_test:qpRBSarm$Tv*YO!n@172.30.220.16:33316/payment_center?charset=utf8',echo=False)
con_device_info = create_engine('mysql+pymysql://pengcheng_zhang:phBnseTGbmUd7cKI@fengkong-tidb.quantgroups.com:4010/rc_user_behavior?charset=utf8'
,echo=False)
con_vcc_device_info = create_engine('mysql+pymysql://bigdata_test:ieneue7ldondk03d@172.30.5.27:8066/acsdb?charset=utf8'
,echo=False)
# vcc_talos信息:
# url: vcc-db.quantgroups.com:3306
# user: rc_slave_user_r
......
# -*- coding:utf-8 -*-
from features.Base_Features import BaseFeatures as BF
from service import Sql_contactsOperator
from service.Sql_complexOrder import *
import datetime,time
import pandas as pd
from datetime import timedelta
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.df_loan_all = getSql_loanAll_v5(str(tuple([self.user_id])).replace(',)',')'))
BF._apply_at = time_now
BF.df_apply_order = pd.DataFrame()
BF.df_loan_rollBack = pd.DataFrame()
BF._df_apply = Sql_contactsOperator.getSql_userApplyQuotaRecord(str(tuple([self.user_id])).replace(',)',')'))
if BF._df_apply.empty == False:
BF._df_apply.sort_values('apply_time',inplace=True)
BF._df_apply.reset_index(drop=True,inplace=True)
if self.orderId:
BF.df_apply_order = BF._df_apply.loc[BF._df_apply['order_no'] == self.orderId]
if BF.df_apply_order.empty == False:
BF._apply_at = datetime.datetime.strptime(BF.df_apply_order['apply_time'].astype(str).values[0],'%Y-%m-%d %H:%M:%S')
if BF.df_loan_all.empty == False:
BF.df_loan_all.sort_values('apply_time',inplace=True)
BF.df_loan_all.reset_index(drop=True,inplace=True)
BF.df_loan_rollBack = get_Loan_rollBack_v5(BF.df_loan_all,BF._apply_at,passdueDay_Negative=True)
def get_loanSettleFrom(df_loan_rollBack):
"""上几笔的订单"""
df_loan_result = pd.DataFrame()
if df_loan_rollBack.empty == False:
# df_loan_rollBack = df_loan_rollBack[df_loan_rollBack["progress"] == 16]
# if df_loan_rollBack.empty == False:
df_loan_result = df_loan_rollBack[df_loan_rollBack['loan_id'] == df_loan_rollBack['loan_id'].max()]
return df_loan_result
class 历史分期中最大逾期天数可正可负():
"""delq_days_max_days_v3"""
def feature(self):
_历史分期中最大逾期天数可正可负 = -9999999
df_loan_result = self.df_loan_rollBack
if df_loan_result.empty == False:
_result =df_loan_result['passdue_day'].max()
_历史分期中最大逾期天数可正可负 = _result
self._result["历史分期中最大逾期天数可正可负"]["value"] = _历史分期中最大逾期天数可正可负
return self._result
class 订单的申请次数():
"""history_apply_cnt_v5"""
def feature(self):
_订单的申请次数 = -9999999
get_new_loan_v4_apply = new_loan_v4_apply(self.user_id,self._apply_at)['count'].values[0]
get_xiaoniu_loan_v4_apply = xiaoniu_loan_v4_apply(self.user_id,self._apply_at)['count'].values[0]
get_old_loan_v4_apply = old_loan_v4_apply(self.user_id)['count'].values[0]
_result = get_new_loan_v4_apply - get_xiaoniu_loan_v4_apply + get_old_loan_v4_apply
_订单的申请次数 = _result
self._result["订单的申请次数"]["value"] = _订单的申请次数
return self._result
class 逾期金额比率():
"""overdue_amount_ratio_v2"""
def feature(self):
_逾期金额比率 = -9999999
df_loan_result = self.df_loan_rollBack
if df_loan_result.empty == False:
df_loan_result_all = df_loan_result['monthly_repayment'].sum()
df_loan_result_passdue_day =df_loan_result[df_loan_result['passdue_day'] >0]['monthly_repayment'].sum()
_result = round(df_loan_result_passdue_day / df_loan_result_all,2)
_逾期金额比率 = _result
self._result["逾期金额比率"]["value"] = _逾期金额比率
return self._result
class 各笔订单最大的不逾期期数比():
"""overdue_days_dis_cont_ratio_v2#overdueDaysGt0DisCont 会有少许精度问题--防止四舍六入五平分"""
def feature(self):
_各笔订单最大的不逾期期数比 = -9999999
df_loan_result = self.df_loan_rollBack
sum_list = []
if df_loan_result.empty == False:
_passdue_day_list = list(set(df_loan_result[df_loan_result['passdue_day'] <= 0]['loan_id'].tolist()))
df_loan_id = df_loan_result[df_loan_result['loan_id'].isin(_passdue_day_list)]
for k,v in df_loan_id.groupby(['loan_id']):
v['term_count'] = len(v)
v['max_term'] = str(v[v['passdue_day'] >0]['term_no'].max()).replace('nan','0')
v['result'] = v['term_count'].values[0] - int(v['max_term'].values[0])
sum_list.append(v['result'].values[0])
_result = sum(sum_list) / len(df_loan_result)
_各笔订单最大的不逾期期数比 =round(_result,2)
self._result["各笔订单最大的不逾期期数比"]["value"] = _各笔订单最大的不逾期期数比
return self._result
This diff is collapsed.
......@@ -41,11 +41,3 @@ class 用户身份证是否过期():
return self._result
# class 用户手机号前三位():
# def feature(self):
# _用户手机号前三位 = -9999999
# id_time= int(str(self._apply_at).split()[0].replace("-", ""))
# card_expires_time = card_expires(self.uuid, self.orderId)
#
# self._result['用户手机号前三位']['value'] = _用户手机号前三位
# return self._result
......@@ -4,6 +4,7 @@ from service.addresss_book_sql import *
import datetime
from service.Sql_cheat import *
import re
import pendulum
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')
......@@ -16,6 +17,10 @@ class __INIT__(BF):
def time_float(str_time):
"""转换为时间戳比大小"""
time_now = time.mktime(time.strptime(str(str_time), '%Y-%m-%d %H:%M:%S'))
return time_now
class 在贷_同业():
"""same_trade_channel_uncompleted_loan_nums 在贷_同业"""
......@@ -58,3 +63,48 @@ class 在途申请单数量_同业():
class 最近一次资产分发拒绝有效期非同业():
"""最近一次资产分发拒绝有效期非同业 """
def feature(self):
_最近一次资产分发拒绝有效期非同业 = 0
get_no_tongye_info = no_tongye_info(self.uuid)['audit_valid_time'].values[0]
if get_no_tongye_info:
"""将非时间类型转成时间类型的字符串"""
get_no_tongye_info_str = str(get_no_tongye_info)
str_time = pendulum.parse(get_no_tongye_info_str).to_datetime_string()
get_audit_valid_time = time_float(str_time)
get_apply_time = time_float(self._apply_at)
if get_audit_valid_time > get_apply_time:
_最近一次资产分发拒绝有效期非同业 = 1
elif get_audit_valid_time < get_apply_time:
_最近一次资产分发拒绝有效期非同业 = 0
else:
_最近一次资产分发拒绝有效期非同业 = 0
self._result['最近一次资产分发拒绝有效期非同业']['value'] = _最近一次资产分发拒绝有效期非同业
return self._result
class 最近一次资产分发拒绝有效期同业():
"""最近一次资产分发拒绝有效期同业 """
def feature(self):
_最近一次资产分发拒绝有效期同业 = -9999999
if self.business_type != 0:
get_y_tongye_info = y_tongye_info(self.business_type,self.channel_no,self.uuid)['audit_valid_time'].values[0]
if get_y_tongye_info:
get_y_tongye_info_str = str(get_y_tongye_info)
str_time = pendulum.parse(get_y_tongye_info_str).to_datetime_string()
get_audit_valid_time = time_float(str_time)
get_apply_time = time_float(self._apply_at)
if get_audit_valid_time > get_apply_time:
_最近一次资产分发拒绝有效期同业 = 1
elif get_audit_valid_time < get_apply_time:
_最近一次资产分发拒绝有效期同业 = 0
else:
_最近一次资产分发拒绝有效期同业 = 0
else:
_最近一次资产分发拒绝有效期同业 = 0
self._result['最近一次资产分发拒绝有效期同业']['value'] = _最近一次资产分发拒绝有效期同业
return self._result
# -*- coding:utf-8 -*-
from features.Base_Features import BaseFeatures as BF
from service.addresss_book_sql import *
import datetime
from service.Sql_vcc import *
import json
import time
from pandas import DataFrame
import numpy as np
import datetime
from datetime import timedelta
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
"""vcc申请交易的时间"""
if self.orderId:
_df = get_orderid_trade(self.orderId)
if _df.empty == False:
BF._apply_at = datetime.datetime.strptime((_df['trade_time'].astype(str).values[0]),'%Y-%m-%d %H:%M:%S')
class 身份证有效期大于30天():
"""user_ocr_info#isValid 身份证是否过期 需求待修改"""
def feature(self):
_身份证有效期大于30 = -9999999
id_time = str(self._apply_at)[0:10]+' ' + '00:00:00'
start = (datetime.datetime.strptime(id_time, '%Y-%m-%d %H:%M:%S'))
card_expires = str(vcc_idcard_expires(self.uuid,self.orderId))
year1 = card_expires[0:4]
month1 = card_expires[4:6]
day1 = card_expires[6:8]
end_time_str = str(year1) + '-' + str(month1) + '-' + str(day1) + ' ' + '00:00:00'
end_time = datetime.datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
if card_expires != '-9999999':
if (end_time - start).days >=30:
_身份证有效期大于30 = 1
elif (end_time - start).days < 30:
_身份证有效期大于30 = 0
self._result['身份证有效期大于30天']['value'] = _身份证有效期大于30
return self._result
\ No newline at end of file
......@@ -267,43 +267,35 @@ def city_dict_df():
df = pd.DataFrame(city_dict, pd.Index(range(1)))
return df
def idcard_dict_df():
"""标准的身份证归属地码表"""
idcard_dict = {'北京': 11,
'天津': 12,
'河北': 13,
'山西': 14,
'内蒙': 15,
'辽宁': 21,
'吉林': 22,
'黑龙江': 23,
'上海': 31,
'江苏': 32,
'浙江': 33,
'安徽': 34,
'福建': 35,
'江西': 36,
'山东': 37,
'河南': 41,
'湖北': 42,
'湖南': 43,
'广东': 44,
'广西': 45,
'海南': 46,
'重庆': 50,
'四川': 51,
'贵州': 52,
'云南': 53,
'西藏': 54,
'陕西': 61,
'甘肃': 62,
'青海': 63,
'宁夏': 64,
'新疆': 65,
'台湾': 71,
'香港': 81,
'澳门': 82,
'海外': 91}
df = pd.DataFrame(idcard_dict, pd.Index(range(1)))
return df
def decive_info(uuid,start_time,end_time):
Sql = """select body,log_time from rc_user_behavior.`anti_fraud_log_kafka` where distinct_id = '{0}' and log_time > '{1}' and log_time < '{2}' order by log_time; """.format(uuid,start_time,end_time)
_df = pd.read_sql(Sql, con=con_device_info)
return _df
def no_tongye_info(uuid):
sql = """select max(audit_valid_time) audit_valid_time from apply_list
where apply_status=5 and assets_result=0 and enable=1
and product_type=0
and uuid='{0}';""".format(uuid)
_df = pd.read_sql(sql, con=con_business_flow)
return _df
def y_tongye_info(bussiness_type,channel_id,uuid):
sql = """select max(audit_valid_time) audit_valid_time from apply_list
where apply_status=5 and assets_result=0 and enable=1
and product_type='{0}'
and channel_id='{1}'
and uuid='{2}';""".format(bussiness_type,channel_id,uuid)
_df = pd.read_sql(sql, con=con_business_flow)
return _df
def vcc_data_payment(user_id,time):
sql = """select bill_date from acs_bill where user_id = '{0}'
and bill_date < '{1}' order by bill_date desc limit 1 """.format(user_id,time)
_df = pd.read_sql(sql, con=con_vcc_device_info)
return _df
\ No newline at end of file
......@@ -144,7 +144,7 @@ def getSql_loanAll_v5(user_id):
_sql = """
select
IFNULL(aqr.order_no ,'') order_no,loan.business_type
,loan.user_id,loan.id as loan_id,loan.progress,fest.contract_loan_amount,fest.loan_paid_at,fest.monthly_interest_rate
,loan.user_id,loan.id as loan_id,loan.progress,fest.contract_loan_amount,fest.loan_paid_at,fest.monthly_interest_rate,fest.monthly_repayment
,case when loan.created_at >='2018-05-08' then aqr.apply_from
when loan.created_at < '2018-05-08' then loan.created_from
else null
......@@ -188,5 +188,24 @@ def old_apptime_resufe(user_id,applytime):
if(l.progress in (6, 8, 19), 1, 0) apply_status,created_from apply_from FROM loan_application_history l
LEFT JOIN loan_account_ext e ON e.loan_id = l.id left join loan_submit_info ls on ls.loan_id = l.id
WHERE l.user_id = '{0}' and l.business_type IN (0, 2, 4,6) AND e.loan_id IS NULL And l.created_at < '{1}';""".format(user_id,applytime)
_df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df
def new_loan_v4_apply(user_id,applytime):
"""查找用户所有新申请详情"""
_sql = """SELECT COUNT(1) count FROM apply_quota_record WHERE user_id = '{0}' AND apply_time < '{1}';""".format(user_id,applytime)
_df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df
def xiaoniu_loan_v4_apply(user_id,applytime):
"""查询小牛计划退货的申请次数"""
_sql = """SELECT COUNT(1) count FROM apply_quota_record a LEFT JOIN loan_account_ext e ON e.order_no = a.order_no
LEFT JOIN loan_application_history l ON l.id = e.loan_id WHERE a.user_id = '{0}' AND l.progress = 48 AND apply_time < '{1}';""".format(user_id,applytime)
_df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df
def old_loan_v4_apply(user_id):
"""查找用户所有老的申请详情"""
_sql = """SELECT COUNT(1) count FROM loan_application_history l LEFT JOIN loan_account_ext e ON e.loan_id = l.id WHERE l.user_id = '{0}' and l.business_type IN (0,2) AND e.loan_id IS NULL""".format(user_id)
_df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df
\ No newline at end of file
......@@ -719,4 +719,30 @@ def vcc_credit_phone(userid,phone):
else '-9999999'
end as as_type from payment_center.bank_card where uid='{0}' and preserve_phone_no='{1}';""".format(userid,phone)
_df = pd.read_sql(_sql, con_vcc_transfer_pay)
return _df
\ No newline at end of file
return _df
#身份证是否过期
def vcc_idcard_expires(uuid=None,order_no=None):
params = {'uuid': str(uuid),"order_id": str(order_no)}
_response = None
try:
_url = "http://operator.liangkebang.com/auth-center/ex/getIdCardInfo.json"
_request = requests.post(_url, data=params)
if _request.status_code == 200:
_response = _request.json()
except Exception as e:
print(e.args)
if _response:
if _response['data']['valid_date_end'] == -9999999:
return list([])
# if _response['data']['features']['user_ocr_info#validDateEnd']['value'] == "?":
# return list([])
ll_idcard = _response['data']['valid_date_end']
if ll_idcard:
if (ll_idcard =='长期') or (ll_idcard =='长期有效'):
return '20301230'
elif isinstance(ll_idcard.replace(".",""),str):
return (ll_idcard.replace(".",""))
\ No newline at end of file
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