def _flowmachine_query_obj(self):
        """
        Return the underlying flowmachine object.

        Returns
        -------
        Query
        """
        locations = self.locations._flowmachine_query_obj
        metric = self.metric._flowmachine_query_obj
        return RedactedJoinedSpatialAggregate(
            joined_spatial_aggregate=JoinedSpatialAggregate(
                locations=locations, metric=metric, method=self.method))
    def join_aggregate(self, metric, method="avg"):
        """
        Join with a metric representing object and aggregate
        spatially.

        Parameters
        ----------
        metric : Query
        method : {"avg", "max", "min", "median", "mode", "stddev", "variance"}

        Returns
        -------
        JoinedSpatialAggregate
        """

        return JoinedSpatialAggregate(metric=metric, locations=self, method=method)
def test_all_above_threshold(get_dataframe):
    """
    Test that values are not returned where there are not enough people in the aggregate.
    """
    in_agg = get_dataframe(
        RedactedJoinedSpatialAggregate(
            joined_spatial_aggregate=JoinedSpatialAggregate(
                locations=daily_location("2016-01-01"),
                metric=RadiusOfGyration("2016-01-01", "2016-01-02"),
            ))).pcod
    assert len(in_agg) > 0
    under_15 = get_dataframe(
        daily_location("2016-01-01").aggregate().numeric_subset(col="value",
                                                                low=0,
                                                                high=15)).pcod
    assert set(under_15).isdisjoint(in_agg)
def test_can_be_aggregated_admin3_distribution(get_dataframe):
    """
    Categorical queries can be aggregated to a spatial level with 'distribution' method.
    """
    locations = locate_subscribers(
        "2016-01-01",
        "2016-01-02",
        spatial_unit=make_spatial_unit("admin", level=3),
        method="most-common",
    )
    metric = SubscriberHandsetCharacteristic("2016-01-01",
                                             "2016-01-02",
                                             characteristic="hnd_type")
    agg = JoinedSpatialAggregate(metric=metric,
                                 locations=locations,
                                 method="distr")
    df = get_dataframe(agg)
    assert ["pcod", "metric", "key", "value"] == list(df.columns)
    assert all(df[df.metric == "value"].groupby("pcod").sum() == 1.0)
Esempio n. 5
0
    def join_aggregate(self, locations, method="avg"):
        """
        Join with a location representing object and aggregate
        spatially.

        Parameters
        ----------
        method : {"avg", "max", "min", "median", "mode", "stddev", "variance"}
        locations :
            Subscriber locating type query

        Returns
        -------
        JoinedSpatialAggregate
            Query object representing a version of this metric aggregated to
            the spatial unit.
        """
        return JoinedSpatialAggregate(metric=self,
                                      locations=locations,
                                      method=method)