Ejemplo n.º 1
0
 def test_ok_cell_radio_in_celltowers_dupes(self):
     # This test covered a bug related to FxOS calling the
     # geolocate API incorrectly.
     app = self.app
     session = self.db_slave_session
     cell = Cell()
     cell.lat = PARIS_LAT
     cell.lon = PARIS_LON
     cell.radio = 0
     cell.mcc = FRANCE_MCC
     cell.mnc = 1
     cell.lac = 2
     cell.cid = 1234
     cell.range = 1000
     session.add(cell)
     session.commit()
     res = app.post_json(
         '%s?key=test' % self.url, {
             "cellTowers": [
                 {"radio": "gsm",
                  "mobileCountryCode": FRANCE_MCC,
                  "mobileNetworkCode": 1,
                  "locationAreaCode": 2,
                  "cellId": 1234},
                 {"radio": "gsm",
                  "mobileCountryCode": FRANCE_MCC,
                  "mobileNetworkCode": 1,
                  "locationAreaCode": 2,
                  "cellId": 1234},
             ]},
         status=200)
     self.assertEqual(res.content_type, 'application/json')
     self.assertEqual(res.json, {"location": {"lat": PARIS_LAT,
                                              "lng": PARIS_LON},
                                 "accuracy": CELL_MIN_ACCURACY})
Ejemplo n.º 2
0
def update_lac(self, radio, mcc, mnc, lac):

    with self.db_session() as session:

        # Select all the cells in this LAC that aren't the virtual
        # cell itself, and derive a bounding box for them.

        q = session.query(Cell).filter(Cell.radio == radio).filter(
            Cell.mcc == mcc).filter(Cell.mnc == mnc).filter(
                Cell.lac == lac).filter(Cell.cid != CELLID_LAC)

        cells = q.all()
        points = [(to_degrees(c.lat), to_degrees(c.lon)) for c in cells]
        min_lat = to_degrees(min([c.min_lat for c in cells]))
        min_lon = to_degrees(min([c.min_lon for c in cells]))
        max_lat = to_degrees(max([c.max_lat for c in cells]))
        max_lon = to_degrees(max([c.max_lon for c in cells]))

        bbox_points = [(min_lat, min_lon), (min_lat, max_lon),
                       (max_lat, min_lon), (max_lat, max_lon)]

        ctr = centroid(points)
        rng = range_to_points(ctr, bbox_points)

        # switch units back to DB preferred centimicrodegres angle
        # and meters distance.
        ctr_lat = from_degrees(ctr[0])
        ctr_lon = from_degrees(ctr[1])
        rng = int(round(rng * 1000.0))

        # Now create or update the LAC virtual cell

        q = session.query(Cell).filter(Cell.radio == radio).filter(
            Cell.mcc == mcc).filter(Cell.mnc == mnc).filter(
                Cell.lac == lac).filter(Cell.cid == CELLID_LAC)

        lac = q.first()

        if lac is None:
            lac = Cell(radio=radio,
                       mcc=mcc,
                       mnc=mnc,
                       lac=lac,
                       cid=CELLID_LAC,
                       lat=ctr_lat,
                       lon=ctr_lon,
                       range=rng)
        else:
            lac.new_measures = 0
            lac.lat = ctr_lat
            lac.lon = ctr_lon
            lac.range = rng

        session.commit()
Ejemplo n.º 3
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = PARIS_LAT
        cell.lon = PARIS_LON
        cell.radio = RADIO_TYPE['gsm']
        cell.mcc = FRANCE_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.range = 1000
        session.add(cell)
        session.commit()

        res = app.post_json(
            '%s?key=test' % self.url, {
                "radioType": "gsm",
                "cellTowers": [
                    {"mobileCountryCode": FRANCE_MCC,
                     "mobileNetworkCode": 1,
                     "locationAreaCode": 2,
                     "cellId": 1234},
                ]},
            status=200)

        self.check_stats(
            counter=[self.metric_url + '.200',
                     self.metric + '.api_key.test',
                     self.metric + '.api_log.test.cell_hit']
        )

        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": PARIS_LAT,
                                                 "lng": PARIS_LON},
                                    "accuracy": CELL_MIN_ACCURACY})
Ejemplo n.º 4
0
def update_lac(self, radio, mcc, mnc, lac):

    with self.db_session() as session:

        # Select all the cells in this LAC that aren't the virtual
        # cell itself, and derive a bounding box for them.

        q = session.query(Cell).filter(
            Cell.radio == radio).filter(
            Cell.mcc == mcc).filter(
            Cell.mnc == mnc).filter(
            Cell.lac == lac).filter(
            Cell.cid != CELLID_LAC).filter(
            Cell.new_measures == 0).filter(
            Cell.lat.isnot(None)).filter(
            Cell.lon.isnot(None))

        cells = q.all()
        if len(cells) == 0:
            return

        points = [(to_degrees(c.lat),
                   to_degrees(c.lon)) for c in cells]
        min_lat = to_degrees(min([c.min_lat for c in cells]))
        min_lon = to_degrees(min([c.min_lon for c in cells]))
        max_lat = to_degrees(max([c.max_lat for c in cells]))
        max_lon = to_degrees(max([c.max_lon for c in cells]))

        bbox_points = [(min_lat, min_lon),
                       (min_lat, max_lon),
                       (max_lat, min_lon),
                       (max_lat, max_lon)]

        ctr = centroid(points)
        rng = range_to_points(ctr, bbox_points)

        # switch units back to DB preferred centimicrodegres angle
        # and meters distance.
        ctr_lat = from_degrees(ctr[0])
        ctr_lon = from_degrees(ctr[1])
        rng = int(round(rng * 1000.0))

        # Now create or update the LAC virtual cell

        q = session.query(Cell).filter(
            Cell.radio == radio).filter(
            Cell.mcc == mcc).filter(
            Cell.mnc == mnc).filter(
            Cell.lac == lac).filter(
            Cell.cid == CELLID_LAC)

        lac = q.first()

        if lac is None:
            lac = Cell(radio=radio,
                       mcc=mcc,
                       mnc=mnc,
                       lac=lac,
                       cid=CELLID_LAC,
                       lat=ctr_lat,
                       lon=ctr_lon,
                       range=rng)
        else:
            lac.new_measures = 0
            lac.lat = ctr_lat
            lac.lon = ctr_lon
            lac.range = rng

        session.commit()
Ejemplo n.º 5
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_master_session
        cell = Cell()
        cell.lat = GB_LAT
        cell.lon = GB_LON
        cell.radio = RADIO_TYPE['cdma']
        cell.mcc = GB_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.range = 10000
        cell.total_measures = 1
        cell.new_measures = 0

        session.add(cell)
        session.commit()

        res = app.post_json('/v1/geosubmit?key=test', {
            "items": [
                {
                    "latitude":
                    GB_LAT + 0.1,
                    "longitude":
                    GB_LON + 0.1,
                    "accuracy":
                    12.4,
                    "radioType":
                    "cdma",
                    "cellTowers": [{
                        "cellId": 1234,
                        "locationAreaCode": 2,
                        "mobileCountryCode": GB_MCC,
                        "mobileNetworkCode": 1,
                    }]
                },
                {
                    "latitude":
                    GB_LAT - 0.1,
                    "longitude":
                    GB_LON - 0.1,
                    "accuracy":
                    22.4,
                    "cellTowers": [{
                        "radioType": "wcdma",
                        "cellId": 2234,
                        "locationAreaCode": 22,
                        "mobileCountryCode": GB_MCC,
                        "mobileNetworkCode": 2,
                    }]
                },
            ]
        },
                            status=200)

        # check that we get an empty response
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {})

        self.assertEqual(session.query(Cell).count(), 2)

        observations = session.query(CellObservation).all()
        self.assertEqual(len(observations), 2)
        radios = set([obs.radio for obs in observations])
        self.assertEqual(radios, set([RADIO_TYPE['cdma'], RADIO_TYPE['umts']]))

        self.check_stats(counter=[
            'geosubmit.api_key.test',
            'items.api_log.test.uploaded.batches',
            'items.api_log.test.uploaded.reports',
            'items.api_log.test.uploaded.cell_observations',
            'items.uploaded.cell_observations',
            'items.uploaded.batches',
            'items.uploaded.reports',
            'request.v1.geosubmit.200',
        ],
                         timer=[
                             'items.api_log.test.uploaded.batch_size',
                             'items.uploaded.batch_size',
                             'request.v1.geosubmit'
                         ])
Ejemplo n.º 6
0
def update_lac(self, radio, mcc, mnc, lac):
    try:
        utcnow = util.utcnow()
        with self.db_session() as session:
            # Select all the cells in this LAC that aren't the virtual
            # cell itself, and derive a bounding box for them.

            cell_query = session.query(Cell).filter(
                Cell.radio == radio).filter(
                Cell.mcc == mcc).filter(
                Cell.mnc == mnc).filter(
                Cell.lac == lac).filter(
                Cell.cid != CELLID_LAC).filter(
                Cell.lat.isnot(None)).filter(
                Cell.lon.isnot(None))

            cells = cell_query.all()

            lac_query = session.query(Cell).filter(
                Cell.radio == radio).filter(
                Cell.mcc == mcc).filter(
                Cell.mnc == mnc).filter(
                Cell.lac == lac).filter(
                Cell.cid == CELLID_LAC)

            if len(cells) == 0:
                # If there are no more underlying cells, delete the lac entry
                lac_query.delete()
            else:
                # Otherwise update the lac entry based on all the cells
                lac_obj = lac_query.first()

                points = [(c.lat, c.lon) for c in cells]
                min_lat = min([c.min_lat for c in cells])
                min_lon = min([c.min_lon for c in cells])
                max_lat = max([c.max_lat for c in cells])
                max_lon = max([c.max_lon for c in cells])

                bbox_points = [(min_lat, min_lon),
                               (min_lat, max_lon),
                               (max_lat, min_lon),
                               (max_lat, max_lon)]

                ctr = centroid(points)
                rng = range_to_points(ctr, bbox_points)

                # Switch units back to DB preferred centimicrodegres angle
                # and meters distance.
                ctr_lat = ctr[0]
                ctr_lon = ctr[1]
                rng = int(round(rng * 1000.0))

                # Now create or update the LAC virtual cell
                if lac_obj is None:
                    lac_obj = Cell(radio=radio,
                                   mcc=mcc,
                                   mnc=mnc,
                                   lac=lac,
                                   cid=CELLID_LAC,
                                   lat=ctr_lat,
                                   lon=ctr_lon,
                                   created=utcnow,
                                   modified=utcnow,
                                   range=rng,
                                   total_measures=len(cells))
                    session.add(lac_obj)
                else:
                    lac_obj.total_measures = len(cells)
                    lac_obj.lat = ctr_lat
                    lac_obj.lon = ctr_lon
                    lac_obj.modified = utcnow
                    lac_obj.range = rng

            session.commit()
    except Exception as exc:  # pragma: no cover
        self.heka_client.raven('error')
        raise self.retry(exc=exc)
Ejemplo n.º 7
0
def update_lac(self, radio, mcc, mnc, lac):
    try:
        utcnow = util.utcnow()
        with self.db_session() as session:
            # Select all the cells in this LAC that aren't the virtual
            # cell itself, and derive a bounding box for them.

            cell_query = session.query(Cell).filter(
                Cell.radio == radio).filter(Cell.mcc == mcc).filter(
                    Cell.mnc == mnc).filter(
                        Cell.lac == lac).filter(Cell.cid != CELLID_LAC).filter(
                            Cell.lat.isnot(None)).filter(Cell.lon.isnot(None))

            cells = cell_query.all()

            lac_query = session.query(Cell).filter(Cell.radio == radio).filter(
                Cell.mcc == mcc).filter(Cell.mnc == mnc).filter(
                    Cell.lac == lac).filter(Cell.cid == CELLID_LAC)

            if len(cells) == 0:
                # If there are no more underlying cells, delete the lac entry
                lac_query.delete()
            else:
                # Otherwise update the lac entry based on all the cells
                lac_obj = lac_query.first()

                points = [(c.lat, c.lon) for c in cells]
                min_lat = min([c.min_lat for c in cells])
                min_lon = min([c.min_lon for c in cells])
                max_lat = max([c.max_lat for c in cells])
                max_lon = max([c.max_lon for c in cells])

                bbox_points = [(min_lat, min_lon), (min_lat, max_lon),
                               (max_lat, min_lon), (max_lat, max_lon)]

                ctr = centroid(points)
                rng = range_to_points(ctr, bbox_points)

                # Switch units back to DB preferred centimicrodegres angle
                # and meters distance.
                ctr_lat = ctr[0]
                ctr_lon = ctr[1]
                rng = int(round(rng * 1000.0))

                # Now create or update the LAC virtual cell
                if lac_obj is None:
                    lac_obj = Cell(radio=radio,
                                   mcc=mcc,
                                   mnc=mnc,
                                   lac=lac,
                                   cid=CELLID_LAC,
                                   lat=ctr_lat,
                                   lon=ctr_lon,
                                   created=utcnow,
                                   modified=utcnow,
                                   range=rng,
                                   total_measures=len(cells))
                    session.add(lac_obj)
                else:
                    lac_obj.total_measures = len(cells)
                    lac_obj.lat = ctr_lat
                    lac_obj.lon = ctr_lon
                    lac_obj.modified = utcnow
                    lac_obj.range = rng

            session.commit()
    except Exception as exc:  # pragma: no cover
        self.heka_client.raven('error')
        raise self.retry(exc=exc)