data_extractor_test.py 2.43 KB
Newer Older
1
import unittest
2 3 4
from datetime import datetime, timedelta

import geopandas as gpd
5
import pandas as pd
6
from shapely.geometry import Point
7 8 9

from context import measprocess as mpc

10 11

class TestRTRDetailExtractor(unittest.TestCase):
12
    def setUp(self):
13 14 15
        self._open_test_uuids = [
            "Ob6c34648-54f3-435c-b5f9-5677c8694ad9",
            "Ocf041649-977f-4957-a27f-215069579c18",
16 17 18
        ]

    def test_basics(self):
19
        details = mpc.rtr.fetch.rtr_details(self._open_test_uuids)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
        self.assertTrue(type(details[0]) == dict)


class TestRTROverviewExtractor(unittest.TestCase):
    def setUp(self):
        self._max_time = datetime.fromtimestamp(1618987288)
        self._min_time = self._max_time - timedelta(days=1)

        self._coords = [(48.201914, 16.363859), (48.194170, 16.385466)]

        self._boundaries = gpd.GeoSeries(
            (Point(lon, lat) for lat, lon in self._coords)
        ).set_crs("EPSG:4326")

    def test_time(self):
35
        results = mpc.rtr.fetch.rtr_overview(
36
            time_min=self._min_time, time_max=self._max_time, max_results=5000, verbose=True
37
        )
38 39 40 41

        self.assertTrue(len(results) > 0)

    def test_cat_tech(self):
42
        results = mpc.rtr.fetch.rtr_overview(
43 44 45 46
            time_min=self._min_time,
            time_max=self._max_time,
            cat_technology="4G",
            max_results=5000,
47
        )
48 49 50 51

        self.assertTrue(len(results) > 0)

    def test_coords(self):
52
        results = mpc.rtr.fetch.rtr_overview(
53 54 55 56 57 58 59
            time_min=self._min_time,
            time_max=self._max_time,
            gps_boundaries=self._boundaries,
            max_results=5000,
        )

        self.assertTrue(len(results) > 0)
60 61 62

    def test_coords_error(self):
        coords = [(48.173759, 16.367682), (48.181447, 16.379107)]
63 64 65
        boundaries = gpd.GeoSeries((Point(lon, lat) for lat, lon in coords)).set_crs(
            "EPSG:4326"
        )
66 67 68

        min_time = self._max_time - timedelta(days=30)

69
        results = mpc.rtr.fetch.rtr_overview(
70 71 72
            gps_boundaries=boundaries,
            time_min=min_time,
            time_max=self._max_time,
73
            max_results=5000,
74 75 76 77 78
        )

        long_min, lat_min, long_max, lat_max = tuple(boundaries.total_bounds)

        self.assertTrue(
79 80 81 82
            (results["lat"].min() >= lat_min)
            and (results["long"].min() >= long_min)
            and (results["lat"].max() <= lat_max)
            and (results["long"].max() <= long_max)
83
        )