Skip to content

Commit

Permalink
Add support for null experiment data (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
econti authored Jun 4, 2020
1 parent 2269aa8 commit 42f27e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
24 changes: 10 additions & 14 deletions static/js/banditLocal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// 16ounc.es
// let experimentId = "01c14c21-b66a-408b-89ba-7d888f0c35de";
// let bandit = new banditml.BanditAPI("a48853ba-6c5a-3202-8711-4ce878833cb3", {[experimentId]: "recs"}, {debugMode: true, banditHostUrl: "https://www.16ounc.es/api/"});
// local
// product set case
// let experimentId = "18c08829-e49e-421f-a13b-77e7d6d0221b";
// product set multi-dynamic case
let experimentId = "fce763c5-eaf6-4b4d-ae42-47d62ecf04ab";
// category case
// let experimentId = "59204365-5e27-4c8c-a21b-e1a81d373979";
function getSessionIdCustom () {
return "1235"
}
let bandit = new banditml.BanditAPI("c52e1439-77bc-3cfd-b422-6a4d9a1e2c8c", {[experimentId]: "recsCategory"}, {debugMode: true, debugOptions: {forceVariantSlug: "control"}, banditHostUrl: "http://localhost:8000/api/", getSessionId: getSessionIdCustom});
let experimentId = "84a8cc7a-9156-41fb-af9d-8001c8e1897b";
let bandit = new banditml.BanditAPI(
apiKey = "6bd9ba8f-bd71-3139-a6e5-41275f34afe9",
recClassByExperimentId = {[experimentId]: "product-recs"},
config = {
debugMode: true,
banditHostUrl: "http://localhost:8000/api/",
debugOptions: {forceVariantSlug: "bandit"}
}
);
2 changes: 1 addition & 1 deletion static/js/banditMl.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ banditml.BanditAPI.prototype.logDecision = function(context, decisionResponse, e
});
};

banditml.BanditAPI.prototype.logReward = function(reward, experimentId, decision = null, decisionId = null) {
banditml.BanditAPI.prototype.logReward = function(reward, experimentId = null, decision = null, decisionId = null) {
const headers = {
"Authorization": `ApiKey ${this.banditApikey}`
};
Expand Down
21 changes: 9 additions & 12 deletions templates/productDescription.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
<link rel="stylesheet" href={{url_for('static', filename='css/productDescription.css')}} />
<link rel="stylesheet" href={{ url_for('static', filename='css/topStyle.css')}} />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<!-- <script type="text/javascript" src="https://gradient-app-bucket-public-staging.s3.amazonaws.com/snippets/banditMl.min.js"></script> -->
<script src={{ url_for('static', filename='js/banditMl.js') }}></script>

<script src={{ url_for('static', filename='js/banditLocal.js') }}></script>

<script>
let banditExperimentId = "2452b52a-8bda-4fb5-b0cd-832e0683d601";
let bandit = new window.BanditAPI(
apiKey = "b3496e1b-228f-33fd-9887-883e8f15d7e1",
recClassByExperimentId = {[banditExperimentId]: "product-recs"},
config = {debugMode: true, banditHostUrl: "https://www.16ounc.es/api/"}
);

function defaultDecisionIds() {
let result = null
Expand Down Expand Up @@ -43,7 +38,7 @@
});
};

// old recommendation logic
// // old recommendation logic
// $.when(defaultDecisionIds()).then(function(recs) {
// filteredRecs = filterRecs(recs);
// populateDecisions(filteredRecs);
Expand All @@ -54,17 +49,17 @@
currentlyViewingProduct: "{{cleanedName}}",
trafficSource: "google",
totalCartValue: null,
},banditExperimentId).then(function () {
},experimentId).then(function () {
bandit.getDecision(
banditExperimentId,
experimentId,
defaultDecisionIds = defaultDecisionIds,
filterRecs = filterRecs,
populateDecisions = populateDecisions
).then(response => {
$('.productRec').click(function () {
bandit.logReward(
reward = {click: 1},
experimentId = banditExperimentId,
experimentId = experimentId,
decision = $(this).attr('id'),
decisionId = response.decision.id);
});
Expand All @@ -76,10 +71,12 @@
bandit.logReward({
"Computer-1": {"purchase": 39.99},
"Mens-Tshirt-2": {"purchase": 19.99}
}, banditExperimentId);
}, experimentId);
});
});

// log all item views to be used in collaborative filtering
bandit.logReward({"{{cleanedName}}": {"view": 1}});

</script>

Expand Down

0 comments on commit 42f27e0

Please sign in to comment.