2021-02-17 08:52:46 -05:00
|
|
|
const { ObjectId } = require('mongodb')
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
|
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-06-28 06:43:44 -04:00
|
|
|
function _getVariantForPercentile(
|
|
|
|
percentile,
|
|
|
|
newLogsUIWithPopupPercentage,
|
|
|
|
newLogsUIWithoutPopupPercentage
|
|
|
|
) {
|
|
|
|
// The thresholds below are upper thresholds
|
|
|
|
const newLogsUIThreshold = newLogsUIWithPopupPercentage
|
|
|
|
const newLogsUIWithoutPopupThreshold =
|
|
|
|
newLogsUIWithPopupPercentage + newLogsUIWithoutPopupPercentage
|
2021-03-23 06:18:28 -04:00
|
|
|
|
2021-06-28 06:43:44 -04:00
|
|
|
// The partitions for each of the variants (range is 0 to 99) are defined as:
|
|
|
|
// * New UI with pop-up: 0 to newLogsUIThreshold (exc)
|
|
|
|
// * New UI without pop-up: newLogsUIThreshold (inc) to newLogsUIWithoutPopupThreshold (exc)
|
|
|
|
// * Existing UI: newLogsUIWithoutPopupThreshold (inc) to 99
|
|
|
|
if (percentile < newLogsUIThreshold) {
|
2021-03-23 06:18:28 -04:00
|
|
|
return NEW_UI_WITH_POPUP
|
2021-06-28 06:43:44 -04:00
|
|
|
} else if (
|
|
|
|
percentile >= newLogsUIThreshold &&
|
|
|
|
percentile < newLogsUIWithoutPopupThreshold
|
|
|
|
) {
|
2021-03-23 06:18:28 -04:00
|
|
|
return NEW_UI_WITHOUT_POPUP
|
|
|
|
} else {
|
|
|
|
return EXISTING_UI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNewLogsUIVariantForUser(user) {
|
2021-06-28 06:43:44 -04:00
|
|
|
const {
|
|
|
|
_id: userId,
|
|
|
|
alphaProgram: isAlphaUser,
|
|
|
|
betaProgram: isBetaUser,
|
|
|
|
} = user
|
|
|
|
if (!userId) {
|
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-06-28 06:43:44 -04:00
|
|
|
} else if (isBetaUser) {
|
|
|
|
return _getVariantForPercentile(
|
|
|
|
userIdAsPercentile,
|
|
|
|
Settings.logsUIPercentageBeta,
|
|
|
|
Settings.logsUIPercentageWithoutPopupBeta
|
|
|
|
)
|
2021-02-17 08:52:46 -05:00
|
|
|
} else {
|
2021-06-28 06:43:44 -04:00
|
|
|
return _getVariantForPercentile(
|
|
|
|
userIdAsPercentile,
|
|
|
|
Settings.logsUIPercentage,
|
|
|
|
Settings.logsUIPercentageWithoutPopup
|
|
|
|
)
|
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
|
|
|
}
|