def test_cid_65535_without_a_valid_lac_sets_cid_to_invalid(self): schema = ValidCellKeySchema() obs, cell = self.get_sample(lac=schema.fields['lac'].missing, cid=65535, psc=1) self.check_normalized_cell(obs, cell, {'cid': schema.fields['cid'].missing})
def test_invalid_cid_with_a_valid_psc(self): schema = ValidCellKeySchema() for cid in self.invalid_cids: for psc in self.valid_pscs: obs, cell = self.get_sample(cid=cid, psc=psc) self.check_normalized_cell( obs, cell, dict(cid=schema.fields['cid'].missing, psc=psc))
def test_invalid_lac_with_a_valid_psc(self): schema = ValidCellKeySchema() for lac in self.invalid_lacs: for psc in self.valid_pscs: obs, cell = self.get_sample(lac=lac, psc=psc) self.check_normalized_cell( obs, cell, dict(lac=schema.fields['lac'].missing, psc=psc))
def incomplete_observation(self, key): # We want to store certain incomplete observations in the database # even though they should not lead to the creation of a station # entry; these are cell observations with a missing value for # LAC and/or CID, and will be inferred from neighboring cells. schema = ValidCellKeySchema() for field in ('lac', 'cid'): if getattr(key, field, None) == schema.fields[field].missing: return True return False
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)
def test_insert_observations_invalid_lac(self): session = self.session schema = ValidCellKeySchema() time = util.utcnow() - timedelta(days=1) today = util.utcnow().date() session.add( Cell(radio=Radio.gsm, mcc=FRANCE_MCC, mnc=2, lac=3, cid=4, new_measures=2, total_measures=5)) session.add(Score(key=ScoreKey.new_cell, userid=1, time=today, value=7)) session.flush() obs = dict(created=time, lat=PARIS_LAT, lon=PARIS_LON, time=time, accuracy=0, altitude=0, altitude_accuracy=0, radio=int(Radio.gsm)) entries = [ { "mcc": FRANCE_MCC, "mnc": 2, "lac": constants.MAX_LAC_ALL + 1, "cid": constants.MAX_CID_ALL + 1, "psc": 5, "asu": 8 }, { "mcc": FRANCE_MCC, "mnc": 2, "lac": schema.fields['lac'].missing, "cid": schema.fields['cid'].missing, "psc": 5, "asu": 8 }, ] for e in entries: e.update(obs) result = insert_measures_cell.delay(entries, userid=1) self.assertEqual(result.get(), 2) observations = session.query(CellObservation).all() self.assertEqual(len(observations), 2) self.assertEqual(set([o.lac for o in observations]), set([schema.fields['lac'].missing])) self.assertEqual(set([o.cid for o in observations]), set([schema.fields['cid'].missing])) # Nothing should change in the initially created Cell record cells = session.query(Cell).all() self.assertEqual(len(cells), 1) self.assertEqual(set([c.new_measures for c in cells]), set([2])) self.assertEqual(set([c.total_measures for c in cells]), set([5]))