Esempio n. 1
0
    def test_get_similarity_from_subscriptions(self):
        """
        Test that the similarity is calculated as the cosine between the two
        vectors of subscriptions shared by the two channels.
        """
        c0, c1, c2, c3, c4 = self.channels[:5]

        c0_c1 = utils.get_similarity_from_subscriptions(c0, c1)  # 1
        c0_c2 = utils.get_similarity_from_subscriptions(c0, c2)  # 0.5
        c1_c2 = utils.get_similarity_from_subscriptions(c1, c2)  # 0.5
        c3_c4 = utils.get_similarity_from_subscriptions(c3, c4)  # 0
        self.assertTrue(c0_c1 > c0_c2)
        self.assertTrue(c0_c1 > c1_c2)
        self.assertTrue(c0_c1 > c3_c4)
        self.assertTrue(c0_c2 > c3_c4)
Esempio n. 2
0
 def test_ignore_ignored_subscription(self):
     """
     Recommendation calculations should ignore recommendations where the
     ignore_for_recommendations field is True.
     """
     c4, c5 = self.channels[4], self.channels[5]
     self.assertEquals(utils.get_similarity_from_subscriptions(c4,
         c5.id), 0)
Esempio n. 3
0
 def test_ignore_old_recommendations(self):
     """
     Recommendation calculations should ignore subscriptions older than
     6 months (16070400 seconds).
     """
     c4, c7 = self.channels[4], self.channels[7]
     self.assertEquals(utils.get_similarity_from_subscriptions(c4,
         c7.id), 0)
Esempio n. 4
0
 def test_ignore_null_ip_address(self):
     """
     get_similarity_from_subscriptions should not count 0.0.0.0 as a common
     IP since it is used if the IP is not known.
     """
     c0, c3 = self.channels[0], self.channels[3]
     self.assertEquals(utils.get_similarity_from_subscriptions(c0,
         c3.id), 0)
Esempio n. 5
0
 def test_ignore_ignored_subscription(self):
     """
     Recommendation calculations should ignore recommendations where the
     ignore_for_recommendations field is True.
     """
     c4, c5 = self.channels[4], self.channels[5]
     self.assertEquals(utils.get_similarity_from_subscriptions(c4, c5.id),
                       0)
Esempio n. 6
0
 def test_ignore_old_recommendations(self):
     """
     Recommendation calculations should ignore subscriptions older than
     6 months (16070400 seconds).
     """
     c4, c7 = self.channels[4], self.channels[7]
     self.assertEquals(utils.get_similarity_from_subscriptions(c4, c7.id),
                       0)
Esempio n. 7
0
 def test_ignore_null_ip_address(self):
     """
     get_similarity_from_subscriptions should not count 0.0.0.0 as a common
     IP since it is used if the IP is not known.
     """
     c0, c3 = self.channels[0], self.channels[3]
     self.assertEquals(utils.get_similarity_from_subscriptions(c0, c3.id),
                       0)
Esempio n. 8
0
    def test_get_similarity_from_subscriptions(self):
        """
        Test that the similarity is calculated as the cosine between the two
        vectors of subscriptions shared by the two channels.
        """
        c0, c1, c2, c3, c4 = self.channels[:5]

        c0_c1 = utils.get_similarity_from_subscriptions(
            c0, c1) # 1
        c0_c2 = utils.get_similarity_from_subscriptions(
            c0, c2) # 0.5
        c1_c2 = utils.get_similarity_from_subscriptions(
            c1, c2) # 0.5
        c3_c4 = utils.get_similarity_from_subscriptions(
            c3, c4) # 0
        self.assertTrue(c0_c1 > c0_c2)
        self.assertTrue(c0_c1 > c1_c2)
        self.assertTrue(c0_c1 > c3_c4)
        self.assertTrue(c0_c2 > c3_c4)