Esempio n. 1
0
 def test_joined_modal_aggregate(self):
     """
     Test join with modal aggregate.
     """
     mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
     rog = SubscriberDegree("2016-01-01", "2016-01-04")
     joined = mfl.join_aggregate(rog, method="mode")
     rawus_mode = (rog.get_dataframe().set_index("subscriber").join(
         mfl.get_dataframe().set_index("subscriber")).set_index(
             "name").ix["Rasuwa"].degree.mode()[0])
     self.assertAlmostEqual(
         joined.get_dataframe().set_index("name").ix["Rasuwa"].degree,
         rawus_mode)
Esempio n. 2
0
    def _unsampled_query_obj(self):
        """
        Return the underlying flowmachine subscriber_degree object.

        Returns
        -------
        Query
        """
        return SubscriberDegree(
            start=self.start,
            stop=self.stop,
            direction=self.direction,
            subscriber_subset=self.subscriber_subset,
        )
Esempio n. 3
0
def test_joined_modal_aggregate(get_dataframe):
    """
    Test join with modal aggregate.
    """
    mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
    rog = SubscriberDegree("2016-01-01", "2016-01-04")
    joined = mfl.join_aggregate(rog, method="mode")
    rawus_mode = (
        get_dataframe(rog)
        .set_index("subscriber")
        .join(get_dataframe(mfl).set_index("subscriber"))
        .set_index("pcod")
        .loc["524 2 05 29"]
        .value.mode()[0]
    )
    assert (
        pytest.approx(rawus_mode)
        == get_dataframe(joined).set_index("pcod").loc["524 2 05 29"].value
    )
Esempio n. 4
0
def test_collects_metrics():
    """
    Test that we can instantiate flowmachine.feature_collection with list of
    objects.
    """

    start, stop = "2016-01-01", "2016-01-03"
    metrics = [
        RadiusOfGyration(start, stop),
        NocturnalEvents(start, stop),
        SubscriberDegree(start, stop),
    ]
    expected_columns = [
        "subscriber",
        "value_radiusofgyration_0",
        "value_nocturnalevents_1",
        "value_subscriberdegree_2",
    ]
    fc = feature_collection(metrics)
    column_names = fc.column_names
    assert expected_columns == column_names