Exemplo n.º 1
0
def recommendations(guid):
    """Return a list of recommendations provided a telemetry client_id."""
    # Use the module global PROXY_MANAGER
    global PROXY_MANAGER

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

        # Lock the context down after we've got basic bits installed
        root_ctx = ctx.child()
        instance = GuidBasedRecommender(root_ctx)
        PROXY_MANAGER.setResource(instance)

    instance = PROXY_MANAGER.getResource()
    cdict = {'guid': guid}
    recommendations = instance.recommend(client_data=cdict,
                                         limit=TAAR_MAX_RESULTS)
    # 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.º 2
0
def recommendations(guid):
    """Return a list of recommendations provided a telemetry client_id."""
    # Use the module global PROXY_MANAGER
    global PROXY_MANAGER

    if PROXY_MANAGER.getResource() is None:
        ctx = default_context()
        logger = ctx[IMozLogging].get_logger('taar-api-lite')

        ctx['CACHE_URL'] = CACHE_URL
        logger.info("Set CACHE_URL to: [{}]".format(ctx['CACHE_URL']))

        # Lock the context down after we've got basic bits installed
        root_ctx = ctx.child()

        instance = GuidBasedRecommender(root_ctx)
        PROXY_MANAGER.setResource(instance)

    instance = PROXY_MANAGER.getResource()


    cdict = {'guid': guid}
    normalization_type = request.args.get('normalize', None)
    if normalization_type is not None:
        cdict['normalize'] = normalization_type

    recommendations = instance.recommend(client_data=cdict,
                                         limit=TAAR_MAX_RESULTS)

    if len(recommendations) != TAAR_MAX_RESULTS:
        recommendations = []

    # 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.º 3
0
def ctx():
    return default_context()
Exemplo n.º 4
0
"""
Pregenerate addon recommendation results for all whitelisted addons.
"""

import json

from srgutil.context import default_context
from srgutil.interfaces import IS3Data
from taar_lite.recommenders import GuidBasedRecommender

ADDON_LIST_BUCKET = 'telemetry-parquet'
WHITELIST_KEY = 'telemetry-ml/addon_recommender/whitelist_addons_database.json'

ctx = default_context()
cache = ctx[IS3Data]

addon_whitelist = cache.get_s3_json_content(ADDON_LIST_BUCKET, WHITELIST_KEY)
grec = GuidBasedRecommender(ctx)


def compute_name(guid, addon_data):
    guid_name = addon_data['name'].get('en-US', None)
    if guid_name is None:
        guid_name = list(addon_data['name'].values())[0]
    return guid_name


output = {}
for guid in addon_whitelist.keys():
    addon_data = addon_whitelist.get(guid, None)
    addon_url = addon_data['url']
Exemplo n.º 5
0
def test_default_context():
    ctx = default_context()
    print(ctx)
Exemplo n.º 6
0
def default_ctx():
    """
    This sets up a basic context for use for testing
    """
    return default_context()
Exemplo n.º 7
0
def test_ctx():
    ctx = default_context()
    ctx['clock'] = ctx[IClock]
    return ctx