Exemplo n.º 1
0
def create_recommendation_manager():
    root_ctx = default_context()
    pf = ProfileFetcher(root_ctx)
    pf.set_client(ProfileController(root_ctx, "us-west-2", "taar_addon_data_20180206"))
    root_ctx["profile_fetcher"] = pf
    r_factory = recommenders.RecommenderFactory(root_ctx.child())
    root_ctx["recommender_factory"] = r_factory
    rm = recommenders.RecommendationManager(root_ctx.child())
    return rm
Exemplo n.º 2
0
def create_recommendation_manager():
    root_ctx = default_context()
    client = ProfileController('us-west-2', 'taar_addon_data_20180206')
    pf = ProfileFetcher(client)
    root_ctx['profile_fetcher'] = pf
    r_factory = recommenders.RecommenderFactory(root_ctx.child())
    root_ctx['recommender_factory'] = r_factory
    rm = recommenders.RecommendationManager(root_ctx.child())
    return rm
Exemplo n.º 3
0
    def check_proxy_manager(PROXY_MANAGER):
        if PROXY_MANAGER.getResource() is None:
            ctx = default_context()
            profile_fetcher = ProfileFetcher(ctx)

            ctx["profile_fetcher"] = profile_fetcher

            # Lock the context down after we've got basic bits installed
            root_ctx = ctx.child()
            r_factory = recommenders.RecommenderFactory(root_ctx)
            root_ctx["recommender_factory"] = r_factory
            instance = recommenders.RecommendationManager(root_ctx.child())
            PROXY_MANAGER.setResource(instance)
        return PROXY_MANAGER.getResource()
Exemplo n.º 4
0
    def recommendations(uuid_client_id):
        """Return a list of recommendations provided a telemetry client_id."""
        # Use the module global PROXY_MANAGER
        global PROXY_MANAGER

        # Coerce the uuid.UUID type into a string
        client_id = str(uuid_client_id)

        branch = request.args.get('branch', '')

        extra_data = {'branch': branch}

        locale = request.args.get('locale', None)
        if locale is not None:
            extra_data['locale'] = locale

        platform = request.args.get('platform', None)
        if platform is not None:
            extra_data['platform'] = platform

        if PROXY_MANAGER.getResource() is None:
            ctx = default_context()
            profile_fetcher = ProfileFetcher(ctx)

            ctx['profile_fetcher'] = profile_fetcher

            # Lock the context down after we've got basic bits installed
            root_ctx = ctx.child()
            r_factory = recommenders.RecommenderFactory(root_ctx)
            root_ctx['recommender_factory'] = r_factory
            instance = recommenders.RecommendationManager(root_ctx.child())
            PROXY_MANAGER.setResource(instance)

        instance = PROXY_MANAGER.getResource()
        recommendations = instance.recommend(client_id=client_id,
                                             limit=TAAR_MAX_RESULTS,
                                             extra_data=extra_data)
        # Strip out weights from TAAR results to maintain compatibility
        # with TAAR 1.0
        jdata = {"results": [x[0] for x in recommendations]}

        response = app.response_class(response=json.dumps(jdata),
                                      status=200,
                                      mimetype='application/json')
        return response
Exemplo n.º 5
0
def recommendations(request, client_id):
    """Return a list of recommendations provided a telemetry client_id."""
    recommendation_manager = cache.get("recommendation_manager")

    extra_data = {}

    locale = request.GET.get('locale', None)
    if locale is not None:
        extra_data['locale'] = locale

    platform = request.GET.get('platform', None)
    if platform is not None:
        extra_data['platform'] = platform

    if recommendation_manager is None:
        hbase_client = HBaseClient(settings.HBASE_HOST)
        profile_fetcher = ProfileFetcher(hbase_client)
        recommendation_manager = recommenders.RecommendationManager(
            profile_fetcher)
        cache.set("recommendation_manager", recommendation_manager,
                  CACHE_EXPIRATION)
    recommendations = recommendation_manager.recommend(
        client_id, settings.TAAR_MAX_RESULTS, extra_data)
    return JsonResponse({"results": recommendations})