当前位置: 首页>>代码示例>>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;未经允许,请勿转载。