async def test_mapping_table(connection, universal_access_token, flowapi_url): mapping_table = "infrastructure.mapping_table_test" query = flowclient.spatial_aggregate( connection=connection(url=flowapi_url, token=universal_access_token), locations=flowclient.daily_location_spec( date="2016-01-01", aggregation_unit="admin3", method="last", mapping_table=mapping_table, ), ) try: result = await query.get_result() except TypeError: result = query.get_result() assert set(result.pcod.tolist()) == {"524 2 05 24"}
async def test_point_mapping_table(connection, universal_access_token, flowapi_url): mapping_table = "geography.test_point_mapping" query = flowclient.spatial_aggregate( connection=connection(url=flowapi_url, token=universal_access_token), locations=flowclient.daily_location_spec( date="2016-01-01", aggregation_unit="lon-lat", method="last", mapping_table=mapping_table, geom_table="geography.test_cluster", geom_table_join_column="cluster_id", ), ) try: result = await query.get_result() except TypeError: result = query.get_result() assert set(result.lon.tolist()) == pytest.approx({26.669991}) assert set(result.lat.tolist()) == pytest.approx({87.85779897})
async def test_geo_result(connection, universal_access_token, flowapi_url): query = flowclient.joined_spatial_aggregate( connection=connection(url=flowapi_url, token=universal_access_token), **{ "locations": flowclient.daily_location_spec( date="2016-01-01", aggregation_unit="admin3", method="last" ), "metric": flowclient.handset_spec( start_date="2016-01-01", end_date="2016-01-02", characteristic="brand", method="last", ), "method": "distr", }, ) try: result = await query.get_result(format="geojson") except TypeError: result = query.get_result(format="geojson") assert geojson.GeoJSON(result).is_valid
import flowclient import pytest @pytest.mark.asyncio @pytest.mark.parametrize("connection", [flowclient.Connection, flowclient.ASyncConnection]) @pytest.mark.parametrize( "query", [ partial( flowclient.spatial_aggregate, locations=flowclient.daily_location_spec( date="2016-01-01", aggregation_unit="admin3", method="last", ), ), partial( flowclient.spatial_aggregate, locations=flowclient.daily_location_spec( date="2016-01-01", aggregation_unit="admin3", method="most-common", event_types=["calls", "sms"], subscriber_subset=None, ), ), partial( flowclient.unique_subscriber_counts,