Values + Binary to kotlin

This commit is contained in:
Alexander Nozik 2018-04-25 22:20:47 +03:00
parent 42a69d1334
commit 42594e119e
15 changed files with 51 additions and 51 deletions

View File

@ -122,8 +122,8 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
//update parameters from meta
meta.optValue("pga").ifPresent {
logger.info("Setting dynamic range to " + it.getInt())
val response = sendAndWait("g" + it.getInt()).trim { it <= ' ' }
logger.info("Setting dynamic range to " + it.int)
val response = sendAndWait("g" + it.int).trim { it <= ' ' }
if (response.contains("=")) {
updateState(PGA, Integer.parseInt(response.substring(4)))
} else {

View File

@ -84,26 +84,26 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
//output values of current and voltage
private var outCurrent by valueState("outCurrent", getter = { s2d(controller.getParameter(address, "PC")) }) { _, value ->
setCurrent(value.getDouble())
setCurrent(value.double)
return@valueState value
}.doubleDelegate
private var outVoltage = valueState("outVoltage", getter = { s2d(controller.getParameter(address, "PV")) }) { _, value ->
if (!controller.setParameter(address, "PV", value.getDouble())) {
if (!controller.setParameter(address, "PV", value.double)) {
notifyError("Can't set the target voltage")
}
return@valueState value
}.doubleDelegate
val output = valueState("output", getter = { controller.talk(address, "OUT?") == "OK" }) { _, value ->
setOutputMode(value.getBoolean())
if (!value.getBoolean()) {
setOutputMode(value.boolean)
if (!value.boolean) {
status = MagnetStatus.OFF
}
}
val monitoring = valueState("monitoring", getter = { monitorTask != null }) { _, value ->
if (value.getBoolean()) {
if (value.boolean) {
startMonitorTask()
} else {
stopMonitorTask()
@ -115,7 +115,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
*
*/
val updating = valueState("updating", getter = { updateTask != null }) { _, value ->
if (value.getBoolean()) {
if (value.boolean) {
startUpdateTask()
} else {
stopUpdateTask()
@ -235,7 +235,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
stopUpdateTask()
updateTask = repeatOnDeviceThread(Duration.ofMillis(delay)) {
try {
val measuredI = current.readBlocking().getDouble()
val measuredI = current.readBlocking().double
val targetI = target.doubleValue
if (Math.abs(measuredI - targetI) > CURRENT_PRECISION) {
val nextI = nextI(measuredI, targetI)

View File

@ -90,13 +90,13 @@ class MagnetDisplay : DeviceDisplayFX<LambdaMagnet>() {
device.states.getState<ValueState>("status")?.onChange{
runLater {
this.statusLabel.text = it.getString()
this.statusLabel.text = it.string
}
}
device.output.onChange {
Platform.runLater {
if (it.getBoolean()) {
if (it.boolean) {
this.statusLabel.textFill = Color.BLUE
} else {
this.statusLabel.textFill = Color.BLACK
@ -105,7 +105,7 @@ class MagnetDisplay : DeviceDisplayFX<LambdaMagnet>() {
}
device.updating.onChange {
val updateTaskRunning = it.getBoolean()
val updateTaskRunning = it.boolean
runLater {
this.setButton.isSelected = updateTaskRunning
targetIField.isDisable = updateTaskRunning
@ -114,7 +114,7 @@ class MagnetDisplay : DeviceDisplayFX<LambdaMagnet>() {
device.monitoring.onChange {
runLater {
monitorButton.isScaleShape = it.getBoolean()
monitorButton.isScaleShape = it.boolean
}
}

View File

@ -69,17 +69,17 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
val controlled = valueState(CONTROLLED_STATE) { value ->
runOnDeviceThread {
val res = control(value.getBoolean())
val res = control(value.boolean)
updateState(CONTROLLED_STATE, res)
}
}
val filament = valueState("filament") { value ->
selectFilament(value.getInt())
selectFilament(value.int)
}
val filamentOn = valueState("filamentOn") { value ->
setFilamentOn(value.getBoolean())
setFilamentOn(value.boolean)
}
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate

View File

@ -141,7 +141,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
device.filamentOn.asBooleanProperty().bindBidirectional(selectedProperty())
}
deviceStateIndicator(this@MspDisplay, "filamentStatus", false) {
when (it.getString()) {
when (it.string) {
"ON" -> Paint.valueOf("red")
"OFF" -> Paint.valueOf("blue")
"WARM-UP", "COOL-DOWN" -> Paint.valueOf("yellow")
@ -185,13 +185,13 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
val pl = plottables[change.key] as TimePlot?
val value = change.valueAdded
if (pl != null) {
if (value.getDouble() > 0) {
if (value.double > 0) {
pl.put(value)
} else {
pl.put(Value.NULL)
}
val titleBase = pl.config.getString("titleBase")
val title = String.format("%s (%.4g)", titleBase, value.getDouble())
val title = String.format("%s (%.4g)", titleBase, value.double)
pl.configureValue("title", title)
}
}

View File

@ -81,7 +81,7 @@ fun Indicator.bind(connection: DeviceDisplayFX<*>, state: String, transform: ((V
bind(connection.valueStateProperty(state)) {
when {
it.isNull -> Color.GRAY
it.getBoolean() -> Color.GREEN
it.boolean -> Color.GREEN
else -> Color.RED
}
}
@ -119,7 +119,7 @@ fun Node.deviceStateToggle(connection: DeviceDisplayFX<*>, state: String, title:
}
connection.valueStateProperty(state).onChange {
runLater {
isSelected = it?.getBoolean() ?: false
isSelected = it?.boolean ?: false
}
}
}

View File

@ -41,7 +41,7 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
var power by valueState("power", getter = { talk("FP?") == "ON" }) { old, value ->
if (old != value) {
setPowerOn(value.getBoolean())
setPowerOn(value.boolean)
}
}.booleanDelegate

View File

@ -135,7 +135,7 @@ open class VacDisplay : DeviceDisplayFX<Sensor>() {
prefHeight = 60.0
alignment = Pos.CENTER_RIGHT
textProperty().bind(valueProperty)
device.meta.optValue("color").ifPresent { colorValue -> textFill = Color.valueOf(colorValue.getString()) }
device.meta.optValue("color").ifPresent { colorValue -> textFill = Color.valueOf(colorValue.string) }
style {
fontSize = 24.pt
fontWeight = FontWeight.BOLD

View File

@ -85,7 +85,7 @@ interface NumassAnalyzer {
* @return
*/
fun getCount(block: NumassBlock, config: Meta): Long {
return analyze(block, config).getValue(COUNT_KEY).getNumber().toLong()
return analyze(block, config).getValue(COUNT_KEY).number.toLong()
}
/**
@ -96,7 +96,7 @@ interface NumassAnalyzer {
* @return
*/
fun getLength(block: NumassBlock, config: Meta = Meta.empty()): Long {
return analyze(block, config).getValue(LENGTH_KEY).getNumber().toLong()
return analyze(block, config).getValue(LENGTH_KEY).number.toLong()
}
fun getAmplitudeSpectrum(block: NumassBlock, config: Meta = Meta.empty()): Table {
@ -133,7 +133,7 @@ interface NumassAnalyzer {
fun Table.countInWindow(loChannel: Short, upChannel: Short): Long {
return this.rows.filter { row ->
row.getInt(NumassAnalyzer.CHANNEL_KEY) in loChannel..(upChannel - 1)
}.mapToLong { it -> it.getValue(NumassAnalyzer.COUNT_KEY).getNumber().toLong() }.sum()
}.mapToLong { it -> it.getValue(NumassAnalyzer.COUNT_KEY).number.toLong() }.sum()
}
/**
@ -200,10 +200,10 @@ fun Table.withBinning(binSize: Int, loChannel: Int? = null, upChannel: Int? = nu
val builder = ListTable.Builder(format)
var chan = loChannel
?: this.getColumn(NumassAnalyzer.CHANNEL_KEY).stream().mapToInt { it.getInt() }.min().orElse(0)
?: this.getColumn(NumassAnalyzer.CHANNEL_KEY).stream().mapToInt { it.int }.min().orElse(0)
val top = upChannel
?: this.getColumn(NumassAnalyzer.CHANNEL_KEY).stream().mapToInt { it.getInt() }.max().orElse(1)
?: this.getColumn(NumassAnalyzer.CHANNEL_KEY).stream().mapToInt { it.int }.max().orElse(1)
while (chan < top - binSize) {
val count = AtomicLong(0)
@ -216,7 +216,7 @@ fun Table.withBinning(binSize: Int, loChannel: Int? = null, upChannel: Int? = nu
this.rows.filter { row ->
row.getInt(NumassAnalyzer.CHANNEL_KEY) in binLo..(binUp - 1)
}.forEach { row ->
count.addAndGet(row.getValue(NumassAnalyzer.COUNT_KEY, 0).getLong())
count.addAndGet(row.getValue(NumassAnalyzer.COUNT_KEY, 0).long)
countRate.accumulateAndGet(row.getDouble(NumassAnalyzer.COUNT_RATE_KEY, 0.0)) { d1, d2 -> d1 + d2 }
countRateDispersion.accumulateAndGet(Math.pow(row.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY, 0.0), 2.0)) { d1, d2 -> d1 + d2 }
}

View File

@ -2,7 +2,7 @@ package inr.numass.scripts.workspace
import hep.dataforge.actions.ActionUtils
import hep.dataforge.context.Context
import hep.dataforge.context.IOManager
import hep.dataforge.io.IOManager
import inr.numass.NumassPlugin
/**

View File

@ -18,7 +18,7 @@ package inr.numass;
import hep.dataforge.actions.ActionUtils;
import hep.dataforge.context.Context;
import hep.dataforge.context.Global;
import hep.dataforge.context.IOManager;
import hep.dataforge.io.IOManager;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta;
import org.apache.commons.cli.*;

View File

@ -194,7 +194,7 @@ fun getFSS(context: Context, meta: Meta): FSS? {
fun pointExpression(expression: String, point: Values): Double {
val exprParams = HashMap<String, Any>()
//Adding all point values to expression parameters
point.names.forEach { name -> exprParams.put(name, point.getValue(name).value()) }
point.names.forEach { name -> exprParams.put(name, point.getValue(name).value) }
//Adding aliases for commonly used parameters
exprParams.put("T", point.getDouble("length"))
exprParams.put("U", point.getDouble("voltage"))
@ -210,7 +210,7 @@ fun addSetMarkers(frame: JFreeChartFrame, sets: Collection<NumassSet>) {
val paint = Color(0.0f, 0.0f, 1.0f, 0.1f)
sets.stream().forEach {
val start = it.startTime;
val stop = it.meta.optValue("end_time").map { it.getTime() }
val stop = it.meta.optValue("end_time").map { it.time }
.orElse(start.plusSeconds(300))
.minusSeconds(60)
val marker = IntervalMarker(start.toEpochMilli().toDouble(), stop.toEpochMilli().toDouble(), paint)
@ -252,10 +252,10 @@ fun Values.unbox(): Map<String, Any?> {
for (field in this.names) {
val value = this.getValue(field)
val obj: Any? = when (value.type) {
ValueType.BOOLEAN -> value.getBoolean()
ValueType.NUMBER -> value.getDouble()
ValueType.STRING -> value.getString()
ValueType.TIME -> value.getTime()
ValueType.BOOLEAN -> value.boolean
ValueType.NUMBER -> value.double
ValueType.STRING -> value.string
ValueType.TIME -> value.time
ValueType.NULL -> null
}
res.put(field, obj)

View File

@ -68,15 +68,15 @@ class MergeDataAction : ManyToOneAction<Table, Table>() {
return dp1
}
val voltage = dp1.getValue(NumassPoint.HV_KEY).getDouble()
val t1 = dp1.getValue(NumassPoint.LENGTH_KEY).getDouble()
val t2 = dp2.getValue(NumassPoint.LENGTH_KEY).getDouble()
val voltage = dp1.getValue(NumassPoint.HV_KEY).double
val t1 = dp1.getValue(NumassPoint.LENGTH_KEY).double
val t2 = dp2.getValue(NumassPoint.LENGTH_KEY).double
val time = t1 + t2
val total = (dp1.getValue(NumassAnalyzer.COUNT_KEY).getInt() + dp2.getValue(NumassAnalyzer.COUNT_KEY).getInt()).toLong()
val total = (dp1.getValue(NumassAnalyzer.COUNT_KEY).int + dp2.getValue(NumassAnalyzer.COUNT_KEY).int).toLong()
val cr1 = dp1.getValue(NumassAnalyzer.COUNT_RATE_KEY).getDouble()
val cr2 = dp2.getValue(NumassAnalyzer.COUNT_RATE_KEY).getDouble()
val cr1 = dp1.getValue(NumassAnalyzer.COUNT_RATE_KEY).double
val cr2 = dp2.getValue(NumassAnalyzer.COUNT_RATE_KEY).double
val cr = (cr1 * t1 + cr2 * t2) / (t1 + t2)
@ -97,7 +97,7 @@ class MergeDataAction : ManyToOneAction<Table, Table>() {
throw IllegalArgumentException()
}
for (dp in d) {
val uset = dp.getValue(NumassPoint.HV_KEY).getDouble()
val uset = dp.getValue(NumassPoint.HV_KEY).double
if (!points.containsKey(uset)) {
points.put(uset, ArrayList())
}

View File

@ -42,11 +42,11 @@ private fun createSummaryNode(storage: Storage): MetaBuilder {
// .setNode("meta", point.meta)
point.meta.useValue("acquisition_time") {
pointBuilder.setValue("length", it.getDouble())
pointBuilder.setValue("length", it.double)
}
point.meta.useValue("events") {
pointBuilder.setValue("count", it.getList().stream().mapToInt { it.getInt() }.sum())
pointBuilder.setValue("count", it.list.stream().mapToInt { it.int }.sum())
}
setBuilder.putNode(pointBuilder)

View File

@ -30,8 +30,8 @@ object NumassFitScanTask : AbstractTask<FitResult>() {
val scanValues: Value = if (config.hasValue("masses")) {
ListValue(config.getValue("masses")
.getList().stream()
.map { it -> Math.pow(it.getDouble() * 1000, 2.0) }
.list.stream()
.map { it -> Math.pow(it.double * 1000, 2.0) }
.collect(Collectors.toList<Any>())
)
} else {
@ -46,11 +46,11 @@ object NumassFitScanTask : AbstractTask<FitResult>() {
val fitConfig = config.getMeta("fit")
sourceNode.dataStream().forEach { table ->
for (i in 0 until scanValues.getList().size) {
val `val` = scanValues.getList()[i]
for (i in 0 until scanValues.list.size) {
val `val` = scanValues.list[i]
val overrideMeta = MetaBuilder(fitConfig)
val resultName = String.format("%s[%s=%s]", table.name, scanParameter, `val`.getString())
val resultName = String.format("%s[%s=%s]", table.name, scanParameter, `val`.string)
// overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", table.getName(), scanParameter, val.getString()));
if (overrideMeta.hasMeta("params.$scanParameter")) {