diff --git a/requirements.txt b/requirements.txt index 06eb5b8..848dbd6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,9 +31,9 @@ chardet==3.0.4 \ idna==2.6 \ --hash=sha256:8c7309c718f94b3a625cb648ace320157ad16ff131ae0af362c9f21b80ef6ec4 \ --hash=sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f -tox==2.9.1 \ - --hash=sha256:8af30fd835a11f3ff8e95176ccba5a4e60779df4d96a9dfefa1a1704af263225 \ - --hash=sha256:752f5ec561c6c08c5ecb167d3b20f4f4ffc158c0ab78855701a75f5cef05f4b8 +tox==3.0.0 \ + --hash=sha256:9ee7de958a43806402a38c0d2aa07fa8553f4d2c20a15b140e9f771c2afeade0 \ + --hash=sha256:96efa09710a3daeeb845561ebbe1497641d9cef2ee0aea30db6969058b2bda2f coverage==4.5.1 \ --hash=sha256:7608a3dd5d73cb06c531b8925e0ef8d3de31fed2544a7de6c63960a1e73ea4bc \ --hash=sha256:3a2184c6d797a125dca8367878d3b9a178b6fdd05fdc2d35d758c3006a1cd694 \ @@ -77,18 +77,18 @@ docutils==0.14 \ --hash=sha256:7a4bd47eaf6596e1295ecb11361139febe29b084a87bf005bf899f9a42edc3c6 \ --hash=sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6 \ --hash=sha256:51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274 -pytest==3.4.2 \ - --hash=sha256:062027955bccbc04d2fcd5d79690947e018ba31abe4c90b2c6721abec734261b \ - --hash=sha256:117bad36c1a787e1a8a659df35de53ba05f9f3398fb9e4ac17e80ad5903eb8c5 +pytest==3.5.0 \ + --hash=sha256:6266f87ab64692112e5477eba395cfedda53b1933ccd29478e671e73b420c19c \ + --hash=sha256:fae491d1874f199537fd5872b5e1f0e74a009b979df9d53d1553fd03da1703e1 pytest-cov==2.5.1 \ --hash=sha256:03aa752cf11db41d281ea1d807d954c4eda35cfa1b21d6971966cc041bbf6e2d \ --hash=sha256:890fe5565400902b0c78b5357004aab1c814115894f4f21370e2433256a3eeec pytest-flask==0.10.0 \ --hash=sha256:2c5a36f9033ef8b6f85ddbefaebdd4f89197fc283f94b20dfe1a1beba4b77f03 \ --hash=sha256:657c7de386215ab0230bee4d76ace0339ae82fcbb34e134e17a29f65032eef03 -python-dateutil==2.7.0 \ - --hash=sha256:8f95bb7e6edbb2456a51a1fb58c8dca942024b4f5844cae62c90aa88afe6e300 \ - --hash=sha256:07009062406cffd554a9b4135cd2ff167c9bf6b7aac61fe946c93e69fad1bbd8 +python-dateutil==2.7.2 \ + --hash=sha256:9d8074be4c993fbe4947878ce593052f71dac82932a677d49194d8ce9778002e \ + --hash=sha256:3220490fb9741e2342e1cf29a503394fdac874bc39568288717ee67047ff29df pytz==2018.3 \ --hash=sha256:ed6509d9af298b7995d69a440e2822288f2eca1681b8cce37673dbb10091e5fe \ --hash=sha256:f93ddcdd6342f94cea379c73cddb5724e0d6d0a1c91c9bdef364dc0368ba4fda \ @@ -107,15 +107,15 @@ urllib3==1.22 \ --hash=sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f pluggy==0.6.0 \ --hash=sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff -py==1.5.2 \ - --hash=sha256:8cca5c229d225f8c1e3085be4fcf306090b00850fefad892f9d96c7b6e2f310f \ - --hash=sha256:ca18943e28235417756316bfada6cd96b23ce60dd532642690dcfdaba988a76d +py==1.5.3 \ + --hash=sha256:983f77f3331356039fdd792e9220b7b8ee1aa6bd2b25f567a963ff1de5a64f6a \ + --hash=sha256:29c9fab495d7528e80ba1e343b958684f4ace687327e6f789a94bf3d1915f881 six==1.11.0 \ --hash=sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb \ --hash=sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9 -virtualenv==15.1.0 \ - --hash=sha256:39d88b533b422825d644087a21e78c45cf5af0ef7a99a1fc9fbb7b481e5c85b0 \ - --hash=sha256:02f8102c2436bb03b3ee6dede1919d1dac8a427541652e5ec95171ec8adbc93a +virtualenv==15.2.0 \ + --hash=sha256:e8e05d4714a1c51a2f5921e62f547fcb0f713ebbe959e0a7f585cc8bef71d11f \ + --hash=sha256:1d7e241b431e7afce47e77f8843a276f652699d1fa4f93b9d8ce0076fd7b0b54 argparse==1.4.0 \ --hash=sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314 \ --hash=sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4 @@ -140,8 +140,8 @@ numpy==1.14.2 \ --hash=sha256:768e777cc1ffdbf97c507f65975c8686ebafe0f3dc8925d02ac117acc4669ce9 \ --hash=sha256:675e0f23967ce71067d12b6944add505d5f0a251f819cfb44bdf8ee7072c090d \ --hash=sha256:a958bf9d4834c72dee4f91a0476e7837b8a2966dc6fcfc42c421405f98d0da51 \ - --hash=sha256:bb370120de6d26004358611441e07acda26840e41dfedc259d7f8cc613f96495 \ - --hash=sha256:f2b1378b63bdb581d5d7af2ec0373c8d40d651941d283a2afd7fc71184b3f570 \ + --hash=sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 \ + --hash=sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 \ --hash=sha256:a1413d06abfa942ca0553bf3bccaff5fdb36d55b84f2248e36228db871147dab \ --hash=sha256:7f76d406c6b998d6410198dcb82688dcdaec7d846aa87e263ccf52efdcfeba30 \ --hash=sha256:a7157c9ac6bddd2908c35ef099e4b643bc0e0ebb4d653deb54891d29258dd329 \ @@ -182,3 +182,70 @@ jedi==0.11.1 \ --hash=sha256:d6e799d04d1ade9459ed0f20de47c32f2285438956a677d083d3c98def59fa97 mozilla-taarlite==0.1.1 \ --hash=sha256:12e50c3debeca99a3afaf6f20b45e5e35b736589144c4f42a7d55dc10a2d1fd0 +parso==0.1.1 \ + --hash=sha256:a7bb86fe0844304869d1c08e8bd0e52be931228483025c422917411ab82d628a \ + --hash=sha256:5815f3fe254e5665f3c5d6f54f086c2502035cb631a91341591b5a564203cffb +pexpect==4.4.0 \ + --hash=sha256:6ff881b07aff0cb8ec02055670443f784434395f90c3285d2ae470f921ade52a \ + --hash=sha256:67b85a1565968e3d5b5e7c9283caddc90c3947a2625bed1905be27bd5a03e47d +pickleshare==0.7.4 \ + --hash=sha256:c9a2541f25aeabc070f12f452e1f2a8eae2abd51e1cd19e8430402bdf4c1d8b5 \ + --hash=sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 +prompt_toolkit==1.0.15 \ + --hash=sha256:3f473ae040ddaa52b52f97f6b4a493cfa9f5920c255a12dc56a7d34397a398a4 \ + --hash=sha256:1df952620eccb399c53ebb359cc7d9a8d3a9538cb34c5a1344bdbeb29fbcc381 \ + --hash=sha256:858588f1983ca497f1cf4ffde01d978a3ea02b01c8a26a8bbc5cd2e66d816917 +ptyprocess==0.5.2 \ + --hash=sha256:e8c43b5eee76b2083a9badde89fd1bbce6c8942d1045146e100b7b5e014f4f1a \ + --hash=sha256:e64193f0047ad603b71f202332ab5527c5e52aa7c8b609704fc28c0dc20c4365 +Pygments==2.2.0 \ + --hash=sha256:78f3f434bcc5d6ee09020f92ba487f95ba50f1e3ef83ae96b9d5ffa1bab25c5d \ + --hash=sha256:dbae1046def0efb574852fab9e90209b23f556367b5a320c0bcb871c77c3e8cc +scipy==1.0.1 \ + --hash=sha256:3fab61f6ffbc1da9e1f8e813ba235929b5f361c1fdd728d120ead8f78560427c \ + --hash=sha256:4a9f5a3adbfd08dd047de48a6b436bd4dae364913aa5b6349a41e9eaeb774050 \ + --hash=sha256:cc85b9d10a5da07a6b27449d17584b1a3d953f7286189f170a6045c6c297b0bc \ + --hash=sha256:76f32095863f7eccecaf5224624d4c7f0f3b922b2cd0d0b0d6f037e4d9c54db6 \ + --hash=sha256:232a848a9935c37ffe2cade857296a13680724aef7d4623160dd08f99dbb9d02 \ + --hash=sha256:3eb28bdc6f40a964761c1cb339e45fef076ea2ca729886e1bce956932ef7e487 \ + --hash=sha256:103fd8253fd3f0df3f50a554abc01b13bee1d70483f23bb03636a74b0a0cbc71 \ + --hash=sha256:f26e54dcdeec3daff6ec71854a7b3bba719b78cf07e2d23645ee09d67a5e93df \ + --hash=sha256:a3287b438b3c13970c4851a34bbc82db11e4680d1d6cdedd066479ca83028042 \ + --hash=sha256:200ca3dfebbd0bbacbc0d7389e6eda77428b49793cc1e0e3247f835687d1a6be \ + --hash=sha256:f7c0624de958e2e2e6353813c78aa4f5f3f1ed0a3567fb496b6dad99f55e695e \ + --hash=sha256:544e6f7796b9c131f8f965967e806da187553abf5d7766278b96a2a76abd19a7 \ + --hash=sha256:4a2837b07e77f8e2fc5303f38e224d7fd9f79f8cbf9c60ac72cf98594e1db6b5 \ + --hash=sha256:11cddcfc348ef593feb4ffe4b69c18a064eca199602f751d34083838bdc2f05a \ + --hash=sha256:164f774de04e546fd10e1894d423b54e36255bb42887e005f0fbfb8eef6736f1 \ + --hash=sha256:800abaa55cfad422f00f5b3802403dd634ab9888f560731c09977a3c35e0acae \ + --hash=sha256:be6f0af3f591c100923158f3e3f0f12fa16a0b231616eda407c528e1f9e10014 \ + --hash=sha256:1766acf2d8ff79ed59cae841d4272587af94772f513619dd217226027bd2ab76 \ + --hash=sha256:f2a51f70ef868c03430ed40d8983daa2f38d2e2160a0de4b57b7d9d070912c76 \ + --hash=sha256:89c1d2a80760a373e7f12f490446c60a7221b641435a789439e8ddb01f5ab7d4 \ + --hash=sha256:823a4b1a2eabd09f9e72003c14ceaac63f54d1f99a49f8c1b534f6a73135e995 \ + --hash=sha256:cc04cf28b9f77255eeb612af41a6f207142f92a082555871f782c773c83b7789 \ + --hash=sha256:8739c67842ed9a1c34c62d6cca6301d0ade40d50ef14ba292bd331f0d6c940ba +simplegeneric==0.8.1 \ + --hash=sha256:dc972e06094b9af5b855b3df4a646395e43d1c9d0d39ed345b7393560d0b9173 +thriftpy==0.3.9 \ + --hash=sha256:309e57d97b5bfa01601393ad4f245451e989d6206a59279e56866b264a99796d +traitlets==4.3.2 \ + --hash=sha256:c6cb5e6f57c5a9bdaa40fa71ce7b4af30298fbab9ece9815b5d995ab6217c7d9 \ + --hash=sha256:9c4bd2d267b7153df9152698efb1050a5d84982d3384a37b2c1f7723ba3e7835 +typing==3.6.4 \ + --hash=sha256:b2c689d54e1144bbcfd191b0832980a21c2dbcf7b5ff7a66248a60c90e951eb8 \ + --hash=sha256:3a887b021a77b292e151afb75323dea88a7bc1b3dfa92176cff8e44c8b68bddf \ + --hash=sha256:d400a9344254803a2368533e4533a4200d21eb7b6b729c173bc38201a74db3f2 +virtualenv-clone==0.3.0 \ + --hash=sha256:b5cfe535d14dc68dfc1d1bb4ac1209ea28235b91156e2bba8e250d291c3fb4f8 \ + --hash=sha256:4507071d81013fd03ea9930ec26bc8648b997927a11fa80e8ee81198b57e0ac7 +wcwidth==0.1.7 \ + --hash=sha256:f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c \ + --hash=sha256:3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e +more-itertools==4.1.0 \ + --hash=sha256:c9ce7eccdcb901a2c75d326ea134e0886abfbea5f93e91cc95de9507c0816c44 \ + --hash=sha256:11a625025954c20145b37ff6309cd54e39ca94f72f6bb9576d1195db6fa2442e \ + --hash=sha256:0dd8f72eeab0d2c3bd489025bb2f6a1b8342f9b198f6fc37b52d15cfa4531fea +backcall==0.1.0 \ + --hash=sha256:38ecd85be2c1e78f77fd91700c76e14667dc21e2713b63876c0eb901196e01e4 \ + --hash=sha256:bbbf4b1e5cd2bdb08f915895b51081c041bac22394fdfcfdfbe9f14b77c08bf2 diff --git a/taar_api/app.py b/taar_api/app.py index f9a501e..43ebf19 100644 --- a/taar_api/app.py +++ b/taar_api/app.py @@ -3,13 +3,10 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flask import Flask -from flask import request from dockerflow.flask import Dockerflow -from taar import recommenders -from taar.context import default_context -from taar.profile_fetcher import ProfileFetcher -from taar import ProfileController +from taar_lite.recommenders import GuidBasedRecommender +from srgutil.context import default_context import json from decouple import config import optparse @@ -19,8 +16,6 @@ dockerflow = Dockerflow(app) VALID_BRANCHES = set(['linear', 'ensemble', 'control']) -DYNAMO_REGION = config('DYNAMO_REGION', default='us-west-2') -DYNAMO_TABLE_NAME = config('DYNAMO_TABLE_NAME', default='taar_addon_data_20180206') TAAR_MAX_RESULTS = config('TAAR_MAX_RESULTS', default=10, cast=int) @@ -38,54 +33,27 @@ class ResourceProxy(object): PROXY_MANAGER = ResourceProxy() -@app.route('/api/recommendations//') -def recommendations(uuid_client_id): +@app.route('/taarlite/api/v1/addon_recommendations//') +def recommendations(guid): """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', '') - - if branch.endswith('-taar'): - branch = branch.replace("-taar", "") - - if branch not in VALID_BRANCHES: - # Force branch to be a control branch if an invalid request - # comes in. - branch = 'control' - - 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 + guid = str(guid) if PROXY_MANAGER.getResource() is None: ctx = default_context() - dynamo_client = ProfileController(region_name=DYNAMO_REGION, - table_name=DYNAMO_TABLE_NAME) - profile_fetcher = ProfileFetcher(dynamo_client) - - 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()) + instance = GuidBasedRecommender(root_ctx) PROXY_MANAGER.setResource(instance) instance = PROXY_MANAGER.getResource() - recommendations = instance.recommend(client_id=client_id, - limit=TAAR_MAX_RESULTS, - extra_data=extra_data) + 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]}