本文整理匯總了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,
)