コード例 #1
0
ファイル: ocid.py プロジェクト: therewillbecode/ichnaea
    def make_import_dict(self, row):
        def row_value(row, key, default, _type):
            if key in row and row[key] not in (None, ""):
                return _type(row[key])
            return default

        data = {}
        data["created"] = datetime.fromtimestamp(row_value(row, "created", 0, int))

        data["modified"] = datetime.fromtimestamp(row_value(row, "updated", 0, int))

        data["lat"] = row_value(row, "lat", None, float)
        data["lon"] = row_value(row, "lon", None, float)

        try:
            radio = row["radio"].lower()
            if radio == "umts":
                radio = "wcdma"
            data["radio"] = Radio[radio]
        except KeyError:  # pragma: no cover
            return None

        if data["radio"] == Radio.cdma:  # pragma: no cover
            # ignore CDMA networks
            return None

        for field in ("mcc", "mnc", "lac", "cid", "psc"):
            data[field] = row_value(row, field, None, int)

        data["range"] = int(row_value(row, "range", 0, float))
        data["total_measures"] = row_value(row, "samples", 0, int)
        if self.cell_type == "ocid":
            data["changeable"] = row_value(row, "changeable", True, bool)
        elif self.cell_type == "cell":  # pragma: no cover
            data["max_lat"] = geocalc.latitude_add(data["lat"], data["lon"], data["range"])
            data["min_lat"] = geocalc.latitude_add(data["lat"], data["lon"], -data["range"])
            data["max_lon"] = geocalc.longitude_add(data["lat"], data["lon"], data["range"])
            data["min_lon"] = geocalc.longitude_add(data["lat"], data["lon"], -data["range"])

        validated = self.cell_model.validate(data)
        if validated is None:
            return None
        for field in ("radio", "mcc", "mnc", "lac", "cid"):
            if validated[field] is None:
                return None
        return validated
コード例 #2
0
 def test_adds_meters_to_longitude(self):
     self.assertAlmostEqual(longitude_add(1.0, 1.0, 1000),
                            1.0166573581, 9)
コード例 #3
0
 def test_returns_max_lon(self):
     self.assertEqual(longitude_add(1.0, 1.0, 10 ** 10),
                      constants.MAX_LON)
コード例 #4
0
 def test_returns_min_lon(self):
     self.assertEqual(longitude_add(1.0, 1.0, -(10 ** 10)),
                      constants.MIN_LON)
コード例 #5
0
 def test_adds_meters_to_longitude(self):
     self.assertAlmostEqual(longitude_add(1.0, 1.0, 1000), 1.0166573581, 9)
コード例 #6
0
 def test_returns_max_lon(self):
     self.assertEqual(longitude_add(1.0, 1.0, 10**10), constants.MAX_LON)
コード例 #7
0
 def test_returns_min_lon(self):
     self.assertEqual(longitude_add(1.0, 1.0, -(10**10)), constants.MIN_LON)
コード例 #8
0
ファイル: cell.py プロジェクト: therewillbecode/ichnaea
 def max_lon(self):
     return geocalc.longitude_add(self.lat, self.lon, self.range)
コード例 #9
0
 def test_adds_meters_to_longitude(self):
     assert round(longitude_add(1.0, 1.0, 1000), 7) == 1.0089845
コード例 #10
0
 def test_returns_max_lon(self):
     assert longitude_add(0.0, 179.0, 1000000) == constants.MAX_LON
コード例 #11
0
 def test_returns_min_lon(self):
     assert longitude_add(0.0, -179.0, -1000000) == constants.MIN_LON