2021-02-17 08:52:46 -05:00
|
|
|
const { ObjectId } = require('mongodb')
|
2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2021-02-17 08:52:46 -05:00
|
|
|
|
2021-03-23 06:18:28 -04:00
|
|
|
const EXISTING_UI = { newLogsUI: false, subvariant: null }
|
|
|
|
const NEW_UI_WITH_POPUP = {
|
|
|
|
newLogsUI: true,
|
2021-04-27 03:52:58 -04:00
|
|
|
subvariant: 'new-logs-ui-with-popup',
|
2021-03-23 06:18:28 -04:00
|
|
|
}
|
|
|
|
const NEW_UI_WITHOUT_POPUP = {
|
|
|
|
newLogsUI: true,
|
2021-04-27 03:52:58 -04:00
|
|
|
subvariant: 'new-logs-ui-without-popup',
|
2021-03-23 06:18:28 -04:00
|
|
|
}
|
|
|
|
|
2021-07-05 09:04:13 -04:00
|
|
|
function _getVariantForPercentile(percentile) {
|
|
|
|
// The current percentages are:
|
|
|
|
// - 33% New UI with pop-up (originally, 5%)
|
|
|
|
// - 33% New UI without pop-up (originally, 5%)
|
|
|
|
// - 34% Existing UI
|
|
|
|
// To ensure group stability, the implementation below respects the original partitions
|
|
|
|
// for the new UI variants: [0, 5[ and [5,10[.
|
|
|
|
// Two new partitions are added: [10, 38[ and [38, 66[. These represent an extra 28p.p.
|
|
|
|
// which, with to the original 5%, add up to 33%.
|
2021-03-23 06:18:28 -04:00
|
|
|
|
2021-07-05 09:04:13 -04:00
|
|
|
if (percentile < 5) {
|
|
|
|
// This partition represents the "New UI with pop-up" group in the original roll-out (5%)
|
2021-03-23 06:18:28 -04:00
|
|
|
return NEW_UI_WITH_POPUP
|
2021-07-05 09:04:13 -04:00
|
|
|
} else if (percentile >= 5 && percentile < 10) {
|
|
|
|
// This partition represents the "New UI without pop-up" group in the original roll-out (5%)
|
|
|
|
return NEW_UI_WITHOUT_POPUP
|
|
|
|
} else if (percentile >= 10 && percentile < 38) {
|
|
|
|
// This partition represents an extra 28% of users getting the "New UI with pop-up"
|
|
|
|
return NEW_UI_WITH_POPUP
|
|
|
|
} else if (percentile >= 38 && percentile < 66) {
|
|
|
|
// This partition represents an extra 28% of users getting the "New UI without pop-up"
|
2021-03-23 06:18:28 -04:00
|
|
|
return NEW_UI_WITHOUT_POPUP
|
|
|
|
} else {
|
|
|
|
return EXISTING_UI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNewLogsUIVariantForUser(user) {
|
2021-07-05 09:04:13 -04:00
|
|
|
const { _id: userId, alphaProgram: isAlphaUser } = user
|
|
|
|
const isSaaS = Boolean(Settings.overleaf)
|
|
|
|
|
|
|
|
if (!userId || !isSaaS) {
|
2021-03-23 06:18:28 -04:00
|
|
|
return EXISTING_UI
|
2021-02-17 08:52:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const userIdAsPercentile = (ObjectId(userId).getTimestamp() / 1000) % 100
|
|
|
|
|
|
|
|
if (isAlphaUser) {
|
2021-03-23 06:18:28 -04:00
|
|
|
return NEW_UI_WITH_POPUP
|
2021-02-17 08:52:46 -05:00
|
|
|
} else {
|
2021-07-05 09:04:13 -04:00
|
|
|
return _getVariantForPercentile(userIdAsPercentile)
|
2021-02-17 08:52:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2021-04-27 03:52:58 -04:00
|
|
|
getNewLogsUIVariantForUser,
|
2021-02-17 08:52:46 -05:00
|
|
|
}
|