commonMain.jetbrains.datalore.plot.base.data.Dummies.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.plot.base.data
import jetbrains.datalore.plot.base.DataFrame
object Dummies {
private const val PREFIX = "__"
fun isDummyVar(varName: String): Boolean {
if (varName.isNotBlank() && varName.length > PREFIX.length && varName.startsWith(
PREFIX
)
) {
val numStr = varName.substring(PREFIX.length)
return numStr.matches("[0-9]+".toRegex())
}
return false
}
fun dummyNames(count: Int): List {
val l = ArrayList()
for (i in 0 until count) {
l.add(PREFIX + i)
}
return l
}
fun newDummy(varName: String): DataFrame.Variable {
require(isDummyVar(varName)) { "Not a dummy var name" }
// no label
return DataFrame.Variable(varName, DataFrame.Variable.Source.ORIGIN, "")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy