Interpreter fails if input value is "non-truthy"
assiotis opened this issue · comments
Marios commented
An interpreted experiment will always return non-true values for non-truthy inputs, e.g. {userid: 0}
or {userid: false}
.
'use strict';
const planout = require('planout');
class Repro extends planout.Experiment {
assign(params, args) {
const script = {
op: 'seq',
seq: [
{
op: 'set',
var: 'num_of_categories',
value: {
choices: {
op: 'array',
values: [1, 5, 10],
},
unit: {
op: 'get',
var: 'userid',
},
op: 'uniformChoice',
},
},
],
};
const interpreterInstance = new planout.Interpreter(
script,
this.getSalt(),
args
);
const results = interpreterInstance.getParams();
Object.keys(results).forEach(result => {
params.set(result, results[result]);
});
return interpreterInstance.inExperiment;
}
// The equivalent works
//assign(params, args) {
// params.set('num_of_categories', new planout.Ops.Random.UniformChoice({choices: [1,5,10],
// 'unit': args.userid}));
//}
configureLogger() {
return;
}
setup() {
this.name = 'exp0';
}
log(event) {
console.log(event);
}
getParamNames() {
return this.getDefaultParamNames();
}
previouslyLogged() {
return this._exposureLogged;
}
}
// failure: will always return undefined
const try1 = new Repro({userid: 0});
console.log(try1.get('num_of_categories'));
// works
const try2 = new Repro({userid: '0'});
console.log(try2.get('num_of_categories'));
// works
const try3 = new Repro({userid: 1});
console.log(try3.get('num_of_categories'));
Guy Aridor commented
Thanks for reporting this, I'll look into it tonight