Beispiel #1
0
def analysis_address(address_list):
    address_data = {}
    try:
        oAddress = Address(address_list)
        address_data = oAddress.run()
    except Exception as e:
        logger.error("analysis address is fail: %s" % (e))
    return address_data
Beispiel #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))
Beispiel #3
0
    def __get_address_phone(self, phone):
        '''
        通讯录相关
        '''
        address_phone = []
        userInfo = YiUser().getByMobile(phone)

        if userInfo:
            dbYiAddressList = YiAddressList().getByUserid(userInfo.user_id)
            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
class OperatorAnalysis(object):
    def __init__(self):
        self.detail_phone = None
        self.detail_url_log = None
        self.oDetail = None
        self.oAddress = None

    def __analysis_address(self, address_list):
        address_data = {}
        try:
            self.oAddress = Address(address_list)
            address_data = self.oAddress.run()
        except Exception as e:
            logger.error("analysis address is fail: %s" % (e))
        return address_data

    def __analysis_detail(self, detail_url):
        detail_data = {}
        detail_other_data = {}
        try:
            json_data = getReportByUrl(detail_url)
            if json_data:
                self.detail_phone = json_data
                self.oDetail = Detail(json_data)
                detail_data, detail_other_data = self.oDetail.run()
        except Exception as e:
            logger.error("detail_url:%s detail is fail: %s" % (detail_url, e))
        return detail_data, detail_other_data

    def getOperatorData(self, address_list, record):
        # 1 运营商数据
        source = 0
        detail_data = detail_other_data = None
        if record is not None:
            source = record.get('source')
            report_url = record.get('report_url')
            detail_url = record.get('detail_url')
            self.detail_url_log = detail_url
            report_data = analysis_report(source, report_url)
            detail_data, detail_other_data = self.__analysis_detail(detail_url)
        try:
            #通话详单标签追加
            self._addNumberLabel()
        except Exception as e:
            logger.info("number_label: 通话详单错误:%s" % e)

        # 2 报告数据,仅聚信立有效
        dict_data = {}
        dict_data['ss_report'] = {}
        dict_data['report'] = {}
        if source in [1, 2]:
            dict_data['report'] = report_data
        elif source == 4:
            dict_data['ss_report'] = report_data

        # 3 通讯录
        address_data = self.__analysis_address(address_list)
        address_analysis = DictMerge()
        address_analysis.set(address_data)
        dict_data['address'] = address_analysis.get()

        # 4  详情数据
        detail_analysis = DictMerge()
        detail_analysis.set(detail_data)
        dict_data['detail'] = detail_analysis.get()

        # 5 详情其它表字段
        detail_other_analysis = DictMerge()
        detail_other_analysis.set(detail_other_data)

        repInfo = {}
        if source in [1, 2] and report_data.get('report_use_time'):
            repInfo['phone_register_month'] = report_data.get(
                'report_use_time')
        elif source in [4, 5, 6] and report_data.get('phone_register_month'):
            repInfo['phone_register_month'] = report_data.get(
                'phone_register_month')

        detail_other_analysis.set(repInfo)
        dict_data['detail_other'] = detail_other_analysis.get()

        return dict_data

    '''
    通话详单标签追加
    '''

    def _addNumberLabel(self):
        if self.detail_phone == None:
            logger.info("number_label: 通话详单错误error_url:%s" %
                        self.detail_url_log)
            logger.error("number_label:没有通话详单")
            return False
        calls = self.detail_phone['raw_data']['members']['transactions'][0][
            'calls']
        pd_detail = pd.DataFrame(calls)
        number_label = NumberLabel()
        phone = list(set(pd_detail['cell_phone']))
        other_cell_phone = tuple(pd_detail['other_cell_phone'])
        detail_stat = number_label.detailApi(phone[0], other_cell_phone)
        if detail_stat == True:
            return True
        return False
class OperatorAnalysis(object):
    def __init__(self):
        self.oDetail = None
        self.oAddress = None

    def __analysis_address(self, address_list):
        address_data = {}
        try:
            self.oAddress = Address(address_list)
            address_data = self.oAddress.run()
        except Exception as e:
            logger.error("analysis address is fail: %s" % (e))
        return address_data

    def __analysis_detail(self, detail_url):
        detail_data = {}
        detail_other_data = {}
        try:
            json_data = getReportByUrl(detail_url)
            if json_data:
                self.oDetail = Detail(json_data)
                detail_data, detail_other_data = self.oDetail.run()
        except Exception as e:
            logger.error("detail_url:%s detail is fail: %s" % (detail_url, e))
        return detail_data, detail_other_data

    def getOperatorData(self, address_list, record):
        # 1 运营商数据
        source = 0
        detail_data = detail_other_data = None
        if record is not None:
            source = record.get('source')
            report_url = record.get('report_url')
            detail_url = record.get('detail_url')
            report_data = analysis_report(source, report_url)
            detail_data, detail_other_data = self.__analysis_detail(detail_url)

        # 2 报告数据,仅聚信立有效
        dict_data = {}
        dict_data['ss_report'] = {}
        dict_data['report'] = {}
        if source in [1, 2]:
            dict_data['report'] = report_data
        elif source == 4:
            dict_data['ss_report'] = report_data

        # 3 通讯录
        address_data = self.__analysis_address(address_list)
        address_analysis = DictMerge()
        address_analysis.set(address_data)
        dict_data['address'] = address_analysis.get()

        # 4  详情数据
        detail_analysis = DictMerge()
        detail_analysis.set(detail_data)
        dict_data['detail'] = detail_analysis.get()

        # 5 详情其它表字段
        detail_other_analysis = DictMerge()
        detail_other_analysis.set(detail_other_data)

        repInfo = {}
        if source in [1, 2] and report_data.get('report_use_time'):
            repInfo['phone_register_month'] = report_data.get(
                'report_use_time')
        elif source in [4, 5, 6] and report_data.get('phone_register_month'):
            repInfo['phone_register_month'] = report_data.get(
                'phone_register_month')

        detail_other_analysis.set(repInfo)
        dict_data['detail_other'] = detail_other_analysis.get()

        return dict_data
Beispiel #6
0
class MultimatchData(object):

    def __init__(self, multimatch):
        self.multimatch = multimatch
        self.aid = multimatch.aid
        self.user_id = multimatch.user_id
        self.loan_id = multimatch.loan_id
        self.request_id = multimatch.id
        self.detail_phone = []
        self.address_phone = []
        self.__init_obj()

    def __init_obj(self):
        # db类
        self.dbUser = None
        self.dbYiAddressList = None
        # analysis类
        self.oAddress = None
        self.oDetail = None

    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))

    def __detail(self, url):
        # 获取通话详单处理对象
        try:
            json_data = OpenJxlStat().getDetail(url)
            if json_data:    
                self.oDetail = Detail(json_data)
        except Exception as e:
            logger.error("user_id:%s jxl detail is fail: %s" % (self.user_id, e))
            self.oDetail = None

    def runMatch(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, "没有纪录")

        # 2. 获取通讯录对象
        self.__address(self.dbUser.mobile)
        self.address_phone = self.oAddress.getDistinctPhone() if self.oAddress else []
        # 3. 获取通话详单对象
        record = OpenJxlStat().getByPhone(self.dbUser.mobile)
        if record :
            self.__detail(record.get('detail_url'))
        self.detail_phone = self.oDetail.getDistinctPhone() if self.oDetail else [] 
        # 4. 二级关系
        oMultiMatch = MultiMatch(self.dbUser.mobile,self.detail_phone,self.address_phone)
        multi_match_res = oMultiMatch.run()
        dict_data = {}
        dict_data['multi_match'] = multi_match_res
        dict_data = self.__mergeData(self.aid, self.user_id, self.request_id, self.loan_id, dict_data)
        return dict_data
    

    def __mergeData(self, aid, user_id, request_id, loan_id, dict_data):

        def mergeUser(dict_data):
            ''' 合并 user_id '''
            if dict_data is None:
                return {}
            if len(dict_data) == 0:
                return {}
            dict_data['aid'] = aid
            dict_data['user_id'] = user_id
            dict_data['request_id'] = request_id
            dict_data['loan_id'] = loan_id
            dict_data['create_time'] = datetime.now()
            return dict_data

        for k in dict_data:
            dict_data[k] = mergeUser(dict_data[k])

        return dict_data