Esempio n. 1
0
 def test_returns_df(self):
     """
     MostFrequentLocations().get_dataframe() returns a dataframe.
     """
     mfl = MostFrequentLocation("2016-01-01", "2016-01-02", level="admin3")
     df = mfl.get_dataframe()
     self.assertIs(type(df), pd.DataFrame)
Esempio n. 2
0
 def test_joined_aggregate(self):
     """
     Test join aggregate.
     """
     mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
     joined = mfl.join_aggregate(
         RadiusOfGyration("2016-01-01", "2016-01-04"))
     self.assertAlmostEqual(
         joined.get_dataframe().set_index("name").ix["Rasuwa"].rog,
         199.956021886114)
Esempio n. 3
0
    def test_equivalent_to_locate_subscribers(self):
        """
        daily_location() is equivalent to the MostFrequentLocation().
        """
        mfl = MostFrequentLocation("2016-01-01", "2016-01-02")
        mfl_df = mfl.get_dataframe()

        dl = daily_location("2016-01-01", method="most-common")
        dl_df = dl.get_dataframe()

        self.assertTrue((dl_df == mfl_df).all().all())
Esempio n. 4
0
 def test_joined_agg_hours_mismatch(self):
     """
     Test that join aggregate with mismatched hours doesn't warn.
     """
     mfl = MostFrequentLocation("2016-01-01 10:00",
                                "2016-01-04",
                                level="admin3")
     with warnings.catch_warnings(record=True) as w:
         joined = mfl.join_aggregate(
             RadiusOfGyration("2016-01-01", "2016-01-04"))
         self.assertFalse(w)
Esempio n. 5
0
    def test_joined_agg_date_mismatch(self):
        """
        Test that join aggregate with mismatched dates raises a warning.
        """
        mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
        with self.assertWarns(UserWarning):
            joined = mfl.join_aggregate(
                RadiusOfGyration("2016-01-02", "2016-01-04"))

        with self.assertWarns(UserWarning):
            joined = mfl.join_aggregate(
                RadiusOfGyration("2016-01-01", "2016-01-05"))
Esempio n. 6
0
 def test_joined_median_aggregate(self):
     """
     Test join with median aggregate.
     """
     mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
     rog = RadiusOfGyration("2016-01-01", "2016-01-04")
     joined = mfl.join_aggregate(rog, method="median")
     rawus_avg = (rog.get_dataframe().set_index("subscriber").join(
         mfl.get_dataframe().set_index("subscriber")).set_index(
             "name").ix["Rasuwa"].rog.median())
     self.assertAlmostEqual(
         joined.get_dataframe().set_index("name").ix["Rasuwa"].rog,
         rawus_avg)
Esempio n. 7
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. 8
0
    def test_lat_lons(self):
        """
        MostFrequentLocations() has the correct values at the lat-lon level.
        """

        mfl = MostFrequentLocation("2016-01-01", "2016-01-02", level="lat-lon")
        df = mfl.get_dataframe()
        df.set_index("subscriber", inplace=True)

        self.assertAlmostEqual(float(df.ix["1QBlwRo4Kd5v3Ogz"].lat),
                               28.941925079951545)
        self.assertAlmostEqual(float(df.ix["1QBlwRo4Kd5v3Ogz"].lon),
                               82.61895799084449)
Esempio n. 9
0
    def test_vsites(self):
        """
        MostFrequentLocation() returns the correct locations.
        """

        mfl = MostFrequentLocation("2016-01-01",
                                   "2016-01-02",
                                   level="versioned-site")
        df = mfl.get_dataframe()
        df.set_index("subscriber", inplace=True)

        self.assertEqual(df.ix["yqQ6m96rp09dn510"].site_id, "wzrXjw")
        self.assertEqual(df.ix["zvaOknzKbEVD2eME"].site_id, "qvkp6J")
Esempio n. 10
0
    def test_equivalent_to_locate_subscribers_with_time(self):
        """
        daily_location() is equivalent to the MostFrequentLocation() with timestamps.
        """
        mfl = MostFrequentLocation("2016-01-01 18:00:00",
                                   "2016-01-02 06:00:00")
        mfl_df = mfl.get_dataframe()

        dl = daily_location("2016-01-01 18:00:00",
                            stop="2016-01-02 06:00:00",
                            method="most-common")
        dl_df = dl.get_dataframe()

        self.assertTrue((dl_df == mfl_df).all().all())
    def _unsampled_query_obj(self):
        """
        Return the underlying flowmachine daily_location object.

        Returns
        -------
        Query
        """
        return MostFrequentLocation(
            start=self.start,
            stop=self.stop,
            hours=self.hours,
            spatial_unit=self.aggregation_unit,
            table=self.event_types,
            subscriber_subset=self.subscriber_subset,
        )