[build statistics] Truncate long values instead of randomization
This commit is contained in:
+17
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.statistics.metrics
|
||||
import org.jetbrains.kotlin.statistics.ValueAnonymizer
|
||||
import org.jetbrains.kotlin.statistics.anonymizeComponentVersion
|
||||
import org.jetbrains.kotlin.statistics.sha256
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
enum class StringOverridePolicy: IMetricContainerFactory<String> {
|
||||
@@ -105,10 +106,22 @@ enum class NumberAnonymizationPolicy : ValueAnonymizer<Long> {
|
||||
override fun anonymize(t: Long) = t
|
||||
},
|
||||
RANDOM_10_PERCENT {
|
||||
override fun anonymize(t: Long) = (t + t * 0.1 * Math.random()).toLong()
|
||||
},
|
||||
RANDOM_01_PERCENT {
|
||||
override fun anonymize(t: Long) = (t + t * 0.01 * Math.random()).toLong()
|
||||
override fun anonymize(t: Long): Long {
|
||||
if (abs(t) < 10) return t
|
||||
val sign = if (t < 0)
|
||||
-1
|
||||
else
|
||||
1
|
||||
val absT = t * sign
|
||||
var div: Long = 1
|
||||
while (div * 10 < absT) {
|
||||
div *= 10
|
||||
}
|
||||
return sign * if (absT / div < 2)
|
||||
absT - absT % (div / 10)
|
||||
else
|
||||
absT - absT % div
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
import org.jetbrains.kotlin.statistics.metrics.NumberAnonymizationPolicy.RANDOM_10_PERCENT
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
class MetricPolicyTest {
|
||||
|
||||
@Test
|
||||
fun numberAnonimization() {
|
||||
assertEquals(-200, RANDOM_10_PERCENT.anonymize(-234))
|
||||
assertEquals(-120, RANDOM_10_PERCENT.anonymize(-123))
|
||||
assertEquals(-9, RANDOM_10_PERCENT.anonymize(-9))
|
||||
assertEquals(0, RANDOM_10_PERCENT.anonymize(0))
|
||||
assertEquals(1, RANDOM_10_PERCENT.anonymize(1))
|
||||
assertEquals(5, RANDOM_10_PERCENT.anonymize(5))
|
||||
assertEquals(9, RANDOM_10_PERCENT.anonymize(9))
|
||||
assertEquals(10, RANDOM_10_PERCENT.anonymize(10))
|
||||
assertEquals(19, RANDOM_10_PERCENT.anonymize(19))
|
||||
assertEquals(20, RANDOM_10_PERCENT.anonymize(29))
|
||||
assertEquals(120, RANDOM_10_PERCENT.anonymize(123))
|
||||
assertEquals(200, RANDOM_10_PERCENT.anonymize(234))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user