예제 #1
0
    def _mailListHandlerApi(self, phone):
        try:
            #获取af_base和af_tag_baes表中的数据
            dict_info = self._getTagAndBaseData(phone)
            if dict_info == False:
                return False

            # 初始化通讯录
            address_list = AddressList().getByUserPhoneDict(phone)
            # 格式通讯录的手机号
            phone_list = self._getUserFordb(address_list)
            phone_list = phone_list.phone
            # 通讯录条数
            phone_list_num = phone_list.count()
            # 将手机号转成元组
            phone_list = self._getTupleList(phone_list)
            if not phone_list:
                logger.info("number_label: %s不存在通讯录" % phone)
                return False

            # 号码标签条数
            label_num = self._getNumberLableNum(phone_list)
            if not label_num:
                logger.info("number_label: %s通讯录号码标签解析失败" % phone)
                print("号码标签解析失败!")
                return False
            dict_info['label_num'] = label_num
            # 通讯录号码数
            dict_info['mail_list_num'] = len(phone_list)
            # 通讯录去重号码数
            dict_info['weight_loss_num'] = len(set(phone_list))
            return dict_info
        except Exception as err:
            print(err)
            return False
예제 #2
0
 def __address(self,user_phone):
     # 获取通信录处理对象
     self.oAddress = None
     self.dbYiAddressList = AddressList().getByUserPhoneDict(user_phone)
     if len(self.dbYiAddressList) > 0:
         try:
             self.oAddress = Address(self.dbYiAddressList)
         except Exception as e:
             logger.error("user_id:%s address %s" % (self.user_id, e))
예제 #3
0
    def _mailListHandler(self, tag_base):
        check_key = self._checkKeyBool("phone", tag_base)
        if not check_key:
            return False
        phone = tag_base.phone
        if not phone or phone == 0:
            print("手机号不能为空")
            return False

        # 初始化通讯录
        address_list = AddressList().getByUserPhoneDict(phone)
        # 格式通讯录的手机号
        phone_list = self._getUserFordb(address_list)
        phone_list = phone_list.phone
        # 通讯录条数
        phone_list_num = phone_list.count()
        # 将手机号转成元组
        phone_list = self._getTupleList(phone_list)
        if not phone_list:
            return False

        try:
            dict_info = {}
            # 号码标签条数
            label_num = self._getNumberLableNum(phone_list)

            if not label_num:
                print("号码标签解析失败!")
                return False
            label_num['label_num'] = label_num

            #user_id
            label_num['user_id'] = tag_base.user_id
            #loan_id
            oAf_base = AfBase()
            base_info = oAf_base.getBaseForbaseid(tag_base.base_id)
            loan_id = 0
            if base_info:
                loan_id = base_info.loan_id
            label_num['loan_id'] = loan_id
            #通讯录号码数
            label_num['mail_list_num'] = len(phone_list)
            #通讯录去重号码数
            label_num['weight_loss_num'] = len(set(phone_list))

            return label_num

        except AttributeError as error:
            print(error)
            return False
        except Exception as err:
            print(err)
            return False
예제 #4
0
    def __analysis(self):
        # 分析数据
        # 1. 用户, 亲属 , 好友认证
        self.dbUser = YiUser().get(self.user_id)
        if self.dbUser is None:
            logger.error("user_id:%s db中没有纪录" % self.user_id)
            raise Exception(1002, "没有纪录")

        self.dbYiFriends = YiFriend().getByUserId(self.user_id)

        # 2. 初始化通讯录和报告
        self.dbYiAddressList = AddressList().getByUserPhoneDict(self.dbUser.mobile)
        try:
            # 通讯录追加
            self._addMailNumberLabel(self.dbUser.mobile)
        except Exception as e:
            logger.info("number_label: 通讯录错误:%s" % e)

        #学信、社保、公积金维度的数据信息验证
        try:
            thirdPartyInfo().runData(self.dbUser)
        except Exception as e:
            logger.info("第三方接口: 学信、社保、公积错误:%s" % e)

        self.jxl_record = OpenJxlStat().getById(self.jxlstat_id)
        logger.info("number_label: user_id:%s" % self.user_id)
        # 3. 调用OperatorAnalysis
        operatorObj = OperatorAnalysis()
        operator_data = operatorObj.getOperatorData(self.dbYiAddressList,self.jxl_record)
        if operatorObj is not None:
            self.oDetail = operatorObj.oDetail
            self.oAddress = operatorObj.oAddress

        # 4. 跟业务模型数据交叉合并
        # 亲属联系人与是否逾期
        self.dbContact = YiFavoriteContact().getByUserId(self.user_id)
        relatives = {}
        if self.dbContact is not None:
            relatives['phone'] = self.dbContact.phone
            relatives['mobile'] = self.dbContact.mobile

        self.contact_due_data = relatives_is_overdue(relatives)
        if self.oAddress is not None:
            self.address_vscontact = self.oAddress.vsContact(relatives)
            self.address_vsuser = self.oAddress.vsUser(self.dbUser.mobile)
            self.address_vsloan = Addrloan(self.oAddress.pd_address).run()
        # 5. 与detail联合匹配
        if self.oDetail is not None:
            self.__detailVs()

        # 6. 黑名单
        self.black_data = self.__blackNum()
        return operator_data
예제 #5
0
def getScore(line_data):
    phone = line_data.get('mobile', '')
    phone = str(phone)
    detail_url = line_data.get('detail_url', '')
    report_url = line_data.get('report_url', '')
    source = line_data.get('source', 0)
    user_id = line_data.get('user_id', 0)
    contact = YiFavoriteContact().getByUserId(user_id)
    if contact is not None:
        print('phone : %s  mobile : %s' % (contact.phone, contact.mobile))
    addrList = AddressList().getByUserPhoneDict(phone)
    print('addrlist len %d' % len(addrList))
    address_data = analysis_address(addrList)
    detail_data, detail_vscontact = analysis_detail(detail_url, contact)
    report_data = analysis_operator_report(source, report_url)
    req_data = {
        'addr_tel_count':
        address_data.get('addr_tel_count', ''),
        'com_r_total_mavg':
        detail_vscontact.get('com_r_total_mavg', ''),
        'com_c_duration':
        detail_vscontact.get('com_c_duration', ''),
        'com_c_duration_rank':
        detail_vscontact.get('com_c_duration_rank', ''),
        'com_answer_duration':
        detail_data.get('com_answer_duration', ''),
        'com_days_answer':
        detail_data.get('com_days_answer', ''),
        'sms_phone_count_nodup':
        report_data.get('sms_phone_count_nodup', ''),
        'call_count_call_time_5min10min':
        report_data.get('call_count_call_time_5min10min', ''),
        'call_duration_holiday_3month':
        report_data.get('call_duration_holiday_3month_t_7', ''),
        'call_duration_workday_3month':
        report_data.get('call_duration_workday_3month_t_7', '')
    }
    req_data_json = json.dumps(req_data)
    print('phone: %s ,req_data: %s' % (phone, req_data_json))
    headers = {'Content-Type': 'application/json'}
    # r = requests.post('http://127.0.0.1:8089/api/xgboost/predict',headers=headers,data=req_data_json)
    r = requests.post('http://10.139.52.241:8089/api/xgboost/predict',
                      headers=headers,
                      data=req_data_json)
    resp_info = json.loads(r.text)
    req_code = resp_info.get('code')
    predict_result = None
    if req_code == '0000':
        req_data = resp_info.get('data')
        dict_req_data = json.loads(req_data)
        predict_result = dict_req_data.get('predict_result')
    return predict_result
예제 #6
0
 def __get_address_phones(self, phones):
     '''
     通讯录相关
     '''
     address_phone = []
     if phones:
         dbAddressList = AddressList().getByUserPhones(phones)
         if len(dbAddressList) > 0:
             try:
                 return dbAddressList
             except Exception as e:
                 logger.error("phone:%s address is fail: %s" % (phone, e))
     return address_phone
예제 #7
0
 def __get_address_phone(self, phone):
     '''
     通讯录相关
     '''
     address_phone = None
     if phone:
         dbAddressList = AddressList().getByUserPhone(phone)
         if len(dbAddressList) > 0:
             try:
                 address_phone = self.__getDistinctPhone(dbAddressList)
             except Exception as e:
                 logger.error("phone:%s address is fail: %s" % (phone, e))
     return address_phone
예제 #8
0
    def __get_address_phone(self, phone):
        '''
        通讯录相关
        '''
        address_phone = []
        userInfo = YiUser().getByMobile(phone)

        if userInfo:
            dbYiAddressList = AddressList().getByUserPhoneDict(userInfo.mobile)
            if len(dbYiAddressList) > 0:
                try:
                    oAddress = Address(dbYiAddressList)
                    address_phone = oAddress.getDistinctPhone()
                except Exception as e:
                    logger.error("phone:%s address is fail: %s" % (phone, e))
        return address_phone
예제 #9
0
    def __analysis(self):
        # 1.初始化通讯录
        addrList = AddressList().getByUserPhoneDict(self.user_phone)
        # 2.通讯录号码标签
        number_label = NumberLabelApi()
        if len(addrList) > 0:
            self.address_tag = number_label.getAddressTag(
                self.user_phone, addrList)

        user_id = self.__getUserId()
        # 3.学信、社保、公积金维度的数据信息验证
        third_party_dict = {
            "aid": self.aid,
            "user_id": user_id,
            "identity_code": self.identity,
            "realname": self.realname
        }
        self.other_data = thirdPartyApi(third_party_dict).run()

        # 4.调用OperatorAnalysis
        operatorObj = OperatorAnalysisApi()
        operator_data = operatorObj.getOperatorData(addrList, self.jxl_record)
        if operatorObj is not None:
            self.oDetail = operatorObj.oDetail
            self.oAddress = operatorObj.oAddress
            self.detail_phone = operatorObj.detail_phone
        '''
        #=============不需要返回start==========
        # 4. 跟业务模型数据交叉合并
        # 亲属联系人与是否逾期(需要与一亿元交互)  返回字段是{'com_r_overdue': 0, 'com_c_overdue': 0}
        relatives = {}
        if self.contact != '':
            relatives = json.loads(self.contact)
            relatives['phone'] = relatives.get("phone")
            relatives['mobile'] = relatives.get("mobile")
        self.contact_due_data = relatives_is_overdue(relatives)
        logger.info("bbbbb=%s" % self.contact_due_data)
        # self.dbContact = YiFavoriteContact().getByUserId(self.user_id)
        # relatives = {}
        # if self.dbContact is not None:
        #     relatives['phone'] = self.dbContact.phone
        #     relatives['mobile'] = self.dbContact.mobile
        #
        # self.contact_due_data = relatives_is_overdue(relatives)
        # =============不需要返回end==========
        '''

        relatives = {}
        if self.contact != '':
            relatives = json.loads(self.contact)
            relatives['phone'] = relatives.get("phone")
            relatives['mobile'] = relatives.get("mobile")
        pd_address = None
        if self.oAddress is not None:
            self.address_vscontact = self.oAddress.vsContact(relatives)
            self.address_vsuser = self.oAddress.vsUser(self.user_phone)
            pd_address = self.oAddress.pd_address
        self.loan, self.loan_total_all = LoanLogic(pd_address, self.user_phone,
                                                   self.contact,
                                                   self.contain).run()

        # 6.详单tag
        if self.detail_phone:
            try:
                calls = self.detail_phone['raw_data']['members'][
                    'transactions'][0]['calls']
                pd_detail = pd.DataFrame(calls)
                other_cell_phone = list(pd_detail['other_cell_phone'])
                self.detail_tag = number_label.getDetailTag(
                    self.user_phone, other_cell_phone)
            except Exception as e:
                logger.error("号码标签vs详单异常: %s" % (e))
        # 7.与detail联合匹配
        if self.oDetail is not None:
            self.__detailVs()

        return operator_data