当前位置: 首页>>代码示例>>Python>>正文


Python GEOCODER.regions_for_mcc方法代码示例

本文整理汇总了Python中ichnaea.geocode.GEOCODER.regions_for_mcc方法的典型用法代码示例。如果您正苦于以下问题:Python GEOCODER.regions_for_mcc方法的具体用法?Python GEOCODER.regions_for_mcc怎么用?Python GEOCODER.regions_for_mcc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ichnaea.geocode.GEOCODER的用法示例。


在下文中一共展示了GEOCODER.regions_for_mcc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ambiguous_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
 def test_ambiguous_mcc(self):
     regions = GEOCODER.regions_for_mcc(234, metadata=True)
     cell = CellFactory.build(mcc=234)
     query = self.model_query(cells=[cell])
     results = self.source.search(query)
     self.check_model_result(results, regions)
     self.check_stats(counter=[
         (self.api_type + '.source',
             ['key:test', 'region:none', 'source:internal',
              'accuracy:low', 'status:hit']),
     ])
开发者ID:voolitels,项目名称:ichnaea,代码行数:13,代码来源:test_internal.py

示例2: test_no_match

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
 def test_no_match(self):
     self.assertEqual(GEOCODER.regions_for_mcc(None), [])
     self.assertEqual(GEOCODER.regions_for_mcc(None, metadata=True), [])
     self.assertEqual(GEOCODER.regions_for_mcc(1), [])
     self.assertEqual(GEOCODER.regions_for_mcc(1, metadata=True), [])
     self.assertEqual(GEOCODER.regions_for_mcc(''), [])
     self.assertEqual(GEOCODER.regions_for_mcc('1', metadata=True), [])
开发者ID:amolk4games,项目名称:ichnaea,代码行数:9,代码来源:test_geocode.py

示例3: test_no_match

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
 def test_no_match(self):
     assert GEOCODER.regions_for_mcc(None) == []
     assert GEOCODER.regions_for_mcc(None, metadata=True) == []
     assert GEOCODER.regions_for_mcc(1) == []
     assert GEOCODER.regions_for_mcc(1, metadata=True) == []
     assert GEOCODER.regions_for_mcc('') == []
     assert GEOCODER.regions_for_mcc('1', metadata=True) == []
开发者ID:amjadm61,项目名称:ichnaea,代码行数:9,代码来源:test_geocode.py

示例4: test_multiple_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_multiple_mcc(self):
        now = util.utcnow()
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        cell = CellAreaFactory(mcc=234, num_cells=6)
        cell2 = CellAreaFactory(mcc=235, num_cells=8)
        self.session.flush()

        query = self.model_query(cells=[cell, cell2])
        results = self.source.search(query)
        self.assertTrue(len(results) > 2)
        best_result = results.best(query.expected_accuracy)
        self.assertEqual(best_result.region_code, region.code)
        self.assertAlmostEqual(best_result.score, 1.25 + cell.score(now), 4)
开发者ID:tomas-cliqz,项目名称:ichnaea,代码行数:15,代码来源:test_internal.py

示例5: test_from_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_from_mcc(self):
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        cell = CellAreaFactory(mcc=235, num_cells=10)
        self.session.flush()

        query = self.model_query(cells=[cell])
        results = self.source.search(query)
        self.check_model_results(results, [region])
        self.assertAlmostEqual(results[0].score, 1.0, 4)
        self.check_stats(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
开发者ID:tomas-cliqz,项目名称:ichnaea,代码行数:16,代码来源:test_internal.py

示例6: test_multiple_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_multiple_mcc(self, geoip_db, http_session,
                          session, source, stats):
        now = util.utcnow()
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        area = CellAreaFactory(mcc=234, num_cells=6)
        area2 = CellAreaFactory(mcc=235, num_cells=8)
        session.flush()

        query = self.model_query(
            geoip_db, http_session, session, stats,
            cells=[area, area2])
        results = source.search(query)
        assert len(results) > 2
        best_result = results.best()
        assert best_result.region_code == region.code
        assert best_result.score == 1.25 + area_score(area, now)
开发者ID:crankycoder,项目名称:ichnaea,代码行数:18,代码来源:test_internal.py

示例7: test_from_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_from_mcc(self, geoip_db, http_session,
                      session, source, stats):
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        area = CellAreaFactory(mcc=235, num_cells=10)
        session.flush()

        query = self.model_query(
            geoip_db, http_session, session, stats,
            cells=[area])
        results = source.search(query)
        self.check_model_results(results, [region])
        assert results[0].score == 1.0
        stats.check(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
开发者ID:crankycoder,项目名称:ichnaea,代码行数:19,代码来源:test_internal.py

示例8: search_cell

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def search_cell(self, query):
        results = self.result_list()
        now = util.utcnow()

        ambiguous_cells = []
        regions = []
        for cell in list(query.cell) + list(query.cell_area):
            code = cell.mobileCountryCode
            mcc_regions = GEOCODER.regions_for_mcc(code, metadata=True)
            # Divide score by number of possible regions for the mcc
            score = 1.0 / (len(mcc_regions) or 1.0)
            for mcc_region in mcc_regions:
                regions.append((mcc_region, score))
            if len(mcc_regions) > 1:
                ambiguous_cells.append(cell)

        # Group by region code
        grouped_regions = {}
        for region, score in regions:
            code = region.code
            if code not in grouped_regions:
                grouped_regions[code] = [region, score]
            else:
                # Sum up scores of multiple matches
                grouped_regions[code][1] += score

        if ambiguous_cells:
            # Only do a database query if the mcc is ambiguous.
            # Use the area models for area and cell entries,
            # as we are only interested in the region here,
            # which won't differ between individual cells inside and area.
            areas = query_areas(
                query, ambiguous_cells, self.area_model, self.raven_client)
            for area in areas:
                code = area.region
                if code and code in grouped_regions:
                    grouped_regions[code][1] += area_score(area, now)

        for region, score in grouped_regions.values():
            results.add(self.result_type(
                region_code=region.code,
                region_name=region.name,
                accuracy=region.radius,
                score=score))

        return results
开发者ID:crankycoder,项目名称:ichnaea,代码行数:48,代码来源:cell.py

示例9: search_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def search_mcc(self, query):
        results = ResultList()

        codes = set()
        for cell in list(query.cell) + list(query.cell_area):
            codes.add(cell.mcc)

        regions = []
        for code in codes:
            regions.extend(GEOCODER.regions_for_mcc(code, metadata=True))

        for region in regions:
            region_code = region.code
            results.add(self.result_type(
                region_code=region_code,
                region_name=region.name,
                accuracy=region.radius))
        return results
开发者ID:voolitels,项目名称:ichnaea,代码行数:20,代码来源:cell.py

示例10: test_blue

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_blue(self):
        now = util.utcnow()
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        blue1 = BlueShardFactory(samples=10)
        blue2 = BlueShardFactory(samples=20)
        blue3 = BlueShardFactory.build(region='DE', samples=100)
        self.session.flush()

        query = self.model_query(blues=[blue1, blue2, blue3])
        results = self.source.search(query)
        self.check_model_results(results, [region])
        best_result = results.best()
        self.assertEqual(best_result.region_code, region.code)
        self.assertAlmostEqual(
            best_result.score, blue1.score(now) + blue2.score(now), 4)
        self.check_stats(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
开发者ID:amolk4games,项目名称:ichnaea,代码行数:22,代码来源:test_internal.py

示例11: test_wifi

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_wifi(self):
        now = util.utcnow()
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        wifi1 = WifiShardFactory(samples=10)
        wifi2 = WifiShardFactory(samples=20)
        wifi3 = WifiShardFactory.build(region='DE', samples=100)
        self.session.flush()

        query = self.model_query(wifis=[wifi1, wifi2, wifi3])
        results = self.source.search(query)
        self.check_model_results(results, [region])
        best_result = results.best(query.expected_accuracy)
        self.assertEqual(best_result.region_code, region.code)
        self.assertAlmostEqual(
            best_result.score, wifi1.score(now) + wifi2.score(now), 4)
        self.check_stats(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
开发者ID:tomas-cliqz,项目名称:ichnaea,代码行数:22,代码来源:test_internal.py

示例12: test_ambiguous_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_ambiguous_mcc(self):
        now = util.utcnow()
        regions = GEOCODER.regions_for_mcc(234, metadata=True)
        cell = CellAreaFactory(mcc=234, num_cells=10)
        self.session.flush()

        query = self.model_query(cells=[cell])
        results = self.source.search(query)
        self.check_model_results(results, regions)
        self.assertEqual(results.best().region_code, 'GB')
        for result in results:
            score = 0.25
            if result.region_code == 'GB':
                score += cell.score(now)
            self.assertAlmostEqual(result.score, score, 4)
        self.check_stats(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
开发者ID:amolk4games,项目名称:ichnaea,代码行数:22,代码来源:test_internal.py

示例13: test_ambiguous_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_ambiguous_mcc(self, geoip_db, http_session,
                           session, source, stats):
        now = util.utcnow()
        regions = GEOCODER.regions_for_mcc(234, metadata=True)
        area = CellAreaFactory(mcc=234, num_cells=10)
        session.flush()

        query = self.model_query(
            geoip_db, http_session, session, stats,
            cells=[area])
        results = source.search(query)
        self.check_model_results(results, regions)
        assert results.best().region_code == 'GB'
        for result in results:
            score = 0.25
            if result.region_code == 'GB':
                score += area_score(area, now)
            assert result.score == score
        stats.check(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
开发者ID:crankycoder,项目名称:ichnaea,代码行数:25,代码来源:test_internal.py

示例14: test_blue

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
    def test_blue(self, geoip_db, http_session,
                  session, source, stats):
        now = util.utcnow()
        region = GEOCODER.regions_for_mcc(235, metadata=True)[0]
        blue1 = BlueShardFactory(samples=10)
        blue2 = BlueShardFactory(samples=20)
        blue3 = BlueShardFactory.build(region='DE', samples=100)
        session.flush()

        query = self.model_query(
            geoip_db, http_session, session, stats,
            blues=[blue1, blue2, blue3])
        results = source.search(query)
        self.check_model_results(results, [region])
        best_result = results.best()
        assert best_result.region_code == region.code
        assert (best_result.score ==
                station_score(blue1, now) + station_score(blue2, now))
        stats.check(counter=[
            (self.api_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:low', 'status:hit']),
        ])
开发者ID:crankycoder,项目名称:ichnaea,代码行数:25,代码来源:test_internal.py

示例15: test_all_valid_mcc

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import regions_for_mcc [as 别名]
 def test_all_valid_mcc(self):
     for mcc in ALL_VALID_MCCS:
         regions = set(GEOCODER.regions_for_mcc(mcc))
         self.assertNotEqual(regions, set())
         self.assertEqual(regions - GEOCODER._valid_regions, set())
开发者ID:amolk4games,项目名称:ichnaea,代码行数:7,代码来源:test_geocode.py


注:本文中的ichnaea.geocode.GEOCODER.regions_for_mcc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。