本文整理汇总了Python中ichnaea.tests.factories.CellFactory.hashkey方法的典型用法代码示例。如果您正苦于以下问题:Python CellFactory.hashkey方法的具体用法?Python CellFactory.hashkey怎么用?Python CellFactory.hashkey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ichnaea.tests.factories.CellFactory
的用法示例。
在下文中一共展示了CellFactory.hashkey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_location_update_cell
# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import hashkey [as 别名]
def test_location_update_cell(self):
now = util.utcnow()
before = now - timedelta(hours=1)
schema = ValidCellKeySchema()
obs_factory = CellObservationFactory
invalid_key = dict(lac=schema.fields['lac'].missing,
cid=schema.fields['cid'].missing)
cell1 = CellFactory(new_measures=3, total_measures=5)
lat1, lon1 = (cell1.lat, cell1.lon)
key1 = dict(lac=cell1.lac, cid=cell1.cid)
obs_factory(lat=lat1, lon=lon1, created=now, **key1)
obs_factory(lat=lat1 + 0.004, lon=lon1 + 0.006, created=now, **key1)
obs_factory(lat=lat1 + 0.006, lon=lon1 + 0.009, created=now, **key1)
# The lac, cid are invalid and should be skipped
obs_factory.create_batch(2, created=now, **invalid_key)
cell2 = CellFactory(lat=lat1 + 1.0, lon=lon1 + 1.0,
new_measures=2, total_measures=4)
lat2, lon2 = (cell2.lat, cell2.lon)
key2 = dict(lac=cell2.lac, cid=cell2.cid)
# the lat/lon is bogus and mismatches the line above on purpose
# to make sure old observations are skipped
obs_factory(lat=lat2 - 2.0, lon=lon2 - 2.0, created=before, **key2)
obs_factory(lat=lat2 - 2.0, lon=lon2 - 2.0, created=before, **key2)
obs_factory(lat=lat2 + 0.001, lon=lon2 + 0.002, created=now, **key2)
obs_factory(lat=lat2 + 0.003, lon=lon2 + 0.006, created=now, **key2)
cell3 = CellFactory(new_measures=10, total_measures=100000)
lat3, lon3 = (cell3.lat, cell3.lon)
obs_factory.create_batch(
10, lat=lat3 + 1.0, lon=lon3 + 1.0,
**dict(lac=cell3.lac, cid=cell3.cid))
self.session.commit()
result = location_update_cell.delay(min_new=1)
self.assertEqual(result.get(), (3, 0))
self.check_stats(
total=2,
timer=['task.data.location_update_cell'],
gauge=['task.data.location_update_cell.new_measures_1_100'],
)
cells = self.session.query(Cell).all()
self.assertEqual(len(cells), 3)
self.assertEqual(set([c.new_measures for c in cells]), set([0]))
for cell in cells:
if cell.hashkey() == cell1.hashkey():
self.assertEqual(cell.lat, lat1 + 0.002)
self.assertEqual(cell.lon, lon1 + 0.003)
if cell.hashkey() == cell2.hashkey():
self.assertEqual(cell.lat, lat2 + 0.001)
self.assertEqual(cell.lon, lon2 + 0.002)
if cell.hashkey() == cell3.hashkey():
expected_lat = ((lat3 * 1000) + (lat3 + 1.0) * 10) / 1010
expected_lon = ((lon3 * 1000) + (lon3 + 1.0) * 10) / 1010
self.assertAlmostEqual(cell.lat, expected_lat, 7)
self.assertAlmostEqual(cell.lon, expected_lon, 7)
示例2: test_update_cell
# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import hashkey [as 别名]
def test_update_cell(self):
now = util.utcnow()
invalid_key = dict(lac=None, cid=None)
observations = []
def obs_factory(**kw):
obs = CellObservationFactory.create(**kw)
observations.append(obs)
cell1 = CellFactory(new_measures=3, total_measures=3)
lat1, lon1 = (cell1.lat, cell1.lon)
key1 = dict(lac=cell1.lac, cid=cell1.cid)
obs_factory(lat=lat1, lon=lon1, created=now, **key1)
obs_factory(lat=lat1 + 0.004, lon=lon1 + 0.006, created=now, **key1)
obs_factory(lat=lat1 + 0.006, lon=lon1 + 0.009, created=now, **key1)
# The lac, cid are invalid and should be skipped
obs_factory(created=now, **invalid_key)
obs_factory(created=now, **invalid_key)
cell2 = CellFactory(lat=lat1 + 1.0, lon=lon1 + 1.0,
new_measures=2, total_measures=3)
lat2, lon2 = (cell2.lat, cell2.lon)
key2 = dict(lac=cell2.lac, cid=cell2.cid)
obs_factory(lat=lat2 + 0.001, lon=lon2 + 0.002, created=now, **key2)
obs_factory(lat=lat2 + 0.003, lon=lon2 + 0.006, created=now, **key2)
cell3 = CellFactory(new_measures=10, total_measures=100000)
lat3, lon3 = (cell3.lat, cell3.lon)
for i in range(10):
obs_factory(lat=lat3 + 1.0, lon=lon3 + 1.0,
**dict(lac=cell3.lac, cid=cell3.cid))
self.session.add_all(observations)
self.session.commit()
result = location_update_cell.delay()
self.assertEqual(result.get(), (3, 0))
self.check_stats(
timer=['task.data.location_update_cell'],
)
cells = self.session.query(Cell).all()
self.assertEqual(len(cells), 3)
self.assertEqual(set([c.new_measures for c in cells]), set([0]))
for cell in cells:
if cell.hashkey() == cell1.hashkey():
self.assertAlmostEqual(cell.lat, lat1 + 0.001667, 6)
self.assertAlmostEqual(cell.lon, lon1 + 0.0025, 6)
if cell.hashkey() == cell2.hashkey():
self.assertAlmostEqual(cell.lat, lat2 + 0.0008, 6)
self.assertAlmostEqual(cell.lon, lon2 + 0.0016, 6)
if cell.hashkey() == cell3.hashkey():
expected_lat = ((lat3 * 1000) + (lat3 + 1.0) * 10) / 1010
expected_lon = ((lon3 * 1000) + (lon3 + 1.0) * 10) / 1010
self.assertAlmostEqual(cell.lat, expected_lat, 7)
self.assertAlmostEqual(cell.lon, expected_lon, 7)
示例3: test_update_cell
# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import hashkey [as 别名]
def test_update_cell(self):
now = util.utcnow()
invalid_key = dict(lac=None, cid=None)
observations = []
def obs_factory(**kw):
obs = CellObservationFactory.build(**kw)
observations.append(obs)
cell1 = CellFactory(total_measures=3)
lat1, lon1 = (cell1.lat, cell1.lon)
key1 = dict(radio=cell1.radio, lac=cell1.lac, cid=cell1.cid)
obs_factory(lat=lat1, lon=lon1, created=now, **key1)
obs_factory(lat=lat1 + 0.004, lon=lon1 + 0.006, created=now, **key1)
obs_factory(lat=lat1 + 0.006, lon=lon1 + 0.009, created=now, **key1)
# The lac, cid are invalid and should be skipped
obs_factory(created=now, **invalid_key)
obs_factory(created=now, **invalid_key)
cell2 = CellFactory(lat=lat1 + 1.0, lon=lon1 + 1.0, total_measures=3)
lat2, lon2 = (cell2.lat, cell2.lon)
key2 = dict(radio=cell2.radio, lac=cell2.lac, cid=cell2.cid)
obs_factory(lat=lat2 + 0.001, lon=lon2 + 0.002, created=now, **key2)
obs_factory(lat=lat2 + 0.003, lon=lon2 + 0.006, created=now, **key2)
cell3 = CellFactory(total_measures=100000)
lat3, lon3 = (cell3.lat, cell3.lon)
key3 = dict(radio=cell3.radio, lac=cell3.lac, cid=cell3.cid)
for i in range(10):
obs_factory(lat=lat3 + 1.0, lon=lon3 + 1.0, **key3)
self.data_queue.enqueue(observations)
self.session.commit()
result = update_cell.delay()
self.assertEqual(result.get(), (3, 0))
cells = self.session.query(Cell).all()
self.assertEqual(len(cells), 3)
for cell in cells:
if cell.hashkey() == cell1.hashkey():
self.assertAlmostEqual(cell.lat, lat1 + 0.001667, 6)
self.assertAlmostEqual(cell.lon, lon1 + 0.0025, 6)
if cell.hashkey() == cell2.hashkey():
self.assertAlmostEqual(cell.lat, lat2 + 0.0008, 6)
self.assertAlmostEqual(cell.lon, lon2 + 0.0016, 6)
if cell.hashkey() == cell3.hashkey():
expected_lat = ((lat3 * 1000) + (lat3 + 1.0) * 10) / 1010
expected_lon = ((lon3 * 1000) + (lon3 + 1.0) * 10) / 1010
self.assertAlmostEqual(cell.lat, expected_lat, 7)
self.assertAlmostEqual(cell.lon, expected_lon, 7)
示例4: test_max_min_range_update
# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import hashkey [as 别名]
def test_max_min_range_update(self):
cell = CellFactory(range=150, total_measures=3)
cell_lat = cell.lat
cell_lon = cell.lon
cell.max_lat = cell.lat + 0.001
cell.min_lat = cell.lat - 0.001
cell.max_lon = cell.lon + 0.001
cell.min_lon = cell.lon - 0.001
k1 = cell.hashkey().__dict__
observations = [
CellObservation(lat=cell.lat, lon=cell.lon - 0.002, **k1),
CellObservation(lat=cell.lat + 0.004, lon=cell.lon - 0.006, **k1),
]
self.data_queue.enqueue(observations)
self.session.commit()
self.assertEqual(update_cell.delay().get(), (1, 0))
cells = self.session.query(Cell).all()
self.assertEqual(len(cells), 1)
cell = cells[0]
self.assertAlmostEqual(cell.lat, cell_lat + 0.0008)
self.assertAlmostEqual(cell.max_lat, cell_lat + 0.004)
self.assertAlmostEqual(cell.min_lat, cell_lat - 0.001)
self.assertAlmostEqual(cell.lon, cell_lon - 0.0016)
self.assertAlmostEqual(cell.max_lon, cell_lon + 0.001)
self.assertAlmostEqual(cell.min_lon, cell_lon - 0.006)
self.assertEqual(cell.range, 468)
self.assertEqual(cell.total_measures, 5)