From 57d4f0f25c3660a7d75ec7e6923d59e26451afbc Mon Sep 17 00:00:00 2001 From: Edoardo Conti Date: Thu, 14 Jan 2021 12:51:17 -0800 Subject: [PATCH] Don't fail when no IP can be fetched (#58) --- Pipfile | 13 ++++ Pipfile.lock | 147 +++++++++++++++++++++++++++++++++++++++ README.md | 6 +- requirements.txt | 40 ----------- static/js/banditLocal.js | 6 +- static/js/banditMl.js | 26 ++++--- 6 files changed, 181 insertions(+), 57 deletions(-) create mode 100644 Pipfile create mode 100644 Pipfile.lock delete mode 100644 requirements.txt diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..5805af5 --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +flask = "*" +instamojo-wrapper = "*" + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..8a1dfc2 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,147 @@ +{ + "_meta": { + "hash": { + "sha256": "94073315ad8ecc46facbc2ea69410886bf731c288800a8da2a8e90e4c415780e" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "certifi": { + "hashes": [ + "sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c", + "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830" + ], + "version": "==2020.12.5" + }, + "chardet": { + "hashes": [ + "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa", + "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==4.0.0" + }, + "click": { + "hashes": [ + "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a", + "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==7.1.2" + }, + "flask": { + "hashes": [ + "sha256:4efa1ae2d7c9865af48986de8aeb8504bf32c7f3d6fdc9353d34b21f4b127060", + "sha256:8a4fdd8936eba2512e9c85df320a37e694c93945b33ef33c89946a340a238557" + ], + "index": "pypi", + "version": "==1.1.2" + }, + "idna": { + "hashes": [ + "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6", + "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.10" + }, + "instamojo-wrapper": { + "hashes": [ + "sha256:5771567d41fa8db940e367d952abe7ba651c40e23945b298fd4f62c9691dbde8", + "sha256:d83eeb0ec712630aa8649b9fb32211638a50643a58f21438dec130767237c4c5" + ], + "index": "pypi", + "version": "==1.2.0" + }, + "itsdangerous": { + "hashes": [ + "sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19", + "sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==1.1.0" + }, + "jinja2": { + "hashes": [ + "sha256:89aab215427ef59c34ad58735269eb58b1a5808103067f7bb9d5836c651b3bb0", + "sha256:f0a4641d3cf955324a89c04f3d94663aa4d638abe8f733ecd3582848e1c37035" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==2.11.2" + }, + "markupsafe": { + "hashes": [ + "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", + "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", + "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", + "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", + "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42", + "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", + "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", + "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", + "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", + "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", + "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", + "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b", + "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", + "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15", + "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", + "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", + "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", + "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", + "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", + "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", + "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", + "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", + "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", + "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", + "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", + "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", + "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", + "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", + "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", + "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", + "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2", + "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7", + "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==1.1.1" + }, + "requests": { + "hashes": [ + "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804", + "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==2.25.1" + }, + "urllib3": { + "hashes": [ + "sha256:19188f96923873c92ccb987120ec4acaa12f0461fa9ce5d3d0772bc965a39e08", + "sha256:d8ff90d979214d7b4f8ce956e80f4028fc6860e4431f731ea4a8c08f23f99473" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", + "version": "==1.26.2" + }, + "werkzeug": { + "hashes": [ + "sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43", + "sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==1.0.1" + } + }, + "develop": {} +} diff --git a/README.md b/README.md index d4e4701..99108eb 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,12 @@ Installation: Create a virtualenv and install requirements ``` -virtualenv env -. env/bin/activate -pip install -r requirements.txt +pipenv install ``` Start the server: ``` -python main.py +pipenv run python main.py ``` Deploy to heroku (on master branch): diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 10a256c..0000000 --- a/requirements.txt +++ /dev/null @@ -1,40 +0,0 @@ -certifi==2018.1.18 -chardet==3.0.4 -click==6.7 -defusedxml==0.5.0 -Flask==0.12.2 -Flask-Login==0.4.1 -Flask-SQLAlchemy==2.3.2 -Flask-WTF==0.14.2 -google-api-python-client==1.6.5 -gunicorn==19.7.1 -httplib2==0.10.3 -idna==2.6 -instamojo-wrapper==1.1 -itsdangerous==0.24 -Jinja2==2.10 -MarkupSafe==1.0 -names==0.3.0 -oauth2client==4.1.2 -oauthlib==2.0.6 -pyasn1==0.4.2 -pyasn1-modules==0.2.1 -PyDrive==1.3.1 -PyJWT==1.5.3 -python-dateutil==2.6.1 -python-social-auth==0.3.6 -python3-openid==3.1.0 -pytz==2017.3 -PyYAML==5.3 -requests==2.18.4 -requests-oauthlib==0.8.0 -rsa==3.4.2 -six==1.11.0 -social-auth-core==1.6.0 -SQLAlchemy==1.2.2 -tabula-py==1.0.0 -uritemplate==3.0.0 -urllib3==1.22 -virtualenv==15.1.0 -Werkzeug==0.14.1 -WTForms==2.1 diff --git a/static/js/banditLocal.js b/static/js/banditLocal.js index fd0b673..7e4d75d 100644 --- a/static/js/banditLocal.js +++ b/static/js/banditLocal.js @@ -1,9 +1,9 @@ -let experimentId = "84a8cc7a-9156-41fb-af9d-8001c8e1897b"; +let experimentId = "4e3b296f-c9b3-4af6-a498-e6d9888aaf55"; let bandit = new banditml.BanditAPI( - apiKey = "6bd9ba8f-bd71-3139-a6e5-41275f34afe9", + apiKey = "4be5e740e5d4ee99accc33b903cdb8e4", recClassByExperimentId = {[experimentId]: "product-recs"}, config = { - debugMode: true, + debugMode: false, banditHostUrl: "http://localhost:8000/api/", debugOptions: {forceVariantSlug: "tf"} } diff --git a/static/js/banditMl.js b/static/js/banditMl.js index 2575ca8..8be432d 100644 --- a/static/js/banditMl.js +++ b/static/js/banditMl.js @@ -331,7 +331,8 @@ banditml.BanditAPI.prototype.validateAndFilterFeaturesInContext = function (cont this.logError(msg, {featureName: featureName}, e); } } else { - console.warn(`Feature ${featureName} is not defined in experiment context. Including it, but check experiment dash.`); + // This is noisy, so let's silence it for now + // console.warn(`Feature ${featureName} is not defined in experiment context. Including it, but check experiment dash.`); filteredFeatures[featureName] = context[featureName]; } } @@ -513,16 +514,21 @@ banditml.BanditAPI.prototype.getDecision = async function ( let context = self.getContext(experimentId); if (!('ipAddress' in context)) { + let ipResult; try { - let ipPromise = self.asyncGetRequest( - self.ipUrl, - params = {}, - headers = { - 'Content-Type': 'application/json', - 'Accept': 'application/json' - } - ); - let ipResult = await ipPromise; + try { + let ipPromise = self.asyncGetRequest( + self.ipUrl, + params = {}, + headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + ); + ipResult = await ipPromise; + } catch (err) { + ipResult = {"ip": "unset-IP-session-" + this.getSessionId()}; + } const ipAddress = ipResult.ip; context.ipAddress = ipAddress; context = self.updateContext(context, experimentId);