当前位置: 首页>>代码示例>>Python>>正文


Python RecommenderAgent.post_implicit_feedback方法代码示例

本文整理汇总了Python中softwarecenter.backend.recagent.RecommenderAgent.post_implicit_feedback方法的典型用法代码示例。如果您正苦于以下问题:Python RecommenderAgent.post_implicit_feedback方法的具体用法?Python RecommenderAgent.post_implicit_feedback怎么用?Python RecommenderAgent.post_implicit_feedback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在softwarecenter.backend.recagent.RecommenderAgent的用法示例。


在下文中一共展示了RecommenderAgent.post_implicit_feedback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RecommendationsPanel

# 需要导入模块: from softwarecenter.backend.recagent import RecommenderAgent [as 别名]
# 或者: from softwarecenter.backend.recagent.RecommenderAgent import post_implicit_feedback [as 别名]
class RecommendationsPanel(FramedHeaderBox):
    """
    Base class for widgets that display recommendations
    """

    __gsignals__ = {"application-activated": (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT,))}

    def __init__(self):
        FramedHeaderBox.__init__(self)
        self.recommender_agent = RecommenderAgent()
        # keep track of applications that have been viewed via a
        # recommendation so that we can detect when a recommended app
        # has been installed
        self.recommended_apps_viewed = set()
        self.backend = get_install_backend()
        self.backend.connect("transaction-started", self._on_transaction_started)
        self.backend.connect("transaction-finished", self._on_transaction_finished)

    def _on_application_activated(self, tile, app):
        self.emit("application-activated", app)
        # we only report on items if the user has opted-in to the
        # recommendations service
        if self.recommender_agent.is_opted_in():
            self.recommended_apps_viewed.add(app.pkgname)
            if network_state_is_connected():
                # let the recommendations service know that a
                # recommended item has been viewed (if it is
                # subsequently installed we will send an additional
                # signal to indicate that, in on_transaction_finished)
                # (there is no need to monitor for an error, etc., for this)
                self.recommender_agent.post_implicit_feedback(app.pkgname, RecommenderFeedbackActions.VIEWED)

    def _on_transaction_started(self, backend, pkgname, appname, trans_id, trans_type):
        if trans_type != TransactionTypes.INSTALL and pkgname in self.recommended_apps_viewed:
            # if the transaction is not an installation we don't want to
            # track it as a recommended item
            self.recommended_apps_viewed.remove(pkgname)

    def _on_transaction_finished(self, backend, result):
        if result.pkgname in self.recommended_apps_viewed:
            self.recommended_apps_viewed.remove(result.pkgname)
            if network_state_is_connected():
                # let the recommendations service know that a
                # recommended item has been successfully installed
                # (there is no need to monitor for an error, etc., for this)
                self.recommender_agent.post_implicit_feedback(result.pkgname, RecommenderFeedbackActions.INSTALLED)

    def _on_recommender_agent_error(self, agent, msg):
        LOG.warn("Error while accessing the recommender agent: %s" % msg)
        # this can happen if:
        #  - there is a real error from the agent
        #  - no cached data is available
        # hide the panel on an error
        self.hide()
开发者ID:pombredanne,项目名称:shop,代码行数:56,代码来源:recommendations.py

示例2: RealTestRecommenderAgent

# 需要导入模块: from softwarecenter.backend.recagent import RecommenderAgent [as 别名]
# 或者: from softwarecenter.backend.recagent.RecommenderAgent import post_implicit_feedback [as 别名]

#.........这里部分代码省略.........
            orig_host = os.environ.get("SOFTWARE_CENTER_RECOMMENDER_HOST")
            self.addCleanup(os.environ.__setitem__,
                "SOFTWARE_CENTER_RECOMMENDER_HOST", orig_host)
        else:
            self.addCleanup(os.environ.pop, "SOFTWARE_CENTER_RECOMMENDER_HOST")
        server = "https://rec.staging.ubuntu.com"
        os.environ["SOFTWARE_CENTER_RECOMMENDER_HOST"] = server
        # most tests need it
        self.recommender_agent = RecommenderAgent()
        self.recommender_agent.connect("error", self.on_query_error)

    def on_query_done(self, recagent, data):
        #print "query done, data: '%s'" % data
        self.loop.quit()
        self.error = False
        self.error_msg = ""

    def on_query_error(self, recagent, error):
        #print "query error received: ", error
        self.loop.quit()
        self.error = True
        self.error_msg = error

    def assertServerReturnsWithNoError(self):
        self.loop.run()
        self.assertFalse(self.error, "got error: '%s'" % self.error_msg)

    def test_recagent_query_server_status(self):
        self.recommender_agent.connect("server-status", self.on_query_done)
        self.recommender_agent.query_server_status()
        self.assertServerReturnsWithNoError()

    @unittest.skip("server returns 401")
    def test_recagent_post_submit_profile(self):
        # NOTE: This requires a working recommender host that is reachable
        db = get_test_db()
        self.recommender_agent.connect(
            "submit-profile-finished", self.on_query_done)
        self.recommender_agent.post_submit_profile(db)
        self.assertServerReturnsWithNoError()
        #print mock_request._post
        
    @unittest.skip("server returns 401")
    def test_recagent_query_submit_anon_profile(self):
        self.recommender_agent.connect(
            "submit-anon-profile-finished", self.on_query_done)
        self.recommender_agent.post_submit_anon_profile(
                uuid="xxxyyyzzz",
                installed_packages=["pitivi", "fretsonfire"],
                extra="")
        self.assertServerReturnsWithNoError()

    @unittest.skip("server returns 401")
    def test_recagent_query_profile(self):
        self.recommender_agent.connect("profile", self.on_query_done)
        self.recommender_agent.query_profile(pkgnames=["pitivi", "fretsonfire"])
        self.assertServerReturnsWithNoError()

    @unittest.skip("server returns 401")
    def test_recagent_query_recommend_me(self):
        self.recommender_agent.connect("recommend-me", self.on_query_done)
        self.recommender_agent.query_recommend_me()
        self.assertServerReturnsWithNoError()

    def test_recagent_query_recommend_app(self):
        self.recommender_agent.connect("recommend-app", self.on_query_done)
        self.recommender_agent.query_recommend_app("pitivi")
        self.assertServerReturnsWithNoError()

    def test_recagent_query_recommend_all_apps(self):
        self.recommender_agent.connect("recommend-all-apps", self.on_query_done)
        self.recommender_agent.query_recommend_all_apps()
        self.assertServerReturnsWithNoError()

    def test_recagent_query_recommend_top(self):
        self.recommender_agent.connect("recommend-top", self.on_query_done)
        self.recommender_agent.query_recommend_top()
        self.assertServerReturnsWithNoError()

    def test_recagent_query_error(self):
        # NOTE: This tests the error condition itself! it simply forces an error
        #       'cuz there definitely isn't a server here  :)
        fake_server = "https://test-no-server-here.staging.ubuntu.com"
        os.environ["SOFTWARE_CENTER_RECOMMENDER_HOST"] = fake_server
        recommender_agent = RecommenderAgent()
        recommender_agent.connect("recommend-top", self.on_query_done)
        recommender_agent.connect("error", self.on_query_error)
        recommender_agent.query_recommend_top()
        self.loop.run()
        self.assertTrue(self.error)

    @unittest.skip("server returns 401")
    def test_recagent_post_implicit_feedback(self):
        self.recommender_agent.connect("submit-implicit-feedback-finished",
                                  self.on_query_done)
        from softwarecenter.enums import RecommenderFeedbackActions
        self.recommender_agent.post_implicit_feedback(
                "bluefish",
                RecommenderFeedbackActions.INSTALLED)
        self.assertServerReturnsWithNoError()
开发者ID:pombredanne,项目名称:shop,代码行数:104,代码来源:test_recagent.py


注:本文中的softwarecenter.backend.recagent.RecommenderAgent.post_implicit_feedback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。