本文整理汇总了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
示例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)
示例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