Commit 2e5c4528 authored by 张鹏程's avatar 张鹏程

Merge branch 'development'

parents 2b9c033c e0f8c4f8
# Created by .ignore support plugin (hsz.mobi)
.idea
.idea/workspace.xml
**/.ipynb_checkpoints
.ipynb_checkpoints
startup.py
......
This diff is collapsed.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -732,13 +732,13 @@
{
"ename": "NameError",
"evalue": "name 'params' is not defined",
"output_type": "error",
"traceback": [
"---------------------------------------------------------------------------",
"NameError Traceback (most recent call last)",
"<ipython-input-9-d29c09fe160d> in <module>()\n 6 test_result = []\n 7 \n----> 8 pbar = tqdm(range(len(params)),'测试接口调用')\n 9 for i in pbar:\n 10 semlock.acquire()\n",
"NameError: name 'params' is not defined"
]
],
"output_type": "error"
}
],
"source": [
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -1470,7 +1470,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
"version": "3.6.6"
}
},
"nbformat": 4,
......
......@@ -75,4 +75,8 @@ con_vccthree_vcc_talos = create_engine('mysql+pymysql://qa:qatest@172.17.5.8:311
con_app_fraud = create_engine('mysql+pymysql://peng.xiong:RMxyUTYgm73TkkQb@fengkong-tidb.quantgroups.com:4010/rc_user_behavior?charset=utf8',echo=False)
con_app_applied_type = create_engine('mysql+pymysql://b_events_w:q3ReZoL9x5asCxcx@10.17.115.6:4010/dp_analysis?charset=utf8',echo=False)
\ No newline at end of file
con_app_applied_type = create_engine('mysql+pymysql://b_events_w:q3ReZoL9x5asCxcx@10.17.115.6:4010/dp_analysis?charset=utf8',echo=False)
"""催收二期"""
con_collection = create_engine('mysql+pymysql://rc-meta-user-pre:YqnqVfIwZFMlkGya@10.17.115.6:4010/rc_meta_data_pre?charset=utf8',echo=False)
No preview for this file type
No preview for this file type
This diff is collapsed.
# -*- coding:utf-8 -*-
from features.Base_Features import BaseFeatures as BF
from service.Sql_server import *
import datetime
from service.Sql_collection import *
from dateutil.relativedelta import relativedelta
from service.Sql_complexOrder import *
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
BF._apply_df = pd.DataFrame()
df_get_order = get_order_id(self.loanId)
BF.order_id = df_get_order['order_no'].values[0]
BF._df= self.get_init(BF.user_id,BF.loanId,BF.termNo)
def get_init(self,user_id,loanId = '',termNo = ''):
df_empty = pd.DataFrame()
if loanId == '' or termNo == '':
return None
df = getSql_loanAll(str(tuple([self.user_id])).replace(',)', ')'))
if df.empty == False:
deadline_current = df.loc[(df['loan_id'] == self.loanId) & (df['term_no'] == self.termNo)]['deadline']
if len(deadline_current) != 0:
deadline_current_time = deadline_current.values[0]
df = get_Loan_rollBack(df,deadline_current_time,passdueDay_Negative=True)
return df
else:
return df_empty
else:
return df_empty
class 用户申请时改订单的申请类型状态值():
"""申请类型: 用户申请时改订单的申请类型状态值 current_loan_post_user_loan_type"""
def feature(self):
_用户申请时改订单的申请类型状态值 = -9999999
df_temp_v4 = get_Application_type(self.order_id,'user_loan_type_v4')
df_temp_v5 = get_Application_type(self.order_id, 'user_loan_type_v5')
if df_temp_v4.empty ==False:
df_temp_v4 = df_temp_v4.sort_values(['value'])
applied_from = df_temp_v4['value'].values[0]
_用户申请时改订单的申请类型状态值 = applied_from
if df_temp_v5.empty ==False:
df_temp_v5 = df_temp_v5.sort_values(['value'])
applied_from = df_temp_v5['value'].values[0]
_用户申请时改订单的申请类型状态值 = applied_from
self._result["用户申请时改订单的申请类型状态值"]["value"] = _用户申请时改订单的申请类型状态值
return self._result
class 历史最大逾期天数v2():
"""历史最大逾期天数 current_loan_post_term_delq_days"""
def feature(self):
_历史最大逾期天数v2 = -9999999
if self._df.empty == False:
self._df['deadline'] = self._df['deadline'].apply(lambda x: str(x))
df_histroy = self._df.loc[(self._df['loan_id'] < self.loanId)&(self._df['progress']== 16)]
df_current = self._df.loc[(self._df['loan_id'] == self.loanId) & (self._df['term_no']< self.termNo)]
df_concat = pd.concat([df_histroy,df_current],axis=0)
deadline_current = self._df.loc[(self._df['loan_id'] == self.loanId) & (self._df['term_no'] == self.termNo)]['deadline'].values[0]
df_concat = df_concat.loc[(df_concat['deadline'] < deadline_current)]
if df_concat.empty ==False:
max_delq_days = df_concat['passdue_day'].max()
_历史最大逾期天数v2 = max_delq_days
self._result["历史最大逾期天数v2"]["value"] = _历史最大逾期天数v2
return self._result
class 当前订单月还款额():
"""当前订单月还款额 current_loan_post_loan_info#monthlyRepayment"""
def feature(self):
_当前订单月还款额 = -9999999
df_temp = get_order_monthly_payment(self.loanId)
if df_temp.empty ==False:
monthly_payment = df_temp['monthly_repayment'].sum()
_当前订单月还款额 = monthly_payment
self._result["当前订单月还款额"]["value"] = _当前订单月还款额
return self._result
class 到期期数非本期中提前还款的占比():
"""到期期数非本期中提前还款的占比 current_loan_post_advance_repay_rate"""
def feature(self):
_到期期数非本期中提前还款的占比 = -9999999
if self._df.empty == False:
self._df['deadline'] = self._df['deadline'].apply(lambda x: str(x))
df_histroy = self._df.loc[(self._df['loan_id'] < self.loanId)&(self._df['progress']== 16)]
df_current = self._df.loc[(self._df['loan_id'] == self.loanId) & (self._df['term_no']< self.termNo)]
df_concat = pd.concat([df_histroy,df_current],axis=0)
deadline_current = self._df.loc[(self._df['loan_id'] == self.loanId) & (self._df['term_no'] == self.termNo)]['deadline'].values[0]
df_concat = df_concat.loc[(df_concat['deadline'] < deadline_current) ]
if df_concat.empty ==False:
df_temp_first = df_concat[df_concat['passdue_day'] < 0]
monthly_payment = len(df_temp_first) / len(df_concat)
_到期期数非本期中提前还款的占比 = round(monthly_payment,6)
self._result["到期期数非本期中提前还款的占比"]["value"] = _到期期数非本期中提前还款的占比
return self._result
requests=2.18.4
tornado=5.0.1
requests==2.18.4
tornado==5.0.1
logging
redis
PyMysql=0.8.0
pandas=0.22.0
PyMysql==0.8.0
pandas==0.22.0
numpy=1.14.2
tornado=5.0.1
tornado==5.0.1
xlrd=1.1.0
scrapy=1.6.0
SQLAlchemy=1.2.5
scrapy==1.6.0
SQLAlchemy==1.2.5
jupyter
paramiko
cpca
lxml=3.8.0
\ No newline at end of file
lxml==3.8.0
\ No newline at end of file
import cpca
import pandas as pd
from config.concat_sql import *
import re
import requests
# 用户申请表
def get_sql_apply_quota_record(user_id,apply_time):
""" 用户申请放款历史 """
sql_online_apply_quota_record = """
select * from apply_quota_record where user_id = {0} and apply_time > '{1}';
"""
_df = pd.read_sql(sql_online_apply_quota_record.format(user_id,apply_time),con=con_tuomin_xyqb)
return _df
"""通过loan_id 获取 order_id"""
def get_order_id(loan_id):
sql_orderid = """select e.order_no,apply_time from apply_quota_record a JOIN loan_account_ext e on
a.order_no = e.order_no where e.loan_id ={0};""".format(loan_id)
_df = pd.read_sql(sql=sql_orderid,con=con_tuomin_xyqb)
return _df
def get_Application_type(order_id,code):
Sql = """select code,name,value from calc_batch_info b JOIN calc_unit_record r on b.batch_uuid = r.batch_uuid
where order_id = '{0}' and code ='{1}' order by r.id desc """.format(order_id,code)
_df = pd.read_sql(sql=Sql,con=con_collection)
return _df
def get_order_monthly_payment(loan_id):
Sql = """SELECT * FROM loan_application_manifest_history WHERE loan_application_history_id ={0};""".format(loan_id)
_df = pd.read_sql(sql=Sql,con=con_tuomin_xyqb)
return _df
\ No newline at end of file
......@@ -802,7 +802,7 @@ def get_Loan_rollBack(df_loan,apply_time):
df_loan['observationTime'] = apply_time
df_loan = df_loan.loc[(df_loan['apply_time'] < df_loan['observationTime']) & (df_loan['loan_paid_at'] <= df_loan['observationTime'] )]
if df_loan.empty == False:
df_loan['repaid_at'] = df_loan['repaid_at'].apply(lambda x : datetime.datetime.strptime(datetime.datetime.strftime(x,'%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S'))
df_loan['repaid_at'] = df_loan['repaid_at'].apply(lambda x : datetime.datetime.strptime(datetime.datetime.strftime(x,'%Y-%m-%d 00:00:00'),'%Y-%m-%d 00:00:00'))
df_loan['deadline'] = df_loan['deadline'].apply(lambda x : datetime.datetime.strptime(datetime.datetime.strftime(x,'%Y-%m-%d 00:00:00'),'%Y-%m-%d 00:00:00'))
df_loan['deadline'] = df_loan['deadline'].apply(lambda x : datetime.datetime.strptime(datetime.datetime.strftime(x,'%Y-%m-%d 00:00:00'),'%Y-%m-%d 00:00:00'))
df_loan['apply_time'] = df_loan['apply_time'].apply(lambda x : datetime.datetime.strptime(datetime.datetime.strftime(x,'%Y-%m-%d 00:00:00'),'%Y-%m-%d 00:00:00'))
......@@ -955,3 +955,48 @@ def get_billDay_list(ApplyTime, IntervalDay):
month_list.append(str(start_.year) + str(start_.month))
start_ = start_ + relativedelta(months=1)
return month_list
def get_phone_black(phone,first_time = False,end_time = False,type_tuple = False,else_type =False):
"""获取手机号黑名单"""
if first_time:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in ('{0}') and status = 1 and created_at >= '{1}' and created_at < '{2}' and type in """ + type_tuple).format(phone,first_time,end_time)
if else_type:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in ('{0}') and status = 1 and created_at >= '{1}' and created_at < '{2}' and type not in """ + type_tuple).format(phone,first_time,end_time)
if first_time == False:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in ('{0}') and created_at < '{1}' and status = 1 and type in """ + type_tuple).format(phone,end_time)
if (else_type ==True) and (first_time == False):
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in ('{0}') and created_at < '{1}' and status = 1 and type not in """ + type_tuple).format(phone,end_time)
_df = pd.read_sql(_sql,con_blacklist3_read)
return _df
def get_emergency_contacts(phone,first_time = False,end_time = False,type_tuple = False,else_type =False):
"""获取紧急联系人"""
if first_time:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in {0} and status = 1 and created_at >= '{1}' and created_at < '{2}' and type in """ + type_tuple).format(phone, first_time, end_time)
if else_type:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in {0} and status = 1 and created_at >= '{1}' and created_at < '{2}' and type not in """ + type_tuple).format(phone,first_time,end_time)
if first_time == False:
_sql =( """select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in {0} and created_at < '{1}' and status = 1 and type in """ + type_tuple).format(phone,end_time)
if (else_type ==True) and (first_time == False):
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where phone_no in {0} and created_at < '{1}' and status = 1 and type not in """ + type_tuple).format(phone,end_time)
_df = pd.read_sql(_sql,con_blacklist3_read)
return _df
def get_id_no_black(phone,first_time = False,end_time = False,type_tuple = False,else_type =False):
"""获取身份证黑名单"""
if first_time:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where id_no in ('{0}') and status = 1 and created_at >= '{1}' and created_at < '{2}' and type in """ + type_tuple).format(phone,first_time,end_time)
if else_type:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where id_no in ('{0}') and status = 1 and created_at >= '{1}' and created_at < '{2}' and type not in """ + type_tuple).format(phone,first_time,end_time)
if first_time == False:
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where id_no in ('{0}') and created_at < '{1}' and status = 1 and type in """ + type_tuple).format(phone,end_time)
if (else_type == True) and (first_time == False):
_sql = (""" select id,major_type majorType, type ,created_at createdAt from black_list_new where id_no in ('{0}') and created_at < '{1}' and status = 1 and type not in """ + type_tuple).format(phone,end_time)
_df = pd.read_sql(_sql,con_blacklist3_read)
return _df
\ No newline at end of file
......@@ -591,23 +591,16 @@ def id_user_credited(validity_date,user_id):
def day_incoming_parts(Same_day_first,Same_day_next):
"""当日客户数"""
print(Same_day_first,Same_day_next)
_Sql = """select count(distinct user_id) count, apply_status applyStatus from risk_record
where created_at >= "{0}" and created_at < "{1}" group by apply_status;""".format(Same_day_first,Same_day_next)
print('----2----')
print(_Sql)
_df = pd.read_sql(_Sql,con_vccthree_vcc_talos)
print('----3----')
return _df
def day_amount_credit(Same_day_first,Same_day_next):
"""当日授信总额度"""
print(Same_day_first,Same_day_next)
_Sql = """select sum(limit_amount) totalCount from acs_limit_record where limit_record_type = 'New'
and limit_amount > 0 and create_time >= "{0}"and create_time < "{1}";""".format(Same_day_first,Same_day_next)
print('----2----')
_df = pd.read_sql(_Sql,con_vccthree_acsdb)
print('----3----')
return _df
def sale_phone_white(phone_no):
......
......@@ -37,7 +37,7 @@ def apps():
(URL.url_new_audit, NewAudit_Handler.New_Audit),
(URL.url_calc_features, Calc_Features_Handler.CalcFeatures),
(URL.url_complex_order, ComplexOrder_Handler.ComplexOrder),
(URL.url_loanPostFeatures, LoanPostFeatures_Handler.loanPostFeatures),
(URL.url_loanPostFeatures, LoanPostFeatures_Handler.loanPostFeatures)
])
......
......@@ -3,7 +3,7 @@ import json
import pandas as pd
import sys,datetime,time
import threading
import paramiko
# import paramiko
import inspect
import requests
......
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