123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import consts;
- import numpy as np;# 近3月开户最高贷款本金
- import time;
- import math;
- import logResult;
- log4r = logResult.logger
- import json;
- #某个日期离当前时间
- def difDate(dateStr):
- return int(str(np.datetime64(np.datetime64(time.strftime("%Y-%m-%d")), "D") -np.datetime64(dateStr, "D")).split(" ")[0]);
- #某个日期离报告期天数
- def difDateReportTime(reportTime,dateStr):
- return int(str(np.datetime64(reportTime, "D") -np.datetime64(dateStr, "D")).split(" ")[0])
- # 最近几个月的日期
- def getLastMonthDate(dateStr,month):
- lastMonthDateStr = dateStr.replace(".", "-")
- # 最近一个月
- lastMonthDate = np.datetime64(lastMonthDateStr, "D") - np.timedelta64(30 * month, 'D')
- return str(lastMonthDate);
- #离当前时间月份
- def difMonthNow(dateStr):
- return math.ceil(int(str(np.datetime64(time.strftime("%Y-%m-%d")) - np.datetime64(dateStr.replace('.', '-'), "D")).split(" ")[0]) / 30);
- #离报告时间月份
- def difMonthReportTime(dateStr,reportTime):
- try:
- reportTimeTmp = np.datetime64(reportTime, "D");
- dateStrTmp = np.datetime64(dateStr, "D");
- except:
- print(dateStr+' 解析截止日期报错')
- month = int(str(reportTimeTmp - dateStrTmp ).split(" ")[0]) / 30;
- return math.ceil(month)
- #转json
- def toJson(df):
- jsonStr = df.to_json(orient="index",force_ascii=False);
- # print(json)
- log4r.info(jsonStr)
- reult = formatJson(json.loads(jsonStr));
- return reult
- def formatJson(jsonObj):
- json_dicts = json.dumps(jsonObj, indent=4, ensure_ascii=False)
- return json_dicts;
- # 判断是否有表头
- def checkHeader(df,allHeaders):
- result = False
- headerList = df.loc[0, :].tolist() # 第0行为表头
- headerList1 = []
- if df.index.size>1:
- headerList1 = df.loc[1, :].tolist() # 第1行为表头
- for header in allHeaders: # 第0行或者1行为表头的话,代表不是数据,否则是数据
- if list(filter(None, header)) == list(filter(None, headerList)) or list(filter(None, header)) == list(
- filter(None, headerList1)):
- result = True;
- break;
- return result;
- #替换还款状态规则
- #1、2、3、4、5、6、7、D、Z、G、B Z/B=7
- def replacePayRcdStatus(df):
- if df.empty:
- return df;
- df['还款状态'] = df['还款状态'].map({"/":0,"*":0,"C":0,"N":0,"#":0,"M":0,"G":7,"D":1,"":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7})
- return df;
- def doFilterCalc(self,dfx):
- dfx = dfx.replace('--', 0)
- return dfx;
- #开户数使用,出现逾期的情况
- def replacePayRcdStatusOverdue(df):
- if df.empty:
- return df;
- df['还款状态'] = df['还款状态'].map({"/":0,"*":0,"C":0,"N":0,"#":0,"M":0,"G":7,"B":7,"Z":7,"D":1,"":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7})
- return df;
- # 替换日期格式转换briefInfo
- def replaceDateCol(dfx):
- if not dfx.empty:
- dfx[1] = dfx[1].str.replace(".", '-') # 2018.09.02->>2018-09-02
- return dfx;
- # 替换日期格式转换briefInfo
- def replaceDateColIdx(dfx,idx):
- if not dfx.empty:
- dfx[idx] = dfx[idx].str.replace(".", '-') # 2018.09.02->>2018-09-02
- return dfx;
- # 科学计数法转换
- def replaceAmt(value):
- if str(value)=="" or str(value)=="--" or str(value)=="nan":
- # return value.replace(',', '')
- return 0.0
- else:
- return float(value.replace(',', ''))
- #转整型
- def toInt(value):
- if str(value)=="" or str(value)=="--" or str(value)=="nan":
- return 0
- else:
- return int(value)
- #替换日期
- def formatDate(str):
- return st
|