Skip to content

Commit

Permalink
Don't fail when no IP can be fetched (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
econti authored Jan 14, 2021
1 parent 1416514 commit 57d4f0f
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 57 deletions.
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -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"
147 changes: 147 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
40 changes: 0 additions & 40 deletions requirements.txt

This file was deleted.

6 changes: 3 additions & 3 deletions static/js/banditLocal.js
Original file line number Diff line number Diff line change
@@ -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"}
}
Expand Down
26 changes: 16 additions & 10 deletions static/js/banditMl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 57d4f0f

Please sign in to comment.