Beispiel #1
0
    def test_backfill_cell_location_update(self):
        from ichnaea.tasks import backfill_cell_location_update
        session = self.db_master_session
        k1 = dict(radio=1, mcc=1, mnc=2, lac=3, cid=4)
        data = [
            Cell(lat=10010000,
                 lon=10010000,
                 new_measures=0,
                 total_measures=1,
                 **k1),
            CellMeasure(lat=10000000, lon=10000000, **k1),
            CellMeasure(lat=10050000, lon=10080000, **k1),
        ]
        session.add_all(data)
        session.commit()

        query = session.query(CellMeasure.id)
        cm_ids = [x[0] for x in query.all()]

        # TODO: refactor this to be constants in the method
        new_measures = [((1, 1, 2, 3, 4), cm_ids)]

        result = backfill_cell_location_update.delay(new_measures)
        self.assertEqual(result.get(), (1, 0))

        cells = session.query(Cell).filter(Cell.cid != CELLID_LAC).all()
        self.assertEqual(len(cells), 1)
        cell = cells[0]
        self.assertEqual(cell.lat, 10020000)
        self.assertEqual(cell.lon, 10030000)
        self.assertEqual(cell.new_measures, 0)
        self.assertEqual(cell.total_measures, 3)
Beispiel #2
0
    def test_backfill_cell_location_update(self):
        from ichnaea.tasks import backfill_cell_location_update

        session = self.db_master_session
        k1 = dict(radio=1, mcc=1, mnc=2, lac=3, cid=4)
        data = [
            Cell(lat=10010000, lon=10010000, new_measures=0, total_measures=1, **k1),
            CellMeasure(lat=10000000, lon=10000000, **k1),
            CellMeasure(lat=10050000, lon=10080000, **k1),
        ]
        session.add_all(data)
        session.commit()

        query = session.query(CellMeasure.id)
        cm_ids = [x[0] for x in query.all()]

        # TODO: refactor this to be constants in the method
        new_measures = [((1, 1, 2, 3, 4), cm_ids)]

        result = backfill_cell_location_update.delay(new_measures)
        self.assertEqual(result.get(), (1, 0))

        cells = session.query(Cell).all()
        self.assertEqual(len(cells), 1)
        cell = cells[0]
        self.assertEqual(cell.lat, 10020000)
        self.assertEqual(cell.lon, 10030000)
        self.assertEqual(cell.new_measures, 0)
        self.assertEqual(cell.total_measures, 3)
Beispiel #3
0
def update_tower(self, radio, mcc, mnc, psc):
    rows_updated = 0
    with self.db_session() as session:
        centroids = compute_matching_towers(session, radio, mcc, mnc, psc)

        if centroids == []:
            return

        tower_proxy = compute_missing_towers(session, radio, mcc, mnc, psc)

        new_cell_measures = defaultdict(set)
        for missing_tower in tower_proxy:
            matching_tower = _nearest_tower(missing_tower['lat'],
                                            missing_tower['lon'],
                                            centroids)
            if matching_tower:
                lac = matching_tower['pt']['lac']
                cid = matching_tower['pt']['cid']
                tower_tuple = (radio, mcc, mnc, lac, cid)

                stmt = text("""
                update
                    cell_measure
                set
                    lac = :lac,
                    cid = :cid
                where
                  id = :id
                """).bindparams(lac=lac, cid=cid, id=missing_tower['id'])

                new_cell_measures[tower_tuple].add(missing_tower['id'])

                result_proxy = session.execute(stmt)
                rows_updated += result_proxy.rowcount
        session.commit()

        # convert new_cell_measures to a JSON friendly representation
        task_arguments = []
        for k, v in new_cell_measures.items():
            task_arguments.append((k, list(v)))

        # Update the cell tower locations with the newly backfilled
        # measurements now
        backfill_cell_location_update.delay(task_arguments)

    return rows_updated
Beispiel #4
0
def update_tower(self, radio, mcc, mnc, psc):
    rows_updated = 0
    with self.db_session() as session:
        centroids = compute_matching_towers(session, radio, mcc, mnc, psc)

        if centroids == []:
            return

        tower_proxy = compute_missing_towers(session, radio, mcc, mnc, psc)

        new_cell_measures = defaultdict(set)
        for missing_tower in tower_proxy:
            matching_tower = _nearest_tower(missing_tower['lat'],
                                            missing_tower['lon'],
                                            centroids)
            if matching_tower:
                lac = matching_tower['pt']['lac']
                cid = matching_tower['pt']['cid']
                tower_tuple = (radio, mcc, mnc, lac, cid)

                stmt = text("""
                update
                    cell_measure
                set
                    lac = :lac,
                    cid = :cid
                where
                  id = :id
                """).bindparams(lac=lac, cid=cid, id=missing_tower['id'])

                new_cell_measures[tower_tuple].add(missing_tower['id'])

                result_proxy = session.execute(stmt)
                rows_updated += result_proxy.rowcount
        session.commit()

        # convert new_cell_measures to a JSON friendly representation
        task_arguments = []
        for k, v in new_cell_measures.items():
            task_arguments.append((k, list(v)))

        # Update the cell tower locations with the newly backfilled
        # measurements now
        backfill_cell_location_update.delay(task_arguments)

    return rows_updated