Example #1
0
 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
Example #2
0
 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
Example #3
0
    def runwsm(self, start_time=None, end_time=None):
        last_day = datetime.now() + timedelta(days=-1)
        if start_time is None:
            start_time = last_day.strftime('%Y-%m-%d 00:00:00')

        if end_time is None:
            end_time = last_day.strftime('%Y-%m-%d 23:59:59')
        #getmobiles
        users_info = YiUserRemitList().getMobiles(start_time, end_time)
        if users_info is None:
            logger.error("users_info:no data to dealwith")
            return False

        #获取开放平台聚信立信息
        for user in users_info:
            try:
                # 1. get detail_datas
                Jxl_datas = OpenJxlStat().getByPhone(user.mobile)
                if Jxl_datas is None:
                    logger.error("mobile:%s  can't get Jxl_datas" %
                                 (user.mobile))
                    continue

                url = Jxl_datas.get('detail_url')
                detail_datas = OpenJxlStat().getDetail(url)
                if detail_datas is None:
                    logger.error("json_url:%s  can't get detail_data" % (url))
                    continue

                # 2. get contacts_mobile and relatives_phone
                mobile_phone = YiFavoriteContact().getByUserId(user.user_id)
                if mobile_phone is None:
                    logger.error("user_id:%s  can't get mobile_phone" %
                                 (user.user_id))
                    continue
                dict_contact_phone = {
                    'mobile': mobile_phone.mobile,
                    'phone': mobile_phone.phone
                }

                # 3. analysis  detail_data
                analysis_datas = Detail(detail_datas).runWsm(
                    dict_contact_phone)
                n = 0
                for key, value in analysis_datas.items():
                    # 4. save analysis_data
                    add_res = AfWsm().addWsm(value, user)
            except Exception as e:
                logger.error("user.mobile:%s is fail: %s" % (user.mobile, e))
        return True
Example #4
0
 def __get_detail_phone(self, phone):
     '''
     详单相关
     '''
     json_data = None
     detail_phone = []
     if phone:
         record = OpenJxlStat().getByPhone(phone)
         if record:
             json_data = OpenJxlStat().getDetail(record.get('detail_url'))
     if json_data:
         try:
             oDetail = Detail(json_data)
             detail_phone = oDetail.getDistinctPhone()
         except Exception as e:
             logger.error("phone:%s jxl detail is fail: %s" % (phone, e))
     return detail_phone
Example #5
0
def analysis_detail(detail_url, contact):
    detail_data = {}
    detail_other_data = {}
    detail_vscontact = {}
    try:
        json_data = getReportByUrl(detail_url)
        if json_data:
            detail_phone = json_data
            oDetail = Detail(json_data)
            detail_data, detail_other_data = oDetail.run()
            if contact is not None:
                dict_contact = {}
                dict_contact['phone'] = contact.phone
                dict_contact['mobile'] = contact.mobile
            detail_vscontact = oDetail.vsContact(dict_contact)
    except Exception as e:
        logger.error("detail_url:%s detail is fail: %s" % (detail_url, e))
    return detail_data, detail_vscontact
Example #6
0
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
Example #7
0
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
Example #8
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