Esempio n. 1
0
    def test_filter_by_date(self, friends, tz_name):
        df = friends.data

        filtered = utils.filter_by_date(
            df,
            start=utils.dt(y=2020, m=3, d=1, tz=pytz.timezone(tz_name)),
            end=utils.dt(y=2020, m=4, d=30, tz=pytz.timezone(tz_name)),
        )
        assert len(filtered) == 3

        filtered = utils.filter_by_date(df,
                                        start="2020-03-01",
                                        end="2020-04-30")
        assert len(filtered) == 3
Esempio n. 2
0
 def test_stats_teflon_musk_all_2014_12(self, panalyzer):
     stats = panalyzer.filter(channels="Bugs Bunny").stats.filter(
         start=dt(2014, 12), period="m")
     assert stats.mc == 1
     assert stats.wc == 0
     assert stats.cc == 0
     assert stats.unique_mc == 0
     assert stats.unique_wc == 0
Esempio n. 3
0
    def test_ts_to_date_and_dt(self, tz_name):
        date = 1598046630000

        target_tz = pytz.timezone(tz_name)
        with_tz = utils.ts_to_date(date, target_tz)
        # Friday, August 21, 2020 9:50:30 PM
        expected_date = utils.dt(y=2020,
                                 m=8,
                                 d=21,
                                 h=21,
                                 minute=50,
                                 second=30,
                                 tz=target_tz)
        assert expected_date == with_tz
Esempio n. 4
0
    def test_ts_to_date(self, tz_name):
        dt = 1454607689000

        target_tz = pytz.timezone(tz_name)

        with_tz = utils.ts_to_date(dt, target_tz)

        expected_date = utils.dt(y=2016,
                                 m=2,
                                 d=4,
                                 h=17,
                                 minute=41,
                                 second=29,
                                 tz=target_tz)
        assert expected_date == with_tz
Esempio n. 5
0
def test_total_number_of_characters_sent(stat_count):
    assert (stat_count(
        attr="cc",
        senders="me",
    ) == 319)

    assert (stat_count(attr="cc", senders="me", start=dt(y=2000),
                       period="y") == 0)
    assert (stat_count(attr="cc", senders="me", start=dt(y=2014),
                       period="y") == 68)
    assert (stat_count(attr="cc", senders="me", start=dt(y=2018),
                       period="y") == 167)
    assert (stat_count(attr="cc", senders="me", start=dt(y=2020),
                       period="y") == 84)

    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2014, m=9),
        period="m",
    ) == 23)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2014, m=11),
        period="m",
    ) == 42)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2014, m=12),
        period="m",
    ) == 3)

    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2018, m=1),
        period="m",
    ) == 167)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2018, m=2),
        period="m",
    ) == 0)

    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=2),
        period="m",
    ) == 62)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=3),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=4),
        period="m",
    ) == 17)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=5),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=6),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=8),
        period="m",
    ) == 5)

    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=2, d=13, h=5),
        period="d",
    ) == 21)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=2, d=13, h=7),
        period="d",
    ) == 0)

    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=2, d=13, h=5),
        period="h",
    ) == 21)
    assert (stat_count(
        attr="cc",
        senders="me",
        start=dt(y=2020, m=2, d=13, h=7),
        period="h",
    ) == 0)
Esempio n. 6
0
def test_total_number_of_words_sent(stat_count):
    assert (stat_count(
        attr="wc",
        senders="me",
    ) == 71)
    assert (stat_count(attr="wc", senders="me", start=dt(y=2000),
                       period="y") == 0)
    assert (stat_count(attr="wc", senders="me", start=dt(y=2014),
                       period="y") == 18)
    assert (stat_count(attr="wc", senders="me", start=dt(y=2018),
                       period="y") == 31)
    assert (stat_count(attr="wc", senders="me", start=dt(y=2020),
                       period="y") == 22)

    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2014, m=9),
        period="m",
    ) == 6)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2014, m=11),
        period="m",
    ) == 11)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2014, m=12),
        period="m",
    ) == 1)

    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2018, m=1),
        period="m",
    ) == 31)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2018, m=2),
        period="m",
    ) == 0)

    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=2),
        period="m",
    ) == 16)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=3),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=4),
        period="m",
    ) == 4)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=5),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=6),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=8),
        period="m",
    ) == 2)

    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=2, d=13),
        period="d",
    ) == 5)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=2, d=13, h=5),
        period="h",
    ) == 5)
    assert (stat_count(
        attr="wc",
        senders="me",
        start=dt(y=2020, m=2, d=13, h=7),
        period="h",
    ) == 0)
Esempio n. 7
0
def test_total_number_of_messages(stat_count):
    assert stat_count(attr="mc") == 31

    assert stat_count(attr="mc", start=dt(y=2000), period="y") == 0
    assert stat_count(attr="mc", start=dt(y=2014), period="y") == 13
    assert stat_count(attr="mc", start=dt(y=2018), period="y") == 3
    assert stat_count(attr="mc", start=dt(y=2020), period="y") == 15

    assert stat_count(attr="mc", start=dt(y=2011, m=11), period="m") == 0
    assert stat_count(attr="mc", start=dt(y=2014, m=9), period="m") == 1
    assert stat_count(attr="mc", start=dt(y=2014, m=11), period="m") == 10
    assert stat_count(attr="mc", start=dt(y=2014, m=12), period="m") == 2

    assert stat_count(attr="mc", start=dt(y=2018, m=1), period="m") == 3
    assert stat_count(attr="mc", start=dt(y=2018, m=5), period="m") == 0

    assert stat_count(attr="mc", start=dt(y=2020, m=2), period="m") == 10
    assert stat_count(attr="mc", start=dt(y=2020, m=3), period="m") == 1  # jpg
    assert stat_count(attr="mc", start=dt(y=2020, m=4), period="m") == 2
    assert stat_count(attr="mc", start=dt(y=2020, m=5), period="m") == 1
    assert stat_count(attr="mc", start=dt(y=2020, m=6), period="m") == 0
    assert stat_count(attr="mc", start=dt(y=2020, m=8), period="m") == 1

    assert stat_count(attr="mc", start=dt(y=2020, m=2, d=13), period="d") == 2
    assert (stat_count(
        attr="mc",
        start=dt(y=2020, m=2, d=13, h=5),
        period="h",
    ) == 2)

    assert (stat_count(
        attr="mc",
        start=dt(y=2020, m=2, d=13, h=5),
        period="d",
    ) == 4)
Esempio n. 8
0
 def test_stats_teflon_musk_partner_2014_9(self, panalyzer):
     stats = panalyzer.filter(channels="Bugs Bunny").stats.filter(
         senders="partner", start=dt(2014, 9), period="m")
     assert stats.unique_mc == 0
     assert stats.cc == 0
Esempio n. 9
0
def test_total_number_of_characters_received(stat_count):
    assert (stat_count(
        attr="cc",
        senders="partner",
    ) == 88)

    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2000),
        period="y",
    ) == 0)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2014),
        period="y",
    ) == 29)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2018),
        period="y",
    ) == 3)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2020),
        period="y",
    ) == 56)

    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2014, m=9),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2014, m=11),
        period="m",
    ) == 29)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2014, m=12),
        period="m",
    ) == 0)

    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2018, m=1),
        period="m",
    ) == 3)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2018, m=2),
        period="m",
    ) == 0)

    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2020, m=2),
        period="m",
    ) == 52)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2020, m=3),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2020, m=5),
        period="m",
    ) == 4)

    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2020, m=2, d=13),
        period="d",
    ) == 30)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2020, m=2, d=14),
        period="d",
    ) == 22)
    assert (stat_count(
        attr="cc",
        senders="partner",
        start=dt(y=2020, m=2, d=18),
        period="d",
    ) == 0)
Esempio n. 10
0
    def test_get_start_based_on_period(self):
        res = utils.get_start_based_on_period(utils.dt(2014, 2, 2), "y")
        assert res == utils.dt(2014, 1, 1)

        res = utils.get_start_based_on_period(utils.dt(2014, 2, 2), "m")
        assert res == utils.dt(2014, 2, 1)
Esempio n. 11
0
 def test_filter_date(self, group_stats):
     filtered = group_stats.filter(start=utils.dt(y=2018), period="y")
     assert filtered.channels == ["marathon"]
     assert filtered.start.year == 2018
     assert filtered.start.month == 4
Esempio n. 12
0
 def test_stats_toke_hal_partner_2014_12(self, panalyzer):
     stats = panalyzer.filter(channels="Tőke Hal").stats.filter(
         senders="partner", start=dt(2014, 12), period="m")
     assert stats.wc == 0
Esempio n. 13
0
 def test_stats_toke_hal_me_2014_11(self, panalyzer):
     stats = panalyzer.filter(channels="Tőke Hal").stats.filter(
         senders="me", start=dt(2014, 11), period="m")
     assert stats.unique_wc == 5
Esempio n. 14
0
 def test_stats_toke_hal_all_2014_11(self, panalyzer):
     stats = panalyzer.filter(channels="Tőke Hal").stats.filter(start=dt(
         2014, 11),
                                                                period="m")
     assert stats.mc == 6
     assert stats.unique_mc == 5
Esempio n. 15
0
 def test_stats_teflon_musk_me_2014_11(self, panalyzer):
     stats = panalyzer.filter(channels="Bugs Bunny").stats.filter(
         senders="me", start=dt(2014, 11), period="m")
     assert stats.wc == 6
Esempio n. 16
0
def test_total_number_of_words(stat_count):
    assert (stat_count(attr="wc", ) == 91)

    assert stat_count(attr="wc", start=dt(y=2000), period="y") == 0
    assert stat_count(attr="wc", start=dt(y=2014), period="y") == 25
    assert stat_count(attr="wc", start=dt(y=2018), period="y") == 32
    assert stat_count(attr="wc", start=dt(y=2020), period="y") == 34

    assert stat_count(attr="wc", start=dt(y=2014, m=9), period="m") == 6
    assert stat_count(attr="wc", start=dt(y=2014, m=11), period="m") == 18
    assert stat_count(attr="wc", start=dt(y=2014, m=12), period="m") == 1

    assert stat_count(attr="wc", start=dt(y=2018, m=1), period="m") == 32
    assert stat_count(attr="wc", start=dt(y=2018, m=2), period="m") == 0

    assert stat_count(attr="wc", start=dt(y=2020, m=2), period="m") == 27
    assert stat_count(attr="wc", start=dt(y=2020, m=3), period="m") == 0
    assert stat_count(attr="wc", start=dt(y=2020, m=4), period="m") == 4
    assert stat_count(attr="wc", start=dt(y=2020, m=5), period="m") == 1
    assert stat_count(attr="wc", start=dt(y=2020, m=6), period="m") == 0
    assert stat_count(attr="wc", start=dt(y=2020, m=8), period="m") == 2

    assert stat_count(attr="wc", start=dt(y=2020, m=2, d=13), period="d") == 14
    assert (stat_count(
        attr="wc",
        start=dt(y=2020, m=2, d=13, h=5),
        period="d",
    ) == 14)
Esempio n. 17
0
def test_total_number_of_words_received(stat_count):
    assert (stat_count(
        attr="wc",
        senders="partner",
    ) == 20)

    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2000),
        period="y",
    ) == 0)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2014),
        period="y",
    ) == 7)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2018),
        period="y",
    ) == 1)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2020),
        period="y",
    ) == 12)

    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2014, m=9),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2014, m=11),
        period="m",
    ) == 7)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2014, m=12),
        period="m",
    ) == 0)

    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2018, m=1),
        period="m",
    ) == 1)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2018, m=2),
        period="m",
    ) == 0)

    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2020, m=2),
        period="m",
    ) == 11)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2020, m=3),
        period="m",
    ) == 0)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2020, m=5),
        period="m",
    ) == 1)

    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2020, m=2, d=13),
        period="d",
    ) == 9)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2020, m=2, d=14),
        period="d",
    ) == 2)
    assert (stat_count(
        attr="wc",
        senders="partner",
        start=dt(y=2020, m=2, d=18),
        period="d",
    ) == 0)
Esempio n. 18
0
 def test_generate_date_series(self):
     res = utils.generate_date_series(utils.dt(2010, 10, 10))
     expected = [utils.dt(i, 2, 4) for i in range(2004, 2021)]
     assert res == expected
Esempio n. 19
0
def test_total_number_of_characters(stat_count):
    assert (stat_count(attr="cc", ) == 407)

    assert stat_count(attr="cc", start=dt(y=2000), period="y") == 0
    assert stat_count(attr="cc", start=dt(y=2014), period="y") == 97
    assert stat_count(attr="cc", start=dt(y=2018), period="y") == 170
    assert stat_count(attr="cc", start=dt(y=2020), period="y") == 140

    assert stat_count(attr="cc", start=dt(y=2014, m=9), period="m") == 23
    assert stat_count(attr="cc", start=dt(y=2014, m=11), period="m") == 71
    assert stat_count(attr="cc", start=dt(y=2014, m=12), period="m") == 3

    assert stat_count(attr="cc", start=dt(y=2018, m=1), period="m") == 170
    assert stat_count(attr="cc", start=dt(y=2018, m=2), period="m") == 0

    assert stat_count(attr="cc", start=dt(y=2020, m=2), period="m") == 114
    assert stat_count(attr="cc", start=dt(y=2020, m=3), period="m") == 0
    assert stat_count(attr="cc", start=dt(y=2020, m=4), period="m") == 17
    assert stat_count(attr="cc", start=dt(y=2020, m=5), period="m") == 4
    assert stat_count(attr="cc", start=dt(y=2020, m=6), period="m") == 0
    assert stat_count(attr="cc", start=dt(y=2020, m=8), period="m") == 5
Esempio n. 20
0
 def test_stats_teflon_musk_all_2014_9(self, panalyzer):
     stats = panalyzer.filter(channels="Bugs Bunny").stats.filter(
         start=dt(2014, 9), period="m")
     assert stats.mc == 1
     assert stats.wc == 6