Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail when no IP can be fetched #58

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Comment on lines +1 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woo!

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