本文整理汇总了Python中ichnaea.models.CellShard.shard_id方法的典型用法代码示例。如果您正苦于以下问题:Python CellShard.shard_id方法的具体用法?Python CellShard.shard_id怎么用?Python CellShard.shard_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ichnaea.models.CellShard
的用法示例。
在下文中一共展示了CellShard.shard_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _queue_and_update_cell
# 需要导入模块: from ichnaea.models import CellShard [as 别名]
# 或者: from ichnaea.models.CellShard import shard_id [as 别名]
def _queue_and_update_cell(self, obs):
sharded_obs = defaultdict(list)
for ob in obs:
sharded_obs[CellShard.shard_id(ob.cellid)].append(ob)
for shard_id, values in sharded_obs.items():
queue = self.celery_app.data_queues['update_cell_' + shard_id]
queue.enqueue([value.to_json() for value in values])
update_cell.delay(shard_id=shard_id).get()
示例2: process_reports
# 需要导入模块: from ichnaea.models import CellShard [as 别名]
# 或者: from ichnaea.models.CellShard import shard_id [as 别名]
def process_reports(self, reports, userid=None):
malformed_reports = 0
positions = set()
observations = {'cell': [], 'wifi': []}
obs_count = {
'cell': {'upload': 0, 'drop': 0},
'wifi': {'upload': 0, 'drop': 0},
}
new_station_count = {'cell': 0, 'wifi': 0}
for report in reports:
cell, wifi, malformed_obs = self.process_report(report)
if cell:
observations['cell'].extend(cell)
obs_count['cell']['upload'] += len(cell)
if wifi:
observations['wifi'].extend(wifi)
obs_count['wifi']['upload'] += len(wifi)
if (cell or wifi):
positions.add((report['lat'], report['lon']))
else:
malformed_reports += 1
for name in ('cell', 'wifi'):
obs_count[name]['drop'] += malformed_obs[name]
# group by unique station key
for name in ('cell', 'wifi'):
station_keys = set()
for obs in observations[name]:
if name == 'cell':
station_keys.add(obs.cellid)
elif name == 'wifi':
station_keys.add(obs.mac)
# determine scores for stations
new_station_count[name] += self.new_stations(name, station_keys)
if observations['cell']:
sharded_obs = defaultdict(list)
for ob in observations['cell']:
shard_id = CellShard.shard_id(ob.cellid)
sharded_obs[shard_id].append(ob)
for shard_id, values in sharded_obs.items():
cell_queue = self.data_queues['update_cell_' + shard_id]
cell_queue.enqueue(list(values), pipe=self.pipe)
if observations['wifi']:
sharded_obs = defaultdict(list)
for ob in observations['wifi']:
shard_id = WifiShard.shard_id(ob.mac)
sharded_obs[shard_id].append(ob)
for shard_id, values in sharded_obs.items():
wifi_queue = self.data_queues['update_wifi_' + shard_id]
wifi_queue.enqueue(list(values), pipe=self.pipe)
self.process_datamap(positions)
self.process_score(userid, positions, new_station_count)
self.emit_stats(
len(reports),
malformed_reports,
obs_count,
)