Commit 80335da5 authored by 路朝阳's avatar 路朝阳

mapping回归测试,更改部分代码

parent c728b9ac
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -1142,7 +1142,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.4"
"version": "3.6.6"
}
},
"nbformat": 4,
......
......@@ -768,7 +768,6 @@
{
"ename": "ValueError",
"evalue": "All objects passed were None",
"output_type": "error",
"traceback": [
"---------------------------------------------------------------------------",
"ValueError Traceback (most recent call last)",
......@@ -777,7 +776,8 @@
"/Users/zhangpengcheng/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pandas/core/reshape/concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, copy)\n 210 keys=keys, levels=levels, names=names,\n 211 verify_integrity=verify_integrity,\n--> 212 copy=copy)\n 213 return op.get_result()\n 214 \n",
"/Users/zhangpengcheng/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pandas/core/reshape/concat.py in __init__(self, objs, axis, join, join_axes, keys, levels, names, ignore_index, verify_integrity, copy)\n 261 \n 262 if len(objs) == 0:\n--> 263 raise ValueError('All objects passed were None')\n 264 \n 265 # consolidate data & figure out what our result ndim is going to be\n",
"ValueError: All objects passed were None"
]
],
"output_type": "error"
}
],
"source": [
......
......@@ -61,11 +61,11 @@ con_urgent_people = create_engine('mysql+pymysql://drisk_controlpro:uijk78ytlk95
,echo=False)
#身份证归属地(省)黑名单标志
con_realtime_hmd = create_engine('mysql+pymysql://vcc_black_list_w:Kz8p0Wf0iw7nIV85@guangdadb.xyqb.com:3306/vcc_black_list?charset=utf8',echo=False)
con_realtime_hmd = create_engine('mysql+pymysql://qa:qatest@172.17.5.8:31110/vcc_black_list?charset=utf8',echo=False)
#近一个月通话记录成功爬取标志
con_day30_sql = create_engine('mysql+pymysql://qa:qatest@172.30.220.9:3306/lkb_spider?charset=utf8',echo=False)
"""vcc 三期"""
con_vccthree_acsdb = create_engine('mysql+pymysql://qa:qatest@172.17.5.10:31110/acsdb?charset=utf8',echo=False)
con_vccthree_acsdb = create_engine('mysql+pymysql://qa:qatest@172.17.5.8:31110/acsdb?charset=utf8',echo=False)
con_vccthree_vcc_talos = create_engine('mysql+pymysql://qa:qatest@172.17.5.10:31110/vcc_talos?charset=utf8',echo=False)
\ No newline at end of file
con_vccthree_vcc_talos = create_engine('mysql+pymysql://qa:qatest@172.17.5.8:31110/vcc_talos?charset=utf8',echo=False)
\ No newline at end of file
......@@ -11,7 +11,6 @@ class __INIT__(BF):
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 = Sql_contactsOperator.getSql_loanAll(str(tuple([self.user_id])).replace(',)',')'))
BF._apply_at = time_now
BF.df_apply_order = pd.DataFrame()
BF.df_loan_rollBack = pd.DataFrame()
......@@ -168,11 +167,16 @@ class delq_days_max():
"""delq_days_max_days_v2 delq_days_max 历史最大逾期天数(可正可负)"""
def feature(self):
_delq_days_max = -9999999
if self.df_loan_rollBack.empty == False:
df_loan = self.df_loan_rollBack#.loc[self.df_loan_rollBack['progress'] == 16]
df_loan['observationTime'] = df_loan['observationTime'].apply(lambda x : datetime.datetime.strptime(datetime.datetime.strftime(x,'%Y-%m-%d 00:00:00'),'%Y-%m-%d 00:00:00'))
df_loan['loan_paid_at'] = df_loan['loan_paid_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 = df_loan[df_loan['observationTime']>df_loan['loan_paid_at']]
df_loan = self.df_loan_rollBack # .loc[self.df_loan_rollBack['progress'] == 16]
df_loan['observationTime'] = df_loan['observationTime'].apply(
lambda x: datetime.datetime.strptime(datetime.datetime.strftime(x, '%Y-%m-%d 00:00:00'),
'%Y-%m-%d 00:00:00'))
df_loan['loan_paid_at'] = df_loan['loan_paid_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 = df_loan[df_loan['observationTime'] > df_loan['loan_paid_at']]
if df_loan.empty == False:
_delq_days_max = df_loan['passdue_day'].max()
self._result['delq_days_max']['value'] = _delq_days_max
......
......@@ -25,6 +25,7 @@ class __INIT__(BF):
BF.df_loan_rollBack = Sql_complexOrder.get_Loan_rollBack(BF.df_loan_all,BF._apply_at)
class 进件订单所在渠道的未结清订单总数():
"""current_channel_unfinished_loan_cnt 进件订单所在渠道的未结清订单总数"""
def feature(self):
_进件订单所在渠道的未结清订单总数 = -9999999
if self._df_loan_apply.empty == False:
......@@ -39,6 +40,7 @@ class 进件订单所在渠道的未结清订单总数():
return self._result
class 进件订单在兜底渠道未结清订单总数():
"""bottom_channel_unfinished_loan_cnt 进件订单在兜底渠道未结清订单总数"""
def feature(self):
_进件订单在兜底渠道未结清订单总数 = -9999999
if self.df_loan_rollBack.empty == False:
......
......@@ -28,7 +28,6 @@ class __INIT__(BF):
BF._created_at = datetime.datetime.strptime(df_auth['modifyDate'].max(), '%Y-%m-%d %H:%M:%S')
BF._apply_at = time_now
BF.register_hmd = user_register(self.uuid)
BF.get_id_hmd = get_idcard_detail(self.uuid)
if self.orderId:
......@@ -44,7 +43,6 @@ class __INIT__(BF):
BF._df_telephone = getSql_unicomCallInfoDataService_one(user_phone = BF._user_phone ,time_start = BF._created_at_from,time_end = BF._created_at)
elif userSource == 'DIANXIN':
BF._df_telephone = getSql_telecomCallInfoDataService_one(user_phone = BF._user_phone,time_start = BF._created_at_from,time_end = BF._created_at)
BF.day30paqu = day30_Call_record_spider(self.uuid)
################################## VCC
......@@ -254,8 +252,9 @@ class 注册手机号码黑名单标志():
"""user_phone_is_black 注册手机号码黑名单标志"""
def feature(self):
_注册手机号码黑名单标志 = -9999999
if self.register_hmd.empty == False:
zhuce_hmd_df = self.register_hmd
register_hmd = user_register(self.uuid)
if register_hmd.empty == False:
zhuce_hmd_df = register_hmd
_df_qgblack_1 = getSql_relation_in_qgblack(str(tuple(zhuce_hmd_df["phone_no"])).replace(',)', ')'),self._apply_at)
_df_qgblack = _df_qgblack_1.drop_duplicates(['phone'])
_注册手机号码黑名单标志 = _df_qgblack['phone'].count()
......@@ -331,8 +330,9 @@ class 手机号归属地黑名单标志():
def feature(self):
_手机号归属地黑名单标志 = -9999999
if self.register_hmd.empty == False:
get_zc_hmd = self.register_hmd["phone_no"].values[0]
register_hmd = user_register(self.uuid)
if register_hmd.empty == False:
get_zc_hmd = register_hmd["phone_no"].values[0]
get_zc_hmd_1 = str(get_zc_hmd)[0:7]
_df = phone_Location_Attribution_black(int(get_zc_hmd_1), self._apply_at)["count"][0]
if _df > 0:
......@@ -348,9 +348,8 @@ class 近一个月通话记录成功爬取标志():
"""user_call_spider_in_m1 近一个月通话记录成功爬取标志"""
def feature(self):
_近一个月通话记录成功爬取标志 = -9999999
if self.day30paqu.empty == False:
day30paqu = self.day30paqu
day30paqu = day30_Call_record_spider(self.uuid)
if day30paqu.empty == False:
day30paqu["days30_spider"] = self._apply_at
day30paqu['days30_spider'] = pd.to_datetime(day30paqu['days30_spider'])
day30paqu['update_at'] = pd.to_datetime(day30paqu['update_at'])
......@@ -424,12 +423,9 @@ class 近150天内有效通话次数():
_150天内有效通话次数 = -9999999
if self._df_telephone.empty == False:
df = self._df_telephone
# df["receiverPhone"] = df["receiverPhone"].map(lambda x: x if re.match(r'^(1[3546789]\d{9})$', str(x)) else np.nan)
# df = df.dropna(subset=["receiverPhone"])
df = df_filter(df)
# df["receiverPhone"] = df["receiverPhone"].astype(np.int64)
df = df.dropna(subset=['tradeTime'])
df["tradeTime"] = df["tradeTime"].astype(np.int)
# df = df[df["tradeTime"] < 120]
df = df.loc[df['tradeTime'] > 120]
_150天内有效通话次数 = len(df)
self._result['近150天内有效通话次数']['value'] = _150天内有效通话次数
......
......@@ -116,7 +116,7 @@ class 测试白名单():
_测试白名单 = -9999999
if self.register_white.empty == False:
get_user_white = self.register_white["id_no"].values[0]
_df = id_is_whitelist(int(get_user_white), self._apply_at)["count"][0]
_df = id_is_whitelist(str(get_user_white), self._apply_at)["count"][0]
if _df > 0:
_df_qgblack_1_1 = 1
else:
......
......@@ -58,6 +58,8 @@ class 当日申请进件客户数():
if day_incoming_from.empty == False:
day_incoming_from = day_incoming_from["count"].sum()
_当日申请进件客户数 = day_incoming_from
elif day_incoming_from.empty == True:
_当日申请进件客户数 = 0
self._result['当日申请进件客户数']['value'] = _当日申请进件客户数
return self._result
......@@ -71,6 +73,8 @@ class 当日申请通过客户数():
day_cross_from = day_cross_from[day_cross_from["applyStatus"]==2]
day_cross_from = day_cross_from["count"].sum()
_当日申请通过客户数 = day_cross_from
elif day_cross_from.empty == True:
_当日申请通过客户数 = 0
self._result['当日申请通过客户数']['value'] = _当日申请通过客户数
return self._result
......
......@@ -15,7 +15,6 @@ class __INIT__(BF):
time_now = datetime.datetime.strptime(datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
BF._created_at = time_now #获取用户的手机号
user_detail = getSql_userPhone_one(str(tuple([self.user_id])).replace(',)',')'))
BF._user_id_one = str(tuple(user_detail['user_id'].tolist())).replace(',)',')')
BF._user_phone = user_detail['phone_no'].values[0]
BF.get_phone_white_from = sale_phone_white(BF._user_phone)
......
......@@ -10,7 +10,7 @@ class __INIT__(BF):
BF.df_loan = get_sql_user_in_loan(self.user_id)
BF.df_loan.sort_values('loan_id',inplace = True)
pass
###多订单一期
class current_loan_order_nums():
"""当前在贷订单数"""
def feature(self):
......@@ -32,7 +32,7 @@ class current_loan_term_nums():
return self._result
class current_loan_max_term():
"""当前在贷最大期数"""
"""uncompleted_loan_max_term_nums 当前在贷最大期数"""
def feature(self):
df_loan = self.df_loan
_current_loan_max_term = -9999999
......@@ -74,7 +74,7 @@ class current_loan_avg_repay():
if df_loan.empty == False:
x,y = str(float(df_loan.loc[df_loan['repayment_status']!=3]['required_repayment'].sum()/df_loan.loc[df_loan['repayment_status']!=3]['term_no'].count())).split('.')
_current_loan_avg_repay = float(x+'.'+y[:6])
self._result[""]['value'] = _current_loan_avg_repay
self._result["current_loan_avg_repay"]['value'] = _current_loan_avg_repay
return self._result
class current_loan_max_repay():
......@@ -191,8 +191,8 @@ class days_from_lastdue():
if df_loan.loc[df_loan['passdue_day'] > 0].empty:
_days_from_lastdue = 0
else:
passdue_day_max = datetime.strptime(str(df_loan.loc[df_loan['passdue_day'] > 0]['deadline'].max()).split(' ')[0],"%Y-%m-%d")
_days_from_lastdue = (datetime.now() - passdue_day_max).days
passdue_day_max = datetime.datetime.strptime(str(df_loan.loc[df_loan['passdue_day'] > 0]['deadline'].max()).split(' ')[0],"%Y-%m-%d")
_days_from_lastdue = (datetime.datetime.now() - passdue_day_max).days
self._result["days_from_lastdue"]['value'] =_days_from_lastdue
return self._result
......@@ -202,8 +202,10 @@ class days_from_lastrepaid():
_days_from_lastrepaid= -9999999
df_loan = self.df_loan
if df_loan.empty == False:
record_last_day = datetime.strptime(str(df_loan.loc[(df_loan['repayment_status'] ==3 )]['repaid_at'].max()).split(' ')[0],"%Y-%m-%d")
_days_from_lastrepaid = int((datetime.now() - record_last_day).days)
df_loan_status = df_loan.loc[(df_loan['repayment_status'] == 3)]
if df_loan_status.empty ==False:
record_last_day = datetime.datetime.strptime(str(df_loan_status['repaid_at'].max()).split(' ')[0],"%Y-%m-%d")
_days_from_lastrepaid = int((datetime.datetime.strptime(datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d '),'%Y-%m-%d ') -record_last_day).days)
self._result["days_from_lastrepaid"]['value'] = _days_from_lastrepaid
return self._result
......@@ -213,8 +215,8 @@ class current_loan_0duedays_rate():
_current_loan_0duedays_rate = -9999999
df_loan = self.df_loan
if df_loan.empty == False:
if (df_loan.loc[datetime.strftime(datetime.now(),'%Y-%m-%d') > pd.to_datetime(df_loan['deadline'],format='%Y-%m-%d')]['plan_id'].count() > 0) &( df_loan.loc[df_loan['passdue_day'] > 0 ]['passdue_day'].count() > 0):
x,y = str(float(df_loan.loc[df_loan['passdue_day'] > 0 ]['passdue_day'].count() / df_loan.loc[datetime.strftime(datetime.now(),'%Y-%m-%d') > pd.to_datetime(df_loan['deadline'],format='%Y-%m-%d')]['plan_id'].count())).split('.')
if (df_loan.loc[datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d') > pd.to_datetime(df_loan['deadline'],format='%Y-%m-%d')]['plan_id'].count() > 0) &( df_loan.loc[df_loan['passdue_day'] > 0 ]['passdue_day'].count() > 0):
x,y = str(float(df_loan.loc[df_loan['passdue_day'] > 0 ]['passdue_day'].count() / df_loan.loc[datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d') > pd.to_datetime(df_loan['deadline'],format='%Y-%m-%d')]['plan_id'].count())).split('.')
_current_loan_0duedays_rate = float(x+'.'+y[:6])
else : _current_loan_0duedays_rate = float(0)
self._result["current_loan_0duedays_rate"]['value'] = _current_loan_0duedays_rate
......@@ -224,9 +226,10 @@ class current_loan_0duedays_rate():
class current_loan_5duedays_rate():
"""在贷逾期5天以上的占比 : 已放款未到期的订单中,分子是到期期数的,逾期>=5天的期数个数 分母是 到期期数的个数"""
def feature(self):
_current_loan_5duedays_rate = -9999999
df_loan = self.df_loan
if df_loan.empty == False:
deadlineDay_cnt = int(df_loan.loc[datetime.strftime(datetime.now(),'%Y-%m-%d') > pd.to_datetime(df_loan['deadline'],format='%Y-%m-%d')]['plan_id'].count())
deadlineDay_cnt = int(df_loan.loc[datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d') > pd.to_datetime(df_loan['deadline'],format='%Y-%m-%d')]['plan_id'].count())
passdueDay_cnt = int(df_loan.loc[df_loan['passdue_day'] > 5 ]['passdue_day'].count())
if deadlineDay_cnt>0 and passdueDay_cnt > 0 :
x,y = str(float(passdueDay_cnt/deadlineDay_cnt)).split('.')
......@@ -275,7 +278,7 @@ class current_loan_apply_cnt():
loan_created_at = df_temp['loan_created_at'].astype(str).values[0]
df_apply_quota_record = get_sql_apply_quota_record(user_id,loan_created_at)
_current_loan_apply_cnt = len(df_apply_quota_record)
self._result["current_loan_refuse_rate"]['value'] = int(_current_loan_apply_cnt)
self._result["current_loan_apply_cnt"]['value'] = int(_current_loan_apply_cnt)
return self._result
class current_loan_refuse_cnt():
......@@ -291,7 +294,9 @@ class current_loan_refuse_cnt():
df_apply_quota_record = get_sql_apply_quota_record(user_id,loan_created_at)
current_loan_apply_cnt = len(df_apply_quota_record)
if current_loan_apply_cnt > 0 :
_current_loan_refuse_cnt = df_apply_quota_record.loc[df_apply_quota_record['apply_status'] == 2 ].sum()
df_apply_quota_record_status = df_apply_quota_record.loc[df_apply_quota_record['apply_status'] == 2]
if len(df_apply_quota_record_status)> 0:
_current_loan_refuse_cnt = df_apply_quota_record_status['uuid'].count()
else:
_current_loan_refuse_cnt = 0
......@@ -311,10 +316,13 @@ class current_loan_refuse_rate():
df_apply_quota_record = get_sql_apply_quota_record(user_id,loan_created_at)
current_loan_apply_cnt = len(df_apply_quota_record)
if current_loan_apply_cnt > 0 :
current_loan_refuse_cnt = df_apply_quota_record.loc[df_apply_quota_record['apply_status'] == 2 ].sum()
if df_apply_quota_record.loc[df_apply_quota_record['apply_status'] == 2 ].empty ==True:
current_loan_refuse_cnt = 0
else:
current_loan_refuse_cnt = df_apply_quota_record.loc[df_apply_quota_record['apply_status'] == 2 ]['uuid'].count()
else:
current_loan_refuse_cnt = 0
if current_loan_apply_cnt > 0 & current_loan_refuse_cnt > 0 :
if current_loan_apply_cnt > 0 & current_loan_refuse_cnt > 0:
_current_loan_refuse_rate = current_loan_apply_cnt/current_loan_refuse_cnt
else:
_current_loan_refuse_rate = 0
......
......@@ -10,13 +10,13 @@ from dateutil.relativedelta import relativedelta
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 = Sql_contactsOperator.getSql_loanAll(str(tuple([self.user_id])).replace(',)',')'))
BF._apply_at = time_now
if self.orderId:
_df = Sql_contactsOperator.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')
# BF.df_loan_all_v2 = Sql_contactsOperator.getSql_loanAll_diangdanv2(str(tuple([self.user_id])).replace(',)', ')'),str(BF._apply_at))
BF.df_loan_all = Sql_contactsOperator.getSql_loanAll(str(tuple([self.user_id])).replace(',)', ')'))
BF.df_loan_rollBack = pd.DataFrame()
if BF.df_loan_all.empty == False:
BF.df_loan_rollBack = get_Loan_rollBack(BF.df_loan_all,BF._apply_at)
......@@ -26,11 +26,16 @@ class has_loan_nums_2018():
"""user_success_loan_cnt#from2018TillNow has_loan_nums_2018 用户2018年放款订单数 """
def feature(self):
_has_loan_nums_2018 = -9999999
df_loan = self.df_loan_rollBack
df_loan_all_v2 = Sql_contactsOperator.getSql_loanAll(str(tuple([self.user_id])).replace(',)', ')'))
df_loan = df_loan_all_v2
df_loan['_apply_at'] = self._apply_at
df_loan = df_loan [df_loan['loan_paid_at'] < df_loan['_apply_at']]
if df_loan.empty == False:
# df_loan.dorp_d
# df_loan.dorp_d apply_time old loan_paid_at
df_loan['loan_paid_at_year'] = df_loan['loan_paid_at'].dt.year
df_loan = df_loan.loc[df_loan['loan_paid_at_year'] >= 2018]
# df_loan = df_loan.drop_duplicates('loan_id',keep='first')
# _has_loan_nums_2018 = df_loan['loan_id'].count()
df_loan = df_loan.drop_duplicates('loan_id',keep='first')
_has_loan_nums_2018 = df_loan['loan_id'].count()
self._result['has_loan_nums_2018']['value'] = _has_loan_nums_2018
......@@ -40,7 +45,10 @@ class has_loan_nums_2019():
"""user_success_loan_cnt#from2019TillNow has_loan_nums_2019 用户2019年放款订单数 """
def feature(self):
_has_loan_nums_2019 = -9999999
df_loan = self.df_loan_rollBack
df_loan_all_v2 = Sql_contactsOperator.getSql_loanAll(str(tuple([self.user_id])).replace(',)', ')'))
df_loan = df_loan_all_v2
df_loan['_apply_at'] = self._apply_at
df_loan = df_loan [df_loan['loan_paid_at'] < df_loan['_apply_at']]
if df_loan.empty == False:
df_loan['loan_paid_at_year'] = df_loan['loan_paid_at'].dt.year
df_loan = df_loan.loc[df_loan['loan_paid_at_year'] >= 2019]
......
......@@ -14,18 +14,21 @@ class __INIT__(BF):
if _df.empty == False:
BF.created_at = datetime.datetime.strptime(_df['apply_time'].astype(str).values[0],'%Y-%m-%d %H:%M:%S')
BF.user_phone = getSql_userPhone(str(tuple([self.user_id])).replace(',)',')'))['phone_no'].tolist()
BF._df = getSql_EmergencyContact(self.user_id,BF.created_at)
BF._df.sort_values('created_at',ascending=False,inplace=True)
BF._df = BF._df.loc[~(BF._df['phone_no'].isin(BF.user_phone))]
# BF._df = BF._df.drop_duplicates(['phone_no'],keep='first')
# BF._df = BF._df.sort_values('created_at')
BF._df = BF._df.iloc[:2]
BF.contacts_phone = BF._df['phone_no'].tolist() # 获取历史联系人手机号
pass
def get_CallPhone(df_auth,uuid,user_phone,contacts_phone,day):
def get_CallPhone(df_auth,uuid,user_phone,contacts_phone,day,apply_time):
userSource = df_auth['userSource'].values[0]
_time = get_CallPhoneTime(userSource,uuid,user_phone,contacts_phone,day)
_time = get_CallPhoneTime(userSource,uuid,user_phone,contacts_phone,day,apply_time)
df_telephone = pd.DataFrame()
if _time:
if userSource == 'YIDONG':
......@@ -43,24 +46,34 @@ def get_CallPhone(df_auth,uuid,user_phone,contacts_phone,day):
return df_telephone
def get_CallPhoneTime(userSource,uuid,user_phone,contacts_phone,day):
def get_CallPhoneTime(userSource,uuid,user_phone,contacts_phone,day,apply_time):
df_telephone = pd.DataFrame()
if userSource == 'YIDONG':
df_telephone = getSql_mobileCallInfoDataService(uuid = uuid,
user_phone = user_phone,
orderby=['timestamp','desc'],limit=1)
orderby=['timestamp','desc'])
elif userSource == 'LIANTONG':
df_telephone = getSql_unicomCallInfoDataService(uuid = uuid,
user_phone = user_phone,
orderby=['timestamp','desc'],limit=1)
orderby=['timestamp','desc'])
elif userSource == 'DIANXIN':
df_telephone = getSql_telecomCallInfoDataService(uuid = uuid,
user_phone = user_phone,
orderby=['timestamp','desc'],limit=1)
orderby=['timestamp','desc'])
###新增
df_telephone['timestamp'] = pd.to_datetime(df_telephone['timestamp'])
df_telephone['apply_at'] = BF.created_at
df_telephone['apply_at'] = pd.to_datetime(df_telephone['apply_at'])
df_telephone['cTime'] = pd.to_datetime(df_telephone['cTime'])
df_telephone = df_telephone.sort_values(['timestamp'])
df_telephone = df_telephone[df_telephone['timestamp'] <= df_telephone['apply_at']]
if df_telephone.empty == False:
df_telephone['timestamp'] = df_telephone['timestamp'].apply(lambda x : str(x))
starttime = str(datetime.datetime.strptime(df_telephone['timestamp'].values[0] ,'%Y-%m-%d %H:%M:%S') - day)
endtime = df_telephone['timestamp'].values[0]
endtime = str(df_telephone['timestamp'].max())
# df_telephone['timestamp'] = df_telephone['timestamp'].apply(lambda x : str(x))
starttime = str(datetime.datetime.strptime(endtime ,'%Y-%m-%d %H:%M:%S') - day)
# endtime = df_telephone['timestamp'].values[0]
return (starttime,endtime)
return None
......@@ -91,9 +104,9 @@ class call_with_relation_cnt_150():
contacts_phone = str(tuple(self.contacts_phone)).replace(',)',')')
df_telephone = get_CallPhone(df_auth,
self.uuid,
str(tuple(self.user_phone)).replace(',)',')') ,
str(tuple(self.user_phone)).replace(',)',')'),
contacts_phone,
datetime.timedelta(days=150))
datetime.timedelta(days=150),self.created_at)
if df_telephone.empty == False:
_call_with_relation_cnt = df_telephone['receiverPhone'].count()
......@@ -112,7 +125,7 @@ class call_with_relation_cnt_90():
df_telephone = get_CallPhone(df_auth,self.uuid,
str(tuple(self.user_phone)).replace(',)',')') ,
contacts_phone,
datetime.timedelta(days=90))
datetime.timedelta(days=90),self.created_at)
if df_telephone.empty == False:
_call_with_relation_cnt = df_telephone['receiverPhone'].count()
......@@ -132,7 +145,7 @@ class call_with_relation_cnt_30():
df_telephone = get_CallPhone(df_auth,self.uuid,
str(tuple(self.user_phone)).replace(',)',')') ,
contacts_phone,
datetime.timedelta(days=30))
datetime.timedelta(days=30),self.created_at)
if df_telephone.empty == False:
_call_with_relation_cnt = df_telephone['receiverPhone'].count()
......@@ -152,7 +165,7 @@ class call_with_relation_cnt_7():
df_telephone = get_CallPhone(df_auth,self.uuid,
str(tuple(self.user_phone)).replace(',)',')') ,
contacts_phone,
datetime.timedelta(days=7))
datetime.timedelta(days=7),self.created_at)
if df_telephone.empty == False:
_call_with_relation_cnt = df_telephone['receiverPhone'].count()
......@@ -491,7 +504,7 @@ class diffdays_fst_call_with_relation():
# df_telephone = pd.concat([df_mobile,df_telecom,df_unicom])
contacts_phone = str(tuple(self.contacts_phone)).replace(',)',')')
df_telephone = get_CallPhone(df_auth,self.uuid,str(tuple(self.user_phone)).replace(',)',')'),contacts_phone,datetime.timedelta(days=150))
df_telephone = get_CallPhone(df_auth,self.uuid,str(tuple(self.user_phone)).replace(',)',')'),contacts_phone,datetime.timedelta(days=150),self.created_at)
if df_telephone.empty == False:
_diffdays_fst_call_with_relation = (datetime.datetime.strptime(str(self.created_at).split(' ')[0],'%Y-%m-%d') - datetime.datetime.strptime(str(pd.to_datetime(df_telephone['cTime']).min()).split(' ')[0],'%Y-%m-%d') ).days
self._result['diffdays_fst_call_with_relation']['value'] = _diffdays_fst_call_with_relation
......@@ -507,7 +520,7 @@ class diffdays_last_call_with_relation():
if df_auth.empty == False:
contacts_phone = str(tuple(self.contacts_phone)).replace(',)',')')
df_telephone = get_CallPhone(df_auth,self.uuid,str(tuple(self.user_phone)).replace(',)',')'),contacts_phone,datetime.timedelta(days=150))
df_telephone = get_CallPhone(df_auth,self.uuid,str(tuple(self.user_phone)).replace(',)',')'),contacts_phone,datetime.timedelta(days=150),self.created_at)
if df_telephone.empty == False:
# _diffdays_last_call_with_relation = (self.created_at - pd.to_datetime(df_telephone['cTime']).max()).days
_diffdays_last_call_with_relation = (datetime.datetime.strptime(str(self.created_at).split(' ')[0],'%Y-%m-%d') - datetime.datetime.strptime(str(pd.to_datetime(df_telephone['cTime']).max()).split(' ')[0],'%Y-%m-%d') ).days
......@@ -527,7 +540,7 @@ class diffdays_call_with_relation():
df_telephone = get_CallPhone(df_auth,self.uuid,
str(tuple(self.user_phone)).replace(',)',')') ,
contacts_phone,
datetime.timedelta(days=150))
datetime.timedelta(days=150),self.created_at)
if df_telephone.empty == False:
diffdays_call_with_relation_min = (datetime.datetime.strptime(str(self.created_at).split(' ')[0],'%Y-%m-%d') - datetime.datetime.strptime(str(pd.to_datetime(df_telephone['cTime']).min()).split(' ')[0],'%Y-%m-%d') ).days
......
......@@ -15,6 +15,7 @@ class __INIT__(BF):
class user_apply_refuse_cnt():
def feature(self):
"""user_apply_refuse_cnt"""
#历史最大逾期天数 : 用户申请拒绝次数(一单一审放款拒绝和循环额度申请拒绝)
_df_loan_refuse_cnt_old = get_sql_loan_refuse_cnt_old(self.user_id)
_df_loan_refuse_cnt_new = get_sql_loan_refuse_cnt_new(self.user_id)
......@@ -24,6 +25,7 @@ class user_apply_refuse_cnt():
return self._result
class diff_apply_to_last_refused_days_rc():
def feature(self):
_df_refused = get_sql_loan_refused(self.user_id)
self._result['diff_apply_to_last_refused_days_rc']['value'] = 1000
......
This diff is collapsed.
......@@ -14,7 +14,11 @@ def getSql_loanAll(user_id):
when loan.created_at < '2018-05-08' then loan.created_from
else null
end as applied_from
,if (sub.created_at is not null, sub.created_at ,loan.created_at) apply_time
-- ,if (sub.created_at is not null, sub.created_at ,loan.created_at) apply_time
,case when loan.created_at >='2018-05-08' then aqr.apply_time
when loan.created_at < '2018-05-08' then if (sub.created_at is not null, sub.created_at ,loan.created_at)
else null
end as apply_time
,plan.id as plan_id,plan.term_no, plan.repayment_status, plan.deadline as deadline,DATE_ADD(plan.deadline,INTERVAL 1 second) as deadline_new
,plan.repaid_at
,plan.current_repayment
......@@ -39,20 +43,21 @@ def get_Loan_rollBack(df_loan,apply_time,passdueDay_Negative=False):
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'] )]
# df_loan = df_loan.loc[ (df_loan['loan_paid_at'] < df_loan['observationTime'] )]
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['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 %H:%M:%S'),'%Y-%m-%d %H:%M:%S'))
df_loan['passdue_day'] = 0
df_loan = df_loan.loc[(df_loan['apply_time'] <= df_loan['observationTime'])]
# df_loan = df_loan.loc[(df_loan['apply_time'] <= df_loan['observationTime'])]
df_loan = df_loan.loc[(df_loan['loan_paid_at'] < df_loan['observationTime'])]
if df_loan.empty == False:
df_loan.loc[(df_loan['repaid_at'] != '2000-01-01')&(df_loan['repaid_at']>df_loan['observationTime']),'repaid_at'] = datetime.datetime.strptime('2000-01-01 00:00:00','%Y-%m-%d 00:00:00')
# 还款时间正常 ,还款状态!=3
df_loan.loc[(df_loan['repaid_at'] != '2000-01-01') & (df_loan['repayment_status'] !=3 ),'repaid_at'] = datetime.datetime.strptime('2000-01-01 00:00:00','%Y-%m-%d 00:00:00')
# df_loan.loc[(df_loan['repaid_at'] == '2000-01-01'),'repayment_status'] = 0
df_loan.loc[(df_loan['repaid_at'] == '2000-01-01')& (df_loan['repayment_status'] != 3),'repayment_status'] = 0
df_loan.loc[(df_loan['repaid_at'] != '2000-01-01') & (df_loan['repayment_status'] !=3),'repaid_at'] = datetime.datetime.strptime('2000-01-01 00:00:00','%Y-%m-%d 00:00:00')
df_loan.loc[(df_loan['repaid_at'] == '2000-01-01'),'repayment_status'] = 0
# df_loan.loc[(df_loan['repaid_at'] == '2000-01-01')& (df_loan['repayment_status'] != 3),'repayment_status'] = 0
df_loan.loc[(df_loan['repayment_status'] == 3),'passdue_day'] = (df_loan['repaid_at'] - df_loan['deadline']).dt.days
df_loan.loc[(df_loan['repayment_status'] != 3)&(df_loan['observationTime'] > df_loan['deadline']) ,'passdue_day'] = (df_loan['observationTime'] - df_loan['deadline']).dt.days
......@@ -60,11 +65,10 @@ def get_Loan_rollBack(df_loan,apply_time,passdueDay_Negative=False):
# df_loan.loc[(df_loan['repaid_at'] != '2000-01-01'),'passdue_day'] = (df_loan['repaid_at'] - df_loan['deadline']).dt.days
# df_loan.loc[(df_loan['repaid_at'] == '2000-01-01')&(df_loan['observationTime'] > df_loan['deadline']) ,'passdue_day'] = (df_loan['observationTime'] - df_loan['deadline']).dt.days
# df_loan.loc[(df_loan['repaid_at'] == '2000-01-01')&(df_loan['repayment_status']==0)&(df_loan['observationTime']<df_loan['deadline']),'passdue_day'] = (df_loan['observationTime'] - df_loan['deadline']).dt.days
if passdueDay_Negative == False:
df_loan.loc[(df_loan['passdue_day'] < 0),'passdue_day'] = 0
_loan_id = []
for k ,v in df_loan.groupby(['loan_id']):
_df = pd.DataFrame(v)
if _df.loc[(_df['repayment_status']==3)]['plan_id'].count() != _df['plan_id'].count():
......
......@@ -236,7 +236,11 @@ def getSql_loanAll(user_id):
when loan.created_at < '2018-05-08' then loan.created_from
else null
end as applied_from
,if (sub.created_at is not null, sub.created_at ,loan.created_at) apply_time
-- ,if (sub.created_at is not null, sub.created_at ,loan.created_at) apply_time
,case when loan.created_at >='2018-05-08' then aqr.apply_time
when loan.created_at < '2018-05-08' then if (sub.created_at is not null, sub.created_at ,loan.created_at)
else null
end as apply_time
,plan.id as plan_id,plan.term_no, plan.repayment_status, plan.deadline as deadline,DATE_ADD(plan.deadline,INTERVAL 1 second) as deadline_new
,plan.repaid_at
,plan.current_repayment,plan.required_repayment
......@@ -253,10 +257,25 @@ def getSql_loanAll(user_id):
and fest.transaction_status in (2,5)
and loan.business_type in (0,2)
order by loan.id,plan.id
""".format(user_id)
""".format(user_id)
_df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df
def getSql_loanAll_diangdanv2(user_id,apply_at):
"""获取用户所有放款订单明细"""
_sql = """SELECT m.* FROM loan_application_history l
JOIN loan_application_manifest_history m ON
l.id = m.loan_application_history_id WHERE
l.user_id in {0} AND l.progress IN (15,16,65)
AND l.business_type IN ( 0, 2, 4, 6 ) and m.loan_paid_at < '{1}' order by m.loan_paid_at desc""".format(user_id,apply_at)
_df = pd.read_sql(_sql,con_tuomin_xyqb)
return _df
def getSql_loan_applyAll(user_id):
"""获取用户所有放款订单明细"""
_sql = """
......@@ -571,11 +590,12 @@ def get_user_bill_info_rows(uuid,_created_at=None,time_from=0):
df = pd.DataFrame()
if _response:
df = pd.DataFrame(_response['data']['features']['user_bill_info_rows']['value'])
time_now = datetime.datetime.strptime(datetime.datetime.strftime((_created_at.replace(day=1) - datetime.timedelta(1)).replace(day=1),'%Y-%m-%d 00:00:00'),'%Y-%m-%d %H:%M:%S')
time_from = time_now - relativedelta(months=+time_from)
df['billDay'] = df['billDay'].apply(lambda stamp: time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stamp/1000)))
# df['billDay'] = pd.to_datetime(df['billDay'])
df = df.loc[(df['billDay']>=str(time_from)) & (df['billDay']<str(time_now))]
if df.empty ==False:
time_now = datetime.datetime.strptime(datetime.datetime.strftime((_created_at.replace(day=1) - datetime.timedelta(1)).replace(day=1),'%Y-%m-%d 00:00:00'),'%Y-%m-%d %H:%M:%S')
time_from = time_now - relativedelta(months=+time_from)
df['billDay'] = df['billDay'].apply(lambda stamp: time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stamp/1000)))
# df['billDay'] = pd.to_datetime(df['billDay'])
df = df.loc[(df['billDay']>str(time_from)) & (df['billDay']<=str(time_now))]
return df
return df
......
......@@ -110,8 +110,8 @@ def get_sql_apply(user_id):
SELECT
user_id,
apply_time,
case when aqr.apply_status = 1 then 1
else 2 end as apply_status,
case when apply_status = 1 then 1
else 2 end as apply_status
FROM
apply_quota_record
WHERE user_id = {0}
......@@ -123,13 +123,17 @@ def get_sql_apply(user_id):
def get_sql_loan_refuse_cnt_old(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 l.progress IN (6,8,19) AND e.loan_id IS NULL
"""
# _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,4,6)
# AND l.progress IN (6,8,19) AND e.loan_id IS NULL
#
# """
_sql = """SELECT COUNT(1) count FROM loan_application_history l JOIN
loan_account_ext e ON e.loan_id = l.id WHERE l.user_id = {0}
and l.business_type IN (0,2,4,6)
AND l.progress = 8 """
_df = pd.read_sql(_sql.format(user_id),con_tuomin_xyqb)
return _df
......
......@@ -470,6 +470,8 @@ def city_sign(uuid=None,order_no=None):
if _response['data']['features']['user_ocr_info#address']['value'] == -9999999:
return list([])
elif _response['data']['features']['user_ocr_info#address']['value'] == '':
return list([])
c_list = []
first_city = ["北京市","上海市","广州市","深圳市"]
second_city = ["成都市", "杭州市", "重庆市", "武汉市", "苏州市", "西安市", "天津市", "南京市", "郑州市", "长沙市", "沈阳市", "青岛市", "宁波市", "东莞市", "无锡市"]
......@@ -533,8 +535,12 @@ def card_expires(uuid=None,order_no=None):
if _response['data']['features']['user_ocr_info#validDateEnd']['value'] == "?":
return list([])
ll_idcard = _response['data']['features']['user_ocr_info#validDateEnd']['value']
if ll_idcard:
return int(ll_idcard)
if ll_idcard =='长期':
return 20301230
elif isinstance(ll_idcard,int):
return int(ll_idcard)
......@@ -585,7 +591,7 @@ def id_user_credited(validity_date,user_id):
def day_incoming_parts(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 < "{0}" group by apply_status;""".format(Same_day_first,Same_day_next)
where created_at >= "{0}" and created_at < "{1}" group by apply_status;""".format(Same_day_first,Same_day_next)
_df = pd.read_sql(_Sql,con_vccthree_vcc_talos)
return _df
......
......@@ -13,7 +13,7 @@ def getSql_authorizationPhone_one(uuid,userPhone):
_sql = """
select parentId as uuid,createDate,modifyDate,userSource,loginName
from t_user_auth_info
where parentId = '{0}' and loginName in ("{1}")
where parentId = '{0}' and loginName in {1}
and userSource in ('YIDONG','LIANTONG','DIANXIN')
""".format(uuid,userPhone)
_df = pd.read_sql(_sql,con_lkbadmin)
......@@ -34,9 +34,11 @@ def getSql_userPhone_one(user_id):
##移动数据库
def getSql_mobileCallInfoDataService_one(uuid = None,user_phone = None,contacts_phone = None,time_start = None,time_end = None):
""" 移动通话记录 """
_sql = """
select uuid,cTime,tradeAddr,tradeWay,tradeType,receiverPhone,tradeTime,phone from comservice_i_mobile_call_info
"""
# _sql = """
# select uuid,cTime,tradeAddr,tradeWay,tradeType,receiverPhone,tradeTime,phone from comservice_i_mobile_call_info
# """
_sql = """ select uuid,cTime,tradeAddr,tradeWay,tradeType,receiverPhone,tradeTime,phone
from comservice_i_mobile_call_info force index(index_mobile_call_info_phone)"""
iswhere = []
if user_phone:
iswhere.append(' phone in {0}'.format(user_phone))
......@@ -56,7 +58,7 @@ def getSql_mobileCallInfoDataService_one(uuid = None,user_phone = None,contacts_
if contacts_phone:
_sql = """
select uuid,cTime,tradeAddr,tradeWay,tradeType,receiverPhone,tradeTime,phone
from comservice_i_mobile_call_info
from comservice_i_mobile_call_info force index(index_mobile_call_info_phone)
where phone in ("{0}")
and receiverPhone in ("{1}")
and cTime BETWEEN '{2}' and '{3}'
......@@ -64,7 +66,7 @@ def getSql_mobileCallInfoDataService_one(uuid = None,user_phone = None,contacts_
else:
_sql = """
select uuid,cTime,tradeAddr,tradeWay,tradeType,receiverPhone,tradeTime,phone
from comservice_i_mobile_call_info
from comservice_i_mobile_call_info force index(index_mobile_call_info_phone)
where phone in ("{0}")
and cTime BETWEEN '{1}' and '{2}'
""".format(user_phone,time_start,time_end)
......@@ -78,7 +80,7 @@ def getSql_unicomCallInfoDataService_one(uuid = None,user_phone = None,contacts_
if contacts_phone:
_sql = """
select uuid,cTime,tradeAddr,callType as tradeWay,tradeType,receiverPhone,tradeTime,phone
from comservice_i_unicom_call_info
from comservice_i_unicom_call_info force index(index_unicom_call_info_phone)
where phone in ("{0}")
and receiverPhone in ("{1}")
and cTime BETWEEN '{2}' and '{3}'
......@@ -87,7 +89,7 @@ def getSql_unicomCallInfoDataService_one(uuid = None,user_phone = None,contacts_
else:
_sql = """
select uuid,cTime,tradeAddr,callType as tradeWay,tradeType,receiverPhone,tradeTime,phone
from comservice_i_unicom_call_info
from comservice_i_unicom_call_info force index(index_unicom_call_info_phone)
where phone in ("{0}")
and cTime BETWEEN '{1}' and '{2}'
""".format(user_phone,time_start,time_end)
......@@ -100,7 +102,7 @@ def getSql_telecomCallInfoDataService_one(uuid = None,user_phone = None,contacts
if contacts_phone:
_sql = """
select uuid,cTime,tradeAddr,callWay as tradeWay,tradeType,receiverPhone,tradeTime,phone
from comservice_i_telecom_call_info
from comservice_i_telecom_call_info force index(index_telecom_call_info_phone)
where phone in ("{0}")
and receiverPhone in ("{1}")
and cTime BETWEEN '{2}' and '{3}'
......@@ -108,7 +110,7 @@ def getSql_telecomCallInfoDataService_one(uuid = None,user_phone = None,contacts
else:
_sql = """
select uuid,cTime,tradeAddr,callWay as tradeWay,tradeType,receiverPhone,tradeTime,phone
from comservice_i_telecom_call_info
from comservice_i_telecom_call_info force index(index_telecom_call_info_phone)
where phone in ("{0}")
and cTime BETWEEN '{1}' and '{2}'
""".format(user_phone,time_start,time_end)
......@@ -189,22 +191,14 @@ def get_lxr_list(uuid=None,order_no=None):
except Exception as e:
print(e.args)
if _response:
# if _response['data']['features']['user_contact_book_info#d7_contact_nums']['value'] == -9999999:
# return list([-9999999])
# if _response['data']['features']['user_contact_book_info#d7_contact_nums']['value'] == []:
# return list([])
ll_phone = pd.DataFrame(_response['data']['features']['user_contact_book_info#d7_contact_nums']['value'])
if len(ll_phone) > 0:
l_phone =ll_phone[0].tolist()
l_phone = [str(i).replace(" ","").replace("-","") for i in l_phone]
l_phone = [i for i in l_phone if re.match(r'^(1[3546789]\d{9})$', str(i))]
return l_phone
# else:
# return list([])
return list([])
# get_lxr_list(uuid='9d75f662-04d4-4536-be35-f14f517a36f6')
......
......@@ -47,18 +47,18 @@ if __name__ == "__main__":
# [i.setFormatter(LogFormatter()) for i in logging.getLogger().handlers]
# tornado.options.parse_command_line()
#
# # #== 本地调试
# app.listen(23011)
# # #== 本地调试get_id_hmd
# app.listen(23017)
# IOLoop.instance().start()
#
from tornado.options import define, options
define("port", default=23010, help="run on the given port ", type=int)
define("port", default=23016, help="run on the given port ", type=int)
define("log_path", default='/tmp', help="log path ", type=str)
tornado.options.parse_command_line()
app = apps()
http_server = tornado.httpserver.HTTPServer(app)
http_server.bind(options.port)
http_server.start(num_processes=0)
http_server.start()
tornado.ioloop.IOLoop.instance().start()
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