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


Python GEOCODER.region_for_cell方法代码示例

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


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

示例1: region

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import region_for_cell [as 别名]
    def region(self, ctr_lat, ctr_lon, mcc, cells):
        region = None
        regions = [cell.region for cell in cells]
        unique_regions = set(regions)
        if len(unique_regions) == 1:
            region = regions[0]
        else:
            # Choose the area region based on the majority of cells
            # inside each region.
            grouped_regions = defaultdict(int)
            for reg in regions:
                grouped_regions[reg] += 1
            max_count = max(grouped_regions.values())
            max_regions = sorted([k for k, v in grouped_regions.items()
                                  if v == max_count])
            # If we get a tie here, randomly choose the first.
            region = max_regions[0]
            if len(max_regions) > 1:
                # Try to break the tie based on the center of the area,
                # but keep the randomly chosen region if this fails.
                area_region = GEOCODER.region_for_cell(
                    ctr_lat, ctr_lon, mcc)
                if area_region is not None:
                    region = area_region

        return region
开发者ID:cemoulto,项目名称:ichnaea,代码行数:28,代码来源:area.py

示例2: upgrade

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import region_for_cell [as 别名]
def upgrade():
    bind = op.get_bind()
    from ichnaea.geocode import GEOCODER

    log.info('Update cell_area regions.')
    stmt = '''\
UPDATE cell_area
SET `region` = "{code}"
WHERE `radio` IN (0, 1, 2, 3) AND `mcc` = {mcc} AND `region` IS NULL
'''
    length = len(MCC_TO_REGION)
    for i, (mcc, code) in enumerate(MCC_TO_REGION.items()):
        op.execute(sa.text(stmt.format(code=code, mcc=mcc)))
        if (i > 0 and i % 10 == 0):
            log.info('Updated %s of %s regions.', i, length)
    log.info('Updated %s of %s regions.', length, length)

    stmt = 'SELECT COUNT(*) FROM cell_area WHERE region IS NULL'
    todo = bind.execute(stmt).fetchone()[0]
    log.info('Updating remaining %s areas.', todo)

    stmt = '''\
SELECT HEX(`areaid`), `mcc`, `lat`, `lon`
FROM cell_area
WHERE `region` IS NULL
'''
    rows = bind.execute(stmt).fetchall()

    areas = {}
    i = 0
    for row in rows:
        if (i > 0 and i % 5000 == 0):
            log.info('Geocoded %s of %s areas.', i, todo)
        code = GEOCODER.region_for_cell(row.lat, row.lon, row.mcc)
        if code not in areas:
            areas[code] = []
        areas[code].append(row[0])
        i += 1
    log.info('Geocoded %s of %s areas.', todo, todo)

    stmt = '''\
UPDATE cell_area
SET `region` = "{code}"
WHERE `areaid` in ({ids})
'''
    for code, areaids in areas.items():
        if not code:
            continue
        ids = 'UNHEX("' + '"), UNHEX("'.join(areaids) + '")'
        op.execute(sa.text(stmt.format(code=code, ids=ids)))
        log.info('Updated %s region.', code)
开发者ID:cemoulto,项目名称:ichnaea,代码行数:53,代码来源:450f02b5e1ca_update_cell_area_region.py

示例3: validate

# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import region_for_cell [as 别名]
    def validate(cls, entry, _raise_invalid=False, **kw):
        validated = super(CellAreaMixin, cls).validate(
            entry, _raise_invalid=_raise_invalid, **kw)
        if validated is not None and 'areaid' not in validated:
            validated['areaid'] = (
                validated['radio'],
                validated['mcc'],
                validated['mnc'],
                validated['lac'],
            )

            if (('region' not in validated or not validated['region']) and
                    validated['lat'] is not None and
                    validated['lon'] is not None):
                validated['region'] = GEOCODER.region_for_cell(
                    validated['lat'], validated['lon'], validated['mcc'])

        return validated
开发者ID:cemoulto,项目名称:ichnaea,代码行数:20,代码来源:cell.py


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