def test_tno_at_lon_lat(get_dataframe):
    """
    Regression test for #108. TNO should work at lon-lat level.
    """
    tno = TotalNetworkObjects(
        start="2016-01-01",
        stop="2016-01-07",
        network_object=make_spatial_unit("versioned-cell"),
        spatial_unit=make_spatial_unit("lon-lat"),
    )
    assert tno.get_dataframe().sum().value == 330
예제 #2
0
def test_bad_params(bad_arg, bad_val):
    """Test value errors are raised for bad params"""
    with pytest.raises(ValueError):
        TotalNetworkObjects(start="2016-01-01",
                            stop="2016-12-30",
                            table="calls",
                            **{bad_arg: bad_val})
def test_bad_total_by():
    """Test value errors are raised for bad 'total_by' param"""
    with pytest.raises(ValueError):
        TotalNetworkObjects(
            start="2016-01-01",
            stop="2016-12-30",
            table="calls",
            total_by="BAD_TOTAL_BY",
        )
def test_bad_statistic():
    """Test that invalid stat for aggregate raises value error."""
    with pytest.raises(ValueError):
        AggregateNetworkObjects(
            total_network_objects=TotalNetworkObjects(start="2016-01-01",
                                                      stop="2016-12-30",
                                                      table="calls"),
            statistic="count",
        )
def test_bad_aggregate_by():
    """Test that invalid 'aggregate_by' param raises value error."""
    with pytest.raises(ValueError):
        AggregateNetworkObjects(
            total_network_objects=TotalNetworkObjects(start="2016-01-01",
                                                      stop="2016-12-30",
                                                      table="calls"),
            aggregate_by="BAD_AGGREGATE_BY",
        )
def test_bad_spatial_units(bad_arg, spatial_unit_type):
    """
    Test InvalidSpatialUnitErrors are raised for bad 'network_object' or
    'spatial_unit' params.
    """
    su = make_spatial_unit(spatial_unit_type)
    with pytest.raises(InvalidSpatialUnitError):
        TotalNetworkObjects(start="2016-01-01",
                            stop="2016-12-30",
                            table="calls",
                            **{bad_arg: su})
예제 #7
0
    def _flowmachine_query_obj(self):
        """
        Return the underlying flowmachine daily_location object.

        Returns
        -------
        Query
        """
        return TotalNetworkObjects(
            start=self.start_date,
            stop=self.end_date,
            spatial_unit=get_spatial_unit_obj(self.aggregation_unit),
            total_by=self.total_by,
        )
예제 #8
0
    def _flowmachine_query_obj(self):
        """
        Return the underlying flowmachine daily_location object.

        Returns
        -------
        Query
        """
        return TotalNetworkObjects(
            start=self.start_date,
            stop=self.end_date,
            level=self.aggregation_unit,
            period=self.period,
        )
예제 #9
0
    def _flowmachine_query_obj(self):
        """
        Return the underlying flowmachine daily_location object.

        Returns
        -------
        Query
        """
        return TotalNetworkObjects(
            start=self.start_date,
            stop=self.end_date,
            spatial_unit=self.aggregation_unit,
            total_by=self.total_by,
            table=self.event_types,
            subscriber_subset=self.subscriber_subset,
        )
def test_count_returns_correct_values(get_dataframe):
    """
    TotalNetworkObjects returns correct values.

    """
    instance = TotalNetworkObjects(start="2016-01-01",
                                   stop="2016-12-30",
                                   table="calls",
                                   total_by="hour")
    df = get_dataframe(instance)

    #
    #  This will compare the very first
    #  value with an independently
    #  computed value.
    #
    assert df.value[34] == 31
예제 #11
0
def test_median_returns_correct_values(get_dataframe):
    """
    features.network.TotalNetworkObjects median aggregate returns correct values.

    """
    instance = AggregateNetworkObjects(
        total_network_objects=TotalNetworkObjects(
            table="calls", period="hour", network_object="versioned-site"),
        by="day",
        statistic="median",
    )

    #
    #  This will compare the very first
    #  value with an independently
    #  computed value.
    #
    assert get_dataframe(instance).head(1)["median"][0] == 25
def test_aggregate_returns_correct_values(stat, expected, get_dataframe):
    """
    AggregateNetworkObjects returns correct values.

    """
    instance = AggregateNetworkObjects(
        total_network_objects=TotalNetworkObjects(start="2016-01-01",
                                                  stop="2016-12-30",
                                                  table="calls",
                                                  total_by="hour"),
        statistic=stat,
    )
    df = get_dataframe(instance)

    #
    #  This will compare the very first
    #  value with an independently
    #  computed value.
    #
    assert pytest.approx(df.value[0]) == expected
def test_mean_returns_correct_values(get_dataframe):
    """
    features.network.TotalNetworkObjects aggregation returns correct values.

    """
    instance = AggregateNetworkObjects(
        total_network_objects=TotalNetworkObjects(
            start="2016-01-01",
            stop="2016-12-30",
            total_by="hour",
            network_object=make_spatial_unit("versioned-site"),
        ),
        aggregate_by="day",
    )

    #
    #  This will compare the very first
    #  value with an independently
    #  computed value.
    #
    assert get_dataframe(instance).head(1)["value"][0] == pytest.approx(
        28.7916666666)
def test_period_agg_default(total_by, aggregate_by_expected):
    """Correct aggregation period is deduced."""
    inst = AggregateNetworkObjects(total_network_objects=TotalNetworkObjects(
        start="2016-01-01", stop="2016-12-30", total_by=total_by))
    assert inst.aggregate_by == aggregate_by_expected