Skip to content

Commit

Permalink
Merge pull request #16 from HubSpot/guy_get_params_log
Browse files Browse the repository at this point in the history
Add getParams as a function on the namespace class
  • Loading branch information
Guy committed Sep 14, 2015
2 parents 505248f + e90b81d commit 9033b31
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 125 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*Changes in 1.2
- The return value of assign now determines whether or not an exposure event will
be automatically logged. If either a truth-y value or nothing is returned from assign, then exposure
will be logged. If a false-y value (excluding undefined) is returned then exposure will not be logged.

-getParams(experimentName) is now a function on the namespace class
43 changes: 26 additions & 17 deletions __tests__/testNamespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,12 @@ describe("Test namespace module", function() {
});

it('should respect auto exposure logging being set to off', function() {
class ExperimentNoExposure extends Experiment {
configureLogger() {
return;
}

log(data) {
globalLog.push(data);
}

previouslyLogged() {
return false;
}

class ExperimentNoExposure extends BaseExperiment {
setup() {
this.setAutoExposureLogging(false);
this.name = 'test_name';
}

getParamNames() {
return this.getDefaultParamNames();
}

assign(params, args) {
params.set('test', 1)
}
Expand Down Expand Up @@ -232,4 +216,29 @@ describe("Test namespace module", function() {
expect(globalLog.length).toEqual(1);
});

it('should work with getParams', () => {
class SimpleExperiment extends BaseExperiment {
assign(params, args) {
params.set('test', 1)
}
};
class TestNamespace2 extends BaseTestNamespace {
setupExperiments() {
this.addExperiment('SimpleExperiment', SimpleExperiment, 100);
}
};
class TestNamespace extends BaseTestNamespace {
setupExperiments() {
return;
}
}
var namespace = new TestNamespace({'userid': 'hi', 'foo': 1, 'bar': 1});
namespace.getParams('SimpleExperiment');
expect(globalLog.length).toEqual(0);
var namespace2 = new TestNamespace2({'userid': 'hi', 'foo': 1, 'bar': 1});
var params = namespace2.getParams('SimpleExperiment');
expect(globalLog.length).toEqual(1);
expect(params).toEqual({'test': 1});
});

});
224 changes: 121 additions & 103 deletions dist/planout.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ return /******/ (function(modules) { // webpackBootstrap

var _assignment2 = _interopRequireDefault(_assignment);

var _libUtils = __webpack_require__(8);
var _libUtils = __webpack_require__(7);

var Experiment = (function () {
function Experiment(inputs) {
Expand Down Expand Up @@ -390,9 +390,9 @@ return /******/ (function(modules) { // webpackBootstrap

var _assignment2 = _interopRequireDefault(_assignment);

var _opsUtils = __webpack_require__(7);
var _opsUtils = __webpack_require__(8);

var _libUtils = __webpack_require__(8);
var _libUtils = __webpack_require__(7);

var Interpreter = (function () {
function Interpreter(serialization, experimentSalt, inputs, environment) {
Expand Down Expand Up @@ -528,7 +528,7 @@ return /******/ (function(modules) { // webpackBootstrap

var _sha12 = _interopRequireDefault(_sha1);

var _libUtils = __webpack_require__(8);
var _libUtils = __webpack_require__(7);

var _bignumberJs = __webpack_require__(11);

Expand Down Expand Up @@ -827,9 +827,9 @@ return /******/ (function(modules) { // webpackBootstrap

var _base = __webpack_require__(9);

var _utils = __webpack_require__(7);
var _utils = __webpack_require__(8);

var _libUtils = __webpack_require__(8);
var _libUtils = __webpack_require__(7);

var Literal = (function (_PlanOutOp) {
function Literal() {
Expand Down Expand Up @@ -1538,18 +1538,18 @@ return /******/ (function(modules) { // webpackBootstrap

var _opsRandomJs = __webpack_require__(3);

var _libUtilsJs = __webpack_require__(8);
var _libUtilsJs = __webpack_require__(7);

var DefaultExperiment = (function (_BaseExperiment) {
var DefaultExperiment = (function (_Experiment) {
function DefaultExperiment() {
_classCallCheck(this, DefaultExperiment);

if (_BaseExperiment != null) {
_BaseExperiment.apply(this, arguments);
if (_Experiment != null) {
_Experiment.apply(this, arguments);
}
}

_inherits(DefaultExperiment, _BaseExperiment);
_inherits(DefaultExperiment, _Experiment);

_createClass(DefaultExperiment, [{
key: "configureLogger",
Expand Down Expand Up @@ -1579,7 +1579,7 @@ return /******/ (function(modules) { // webpackBootstrap
}]);

return DefaultExperiment;
})(BaseExperiment);
})(_experimentJs2["default"]);

var Namespace = (function () {
function Namespace() {
Expand Down Expand Up @@ -1832,6 +1832,24 @@ return /******/ (function(modules) { // webpackBootstrap
}
}
}
}, {
key: "getParams",
value: function getParams(experimentName) {
_get(Object.getPrototypeOf(SimpleNamespace.prototype), "requireExperiment", this).call(this);
if (this._experiment && this.getOriginalExperimentName() === experimentName) {
return this._experiment.getParams();
} else {
return null;
}
}
}, {
key: "getOriginalExperimentName",
value: function getOriginalExperimentName() {
if (this._experiment) {
return this._experiment.getName().split("-")[1];
}
return null;
}
}, {
key: "get",
value: function get(name, defaultVal) {
Expand Down Expand Up @@ -1916,7 +1934,7 @@ return /******/ (function(modules) { // webpackBootstrap

var _opsRandom = __webpack_require__(3);

var _libUtils = __webpack_require__(8);
var _libUtils = __webpack_require__(7);

var Assignment = (function () {
function Assignment(experimentSalt, overrides) {
Expand Down Expand Up @@ -2026,95 +2044,6 @@ return /******/ (function(modules) { // webpackBootstrap

/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

var _core = __webpack_require__(4);

var core = _interopRequireWildcard(_core);

var _random = __webpack_require__(3);

var random = _interopRequireWildcard(_random);

var _libUtils = __webpack_require__(8);

var initFactory = function initFactory() {
return {
'literal': core.Literal,
'get': core.Get,
'set': core.Set,
'seq': core.Seq,
'return': core.Return,
'index': core.Index,
'array': core.Arr,
'equals': core.Equals,
'and': core.And,
'or': core.Or,
'>': core.GreaterThan,
'<': core.LessThan,
'>=': core.GreaterThanOrEqualTo,
'<=': core.LessThanOrEqualTo,
'%': core.Mod,
'/': core.Divide,
'not': core.Not,
'round': core.Round,
'negative': core.Negative,
'min': core.Min,
'max': core.Max,
'length': core.Length,
'coalesce': core.Coalesce,
'map': core.Map,
'cond': core.Cond,
'product': core.Product,
'sum': core.Sum,
'randomFloat': random.RandomFloat,
'randomInteger': random.RandomInteger,
'bernoulliTrial': random.BernoulliTrial,
'bernoulliFilter': random.BernoulliFilter,
'uniformChoice': random.UniformChoice,
'weightedChoice': random.WeightedChoice,
'sample': random.Sample
};
};

var operators = initFactory();

var isOperator = function isOperator(op) {
return (0, _libUtils.isObject)(op) && op.op;
};

var operatorInstance = function operatorInstance(params) {
var op = params.op;
if (!operators[op]) {
throw 'Unknown Operator {op}';
}

return new operators[op](params);
};

var StopPlanOutException = function StopPlanOutException(inExperiment) {
_classCallCheck(this, StopPlanOutException);

this.inExperiment = inExperiment;
};

exports.initFactory = initFactory;
exports.isOperator = isOperator;
exports.operatorInstance = operatorInstance;
exports.StopPlanOutException = StopPlanOutException;

/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {

/* Most of these functions are from the wonderful Underscore package http://underscorejs.org/
Expand Down Expand Up @@ -2404,6 +2333,95 @@ return /******/ (function(modules) { // webpackBootstrap
exports['default'] = { deepCopy: deepCopy, map: map, reduce: reduce, getParameterByName: getParameterByName, forEach: forEach, trimTrailingWhitespace: trimTrailingWhitespace, hasKey: hasKey, shallowCopy: shallowCopy, extend: extend, isObject: isObject, isArray: isArray, range: range };
module.exports = exports['default'];

/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {

'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

var _core = __webpack_require__(4);

var core = _interopRequireWildcard(_core);

var _random = __webpack_require__(3);

var random = _interopRequireWildcard(_random);

var _libUtils = __webpack_require__(7);

var initFactory = function initFactory() {
return {
'literal': core.Literal,
'get': core.Get,
'set': core.Set,
'seq': core.Seq,
'return': core.Return,
'index': core.Index,
'array': core.Arr,
'equals': core.Equals,
'and': core.And,
'or': core.Or,
'>': core.GreaterThan,
'<': core.LessThan,
'>=': core.GreaterThanOrEqualTo,
'<=': core.LessThanOrEqualTo,
'%': core.Mod,
'/': core.Divide,
'not': core.Not,
'round': core.Round,
'negative': core.Negative,
'min': core.Min,
'max': core.Max,
'length': core.Length,
'coalesce': core.Coalesce,
'map': core.Map,
'cond': core.Cond,
'product': core.Product,
'sum': core.Sum,
'randomFloat': random.RandomFloat,
'randomInteger': random.RandomInteger,
'bernoulliTrial': random.BernoulliTrial,
'bernoulliFilter': random.BernoulliFilter,
'uniformChoice': random.UniformChoice,
'weightedChoice': random.WeightedChoice,
'sample': random.Sample
};
};

var operators = initFactory();

var isOperator = function isOperator(op) {
return (0, _libUtils.isObject)(op) && op.op;
};

var operatorInstance = function operatorInstance(params) {
var op = params.op;
if (!operators[op]) {
throw 'Unknown Operator {op}';
}

return new operators[op](params);
};

var StopPlanOutException = function StopPlanOutException(inExperiment) {
_classCallCheck(this, StopPlanOutException);

this.inExperiment = inExperiment;
};

exports.initFactory = initFactory;
exports.isOperator = isOperator;
exports.operatorInstance = operatorInstance;
exports.StopPlanOutException = StopPlanOutException;

/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
Expand All @@ -2420,7 +2438,7 @@ return /******/ (function(modules) { // webpackBootstrap

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var _libUtils = __webpack_require__(8);
var _libUtils = __webpack_require__(7);

var PlanOutOp = (function () {
function PlanOutOp(args) {
Expand Down
2 changes: 1 addition & 1 deletion dist/planout.map.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/planout.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9033b31

Please sign in to comment.