From 0c77e733cf3943decd1e7caca8cade659c640e84 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Wed, 5 Apr 2017 02:09:11 +0200 Subject: [PATCH] Unification of minVisit parameter More info: https://github.com/brave/browser-laptop/pull/8066 --- README.md | 8 ++++---- index.js | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 220a359..e3e1c6c 100644 --- a/README.md +++ b/README.md @@ -162,13 +162,13 @@ In order to calculate the score, options can be provided when creating the object. The defaults are: - { minDuration : 10 * 1000 + { minPublisherDuration : 8 * 1000 , numFrames : 30 , frameSize : 24 * 60 * 60 * 1000 } When `addVisit` is invoked, -the duration must be at least `minDuration` milliseconds in length. +the duration must be at least `minPublisherDuration` milliseconds in length. If so, then one or more "scorekeepers" are run to calculate the score for the visit, using both the `options` and `props`. @@ -198,8 +198,8 @@ only the `concave` scorekeeper makes use of these. The defaults are: { _d : 1 / (30 * 1000) // 0.0000333... - , _a : (1 / (_d * 2)) - minDuration // 5000 - , _b : minDuration - _a // 5000 + , _a : (1 / (_d * 2)) - minPublisherDuration // 5000 + , _b : minPublisherDuration - _a // 5000 } The sliding window consist of `numFrames` frames, diff --git a/index.js b/index.js index 24f3173..6d3b824 100644 --- a/index.js +++ b/index.js @@ -113,11 +113,10 @@ var Synopsis = function (options) { this.options = options || {} this.options.scorekeepers = underscore.keys(Synopsis.prototype.scorekeepers) - underscore.defaults(this.options, { minDuration: 10 * 1000, + underscore.defaults(this.options, { minPublisherDuration: 8 * 1000, numFrames: 30, frameSize: 24 * 60 * 60 * 1000, _d: 1 / (30 * 1000), - minPublisherDuration: 0, minPublisherVisits: 0 }) if (!this.options.scorekeepers[this.options.scorekeeper]) { @@ -128,10 +127,10 @@ var Synopsis = function (options) { this.options.emptyScores[scorekeeper] = 0 }, this) - underscore.defaults(this.options, { _a: (1 / (this.options._d * 2)) - this.options.minDuration }) + underscore.defaults(this.options, { _a: (1 / (this.options._d * 2)) - this.options.minPublisherDuration }) this.options._a2 = this.options._a * 2 this.options._a4 = this.options._a2 * 2 - underscore.defaults(this.options, { _b: this.options.minDuration - this.options._a }) + underscore.defaults(this.options, { _b: this.options.minPublisherDuration - this.options._a }) this.options._b2 = this.options._b * this.options._b underscore.keys(this.publishers).forEach(function (publisher) { @@ -164,7 +163,7 @@ var Synopsis = function (options) { Synopsis.prototype.addVisit = function (location, duration, markup) { var publisher - if (duration < this.options.minDuration) return + if (duration < this.options.minPublisherDuration) return try { publisher = getPublisher(location, markup) } catch (ex) { return } if (!publisher) return @@ -205,7 +204,7 @@ Synopsis.prototype.addPublisher = function (publisher, props) { if (!props) return if (typeof props === 'number') props = { duration: props } - if ((!props.stickyP) && (props.duration < this.options.minDuration)) return + if ((!props.stickyP) && (props.duration < this.options.minPublisherDuration)) return scores = this.scores(props) if (!scores) return