This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change URL suggestions to consider last access timestamp and access c…
…ount * Re-order results to show history items before bookmark items * Record number of times site is visited * Re-order history items based on number of times visited and last access timestamp * Update and create tests Fixes: #3049 Auditors: @bbondy Test plan: A new attribute, count, is added to history items in the sites section of save-session-1. This attribute records the number of times a site has been accessed. The test plan is broken in two components, one to verify the count attribute is incremented on access, the second to verify that the count and last access time are used when sorting history suggestions. Scenario 1 Part A 1. Clear save-session-1 2. Access a site 3. Close browser 4. Verify that the count attribute for the saved site in save-session-1 has a value of 1 Part B 1. Open browser 2. Navigate to site from Part A 3. Close browser 4. Verify that the count attribute for the saved site in save-session-1 has an incremented value Scenario 2 1. Clear save-session-1 2. Open browser 3. Visit gm.com and gm.ca 4. Close browser 5. Verify that the count attributes of the two new sites are identical (1) 6. Open browser to a new tab 7. Enter ‘gm’ into the url bar 8. Verify that the most recently visited of the two gm sites is the first entry in the history auto-suggest list
- Loading branch information
Showing
6 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const appConfig = require('../../../js/constants/appConfig') | ||
|
||
const sigmoid = (t) => { | ||
return 1 / (1 + Math.pow(Math.E, -t)) | ||
} | ||
|
||
const ONE_DAY = 1000 * 60 * 60 * 24 | ||
|
||
/* | ||
* Calculate the sorting priority for a history item based on number of | ||
* accesses and time since last access | ||
* | ||
* @param {number} count - The number of times this site has been accessed | ||
* @param {number} currentTime - Current epoch millisecnds | ||
* @param {boolean} lastAccessedTime - Epoch milliseconds of last access | ||
* | ||
*/ | ||
module.exports.sortingPriority = (count, currentTime, lastAccessedTime, ageDecayConstant) => { | ||
// number of days since last access (with fractional component) | ||
const ageInDays = (currentTime - (lastAccessedTime || currentTime)) / ONE_DAY | ||
// decay factor based on age | ||
const ageFactor = 1 - ((sigmoid(ageInDays / ageDecayConstant) - 0.5) * 2) | ||
// sorting priority | ||
// console.log(count, ageInDays, ageFactor, count * ageFactor) | ||
return count * ageFactor | ||
} | ||
|
||
/* | ||
* Sort two history items by priority | ||
* | ||
* @param {ImmutableObject} s1 - first history item | ||
* @param {ImmutableObject} s2 - second history item | ||
* | ||
* Return the relative order of two site entries taking into consideration | ||
* the number of times the site has been accessed and the length of time | ||
* since the last access. | ||
* | ||
* The base sort order is determined by the count attribute of the site | ||
* entry. A modifier is then computed based on the length of time since | ||
* the last access. A sigmoid function is used to weight more recent | ||
* entries higher than entries in the past. This is not a linear function, | ||
* entries in the far past with many counts will still be discounted | ||
* heavily as the sigmoid modifier will cancel most of the count | ||
* base parameter. | ||
* | ||
* Below is a sample comparison of two sites that have been accessed | ||
* recently (but not at the identical time). Each site is accessed | ||
* 9 times. The count is discounted by an aging factor calculated | ||
* using the sigmoid decay function. | ||
* | ||
* http://www.gm.ca/gm/ | ||
* | ||
* ageInDays 0.17171469907407408 | ||
* ageFactor 0.9982828546969802 | ||
* count 9 | ||
* priority 0.9982828546969802 | ||
* | ||
* http://www.gm.com/index.html | ||
* | ||
* ageInDays 0.17148791666666666 | ||
* ageFactor 0.9982851225143763 | ||
* count 9 | ||
* priority 0.9982851225143763 | ||
* | ||
*/ | ||
module.exports.sortByAccessCountWithAgeDecay = (s1, s2) => { | ||
const s1Priority = module.exports.sortingPriority( | ||
s1.get('count') || 0, | ||
(new Date()).getTime(), | ||
s1.get('lastAccessedTime') || (new Date()).getTime(), | ||
appConfig.urlSuggestions.ageDecayConstant | ||
) | ||
const s2Priority = module.exports.sortingPriority( | ||
s2.get('count') || 0, | ||
(new Date()).getTime(), | ||
s2.get('lastAccessedTime') || (new Date()).getTime(), | ||
appConfig.urlSuggestions.ageDecayConstant | ||
) | ||
return s2Priority - s1Priority | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* global describe, it */ | ||
const suggestion = require('../../../app/renderer/lib/suggestion') | ||
const assert = require('assert') | ||
|
||
require('../braveUnit') | ||
|
||
const AGE_DECAY = 50 | ||
|
||
describe('suggestion', function () { | ||
it('sorts sites correctly', function () { | ||
assert.ok(suggestion.sortingPriority(10, 100, 50, AGE_DECAY) > suggestion.sortingPriority(10, 100, 40, AGE_DECAY), 'newer sites with equal access counts sort earlier') | ||
assert.ok(suggestion.sortingPriority(10, 100, 50, AGE_DECAY) < suggestion.sortingPriority(11, 100, 40, AGE_DECAY), 'Sites with higher access counts sort earlier (unless time delay overriden)') | ||
assert.ok(suggestion.sortingPriority(10, 10000000000, 10000000000, AGE_DECAY) > suggestion.sortingPriority(11, 10000000000, 1000000000, AGE_DECAY), 'much newer sites without lower counts sort with higher priority') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters