def main( date, aws_access_key_id, aws_secret_access_key, bucket, prefix, elastic_net_param, reg_param, min_installed_addons, client_sample_date_from, sample_rate, ): print("Sampling clients since {}".format(client_sample_date_from)) # Clobber the AWS access credentials os.environ["AWS_ACCESS_KEY_ID"] = aws_access_key_id os.environ["AWS_SECRET_ACCESS_KEY"] = aws_secret_access_key ctx = default_context() APP_NAME = "TaarEnsemble" conf = SparkConf().setAppName(APP_NAME) spark = SparkSession.builder.config(conf=conf).getOrCreate() taar_training = extract( spark, client_sample_date_from, min_installed_addons, sample_rate ) coefs = transform(ctx, spark, taar_training, reg_param, elastic_net_param) load(coefs, date, prefix, bucket)
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
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
def load_recommenders(ctx): from taar.recommenders import LocaleRecommender from taar.recommenders import SimilarityRecommender from taar.recommenders import CollaborativeRecommender ctx = default_context() reload_configuration() lr = LocaleRecommender(ctx) sr = SimilarityRecommender(ctx) cr = CollaborativeRecommender(ctx) return {LOCALE: lr, COLLABORATIVE: cr, SIMILARITY: sr}
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()
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
from funcsigs import signature as inspect_sig import funcsigs from taar.schema import INTERVENTION_A from taar.schema import INTERVENTION_B from taar.schema import INTERVENTION_CONTROL from taar.context import default_context from .lazys3 import LazyJSONLoader import random # We need to build a default logger for the schema validation as there # is no class to bind to yet. ctx = default_context() schema_logger = ctx[IMozLogging].get_logger('taar.schema_validate') TEST_CLIENT_IDS = [ '00000000-0000-0000-0000-000000000000', '11111111-1111-1111-1111-111111111111', '22222222-2222-2222-2222-222222222222', '33333333-3333-3333-3333-333333333333' ] EMPTY_TEST_CLIENT_IDS = [ '00000000-aaaa-0000-0000-000000000000', '11111111-aaaa-1111-1111-111111111111', '22222222-aaaa-2222-2222-222222222222', '33333333-aaaa-3333-3333-333333333333' ]
def __init__(self, *args, **kwargs): self._ctx = default_context() self._ctx["profile_fetcher"] = kwargs["profile_fetcher"] super(ProfileFetcherEnabledRecommendationManager, self).__init__(args, kwargs)