// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.stats.experiment

import com.intellij.internal.statistic.DeviceIdManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.registry.Registry

/*
 * For now, we decide about AB experiment inside IDE using user id and salt
 */
class EmulatedExperiment {
    companion object {
        const val GROUP_A_EXPERIMENT_VERSION: Int = 7
        const val GROUP_B_EXPERIMENT_VERSION: Int = 8
        const val IS_ENABLED = true

        fun shouldRank(experimentVersion: Int): Boolean {
            return experimentVersion == GROUP_B_EXPERIMENT_VERSION && !Registry.`is`("completion.stats.exit.experiment")
        }
    }

    fun emulate(experimentVersion: Int, performExperiment: Boolean, salt: String): Int? {
        val application = ApplicationManager.getApplication()
        if (!application.isEAP || application.isUnitTestMode || experimentVersion != 2 || performExperiment || !IS_ENABLED) {
            return null
        }

        val userId = DeviceIdManager.getOrGenerateId()
        val hash = (userId + salt).hashCode() % 16
        return when (hash) {
            3 -> GROUP_A_EXPERIMENT_VERSION
            4 -> GROUP_B_EXPERIMENT_VERSION
            else -> null
        }
    }
}
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.stats.experiment

import com.intellij.internal.statistic.DeviceIdManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.registry.Registry
import kotlin.math.abs

/*
 * For now, we decide about AB experiment inside IDE using user id and salt
 */
class EmulatedExperiment {
    companion object {
        const val GROUP_A_EXPERIMENT_VERSION: Int = 7
        const val GROUP_B_EXPERIMENT_VERSION: Int = 8
        const val IS_ENABLED = true

        fun shouldRank(experimentVersion: Int): Boolean {
            return experimentVersion == GROUP_B_EXPERIMENT_VERSION && !Registry.`is`("completion.stats.exit.experiment")
        }
    }

    fun emulate(experimentVersion: Int, performExperiment: Boolean, salt: String): Int? {
        val application = ApplicationManager.getApplication()
        if (!application.isEAP || application.isUnitTestMode || experimentVersion != 2 || performExperiment || !IS_ENABLED) {
            return null
        }

        val userId = DeviceIdManager.getOrGenerateId()
        val hash = abs((userId + salt).hashCode()) % 8
        return when (hash) {
            3 -> GROUP_A_EXPERIMENT_VERSION
            4 -> GROUP_B_EXPERIMENT_VERSION
            else -> null
        }
    }
}
Increase the number of AB experiment participants (x4)
[stats-collector] Increase the number of AB experiment participants (x4)

GitOrigin-RevId: e56710dffe69f4bafa7be3805c3f0d60e90c0529
allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community