當前位置: 首頁>>代碼示例>>Python>>正文


Python models.TogetherManager類代碼示例

本文整理匯總了Python中metashare.recommendations.models.TogetherManager的典型用法代碼示例。如果您正苦於以下問題:Python TogetherManager類的具體用法?Python TogetherManager怎麽用?Python TogetherManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TogetherManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

 def setUp(self):
     """
     Import test fixtures and add resource pairs to TogetherManager
     """
     test_utils.setup_test_storage()
     self.res_1 = _import_resource('elra112.xml')
     self.res_2 = _import_resource('elra135.xml')
     self.res_3 = _import_resource('elra260.xml')
     self.res_4 = _import_resource('elra295.xml')
     man = TogetherManager.getManager(Resource.VIEW)
     count = 0
     while (count < 5):
         man.addResourcePair(self.res_1, self.res_2)
         count += 1
     count = 0
     while (count < 10):
         man.addResourcePair(self.res_1, self.res_3)
         count += 1
     count = 0
     while (count < 3):
         man.addResourcePair(self.res_1, self.res_4)
         count += 1
     man = TogetherManager.getManager(Resource.DOWNLOAD)
     count = 0
     while (count < 15):
         man.addResourcePair(self.res_1, self.res_2)
         count += 1
     count = 0
     while (count < 10):
         man.addResourcePair(self.res_1, self.res_3)
         count += 1
     count = 0
     while (count < 5):
         man.addResourcePair(self.res_1, self.res_4)
         count += 1
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:35,代碼來源:tests.py

示例2: test_delete_deep

    def test_delete_deep(self):

        # test views:
        man = TogetherManager.getManager(Resource.VIEW)
        tracker = SessionResourcesTracker()
        tracker.add_view(self.res_1, datetime.datetime(2012, 7, 16, 18, 0, 0))
        tracker.add_view(self.res_2, datetime.datetime(2012, 7, 16, 18, 0, 1))
        # both resources have been viewed 'together'
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        # deep delete resource
        self.res_1.delete_deep()
        self.assertEquals(0, len(man.getTogetherList(self.res_2, 0)))

        # test downloads:
        man = TogetherManager.getManager(Resource.DOWNLOAD)
        tracker.add_download(self.res_3, datetime.datetime(2012, 7, 16, 18, 0, 0))
        tracker.add_download(self.res_4, datetime.datetime(2012, 7, 16, 18, 0, 1))
        # both resources have been downloaded 'together'
        self.assertEquals(1, len(man.getTogetherList(self.res_3, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_4, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_3, self.res_4))
        # deep delete resource
        self.res_3.delete_deep()
        self.assertEquals(0, len(man.getTogetherList(self.res_4, 0)))
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:26,代碼來源:tests.py

示例3: test_usage

    def test_usage(self):

        # test views:
        man = TogetherManager.getManager(Resource.VIEW)
        tracker = SessionResourcesTracker()
        tracker.add_view(self.res_1, datetime.datetime(2012, 7, 16, 18, 0, 0))
        tracker.add_view(self.res_2, datetime.datetime(2012, 7, 16, 18, 0, 1))
        # both resources have been viewed 'together'
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        # viewing the same resource again does NOT increase the count
        tracker.add_view(self.res_2, datetime.datetime(2012, 7, 16, 18, 0, 2))
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        # viewing a resource after the max view interval changes nothing
        tracker.add_view(self.res_3, datetime.datetime(2012, 7, 16, 18, 0, 10))
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        self.assertEquals(0, len(man.getTogetherList(self.res_3, 0)))
        # add another resource
        tracker.add_view(self.res_4, datetime.datetime(2012, 7, 16, 18, 0, 12))
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        self.assertEquals(1, len(man.getTogetherList(self.res_3, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_4, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_3, self.res_4))

        # test downloads:
        man = TogetherManager.getManager(Resource.DOWNLOAD)
        tracker.add_download(self.res_1, datetime.datetime(2012, 7, 16, 18, 0, 0))
        tracker.add_download(self.res_2, datetime.datetime(2012, 7, 16, 18, 0, 1))
        # both resources have been downloaded 'together'
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        # downloading the same resource again does NOT increase the count
        tracker.add_download(self.res_2, datetime.datetime(2012, 7, 16, 18, 0, 2))
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        # downloading a resource after the max download interval changes nothing
        tracker.add_download(self.res_3, datetime.datetime(2012, 7, 16, 18, 0, 20))
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        self.assertEquals(0, len(man.getTogetherList(self.res_3, 0)))
        # add another resource
        tracker.add_download(self.res_4, datetime.datetime(2012, 7, 16, 18, 0, 22))
        self.assertEquals(1, len(man.getTogetherList(self.res_1, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_2, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
        self.assertEquals(1, len(man.getTogetherList(self.res_3, 0)))
        self.assertEquals(1, len(man.getTogetherList(self.res_4, 0)))
        self.assertEquals(1, man.getTogetherCount(self.res_3, self.res_4))
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:58,代碼來源:tests.py

示例4: get_download_recommendations

def get_download_recommendations(resource):
    """
    Returns a list of ranked download recommendations for the given resource.
    """
    # TODO: decide what threshold to use; may restrict recommendation to top X resources of the list 
    return TogetherManager.getManager(Resource.DOWNLOAD)\
      .getTogetherList(resource, 0)
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:7,代碼來源:recommendations.py

示例5: test_sorting

 def test_sorting(self):
     man = TogetherManager.getManager(Resource.VIEW)
     sorted_res = man.getTogetherList(self.res_1, 0)
     self.assertEqual(3, len(sorted_res))
     self.assertEquals(self.res_3, sorted_res[0])
     self.assertEquals(self.res_2, sorted_res[1])
     self.assertEquals(self.res_4, sorted_res[2])
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:7,代碼來源:tests.py

示例6: test_publication_status_filter

 def test_publication_status_filter(self):
     self.res_3.storage_object.publication_status = INGESTED
     self.res_3.storage_object.save()
     self.res_3.storage_object.update_storage()
     man = TogetherManager.getManager(Resource.VIEW)
     sorted_res = man.getTogetherList(self.res_1, 0)
     self.assertEqual(2, len(sorted_res))
     self.assertEquals(self.res_2, sorted_res[0])
     self.assertEquals(self.res_4, sorted_res[1])
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:9,代碼來源:tests.py

示例7: test_deleted_filter

 def test_deleted_filter(self):
     self.res_2.storage_object.deleted = True
     self.res_2.storage_object.save()
     self.res_2.storage_object.update_storage()
     man = TogetherManager.getManager(Resource.VIEW)
     sorted_res = man.getTogetherList(self.res_1, 0)
     self.assertEqual(2, len(sorted_res))
     self.assertEquals(self.res_3, sorted_res[0])
     self.assertEquals(self.res_4, sorted_res[1])
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:9,代碼來源:tests.py

示例8: _add_resource_to_set

 def _add_resource_to_set(self, res_set, res, res_type):
     """
     Adds the given resource to the given resource set; 
     resource is of the given resource type, 
     either Resource.VIEW or Resource.DOWNLOAD.
     """
     if not res in res_set:
         # update TogetherManager with new pairs
         man = TogetherManager.getManager(res_type)
         for _res in res_set:
             man.addResourcePair(_res, res)
         res_set.add(res)
開發者ID:jvivaldi,項目名稱:META-SHARE,代碼行數:12,代碼來源:recommendations.py

示例9: test_unique_together_constraint

 def test_unique_together_constraint(self):
     man = TogetherManager.getManager(Resource.VIEW)
     man.addResourcePair(self.res_1, self.res_2)
     res_count_dict = man.resourcecountdict_set.get(
       lrid=self.res_1.storage_object.identifier)
     try:
         res_count_dict.resourcecountpair_set.create(
           lrid = self.res_2.storage_object.identifier)
         self.fail("Should have raised an exception")
     except IntegrityError:
         # reset database connection; required for PostgreSQL
         from django import db
         db.close_connection()
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:13,代碼來源:tests.py

示例10: test_delete_deep_with_keeping_recommendations

 def test_delete_deep_with_keeping_recommendations(self):
     """
     tests that deep deleting a resource keeps the recommendations if requested
     """
     man = TogetherManager.getManager(Resource.VIEW)
     self.assertEquals(0, man.getTogetherCount(self.res_1, self.res_2))
     man.addResourcePair(self.res_1, self.res_2)
     self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
     self.assertEquals(2, len(ResourceCountPair.objects.all()))
     self.assertEquals(2, len(ResourceCountDict.objects.all()))
     self.res_1.delete_deep(keep_stats=True)
     # recommendations stay the same
     self.assertEquals(2, len(ResourceCountPair.objects.all()))
     self.assertEquals(2, len(ResourceCountDict.objects.all()))
開發者ID:jvivaldi,項目名稱:META-SHARE,代碼行數:14,代碼來源:tests.py

示例11: _add_resource_to_set

 def _add_resource_to_set(self, res_set, res, res_type):  
     """
     Adds the given resource to the given resource set; 
     resource is of the given resource type, 
     either Resource.VIEW or Resource.DOWNLOAD.
     """  
     if not res in res_set:
         # update TogetherManager with new pairs but make sure that only one
         # thread updates the TogetherManager at a time 
         with SessionResourcesTracker.lock:
             man = TogetherManager.getManager(res_type)
             for _res in res_set:
                 man.addResourcePair(_res, res)
             res_set.add(res)
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:14,代碼來源:recommendations.py

示例12: test_counts

 def test_counts(self):
     """
     tests the addResourcePair and getTogetherCount methods of TogetherManager
     """
     man = TogetherManager.getManager(Resource.VIEW)
     self.assertEquals(0, man.getTogetherCount(self.res_1, self.res_2))
     man.addResourcePair(self.res_1, self.res_2)
     self.assertEquals(0, man.getTogetherCount(self.res_1, self.res_3))
     self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
     self.assertEquals(1, man.getTogetherCount(self.res_2, self.res_1))
     man.addResourcePair(self.res_1, self.res_3)
     self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_3))
     self.assertEquals(1, man.getTogetherCount(self.res_3, self.res_1))
     man.addResourcePair(self.res_1, self.res_2)
     self.assertEquals(2, man.getTogetherCount(self.res_1, self.res_2))
     self.assertEquals(2, man.getTogetherCount(self.res_2, self.res_1))
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:16,代碼來源:tests.py

示例13: test_delete_deep_with_keeping_recommendations

 def test_delete_deep_with_keeping_recommendations(self):
     """
     tests that deep deleting a resource keeps the recommendations if requested
     """
     man = TogetherManager.getManager(Resource.VIEW)
     self.assertEquals(0, man.getTogetherCount(self.res_1, self.res_2))
     man.addResourcePair(self.res_1, self.res_2)
     self.assertEquals(1, man.getTogetherCount(self.res_1, self.res_2))
     self.assertEquals(2, len(ResourceCountPair.objects.all()))
     self.assertEquals(2, len(ResourceCountDict.objects.all()))
     self.assertEquals(3, len(resourceInfoType_model.objects.all()))
     self.assertEquals(3, len(StorageObject.objects.all()))
     self.res_1.storage_object.delete()
     self.res_1.delete_deep(keep_stats=True)
     self.assertEquals(2, len(resourceInfoType_model.objects.all()))
     self.assertEquals(2, len(StorageObject.objects.all()))
     # recommendations stay the same
     self.assertEquals(2, len(ResourceCountPair.objects.all()))
     self.assertEquals(2, len(ResourceCountDict.objects.all()))
     # recommendations are deleted after repairing them
     call_command('repair_recommendations', interactive=False)
     self.assertEquals(0, len(ResourceCountPair.objects.all()))
     self.assertEquals(1, len(ResourceCountDict.objects.all()))
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:23,代碼來源:tests.py

示例14: test_downloads

    def test_downloads(self):
        # client 1 downloads all 4 resources
        client_1 = Client()
        client_1.login(username='normaluser', password='secret')
        man = TogetherManager.getManager(Resource.DOWNLOAD)
        response = _download_resource(client_1, self.res_1)
        self.assertEquals(200, response.status_code)
        download_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(0, len(download_res))

        response = _download_resource(client_1, self.res_2)
        self.assertEquals(200, response.status_code)
        download_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(1, len(download_res))
        download_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(1, len(download_res))
        self.assertEqual(1, man.getTogetherCount(self.res_1, self.res_2))

        response = _download_resource(client_1, self.res_3)
        self.assertEquals(200, response.status_code)
        download_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(2, len(download_res))
        download_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(2, len(download_res))
        download_res = man.getTogetherList(self.res_3, 0)
        self.assertEqual(2, len(download_res))

        response = _download_resource(client_1, self.res_4)
        self.assertEquals(200, response.status_code)
        download_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(3, len(download_res))
        download_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(3, len(download_res))
        download_res = man.getTogetherList(self.res_3, 0)
        self.assertEqual(3, len(download_res))
        download_res = man.getTogetherList(self.res_4, 0)
        self.assertEqual(3, len(download_res))

        # another client downloads 2 of the resources, counts are increased
        client_2 = Client()
        client_2.login(username='normaluser2', password='secret')
        response = _download_resource(client_2, self.res_1)
        self.assertEquals(200, response.status_code)
        download_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(3, len(download_res))

        response = _download_resource(client_2, self.res_2)
        self.assertEquals(200, response.status_code)
        download_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(3, len(download_res))
        download_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(3, len(download_res))
        # counts of res_1 and res_2 appearing together is increased
        self.assertEqual(2, man.getTogetherCount(self.res_1, self.res_2))

        # make sure that views are no touched;
        # in the web interface, the resource has of course to be viewed first
        # before it could be downloaded 
        man = TogetherManager.getManager(Resource.VIEW)
        view_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(0, len(view_res))
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:61,代碼來源:tests.py

示例15: test_views

    def test_views(self):
        # client 1 views all 4 resources
        client_1 = Client()
        man = TogetherManager.getManager(Resource.VIEW)
        response = client_1.get(self.res_1.get_absolute_url(), follow = True)
        self.assertEquals(200, response.status_code)
        view_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(0, len(view_res))

        response = client_1.get(self.res_2.get_absolute_url(), follow = True)
        self.assertEquals(200, response.status_code)
        view_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(1, len(view_res))
        view_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(1, len(view_res))
        self.assertEqual(1, man.getTogetherCount(self.res_1, self.res_2))

        response = client_1.get(self.res_3.get_absolute_url(), follow = True)
        self.assertEquals(200, response.status_code)
        view_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(2, len(view_res))
        view_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(2, len(view_res))
        view_res = man.getTogetherList(self.res_3, 0)
        self.assertEqual(2, len(view_res))

        response = client_1.get(self.res_4.get_absolute_url(), follow = True)
        self.assertEquals(200, response.status_code)
        view_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(3, len(view_res))
        view_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(3, len(view_res))
        view_res = man.getTogetherList(self.res_3, 0)
        self.assertEqual(3, len(view_res))
        view_res = man.getTogetherList(self.res_4, 0)
        self.assertEqual(3, len(view_res))

        # another client views 2 of the resources, counts are increased
        client_2 = Client()
        response = client_2.get(self.res_1.get_absolute_url(), follow = True)
        self.assertEquals(200, response.status_code)
        view_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(3, len(view_res))

        response = client_2.get(self.res_2.get_absolute_url(), follow = True)
        self.assertEquals(200, response.status_code)
        view_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(3, len(view_res))
        view_res = man.getTogetherList(self.res_2, 0)
        self.assertEqual(3, len(view_res))
        # counts of res_1 and res_2 appearing together is increased
        self.assertEqual(2, man.getTogetherCount(self.res_1, self.res_2))

        # make sure that downloads are no touched
        man = TogetherManager.getManager(Resource.DOWNLOAD)
        download_res = man.getTogetherList(self.res_1, 0)
        self.assertEqual(0, len(download_res))

        # make sure that statistics are updated when a resource is 
        # completely removed
        saveLRStats(self.res_1, UPDATE_STAT)
        saveLRStats(self.res_2, UPDATE_STAT)
        saveLRStats(self.res_3, UPDATE_STAT)
        saveLRStats(self.res_4, UPDATE_STAT)
        self.assertEquals(9, len(LRStats.objects.all()))
        self.assertEquals(228, len(UsageStats.objects.all()))
        remove_resource(self.res_1.storage_object)
        self.assertEquals(7, len(LRStats.objects.all()))
        self.assertEquals(181, len(UsageStats.objects.all()))
開發者ID:MiltosD,項目名稱:CEFELRC,代碼行數:69,代碼來源:tests.py


注:本文中的metashare.recommendations.models.TogetherManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。