Update dependencies and API

This commit is contained in:
Alexander Nozik 2021-11-13 13:30:39 +03:00
parent 91c732a09e
commit 4e590d3e14
108 changed files with 498 additions and 576 deletions

View File

@ -1,65 +0,0 @@
buildscript {
ext.kotlin_version = "1.4.30"
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins{
id 'org.openjfx.javafxplugin' version '0.0.9' apply false
}
allprojects {
apply plugin: 'java'
apply plugin: "org.jetbrains.kotlin.jvm"
group = 'inr.numass'
version = '1.0.0'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile 'org.jetbrains:annotations:16.0.2'
testImplementation group: 'junit', name: 'junit', version: '4.+'
//Spock dependencies. To be removed later
testCompile 'org.codehaus.groovy:groovy-all:2.5.+'
testCompile "org.spockframework:spock-core:1.2-groovy-2.5"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
javaParameters = true
freeCompilerArgs += [
'-Xjvm-default=enable',
"-progressive",
"-Xuse-experimental=kotlin.Experimental"
]
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
javaParameters = true
freeCompilerArgs += [
'-Xjvm-default=enable',
"-progressive",
"-Xuse-experimental=kotlin.Experimental"
]
}
}
}

62
build.gradle.kts Normal file
View File

@ -0,0 +1,62 @@
plugins {
kotlin("jvm") version "1.5.31"
id("org.openjfx.javafxplugin") version "0.0.9" apply false
id("com.github.johnrengelman.shadow") version "7.1.0" apply false
}
allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
group = "inr.numass"
version = "1.1.0"
repositories {
mavenCentral()
jcenter()
}
dependencies {
api(kotlin("reflect"))
api("org.jetbrains:annotations:23.0.0")
testImplementation("junit:junit:4.13.2")
//Spock dependencies. To be removed later
// https://mvnrepository.com/artifact/org.spockframework/spock-core
testImplementation("org.spockframework:spock-core:2.0-groovy-3.0")
}
tasks {
compileJava{
options.encoding = "UTF-8"
}
compileTestJava{
options.encoding = "UTF-8"
}
compileKotlin {
kotlinOptions {
jvmTarget = "16"
javaParameters = true
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xjvm-default=all",
"-progressive",
"-Xuse-experimental=kotlin.Experimental"
)
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "16"
javaParameters = true
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xjvm-default=all",
"-progressive",
"-Xuse-experimental=kotlin.Experimental"
)
}
}
}
}

View File

@ -3,8 +3,8 @@ description = 'dataforge-control'
dependencies {
// Adding dependencies here will add the dependencies to each subproject.
compile project(':dataforge-core')
api project(':dataforge-core')
//TODO consider removing storage dependency
compile project(':dataforge-storage')
compile 'org.scream3r:jssc:2.8.0'
api project(':dataforge-storage')
api 'org.scream3r:jssc:2.8.0'
}

View File

@ -75,7 +75,6 @@ interface Device : AutoConnectible, Metoid, ContextAware, Named, Stateful {
*/
val type: String
@JvmDefault
override val logger: Logger
get() = optConnection(LOGGER_ROLE, Logger::class.java).orElse(context.logger)

View File

@ -1,8 +1,7 @@
description = 'dataforge-core'
dependencies {
compile 'ch.qos.logback:logback-classic:1.2.3'
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.0'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version
compile group: 'javax.cache', name: 'cache-api', version: '1.1.0'
api 'ch.qos.logback:logback-classic:1.2.3'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.0'
api group: 'javax.cache', name: 'cache-api', version: '1.1.0'
}

View File

@ -17,6 +17,6 @@
description = 'json meta type for dataforge'
dependencies {
compile project(":dataforge-core")
compile 'com.github.cliftonlabs:json-simple:3.0.2'
api project(":dataforge-core")
api 'com.github.cliftonlabs:json-simple:3.0.2'
}

View File

@ -22,6 +22,7 @@
package hep.dataforge.io
import hep.dataforge.io.envelopes.MetaType
import java.util.*
class JSONMetaType : MetaType {
override val codes: List<Short> = listOf(0x4a53, 1)//JS
@ -32,7 +33,7 @@ class JSONMetaType : MetaType {
override val writer: MetaStreamWriter = JSONMetaWriter
override val fileNameFilter: (String) -> Boolean = { it.toLowerCase().endsWith(".json") }
override val fileNameFilter: (String) -> Boolean = { it.lowercase(Locale.getDefault()).endsWith(".json") }
}
val jsonMetaType = JSONMetaType()

View File

@ -60,7 +60,7 @@ public class Template implements Metoid, UnaryOperator<Meta> {
}
/**
* Compile template using given meta and value providers.
* api template using given meta and value providers.
*
* @param valueProvider
* @param metaProvider
@ -80,7 +80,7 @@ public class Template implements Metoid, UnaryOperator<Meta> {
parent.replaceChildNode(node, def.getMeta(includePath));
} else {
LoggerFactory.getLogger(MetaUtils.class)
.warn("Can't compile template meta node with name {} not provided", includePath);
.warn("Can't api template meta node with name {} not provided", includePath);
}
}
});

View File

@ -3,12 +3,6 @@ package hep.dataforge
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaNode
import hep.dataforge.names.Name
import java.util.stream.Collectors
import java.util.stream.Stream
fun <T> Stream<T>.toList(): List<T> {
return collect(Collectors.toList())
}
fun String?.asName(): Name {
return Name.of(this)

View File

@ -113,7 +113,7 @@ class CachePlugin(meta: Meta) : BasicPlugin(meta) {
private fun evalData() {
data.goal.run()
(data.goal as Goal<V>).onComplete { res, err ->
data.goal.onComplete { res, err ->
if (err != null) {
result.completeExceptionally(err)
} else {

View File

@ -36,7 +36,6 @@ interface ContextAware {
*/
val context: Context
@JvmDefault
val logger: Logger
get() = if (this is Named) {
LoggerFactory.getLogger(context.name + "." + (this as Named).name)

View File

@ -23,7 +23,6 @@ package hep.dataforge.context
import hep.dataforge.meta.Meta
import hep.dataforge.nullable
import hep.dataforge.toList
import hep.dataforge.utils.MetaFactory
import java.util.*
import java.util.stream.Stream

View File

@ -16,7 +16,6 @@ import hep.dataforge.meta.buildMeta
import hep.dataforge.nullable
import hep.dataforge.providers.Provider
import hep.dataforge.providers.Provides
import hep.dataforge.toList
import java.util.concurrent.Executor
import java.util.function.BiConsumer
import java.util.function.Consumer

View File

@ -28,7 +28,6 @@ import hep.dataforge.io.MetaFileReader
import hep.dataforge.io.envelopes.EnvelopeReader
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.Meta
import hep.dataforge.toList
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path

View File

@ -32,7 +32,6 @@ import hep.dataforge.description.NodeDefs
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.toList
import hep.dataforge.utils.NamingUtils.wildcardMatch
import java.io.IOException
import java.nio.file.Files

View File

@ -60,7 +60,6 @@ interface Binary : Serializable {
*/
val size: Long
@JvmDefault
fun stream(offset: Long): InputStream = stream.also { it.skip(offset) }
/**
@ -71,7 +70,7 @@ interface Binary : Serializable {
* @return
* @throws IOException
*/
@JvmDefault
fun read(offset: Int, size: Int): ByteBuffer {
return buffer.run {
position(offset)
@ -84,7 +83,7 @@ interface Binary : Serializable {
/**
*
*/
@JvmDefault
fun read(start: Int): ByteBuffer {
return read(start, (size - start).toInt())
}

View File

@ -32,7 +32,7 @@ interface Described {
*
* @return
*/
@JvmDefault
val descriptor: NodeDescriptor
get() = Descriptors.forJavaType("node", this.javaClass)
}

View File

@ -57,7 +57,7 @@ interface OutputManager : Plugin {
/**
*
*/
@JvmDefault
operator fun get(stage: String, name: String, type: String? = null): Output {
return get {
OUTPUT_NAME_KEY to name
@ -67,7 +67,7 @@ interface OutputManager : Plugin {
}
@JvmDefault
operator fun get(name: String): Output {
return get {
OUTPUT_NAME_KEY to name

View File

@ -21,6 +21,7 @@ import hep.dataforge.io.MetaStreamWriter
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaUtils
import java.io.*
import java.util.*
val binaryMetaType = BinaryMetaType()
@ -35,7 +36,7 @@ class BinaryMetaType : MetaType {
override val name: String = "binary"
override val fileNameFilter: (String)->Boolean = { str -> str.toLowerCase().endsWith(".meta") }
override val fileNameFilter: (String)->Boolean = { str -> str.lowercase(Locale.getDefault()).endsWith(".meta") }
override val reader: MetaStreamReader = MetaStreamReader { stream, length ->
@ -55,8 +56,8 @@ class BinaryMetaType : MetaType {
@Throws(IOException::class)
override fun write(stream: OutputStream, meta: Meta) {
MetaUtils.writeMeta(ObjectOutputStream(stream), meta)
stream.write('\r'.toInt())
stream.write('\n'.toInt())
stream.write('\r'.code)
stream.write('\n'.code)
}
}

View File

@ -56,7 +56,7 @@ open class DefaultEnvelopeType : EnvelopeType {
/**
* The set of symbols that separates tag from metadata and data
*/
val SEPARATOR = byteArrayOf('\r'.toByte(), '\n'.toByte())
val SEPARATOR = byteArrayOf('\r'.code.toByte(), '\n'.code.toByte())
}
}

View File

@ -45,7 +45,6 @@ interface EnvelopeReader {
/**
* Read the envelope from channel
*/
@JvmDefault
fun read(channel: ReadableByteChannel): Envelope {
return read(Channels.newInputStream(channel))
}
@ -53,7 +52,6 @@ interface EnvelopeReader {
/**
* Read the envelope from buffer (could produce lazy envelope)
*/
@JvmDefault
fun read(buffer: ByteBuffer): Envelope {
return read(BufferChannel(buffer))//read(ByteArrayInputStream(buffer.array()))
}
@ -61,7 +59,6 @@ interface EnvelopeReader {
/**
* Read the envelope from NIO file (could produce lazy envelope)
*/
@JvmDefault
fun read(file: Path): Envelope {
return Files.newByteChannel(file, READ).use { read(it) }
}

View File

@ -33,11 +33,9 @@ interface EnvelopeType {
val name: String
val reader: EnvelopeReader
get() = getReader(emptyMap())
val reader: EnvelopeReader get() = getReader(emptyMap())
val writer: EnvelopeWriter
get() = getWriter(emptyMap())
val writer: EnvelopeWriter get() = getWriter(emptyMap())
fun description(): String
@ -82,7 +80,8 @@ interface EnvelopeType {
}
}
} catch (ex: Exception) {
LoggerFactory.getLogger(EnvelopeType::class.java).warn("Could not infer envelope type of file {} due to exception: {}", path, ex)
LoggerFactory.getLogger(EnvelopeType::class.java)
.warn("Could not infer envelope type of file {} due to exception: {}", path, ex)
null
}

View File

@ -9,7 +9,6 @@ import hep.dataforge.context.Global
import hep.dataforge.io.MetaStreamReader
import hep.dataforge.io.MetaStreamWriter
import hep.dataforge.io.envelopes.Envelope.Companion.META_TYPE_PROPERTY
import hep.dataforge.toList
/**
*

View File

@ -18,7 +18,6 @@ package hep.dataforge.io.envelopes
import hep.dataforge.data.binary.Binary
import hep.dataforge.meta.Meta
import java.io.IOException
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
@ -35,14 +34,12 @@ open class SimpleEnvelope(meta: Meta = Meta.empty(), data: Binary = Binary.EMPTY
override var data: Binary = data
protected set
@Throws(IOException::class)
private fun writeObject(out: ObjectOutputStream) {
DefaultEnvelopeWriter(DefaultEnvelopeType.INSTANCE, binaryMetaType).write(out, this)
private fun writeObject(output: ObjectOutputStream) {
DefaultEnvelopeWriter(DefaultEnvelopeType.INSTANCE, binaryMetaType).write(output, this)
}
@Throws(IOException::class, ClassNotFoundException::class)
private fun readObject(`in`: ObjectInputStream) {
val envelope = DefaultEnvelopeReader.INSTANCE.read(`in`)
private fun readObject(input: ObjectInputStream) {
val envelope = DefaultEnvelopeReader.INSTANCE.read(input)
this.meta = envelope.meta
this.data = envelope.data

View File

@ -24,7 +24,6 @@ import java.nio.ByteBuffer
import java.nio.channels.Channels
import java.nio.channels.ReadableByteChannel
import java.text.ParseException
import java.util.*
import java.util.regex.Pattern
/**
@ -40,13 +39,9 @@ class TaglessEnvelopeType : EnvelopeType {
return "Tagless envelope. Text only. By default uses XML meta with utf encoding and data end auto-detection."
}
override fun getReader(properties: Map<String, String>): EnvelopeReader {
return TaglessReader(properties)
}
override fun getReader(properties: Map<String, String>): EnvelopeReader = TaglessReader(properties)
override fun getWriter(properties: Map<String, String>): EnvelopeWriter {
return TaglessWriter(properties)
}
override fun getWriter(properties: Map<String, String>): EnvelopeWriter = TaglessWriter(properties)
class TaglessWriter(var properties: Map<String, String> = emptyMap()) : EnvelopeWriter {
@ -88,12 +83,8 @@ class TaglessEnvelopeType : EnvelopeType {
class TaglessReader(private val override: Map<String, String>) : EnvelopeReader {
private val BUFFER_SIZE = 1024
@Throws(IOException::class)
override fun read(stream: InputStream): Envelope {
return read(Channels.newChannel(stream))
}
override fun read(stream: InputStream): Envelope = read(Channels.newChannel(stream))
override fun read(channel: ReadableByteChannel): Envelope {
val properties = HashMap(override)
@ -106,8 +97,7 @@ class TaglessEnvelopeType : EnvelopeType {
/**
* Read lines using provided channel and buffer. Buffer state is changed by this operation
*/
private fun readLines(channel: ReadableByteChannel, buffer: ByteBuffer): Sequence<String> {
return sequence {
private fun readLines(channel: ReadableByteChannel, buffer: ByteBuffer): Sequence<String> = sequence {
val builder = ByteArrayOutputStream()
while (true) {
if (!buffer.hasRemaining()) {
@ -123,19 +113,22 @@ class TaglessEnvelopeType : EnvelopeType {
}
val b = buffer.get()
builder.write(b.toInt())
if (b == '\n'.toByte()) {
if (b == '\n'.code.toByte()) {
yield(String(builder.toByteArray(), Charsets.UTF_8))
builder.reset()
}
}
}
}
@Throws(IOException::class)
private fun readMeta(channel: ReadableByteChannel, buffer: ByteBuffer, properties: MutableMap<String, String>): Meta {
private fun readMeta(
channel: ReadableByteChannel,
buffer: ByteBuffer,
properties: MutableMap<String, String>,
): Meta {
val sb = StringBuilder()
val metaEnd = properties.getOrDefault(DATA_START_PROPERTY, DEFAULT_DATA_START)
readLines(channel, buffer).takeWhile { it.trim { it <= ' ' } != metaEnd }.forEach { line ->
readLines(channel, buffer).takeWhile { it.trim { char -> char <= ' ' } != metaEnd }.forEach { line ->
if (line.startsWith("#?")) {
readProperty(line.trim(), properties)
} else if (line.isEmpty() || line.startsWith("#~")) {
@ -161,13 +154,19 @@ class TaglessEnvelopeType : EnvelopeType {
@Throws(IOException::class)
private fun readData(channel: ReadableByteChannel, buffer: ByteBuffer, properties: Map<String, String>): ByteBuffer {
private fun readData(
channel: ReadableByteChannel,
buffer: ByteBuffer,
properties: Map<String, String>,
): ByteBuffer {
val array = ByteArray(buffer.remaining());
buffer.get(array)
if (properties.containsKey(DATA_LENGTH_PROPERTY)) {
val result = ByteBuffer.allocate(Integer.parseInt(properties[DATA_LENGTH_PROPERTY]))
result.put(array)//TODO fix it to not use direct array access
if(result.limit() < result.capacity()) {
channel.read(result)
}
return result
} else {
val baos = ByteArrayOutputStream()
@ -209,7 +208,7 @@ class TaglessEnvelopeType : EnvelopeType {
const val DEFAULT_META_START = "#~META~#"
const val DATA_START_PROPERTY = "dataSeparator"
const val DEFAULT_DATA_START = "#~DATA~#"
private val BUFFER_SIZE = 1024
val INSTANCE = TaglessEnvelopeType()
}

View File

@ -25,6 +25,7 @@ import hep.dataforge.io.MetaStreamReader
import hep.dataforge.io.MetaStreamWriter
import hep.dataforge.io.XMLMetaReader
import hep.dataforge.io.XMLMetaWriter
import java.util.*
val xmlMetaType = XMLMetaType()
@ -38,7 +39,7 @@ class XMLMetaType : MetaType {
override val writer: MetaStreamWriter = XMLMetaWriter()
override val fileNameFilter: (String) -> Boolean = { str -> str.toLowerCase().endsWith(".xml") }
override val fileNameFilter: (String) -> Boolean = { str -> str.lowercase(Locale.getDefault()).endsWith(".xml") }
companion object {
const val XML_META_TYPE = "XML"

View File

@ -61,7 +61,7 @@ interface TextOutput : Output {
render("", meta)
}
@JvmDefault
fun renderText(text: String, color: Color) {
renderText(text, TextColor(color))
}

View File

@ -17,7 +17,6 @@ package hep.dataforge.names
import java.util.stream.Stream
import java.util.stream.StreamSupport
import kotlin.streams.toList
/**
*
@ -129,7 +128,7 @@ interface Name : Comparable<Name> {
* @param name
* @return
*/
@JvmDefault
operator fun plus(name: Name): Name {
return join(this, name)
}
@ -140,14 +139,14 @@ interface Name : Comparable<Name> {
* @param name
* @return
*/
@JvmDefault
operator fun plus(name: String): Name {
return join(this, ofSingle(name))
}
fun asArray(): Array<String>
@JvmDefault
fun equals(name: String): Boolean {
return this.toString() == name
}

View File

@ -79,7 +79,7 @@ sealed class State<T : Any>(
init {
if (def != null) {
channel.offer(def)
channel.trySend(def).isSuccess
ref.set(def)
valid = true
}
@ -91,7 +91,7 @@ sealed class State<T : Any>(
private fun updateValue(value: T) {
ref.set(value)
//TODO evict on full
channel.offer(value)
channel.trySend(value).isSuccess
valid = true
logger.debug("State {} changed to {}", name, value)
}

View File

@ -33,7 +33,7 @@ interface Column : Named, Iterable<Value>, Serializable {
val format: ColumnFormat
@JvmDefault
override val name: String
get() = format.name
@ -62,7 +62,7 @@ interface Column : Named, Iterable<Value>, Serializable {
* Get the values as a stream
* @return
*/
@JvmDefault
fun stream(): Stream<Value> {
return StreamSupport.stream(spliterator(), false)
}

View File

@ -4,7 +4,6 @@ import hep.dataforge.Named
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.meta.SimpleMetaMorph
import hep.dataforge.toList
import hep.dataforge.values.Value
import hep.dataforge.values.ValueType
import java.util.*

View File

@ -18,7 +18,6 @@ package hep.dataforge.tables
import hep.dataforge.exceptions.NamingException
import hep.dataforge.nullable
import hep.dataforge.toList
import hep.dataforge.values.*
import java.util.function.Predicate
import java.util.stream.Stream
@ -132,7 +131,8 @@ fun Table.addColumn(format: ColumnFormat, transform: Values.() -> Any): Table {
return ColumnTable.copy(this).buildColumn(format, transform)
}
fun Table.addColumn(name: String, type: ValueType, transform: Values.() -> Any): Table = addColumn(ColumnFormat.build(name, type), transform)
fun Table.addColumn(name: String, type: ValueType, transform: Values.() -> Any): Table =
addColumn(ColumnFormat.build(name, type), transform)
fun Table.replaceColumn(name: String, transform: Values.() -> Any): Table {
return ColumnTable.copy(this).replaceColumn(name, transform)
@ -149,12 +149,10 @@ fun Table.sort(comparator: Comparator<Values>): Table {
}
fun Table.sort(name: String = format.first().name, ascending: Boolean = true): Table {
return sort(
Comparator { o1: Values, o2: Values ->
return sort { o1: Values, o2: Values ->
val signum = if (ascending) +1 else -1
o1.getValue(name).compareTo(o2.getValue(name)) * signum
}
)
}
@ -177,15 +175,13 @@ class RowReducer(val default: (Iterable<Value>) -> Value) {
reducers[key] = reducer
}
fun sumByDouble(key: String) = rule(key) { rows -> rows.sumByDouble { it.double }.asValue() }
fun sumByInt(key: String) = rule(key) { rows -> rows.sumBy { it.int }.asValue() }
fun sumByDouble(key: String) = rule(key) { rows -> rows.sumOf { it.double }.asValue() }
fun sumByInt(key: String) = rule(key) { rows -> rows.sumOf { it.int }.asValue() }
fun averageByDouble(key: String) = rule(key) { rows -> rows.map { it.double }.average().asValue() }
fun averageByInt(key: String) = rule(key) { rows -> rows.map { it.int }.average().asValue() }
fun reduce(key: String, values: Iterable<Value>): Value {
return reducers.getOrDefault(key, default).invoke(values)
}
fun reduce(key: String, values: Iterable<Value>): Value = reducers.getOrDefault(key, default).invoke(values)
/**
* Reduce list of rows to a single row
@ -206,7 +202,7 @@ class RowReducer(val default: (Iterable<Value>) -> Value) {
fun Table.sumByStep(key: String, step: Double, customizer: (RowReducer) -> Unit = {}): Table {
assert(step > 0) { "Step must be positive" }
val reducer = RowReducer { rows -> rows.sumByDouble { it.double }.asValue() }.apply {
val reducer = RowReducer { rows -> rows.sumOf { it.double }.asValue() }.apply {
averageByDouble(key)
}.apply(customizer)

View File

@ -33,7 +33,7 @@ import java.util.stream.StreamSupport
*/
interface ValuesSource : Iterable<Values> {
@JvmDefault
val rows: Stream<Values>
get() = StreamSupport.stream(this.spliterator(), false)

View File

@ -24,7 +24,6 @@ import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeParseException
import java.util.stream.Stream
import kotlin.streams.toList
/**
* The list of supported Value types.
@ -61,15 +60,15 @@ interface Value : Serializable, Comparable<Value> {
*/
val boolean: Boolean
@JvmDefault
val double: Double
get() = number.toDouble()
@JvmDefault
val int: Int
get() = number.toInt()
@JvmDefault
val long: Long
get() = number.toLong()
@ -80,7 +79,7 @@ interface Value : Serializable, Comparable<Value> {
*/
val time: Instant
@JvmDefault
val binary: ByteBuffer
get() = ByteBuffer.wrap(string.toByteArray())
@ -100,11 +99,11 @@ interface Value : Serializable, Comparable<Value> {
*
* @return
*/
@JvmDefault
val list: List<Value>
get() = listOf(this)
@JvmDefault
val isNull: Boolean
get() = this.type == ValueType.NULL
@ -113,7 +112,7 @@ interface Value : Serializable, Comparable<Value> {
*
* @return
*/
@JvmDefault
val isList: Boolean
get() = false
@ -122,7 +121,7 @@ interface Value : Serializable, Comparable<Value> {
*/
val value: Any
@JvmDefault
override fun compareTo(other: Value): Int {
return when (type) {
ValueType.NUMBER -> ValueUtils.NUMBER_COMPARATOR.compare(number, other.number)

View File

@ -22,7 +22,7 @@ import java.util.*
interface ValueProvider {
@JvmDefault
fun hasValue(path: String): Boolean {
return optValue(path).isPresent
}
@ -30,113 +30,113 @@ interface ValueProvider {
@Provides(VALUE_TARGET)
fun optValue(path: String): Optional<Value>
@JvmDefault
fun getValue(path: String): Value {
return optValue(path).orElseThrow<NameNotFoundException> { NameNotFoundException(path) }
}
@Provides(BOOLEAN_TARGET)
@JvmDefault
fun optBoolean(name: String): Optional<Boolean> {
return optValue(name).map<Boolean> { it.boolean }
}
@JvmDefault
fun getBoolean(name: String, def: Boolean): Boolean {
return optValue(name).map<Boolean> { it.boolean }.orElse(def)
}
@JvmDefault
fun getBoolean(name: String, def: () -> Boolean): Boolean {
return optValue(name).map<Boolean> { it.boolean }.orElseGet(def)
}
@JvmDefault
fun getBoolean(name: String): Boolean {
return getValue(name).boolean
}
@Provides(NUMBER_TARGET)
@JvmDefault
fun optNumber(name: String): Optional<Number> {
return optValue(name).map<Number> { it.number }
}
@JvmDefault
fun getDouble(name: String, def: Double): Double {
return optValue(name).map<Double> { it.double }.orElse(def)
}
@JvmDefault
fun getDouble(name: String, def: () -> Double): Double {
return optValue(name).map<Double> { it.double }.orElseGet(def)
}
@JvmDefault
fun getDouble(name: String): Double {
return getValue(name).double
}
@JvmDefault
fun getInt(name: String, def: Int): Int {
return optValue(name).map<Int> { it.int }.orElse(def)
}
@JvmDefault
fun getInt(name: String, def: () -> Int): Int {
return optValue(name).map<Int> { it.int }.orElseGet(def)
}
@JvmDefault
fun getInt(name: String): Int {
return getValue(name).int
}
@JvmDefault
@Provides(STRING_TARGET)
fun optString(name: String): Optional<String> {
return optValue(name).map<String> { it.string }
}
@JvmDefault
fun getString(name: String, def: String): String {
return optString(name).orElse(def)
}
@JvmDefault
fun getString(name: String, def: () -> String): String {
return optString(name).orElseGet(def)
}
@JvmDefault
fun getString(name: String): String {
return getValue(name).string
}
@JvmDefault
fun getValue(name: String, def: Any): Value {
return optValue(name).orElse(Value.of(def))
}
@JvmDefault
fun getValue(name: String, def: () -> Value): Value {
return optValue(name).orElseGet(def)
}
@Provides(TIME_TARGET)
@JvmDefault
fun optTime(name: String): Optional<Instant> {
return optValue(name).map { it.time }
}
@JvmDefault
fun getStringArray(name: String): Array<String> {
val vals = getValue(name).list
return Array(vals.size) { vals[it].string }
}
@JvmDefault
fun getStringArray(name: String, def: () -> Array<String>): Array<String> {
return if (this.hasValue(name)) {
getStringArray(name)
@ -145,7 +145,7 @@ interface ValueProvider {
}
}
@JvmDefault
fun getStringArray(name: String, def: Array<String>): Array<String> {
return if (this.hasValue(name)) {
getStringArray(name)

View File

@ -137,40 +137,40 @@ object ValueUtils {
@Throws(IOException::class)
fun DataOutput.writeValue(value: Value) {
if (value.isList) {
writeByte('*'.toInt()) // List designation
writeByte('*'.code) // List designation
writeShort(value.list.size)
for (subValue in value.list) {
writeValue(subValue)
}
} else {
when (value.type) {
ValueType.NULL -> writeChar('0'.toInt()) // null
ValueType.NULL -> writeChar('0'.code) // null
ValueType.TIME -> {
writeByte('T'.toInt())//Instant
writeByte('T'.code)//Instant
writeLong(value.time.epochSecond)
writeLong(value.time.nano.toLong())
}
ValueType.STRING -> {
this.writeByte('S'.toInt())//String
this.writeByte('S'.code)//String
IOUtils.writeString(this, value.string)
}
ValueType.NUMBER -> {
val num = value.number
when (num) {
is Double -> {
writeByte('D'.toInt()) // double
writeByte('D'.code) // double
writeDouble(num.toDouble())
}
is Int -> {
writeByte('I'.toInt()) // integer
writeByte('I'.code) // integer
writeInt(num.toInt())
}
is Long -> {
writeByte('L'.toInt())
writeByte('L'.code)
writeLong(num.toLong())
}
else -> {
writeByte('N'.toInt()) // BigDecimal
writeByte('N'.code) // BigDecimal
val decimal = num.toBigDecimal()
val bigInt = decimal.unscaledValue().toByteArray()
val scale = decimal.scale()
@ -181,13 +181,13 @@ fun DataOutput.writeValue(value: Value) {
}
}
ValueType.BOOLEAN -> if (value.boolean) {
writeByte('+'.toInt()) //true
writeByte('+'.code) //true
} else {
writeByte('-'.toInt()) // false
writeByte('-'.code) // false
}
ValueType.BINARY -> {
val binary = value.binary
writeByte('X'.toInt())
writeByte('X'.code)
writeInt(binary.limit())
write(binary.array())
}
@ -199,7 +199,7 @@ fun DataOutput.writeValue(value: Value) {
* Value deserialization
*/
fun DataInput.readValue(): Value {
val type = readByte().toChar()
val type = readByte().toInt().toChar()
when (type) {
'*' -> {
val listSize = readShort()
@ -240,7 +240,7 @@ fun DataInput.readValue(): Value {
fun ByteBuffer.getValue(): Value {
val type = get().toChar()
val type = get().toInt().toChar()
when (type) {
'*' -> {
val listSize = getShort()
@ -286,7 +286,7 @@ fun ByteBuffer.getValue(): Value {
fun ByteBuffer.putValue(value: Value) {
if (value.isList) {
put('*'.toByte()) // List designation
put('*'.code.toByte()) // List designation
if (value.list.size > Short.MAX_VALUE) {
throw RuntimeException("The array values of size more than ${Short.MAX_VALUE} could not be serialized")
}
@ -294,14 +294,14 @@ fun ByteBuffer.putValue(value: Value) {
value.list.forEach { putValue(it) }
} else {
when (value.type) {
ValueType.NULL -> put('0'.toByte()) // null
ValueType.NULL -> put('0'.code.toByte()) // null
ValueType.TIME -> {
put('T'.toByte())//Instant
put('T'.code.toByte())//Instant
putLong(value.time.epochSecond)
putLong(value.time.nano.toLong())
}
ValueType.STRING -> {
put('S'.toByte())//String
put('S'.code.toByte())//String
if (value.string.length > Int.MAX_VALUE) {
throw RuntimeException("The string valuse of size more than ${Int.MAX_VALUE} could not be serialized")
}
@ -311,19 +311,19 @@ fun ByteBuffer.putValue(value: Value) {
val num = value.number
when (num) {
is Double -> {
put('D'.toByte()) // double
put('D'.code.toByte()) // double
putDouble(num.toDouble())
}
is Int -> {
put('I'.toByte()) // integer
put('I'.code.toByte()) // integer
putInt(num.toInt())
}
is Long -> {
put('L'.toByte())
put('L'.code.toByte())
putLong(num.toLong())
}
is BigDecimal -> {
put('N'.toByte()) // BigDecimal
put('N'.code.toByte()) // BigDecimal
val bigInt = num.unscaledValue().toByteArray()
val scale = num.scale()
if (bigInt.size > Short.MAX_VALUE) {
@ -339,12 +339,12 @@ fun ByteBuffer.putValue(value: Value) {
}
}
ValueType.BOOLEAN -> if (value.boolean) {
put('+'.toByte()) //true
put('+'.code.toByte()) //true
} else {
put('-'.toByte()) // false
put('-'.code.toByte()) // false
}
ValueType.BINARY -> {
put('X'.toByte())
put('X'.code.toByte())
val binary = value.binary
putInt(binary.limit())
put(binary.array())

View File

@ -19,7 +19,6 @@ import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.meta.MetaMorph
import hep.dataforge.names.NameSetContainer
import java.util.*
/**
* A named set of values with fixed name list.
@ -32,7 +31,7 @@ interface Values : NameSetContainer, ValueProvider, MetaMorph, Iterable<NamedVal
* @param path
* @return
*/
@JvmDefault
override fun hasValue(path: String): Boolean {
return this.names.contains(path)
}
@ -43,12 +42,12 @@ interface Values : NameSetContainer, ValueProvider, MetaMorph, Iterable<NamedVal
* @param num
* @return
*/
@JvmDefault
operator fun get(num: Int): Value {
return getValue(this.names.get(num))
}
@JvmDefault
operator fun get(key: String): Value {
return getValue(key)
}
@ -57,7 +56,7 @@ interface Values : NameSetContainer, ValueProvider, MetaMorph, Iterable<NamedVal
* Convert a DataPoint to a Map. Order is not guaranteed
* @return
*/
@JvmDefault
fun asMap(): Map<String, Value> {
val res = HashMap<String, Value>()
for (field in this.names) {
@ -66,7 +65,7 @@ interface Values : NameSetContainer, ValueProvider, MetaMorph, Iterable<NamedVal
return res
}
@JvmDefault
override fun iterator(): Iterator<NamedValue> {
return names.map { NamedValue(it, get(it)) }.iterator()
}
@ -77,12 +76,12 @@ interface Values : NameSetContainer, ValueProvider, MetaMorph, Iterable<NamedVal
* @param name
* @return
*/
@JvmDefault
fun hasTag(name: String): Boolean {
return names.contains(name) && getValue(name).boolean
}
@JvmDefault
override fun toMeta(): Meta {
val builder = MetaBuilder("point")
for (name in namesAsArray()) {

View File

@ -70,7 +70,7 @@ interface Workspace : ContextAware, Provider {
* @param dataPath Fully qualified data name
* @return
*/
@JvmDefault
fun getData(dataPath: String): Data<*> {
return data.getData(dataPath)
}
@ -90,7 +90,7 @@ interface Workspace : ContextAware, Provider {
* @param taskName
* @return
*/
@JvmDefault
fun getTask(taskName: String): Task<*> {
return optTask(taskName) ?: throw NameNotFoundException(taskName)
}
@ -104,7 +104,7 @@ interface Workspace : ContextAware, Provider {
* @param overlay use given meta as overaly for existing meta with the same name
* @return
*/
@JvmDefault
fun runTask(taskName: String, config: Meta, overlay: Boolean): DataNode<*> {
val task = getTask(taskName)
val taskConfig = if (overlay && hasTarget(config.name)) {
@ -116,7 +116,7 @@ interface Workspace : ContextAware, Provider {
return runTask(model)
}
@JvmDefault
fun runTask(taskName: String, config: Meta): DataNode<*> {
return this.runTask(taskName, config, true)
}
@ -127,7 +127,7 @@ interface Workspace : ContextAware, Provider {
* @param config
* @return
*/
@JvmDefault
fun runTask(config: Meta): DataNode<*> {
return runTask(config.name, config)
}
@ -139,7 +139,7 @@ interface Workspace : ContextAware, Provider {
* @param target
* @return
*/
@JvmDefault
fun runTask(taskName: String, target: String = taskName): DataNode<*> {
return runTask(taskName, optTarget(target) ?: Meta.empty())
}
@ -150,7 +150,7 @@ interface Workspace : ContextAware, Provider {
* @param model
* @return
*/
@JvmDefault
fun runTask(model: TaskModel): DataNode<*> {
return this.getTask(model.name).run(model)
}
@ -169,7 +169,7 @@ interface Workspace : ContextAware, Provider {
* @param name
* @return
*/
@JvmDefault
fun getTarget(name: String): Meta {
return optTarget(name) ?: throw NameNotFoundException(name)
}
@ -180,7 +180,7 @@ interface Workspace : ContextAware, Provider {
* @param name
* @return
*/
@JvmDefault
fun hasTarget(name: String): Boolean {
return optTarget(name) != null
}
@ -194,7 +194,7 @@ interface Workspace : ContextAware, Provider {
override var context: Context
@JvmDefault
fun loadFrom(meta: Meta): Workspace.Builder {
if (meta.hasValue("context")) {
context = Global.getContext(meta.getString("context"))
@ -243,7 +243,7 @@ interface Workspace : ContextAware, Provider {
* @param dataConfig
* @return
*/
@JvmDefault
fun data(place: String, dataConfig: Meta): Workspace.Builder {
return data(place, DataLoader.SMART.build(context, dataConfig))
}
@ -256,7 +256,7 @@ interface Workspace : ContextAware, Provider {
* @param dataConfig
* @return
*/
@JvmDefault
fun data(place: String, factory: DataLoader<out Any>, dataConfig: Meta): Workspace.Builder {
return data(place, factory.build(context, dataConfig))
}
@ -269,29 +269,29 @@ interface Workspace : ContextAware, Provider {
* @param meta
* @return
*/
@JvmDefault
fun staticData(name: String, obj: Any, meta: Meta): Workspace.Builder {
return data(name, Data.buildStatic(obj, meta))
}
@JvmDefault
fun staticData(name: String, obj: Any): Workspace.Builder {
return data(name, Data.buildStatic(obj))
}
@JvmDefault
fun fileData(place: String, filePath: String, meta: Meta): Workspace.Builder {
return data(place, DataUtils.readFile(context.getFile(filePath), meta))
}
@JvmDefault
fun fileData(dataName: String, filePath: String): Workspace.Builder {
return fileData(dataName, filePath, Meta.empty())
}
fun target(name: String, meta: Meta): Workspace.Builder
@JvmDefault
fun target(meta: Meta): Workspace.Builder {
return target(meta.name, meta)
}
@ -299,7 +299,7 @@ interface Workspace : ContextAware, Provider {
fun task(task: Task<*>): Workspace.Builder
@Throws(IllegalAccessException::class, InstantiationException::class)
@JvmDefault
fun task(type: Class<Task<*>>): Workspace.Builder {
return task(type.getConstructor().newInstance())
}

View File

@ -56,7 +56,7 @@ interface Task<out R : Any> : Named, Described {
*
* @param model
*/
@JvmDefault
fun validate(model: TaskModel) {
//do nothing
}

View File

@ -21,7 +21,6 @@ import org.junit.Assert.assertEquals
import org.junit.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.nio.charset.Charset
class TaglessEnvelopeTest {
@ -33,7 +32,6 @@ class TaglessEnvelopeTest {
private val envelopeType = TaglessEnvelopeType.INSTANCE
@Test
@Throws(IOException::class)
fun testWriteRead() {
val baos = ByteArrayOutputStream()
envelopeType.writer.write(baos, envelope)
@ -47,7 +45,6 @@ class TaglessEnvelopeTest {
}
@Test
@Throws(IOException::class)
fun testShortForm() {
val envString = "<meta myValue=\"12\"/>\n" +
"#~DATA~#\n" +

View File

@ -8,13 +8,13 @@ description = "A tornadofx based kotlin library"
dependencies {
compile project(':dataforge-plots')
compile project(':dataforge-gui:dataforge-html')
compile 'org.controlsfx:controlsfx:8.40.14'
compile "no.tornado:tornadofx:1.7.19"
compile 'no.tornado:tornadofx-controlsfx:0.1.1'
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.2'
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.5.0'
api project(':dataforge-plots')
api project(':dataforge-gui:dataforge-html')
api 'org.controlsfx:controlsfx:8.40.14'
api "no.tornado:tornadofx:1.7.19"
api 'no.tornado:tornadofx-controlsfx:0.1.1'
api group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.2'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.5.0'
// optional dependency for JFreeChart
//compileOnly project(":dataforge-plots:plots-jfc")

View File

@ -1,6 +1,6 @@
description = "An html rendering core and HTML output"
dependencies {
compile project(':dataforge-core')
compile 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.11'
api project(':dataforge-core')
api 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.11'
}

View File

@ -1,6 +1,6 @@
plugins{
id "application"
id "com.github.johnrengelman.shadow" version "2.0.1"
id "com.github.johnrengelman.shadow"
}
apply plugin: 'kotlin'
@ -13,8 +13,8 @@ mainClassName = mainClass
description = "A demonstration for plots capabilities"
dependencies {
compile project(':dataforge-plots:plots-jfc')
compile project(':dataforge-gui')
api project(':dataforge-plots:plots-jfc')
api project(':dataforge-gui')
}

View File

@ -24,7 +24,7 @@ apply plugin: 'kotlin'
description = "A gui for workspace creation and manipulation"
dependencies {
compile project(':dataforge-gui')
api project(':dataforge-gui')
}
application{

View File

@ -44,7 +44,7 @@ class FXPlugin(meta: Meta = Meta.empty()) : BasicPlugin(meta) {
*/
override fun attach(context: Context) {
super.attach(context)
if (FX.getApplication(DefaultScope) == null) {
if (FX.getApplication(FX.defaultScope) == null) {
if (consoleMode) {
Thread {
context.logger.debug("Starting FX application surrogate")
@ -70,7 +70,7 @@ class FXPlugin(meta: Meta = Meta.empty()) : BasicPlugin(meta) {
* Define an application to use in this context
*/
fun setApp(app: Application, stage: Stage) {
FX.registerApplication(DefaultScope, app, stage)
FX.registerApplication(FX.defaultScope, app, stage)
}
/**

View File

@ -18,7 +18,6 @@ package hep.dataforge.fx.meta
import hep.dataforge.fx.dfIconView
import hep.dataforge.meta.Meta
import hep.dataforge.toList
import hep.dataforge.values.Value
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty

View File

@ -131,7 +131,7 @@ class OutputContainer(val context: Context, val meta: Meta) :
}
override fun computeValue(): ObservableList<String> {
return outputs.keys.toList().observable()
return outputs.keys.toList().asObservable()
}
}
onUserSelect {
@ -169,7 +169,7 @@ class FXOutputManager(
viewConsumer: Context.(OutputContainer) -> Unit = { getOrLoad(FXPlugin::class.java).display(it) }
) : OutputManager, BasicPlugin(meta) {
override val tag = PluginTag(name = "output.fx", dependsOn = *arrayOf("hep.dataforge:fx"))
override val tag = PluginTag(name = "output.fx", dependsOn = arrayOf("hep.dataforge:fx"))
override fun attach(context: Context) {
super.attach(context)

View File

@ -152,7 +152,7 @@ class FXTextOutput(context: Context) : FXOutput(context), TextOutput {
}
private fun countLines(): Int {
return textArea.text.chars().filter { value: Int -> value == '\n'.toInt() }.count().toInt()
return textArea.text.chars().filter { value: Int -> value == '\n'.code }.count().toInt()
}
/**

View File

@ -59,7 +59,7 @@ class TableDisplay(title: String? = null) : Fragment(title = title, icon = dfIco
(0 until table.size()).forEach { i ->
rows += (0 until format.count())
.map { j -> buildCell(i, j, table.get(format.names[j], i)) }
.observable()
.asObservable()
}
}
}

View File

@ -1,5 +1,5 @@
description = 'Commons math dependency and some useful tools'
dependencies {
compile 'org.apache.commons:commons-math3:3.+'
compile project(':dataforge-core')
api 'org.apache.commons:commons-math3:3.+'
api project(':dataforge-core')
}

View File

@ -14,9 +14,9 @@ class DSNumber(val ds: DerivativeStructure, nc: DSField) : FieldCompat<Number, D
return ds.getPartialDerivative(*nc.names.map { orders[it] ?: 0 }.toIntArray())
}
override fun toByte(): Byte = ds.value.toByte()
override fun toByte(): Byte = ds.value.toInt().toByte()
override fun toChar(): Char = ds.value.toChar()
override fun toChar(): Char = ds.value.toInt().toChar()
override fun toDouble(): Double = ds.value
@ -26,7 +26,7 @@ class DSNumber(val ds: DerivativeStructure, nc: DSField) : FieldCompat<Number, D
override fun toLong(): Long = ds.value.toLong()
override fun toShort(): Short = ds.value.toShort()
override fun toShort(): Short = ds.value.toInt().toShort()
/**
* Return new DSNumber, obtained by applying given function to underlying ds

View File

@ -55,13 +55,7 @@ class ExpressionField<in T, R>(val names: NameList, private val field: Field<T,
override val zero: Expression<R> = BasicExpression { field.one }
override fun transform(n: T): Expression<R> {
return if (n is Expression<*>) {
n as Expression<R>
} else {
BasicExpression { field.transform(n) }
}
}
override fun transform(n: T): Expression<R> = n as? Expression<R> ?: BasicExpression { field.transform(n) }
override fun add(a: T, b: T): Expression<R> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.

View File

@ -9,5 +9,5 @@
description = 'dataforge-plots'
dependencies {
compile project(':dataforge-core')
api project(':dataforge-core')
}

View File

@ -8,9 +8,9 @@
description = 'jFreeChart plugin'
dependencies {
compile 'org.jfree:jfreesvg:3.3'
api 'org.jfree:jfreesvg:3.3'
// https://mvnrepository.com/artifact/org.jfree/jfreechart-fx
compile group: 'org.jfree', name: 'jfreechart-fx', version: '1.0.1'
api group: 'org.jfree', name: 'jfreechart-fx', version: '1.0.1'
compile project(":dataforge-plots")
api project(":dataforge-plots")
}

View File

@ -151,7 +151,7 @@ class JFreeChartFrame : XYPlotFrame(), FXPlotFrame, Serializable {
}
private fun getAxis(axisMeta: Meta): ValueAxis {
return when (axisMeta.getString("type", "number").toLowerCase()) {
return when (axisMeta.getString("type", "number").lowercase()) {
"log" -> getLogAxis(axisMeta)
"time" -> getDateAxis(axisMeta)
else -> getNumberAxis(axisMeta)
@ -273,7 +273,7 @@ class JFreeChartFrame : XYPlotFrame(), FXPlotFrame, Serializable {
val render: XYLineAndShapeRenderer = if (config.getBoolean("showErrors", true)) {
XYErrorRenderer()
} else {
when (config.getString("connectionType", "DEFAULT").toUpperCase()) {
when (config.getString("connectionType", "DEFAULT").uppercase()) {
"STEP" -> XYStepRenderer()
"SPLINE" -> XYSplineRenderer()
else -> XYLineAndShapeRenderer()

View File

@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.0.0"
id "com.github.johnrengelman.shadow"
id 'application'
}
@ -19,6 +19,6 @@ compileKotlin {
}
dependencies {
compile project(':dataforge-plots:plots-jfc')
compile project(':dataforge-gui')
api project(':dataforge-plots:plots-jfc')
api project(':dataforge-gui')
}

View File

@ -11,10 +11,8 @@ import hep.dataforge.tables.Adapters
import hep.dataforge.tables.ListTable
import hep.dataforge.tables.MetaTableFormat
import hep.dataforge.tables.Table
import hep.dataforge.toList
import hep.dataforge.values.Value
import hep.dataforge.values.ValueMap
import java.util.*
/**
* @author Alexander Nozik
@ -28,9 +26,9 @@ object DataPlotUtils {
names.add("x")
frame.plots.stream().map { it.second }
.filter {!visibleOnly || it.config.getBoolean("visible", true) }
.filter { !visibleOnly || it.config.getBoolean("visible", true) }
.forEach {
(it as? Plot)?.let {plot->
(it as? Plot)?.let { plot ->
names.add(plot.title)
plot.data.forEach { point ->
val x = Adapters.getXValue(plot.adapter, point)

View File

@ -24,7 +24,6 @@ import hep.dataforge.meta.*
import hep.dataforge.tables.Adapters
import hep.dataforge.tables.Adapters.DEFAULT_XY_ADAPTER
import hep.dataforge.tables.Adapters.buildXYDataPoint
import hep.dataforge.toList
import hep.dataforge.values.Value
import hep.dataforge.values.ValueType.BOOLEAN
import hep.dataforge.values.ValueType.NUMBER
@ -45,7 +44,8 @@ import kotlin.collections.set
ValueDef(key = "range.to", type = arrayOf(NUMBER), def = "1.0", info = "Upper boundary for calculation range"),
ValueDef(key = "density", type = arrayOf(NUMBER), def = "200", info = "Minimal number of points per plot")
)
class XYFunctionPlot(name: String, meta: Meta = Meta.empty(), val function: (Double) -> Double) : XYPlot(name, meta, Adapters.DEFAULT_XY_ADAPTER) {
class XYFunctionPlot(name: String, meta: Meta = Meta.empty(), val function: (Double) -> Double) :
XYPlot(name, meta, Adapters.DEFAULT_XY_ADAPTER) {
private val cache = TreeMap<Double, Double>()
@ -169,7 +169,14 @@ class XYFunctionPlot(name: String, meta: Meta = Meta.empty(), val function: (Dou
const val DEFAULT_DENSITY = 200
@JvmOverloads
fun plot(name: String, from: Double, to: Double, numPoints: Int = DEFAULT_DENSITY, meta: Meta = Meta.empty(), function: (Double) -> Double): XYFunctionPlot {
fun plot(
name: String,
from: Double,
to: Double,
numPoints: Int = DEFAULT_DENSITY,
meta: Meta = Meta.empty(),
function: (Double) -> Double,
): XYFunctionPlot {
val p = XYFunctionPlot(name, meta, function)
p.range = Pair(from, to)
p.density = numPoints

View File

@ -24,7 +24,6 @@ import hep.dataforge.meta.MetaBuilder
import hep.dataforge.tables.Adapters
import hep.dataforge.tables.ValuesAdapter
import hep.dataforge.tables.ValuesAdapter.ADAPTER_KEY
import hep.dataforge.toList
import hep.dataforge.values.Value
import hep.dataforge.values.ValueType
import hep.dataforge.values.Values
@ -41,12 +40,15 @@ import java.util.stream.Stream
@ValueDefs(
ValueDef(key = "color", info = "The color of line or symbol.", tags = ["widget:color"]),
ValueDef(key = "thickness", type = [ValueType.NUMBER], def = "1", info = "Thickness of the line if it is present"),
ValueDef(key = "connectionType", def = "DEFAULT", enumeration = XYPlot.ConnectionType::class, info = "Connection line type")
ValueDef(key = "connectionType",
def = "DEFAULT",
enumeration = XYPlot.ConnectionType::class,
info = "Connection line type")
)
@NodeDef(key = ADAPTER_KEY, info = "An adapter to interpret the dataset", tags = [FINAL_TAG])
abstract class XYPlot(name: String, meta: Meta, adapter: ValuesAdapter?) : AbstractPlot(name, meta, adapter) {
enum class ConnectionType{
enum class ConnectionType {
DEFAULT,
STEP,
SPLINE
@ -57,7 +59,8 @@ abstract class XYPlot(name: String, meta: Meta, adapter: ValuesAdapter?) : Abstr
}
fun getData(from: Value, to: Value, numPoints: Int): List<Values> {
return getData(MetaBuilder("").putValue("xRange.from", from).putValue("xRange.to", to).putValue("numPoints", numPoints))
return getData(MetaBuilder("").putValue("xRange.from", from).putValue("xRange.to", to)
.putValue("numPoints", numPoints))
}
/**

View File

@ -1,5 +1,5 @@
description = 'dataforge-fitting'
dependencies {
compile project(':dataforge-maths')
api project(':dataforge-maths')
}

View File

@ -1,5 +1,5 @@
description = 'dataforge-minuit'
dependencies {
compile project(':dataforge-stat')
api project(':dataforge-stat')
}

View File

@ -33,7 +33,7 @@ interface Fitter : Named {
fun run(state: FitState, parentLog: History?, meta: Meta): FitResult
@JvmDefault
fun run(state: FitState, parentLog: History? = null, meta: KMetaBuilder.() -> Unit): FitResult {
return run(state, parentLog, buildMeta("fit", meta))
}

View File

@ -1,5 +1,5 @@
description = 'New API and implementation of dataforge-storage'
dependencies {
compile project(':dataforge-core')
api project(':dataforge-core')
}

View File

@ -54,7 +54,7 @@ interface StorageElement : Named, Metoid, Provider, ContextAware, AutoConnectibl
/**
* Full name relative to root storage
*/
@JvmDefault
val fullName: Name
get() = if (parent == null) {
Name.empty()
@ -88,7 +88,7 @@ interface Storage : StorageElement {
* Get storage element (name notation for recursive calls). Null if not present
*/
@Provides(STORAGE_TARGET)
@JvmDefault
operator fun get(name: String): StorageElement? {
return get(Name.of(name))
}
@ -96,7 +96,7 @@ interface Storage : StorageElement {
/**
* Resolve storage element by its fully qualified name
*/
@JvmDefault
operator fun get(name: Name): StorageElement? {
return if (name.length == 1) {
children.find { it.name == name.unescaped }
@ -105,13 +105,13 @@ interface Storage : StorageElement {
}
}
@JvmDefault
override fun getDefaultTarget(): String = STORAGE_TARGET
/**
* By default closes all children on close. If overridden, children should be closed before parent.
*/
@JvmDefault
override fun close() {
children.forEach { it.close() }
}
@ -201,7 +201,7 @@ interface StorageElementType : Named {
*/
fun create(context: Context, meta: Meta, parent: StorageElement? = null): StorageElement
@JvmDefault
fun create(parent: StorageElement, meta: Meta): StorageElement {
return create(parent.context, meta, parent)
}

View File

@ -202,7 +202,7 @@ class AppendableFileTableLoader(
private val textTableReader: (ByteBuffer, TableFormat) -> Values = { buffer, format ->
val line = buildString {
do {
val char = buffer.get().toChar()
val char = buffer.get().toInt().toChar()
append(char)
} while (char != '\n')
}
@ -213,7 +213,7 @@ private val textTableReader: (ByteBuffer, TableFormat) -> Values = { buffer, for
private val binaryTableReader: (ByteBuffer, TableFormat) -> Values = { buffer, format ->
ValueMap(format.names.associate { it to buffer.getValue() }.toMap()).also {
do {
val char = buffer.get().toChar()
val char = buffer.get().toInt().toChar()
} while (char != '\n')
}
}
@ -238,7 +238,7 @@ class TableLoaderType : FileStorageElementType {
format.names.map { values[it] }.forEach {
stream.writeValue(it)
}
stream.writeByte('\n'.toInt())
stream.writeByte('\n'.code)
stream.flush()
ByteBuffer.wrap(baos.toByteArray())
}

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -6,8 +6,10 @@ compileGroovy.dependsOn(compileKotlin)
compileGroovy.classpath += files(compileKotlin.destinationDir)
dependencies {
compile project(":dataforge-core")
compile 'org.codehaus.groovy:groovy-all:2.5+'
api project(":dataforge-core")
// https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all
api 'org.codehaus.groovy:groovy-all:3.0.9'
testCompile project(":dataforge-gui")
testImplementation project(":dataforge-gui")
}

View File

@ -1,7 +1,7 @@
plugins {
id 'groovy'
id 'application'
id "com.github.johnrengelman.shadow" version "7.0.0"
id "com.github.johnrengelman.shadow"
}
@ -16,12 +16,12 @@ plugins {
description = 'The grind plugin for dataforge framework'
dependencies {
compile project(':grind')
compile project(':dataforge-plots:plots-jfc')
compile project(':dataforge-gui')
compile group: 'org.jline', name: 'jline', version: '3.5.1'
// compile group: 'net.java.dev.jna', name: 'jna', version: '4.4.0'
compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.16'
api project(':grind')
api project(':dataforge-plots:plots-jfc')
api project(':dataforge-gui')
api group: 'org.jline', name: 'jline', version: '3.5.1'
// api group: 'net.java.dev.jna', name: 'jna', version: '4.4.0'
api group: 'org.fusesource.jansi', name: 'jansi', version: '1.16'
}
task shell(dependsOn: classes, type: JavaExec) {

View File

@ -1,6 +1,6 @@
apply plugin: 'groovy'
dependencies {
compile project(':grind')
compile project(':dataforge-maths')
api project(':grind')
api project(':dataforge-maths')
}

View File

@ -7,6 +7,7 @@ import hep.dataforge.meta.Meta
import hep.dataforge.workspace.Workspace
import hep.dataforge.workspace.tasks.Task
import org.jetbrains.annotations.NotNull
import org.slf4j.Logger
/**
* Workspace wrapper that implements methodMissing for tasks and propertyMissing for targets
@ -20,8 +21,6 @@ class GrindWorkspace implements Workspace {
this.workspace = workspace
}
@Override
DataNode<?> getData() {
return workspace.getData()
@ -57,6 +56,11 @@ class GrindWorkspace implements Workspace {
return workspace.context
}
@Override
Logger getLogger() {
return workspace.context.getLogger()
}
def methodMissing(String name, Object args) {
String str = args.getClass().isArray() ? ((Object[]) args).join(" ") : args.toString()
return runTask(name, str)

View File

@ -55,7 +55,7 @@ class WorkspaceSpec {
* @return
*/
@MethodDescription("Load data via closure")
void data(@DelegatesTo(value = DataNodeSpec, strategy = Closure.DELEGATE_FIRST) Closure cl) {
void data(@DelegatesTo(value = DataNodeSpec, strategy = Closure.DELEGATE_ONLY) Closure cl) {
builder.data("", DataNodeSpec.buildNode(builder.context, cl))
}

View File

@ -1,33 +1,10 @@
allprojects {
apply plugin: "kotlin"
// apply plugin: 'org.openjfx.javafxplugin'
//
// javafx {
// modules = [ 'javafx.controls' ]
// }
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
javaParameters = true
}
}
kotlin {
experimental {
coroutines "enable"
}
}
}
dependencies {
compile project(':dataforge-plots:plots-jfc')
compile project(':dataforge-control')
compile project(':dataforge-gui')
api project(':dataforge-plots:plots-jfc')
api project(':dataforge-control')
api project(':dataforge-gui')
// https://mvnrepository.com/artifact/commons-cli/commons-cli
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
api group: 'commons-cli', name: 'commons-cli', version: '1.4'
}

View File

@ -1,6 +1,6 @@
plugins {
id "application"
id 'com.github.johnrengelman.shadow' version '2.0.1'
id 'com.github.johnrengelman.shadow'
}
@ -22,8 +22,8 @@ configurations {
dependencies {
//DataForge dependencies
compile project(':numass-control')
//compile project(':numass-server')
api project(':numass-control')
//api project(':numass-server')
// optional device classpath
devices project(':numass-control:cryotemp')

View File

@ -8,7 +8,7 @@ version = "0.2.0";
//mainClassName = "inr.numass.readvac.Main"
dependencies {
compile project(':numass-control')
api project(':numass-control')
}
application{

View File

@ -31,7 +31,7 @@ internal fun createChannel(meta: Meta): PKT8Channel {
val coefs = meta.getValue("coefs").list
val r0 = meta.getDouble("r0", 1000.0)
return PKT8Channel(meta) { r ->
coefs.indices.sumByDouble { coefs[it].double * Math.pow(r0 / r, it.toDouble()) }
coefs.indices.sumOf { coefs[it].double * Math.pow(r0 / r, it.toDouble()) }
}
}
else -> throw RuntimeException("Unknown transformation type")

View File

@ -17,6 +17,6 @@
version = "0.1.0"
dependencies {
compile project(':numass-control')
compile project(':numass-core')
api project(':numass-control')
api project(':numass-core')
}

View File

@ -31,7 +31,6 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import java.io.DataInputStream
import java.io.OutputStream
import java.lang.Math.pow
import java.net.Socket
import java.nio.ByteBuffer
import java.nio.ByteOrder
@ -39,8 +38,8 @@ import java.time.Duration
import java.time.Instant
import java.util.*
import java.util.concurrent.atomic.AtomicLong
import kotlin.collections.HashMap
import kotlin.math.ceil
import kotlin.math.pow
internal val Byte.positive
get() = toInt() and 0xFF
@ -254,7 +253,7 @@ class DanteClient(override val context: Context,val ip: String, chainLength: In
}
return sequence {
val intBuffer = ByteBuffer.wrap(message!!.payload).asIntBuffer()
val intBuffer = ByteBuffer.wrap(message.payload).asIntBuffer()
while (intBuffer.hasRemaining()) {
yield(intBuffer.get())
}
@ -298,7 +297,7 @@ class DanteClient(override val context: Context,val ip: String, chainLength: In
assert(en_fil_flattop in 1..15)
assert(fast_peak_time in 1..31)
assert(fast_flattop in 1..31)
assert(recovery_time in (0.0..pow(2.0, 24.0) - 1))
assert(recovery_time.toDouble() in (0.0..2.0.pow(24.0) - 1))
assert(zero_peak_rate in 0..500)
assert(inverted_input in listOf(0, 1))
assert((en_fil_peak_time + en_fil_flattop) * 2 < 1023)

View File

@ -20,5 +20,5 @@ if (!hasProperty('mainClass')) {
mainClassName = mainClass
dependencies {
compile project(':numass-control')
api project(':numass-control')
}

View File

@ -8,7 +8,7 @@ if (!hasProperty('mainClass')) {
mainClassName = mainClass
dependencies {
compile project(':numass-control')
api project(':numass-control')
}
task talkToServer(type: JavaExec) {

View File

@ -9,5 +9,5 @@ mainClassName = mainClass
dependencies {
compile project(':numass-control')
api project(':numass-control')
}

View File

@ -95,7 +95,7 @@ fun Indicator.bind(connection: DeviceDisplayFX<*>, state: String, transform: ((V
fun EventTarget.deviceStateIndicator(connection: DeviceDisplayFX<*>, state: String, showName: Boolean = true, transform: ((Value) -> Paint)? = null) {
if (connection.device.stateNames.contains(state)) {
if (showName) {
text("${state.toUpperCase()}: ")
text("${state.uppercase()}: ")
}
indicator {
bind(connection, state, transform);

View File

@ -3,7 +3,7 @@ apply plugin: 'application'
version = "0.6.0"
dependencies {
compile project(':numass-control')
api project(':numass-control')
}
application{

View File

@ -23,7 +23,7 @@ class ThyroContVacDevice(context: Context, meta: Meta) : PortSensor(context, met
return GenericPortController(context, port) { it.endsWith("\r") }
}
private fun String.checksum(): Char = (sumBy { it.toInt() } % 64 + 64).toChar()
private fun String.checksum(): Char = (sumBy { it.code } % 64 + 64).toChar()
private fun wrap(str: String): String = buildString {
append(str)

View File

@ -2,11 +2,11 @@ description = "A bse package with minimal dependencies for numass"
dependencies {
compile project(":numass-core:numass-data-api")
compile project(":numass-core:numass-data-proto")
compile project(":dataforge-storage")
compile project(":dataforge-core:dataforge-json")
api project(":numass-core:numass-data-api")
api project(":numass-core:numass-data-proto")
api project(":dataforge-storage")
api project(":dataforge-core:dataforge-json")
// https://mvnrepository.com/artifact/com.github.robtimus/sftp-fs
compile group: 'com.github.robtimus', name: 'sftp-fs', version: '1.1.3'
api group: 'com.github.robtimus', name: 'sftp-fs', version: '1.1.3'
}

View File

@ -71,7 +71,6 @@ interface NumassSet : Named, Metoid, Iterable<NumassPoint>, Provider {
return optPoint(java.lang.Double.parseDouble(voltage))
}
@JvmDefault
override fun getDefaultTarget(): String {
return NUMASS_POINT_PROVIDER_KEY
}

View File

@ -14,7 +14,7 @@ repositories {
}
dependencies {
implementation("com.google.protobuf:protobuf-java:3.17.1")
api("com.google.protobuf:protobuf-java:3.17.1")
api(project(":numass-core:numass-data-api"))
api(project(":dataforge-storage"))
}

View File

@ -25,7 +25,6 @@ import java.nio.ByteBuffer
import java.nio.channels.FileChannel
import java.nio.file.Path
import java.nio.file.StandardOpenOption
import java.util.*
/**
* An envelope type for legacy numass tags. Reads legacy tag and writes DF02 tags
@ -106,8 +105,9 @@ class NumassEnvelopeType : EnvelopeType {
companion object {
val INSTANCE = NumassEnvelopeType()
val LEGACY_START_SEQUENCE = byteArrayOf('#'.toByte(), '!'.toByte())
val LEGACY_END_SEQUENCE = byteArrayOf('!'.toByte(), '#'.toByte(), '\r'.toByte(), '\n'.toByte())
val LEGACY_START_SEQUENCE = byteArrayOf('#'.code.toByte(), '!'.code.toByte())
val LEGACY_END_SEQUENCE =
byteArrayOf('!'.code.toByte(), '#'.code.toByte(), '\r'.code.toByte(), '\n'.code.toByte())
/**
* Replacement for standard type infer to include legacy type
@ -121,10 +121,10 @@ class NumassEnvelopeType : EnvelopeType {
val buffer = it.map(FileChannel.MapMode.READ_ONLY, 0, 6)
when {
//TODO use templates from appropriate types
buffer.get(0) == '#'.toByte() && buffer.get(1) == '!'.toByte() -> INSTANCE
buffer.get(0) == '#'.toByte() && buffer.get(1) == '!'.toByte() &&
buffer.get(4) == 'T'.toByte() && buffer.get(5) == 'L'.toByte() -> TaglessEnvelopeType.INSTANCE
buffer.get(0) == '#'.toByte() && buffer.get(1) == '~'.toByte() -> DefaultEnvelopeType.INSTANCE
buffer.get(0) == '#'.code.toByte() && buffer.get(1) == '!'.code.toByte() -> INSTANCE
buffer.get(0) == '#'.code.toByte() && buffer.get(1) == '!'.code.toByte() &&
buffer.get(4) == 'T'.code.toByte() && buffer.get(5) == 'L'.code.toByte() -> TaglessEnvelopeType.INSTANCE
buffer.get(0) == '#'.code.toByte() && buffer.get(1) == '~'.code.toByte() -> DefaultEnvelopeType.INSTANCE
else -> null
}
}

View File

@ -69,16 +69,16 @@ class ChernovProcessor(
val timeInTicks = (pos + buffer.position() - 1)
val event = OrphanNumassEvent(amp.toShort(), (timeInTicks * tickSize).toLong())
val event = OrphanNumassEvent(amp.toInt().toShort(), (timeInTicks * tickSize).toLong())
yield(event)
//subtracting event from buffer copy
for (x in (signalRange.first + timeInTicks.toInt())..(signalRange.endInclusive + timeInTicks.toInt())) {
for (x in (signalRange.first + timeInTicks.toInt())..(signalRange.last + timeInTicks.toInt())) {
//TODO check all roundings
if (x >= 0 && x < buffer.limit()) {
val oldValue = buffer.get(x)
val newValue = oldValue - amp * signal(x - timeInTicks) / signalMax
buffer.put(x, newValue.toShort())
buffer.put(x, newValue.toInt().toShort())
}
}
println(buffer.array().joinToString())

View File

@ -12,7 +12,7 @@ class ChernovProcessorTest {
val events = mapOf<Double, Double>(10.0 to 1.0, 16.0 to 0.5)
val buffer = ShortArray(40) { i ->
events.entries.sumByDouble { (pos, amp) -> amp * gaussian.value(pos - i.toDouble()) }.toInt().toShort()
events.entries.sumOf { (pos, amp) -> amp * gaussian.value(pos - i.toDouble()) }.toInt().toShort()
}
@Test

View File

@ -22,7 +22,6 @@ import hep.dataforge.tables.ListTable
import hep.dataforge.tables.Table
import hep.dataforge.tables.TableFormat
import hep.dataforge.tables.TableFormatBuilder
import hep.dataforge.toList
import inr.numass.data.api.NumassBlock
import inr.numass.data.api.NumassEvent
import inr.numass.data.api.NumassPoint.Companion.HV_KEY

View File

@ -172,8 +172,8 @@ fun Sequence<NumassEvent>.getAmplitudeSpectrum(
}
val minChannel = config.getInt("window.lo") { spectrum.keys.min() ?: 0 }
val maxChannel = config.getInt("window.up") { spectrum.keys.max() ?: 4096 }
val minChannel = config.getInt("window.lo") { spectrum.keys.minOrNull() ?: 0 }
val maxChannel = config.getInt("window.up") { spectrum.keys.maxOrNull() ?: 4096 }
return ListTable.Builder(format)
.rows(IntStream.range(minChannel, maxChannel)

View File

@ -30,18 +30,8 @@ import inr.numass.data.analyzers.NumassAnalyzer.Companion.LENGTH_KEY
import inr.numass.data.analyzers.TimeAnalyzer.AveragingMethod.*
import inr.numass.data.api.*
import inr.numass.data.api.NumassPoint.Companion.HV_KEY
import java.util.*
import java.util.concurrent.atomic.AtomicLong
import kotlin.collections.List
import kotlin.collections.asSequence
import kotlin.collections.count
import kotlin.collections.first
import kotlin.collections.map
import kotlin.collections.set
import kotlin.collections.sortBy
import kotlin.collections.sumBy
import kotlin.collections.sumByDouble
import kotlin.collections.toMutableList
import kotlin.math.*
import kotlin.streams.asSequence
@ -163,20 +153,20 @@ open class TimeAnalyzer(processor: SignalProcessor? = null) : AbstractAnalyzer(p
.build()
}
val totalTime = sumByDouble { it.getDouble(LENGTH_KEY) }
val totalTime = sumOf { it.getDouble(LENGTH_KEY) }
val (countRate, countRateDispersion) = when (method) {
ARITHMETIC -> Pair(
sumByDouble { it.getDouble(COUNT_RATE_KEY) } / size,
sumByDouble { it.getDouble(COUNT_RATE_ERROR_KEY).pow(2.0) } / size / size
sumOf { it.getDouble(COUNT_RATE_KEY) } / size,
sumOf { it.getDouble(COUNT_RATE_ERROR_KEY).pow(2.0) } / size / size
)
WEIGHTED -> Pair(
sumByDouble { it.getDouble(COUNT_RATE_KEY) * it.getDouble(LENGTH_KEY) } / totalTime,
sumByDouble { (it.getDouble(COUNT_RATE_ERROR_KEY) * it.getDouble(LENGTH_KEY) / totalTime).pow(2.0) }
sumOf { it.getDouble(COUNT_RATE_KEY) * it.getDouble(LENGTH_KEY) } / totalTime,
sumOf { (it.getDouble(COUNT_RATE_ERROR_KEY) * it.getDouble(LENGTH_KEY) / totalTime).pow(2.0) }
)
GEOMETRIC -> {
val mean = exp(sumByDouble { ln(it.getDouble(COUNT_RATE_KEY)) } / size)
val variance = (mean / size).pow(2.0) * sumByDouble {
val mean = exp(sumOf { ln(it.getDouble(COUNT_RATE_KEY)) } / size)
val variance = (mean / size).pow(2.0) * sumOf {
(it.getDouble(COUNT_RATE_ERROR_KEY) / it.getDouble(
COUNT_RATE_KEY
)).pow(2.0)
@ -187,7 +177,7 @@ open class TimeAnalyzer(processor: SignalProcessor? = null) : AbstractAnalyzer(p
return ValueMap.Builder(first())
.putValue(LENGTH_KEY, totalTime)
.putValue(COUNT_KEY, sumBy { it.getInt(COUNT_KEY) })
.putValue(COUNT_KEY, sumOf { it.getInt(COUNT_KEY) })
.putValue(COUNT_RATE_KEY, countRate)
.putValue(COUNT_RATE_ERROR_KEY, sqrt(countRateDispersion))
.build()

View File

@ -5,46 +5,26 @@ plugins {
apply plugin: 'kotlin'
//apply plugin: 'org.openjfx.javafxplugin'
//
//javafx {
// modules = [ 'javafx.controls' ]
//}
//if (!hasProperty('mainClass')) {
// ext.mainClass = 'inr.numass.LaunchGrindShell'
//}
mainClassName = 'inr.numass.LaunchGrindShell'
description = "Main numass project"
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileGroovy.dependsOn(compileKotlin)
compileGroovy.classpath += files(compileKotlin.destinationDir)
dependencies {
compile group: 'commons-cli', name: 'commons-cli', version: '1.+'
compile group: 'commons-io', name: 'commons-io', version: '2.+'
compile project(':numass-core')
compile project(':numass-core:numass-signal-processing')
api group: 'commons-cli', name: 'commons-cli', version: '1.+'
api group: 'commons-io', name: 'commons-io', version: '2.+'
api project(':numass-core')
api project(':numass-core:numass-signal-processing')
compileOnly "org.jetbrains.kotlin:kotlin-main-kts:1.3.21"
compile project(':dataforge-stat:dataforge-minuit')
compile project(':grind:grind-terminal')
compile project(":dataforge-gui")
//compile "hep.dataforge:dataforge-html"
api project(':dataforge-stat:dataforge-minuit')
api project(':grind:grind-terminal')
api project(":dataforge-gui")
//api "hep.dataforge:dataforge-html"
// https://mvnrepository.com/artifact/org.ehcache/ehcache
//compile group: 'org.ehcache', name: 'ehcache', version: '3.4.0'
//api group: 'org.ehcache', name: 'ehcache', version: '3.4.0'
}

View File

@ -1,5 +1,6 @@
package inr.numass
import groovy.cli.picocli.CliBuilder
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.fx.output.FXOutputManager
@ -8,7 +9,6 @@ import hep.dataforge.grind.workspace.GrindWorkspace
import hep.dataforge.plots.jfreechart.JFreeChartPlugin
import hep.dataforge.workspace.FileBasedWorkspace
import hep.dataforge.workspace.Workspace
import groovy.cli.commons.CliBuilder
/**
* Created by darksnake on 29-Aug-16.

View File

@ -31,7 +31,7 @@ suspend fun Sequence<OrphanNumassEvent>.generateBlock(start: Instant, length: Lo
private class MergingState(private val chains: List<Chain<OrphanNumassEvent>>) {
suspend fun poll(): OrphanNumassEvent {
val next = chains.minBy { it.value.timeOffset } ?: chains.first()
val next = chains.minByOrNull { it.value.timeOffset } ?: chains.first()
val res = next.value
next.next()
return res
@ -64,7 +64,8 @@ fun Chain<OrphanNumassEvent>.withDeadTime(deadTime: (OrphanNumassEvent) -> Long)
object NumassGenerator {
val defaultAmplitudeGenerator: RandomGenerator.(OrphanNumassEvent?, Long) -> Short = { _, _ -> ((nextDouble() + 2.0) * 100).toShort() }
val defaultAmplitudeGenerator: RandomGenerator.(OrphanNumassEvent?, Long) -> Short =
{ _, _ -> ((nextDouble() + 2.0) * 100).toInt().toShort() }
/**
* Generate an event chain with fixed count rate
@ -133,6 +134,6 @@ object NumassGenerator {
}
val distribution = EnumeratedRealDistribution(channels, values)
return generateEvents(cr, rnd) { _, _ -> distribution.sample().toShort() }
return generateEvents(cr, rnd) { _, _ -> distribution.sample().toInt().toShort() }
}
}

View File

@ -30,7 +30,6 @@ import org.apache.commons.math3.random.RandomGenerator
import java.lang.Math.max
import java.time.Duration
import java.time.Instant
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
@ -91,7 +90,7 @@ class PileUpSimulator {
throw Error()
}
return (prevChanel + coef * nextChanel).toShort()
return (prevChanel + coef * nextChanel).toInt().toShort()
}
/**

View File

@ -281,7 +281,7 @@ object LossCalculator {
0.0
} else {
val probs = getLossProbabilities(x)
(1 until probs.size).sumByDouble { i ->
(1 until probs.size).sumOf { i ->
probs[i] * getLossValue(i, Ei, Ef)
}
}

View File

@ -116,7 +116,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
return if (fss == null) {
sourceFunction.value(0.0, eIn, set)
} else {
(0 until fss.size()).sumByDouble { fss.getP(it) * sourceFunction.value(fss.getE(it), eIn, set) }
(0 until fss.size()).sumOf { fss.getP(it) * sourceFunction.value(fss.getE(it), eIn, set) }
}
}

View File

@ -84,20 +84,22 @@ fun main() {
val rawSpectrum = analyzer.getAmplitudeSpectrum(point, meta).withBinning(20)
group.add(DataPlot.plot("raw", rawSpectrum, AMPLITUDE_ADAPTER))
val rawNorm = rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxBy { it.double }!!.double
val rawNorm = rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxByOrNull { it.double }!!.double
val normalizedSpectrum = ColumnTable.copy(rawSpectrum)
.replaceColumn(NumassAnalyzer.COUNT_RATE_KEY) { it.getDouble(NumassAnalyzer.COUNT_RATE_KEY) / rawNorm }
normalizedFrame.add(DataPlot.plot("${setName}_raw", normalizedSpectrum, AMPLITUDE_ADAPTER))
println("[$setName] Raw spectrum integral: ${rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumByDouble { it.double }}")
println("[$setName] Raw spectrum integral: ${
rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumOf { it.double }
}")
group.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20), AMPLITUDE_ADAPTER))
val filteredSpectrum = analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20)
group.add(DataPlot.plot("invertedFilter", filteredSpectrum, AMPLITUDE_ADAPTER))
val filteredNorm = filteredSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxBy { it.double }!!.double
val filteredNorm = filteredSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxByOrNull { it.double }!!.double
val normalizedFilteredSpectrum = ColumnTable.copy(filteredSpectrum)
.replaceColumn(NumassAnalyzer.COUNT_RATE_KEY) { it.getDouble(NumassAnalyzer.COUNT_RATE_KEY) / filteredNorm }
@ -112,6 +114,8 @@ fun main() {
group.add(DataPlot.plot("pileup", pileupSpectrum, AMPLITUDE_ADAPTER))
println("[$setName] Pileup spectrum integral: ${pileupSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumByDouble { it.double }}")
println("[$setName] Pileup spectrum integral: ${
pileupSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumOf { it.double }
}")
}
}

View File

@ -86,20 +86,22 @@ fun main() {
val rawSpectrum = analyzer.getAmplitudeSpectrum(point, meta).withBinning(20)
group.add(DataPlot.plot("raw", rawSpectrum, AMPLITUDE_ADAPTER))
val rawNorm = rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxBy { it.double }!!.double
val rawNorm = rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxByOrNull { it.double }!!.double
val normalizedSpectrum = ColumnTable.copy(rawSpectrum)
.replaceColumn(NumassAnalyzer.COUNT_RATE_KEY) { it.getDouble(NumassAnalyzer.COUNT_RATE_KEY) / rawNorm }
normalizedFrame.add(DataPlot.plot("${setName}_raw", normalizedSpectrum, AMPLITUDE_ADAPTER))
println("[$setName] Raw spectrum integral: ${rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumByDouble { it.double }}")
println("[$setName] Raw spectrum integral: ${
rawSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumOf { it.double }
}")
group.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20), AMPLITUDE_ADAPTER))
val filteredSpectrum = analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20)
group.add(DataPlot.plot("invertedFilter", filteredSpectrum, AMPLITUDE_ADAPTER))
val filteredNorm = filteredSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxBy { it.double }!!.double
val filteredNorm = filteredSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).maxByOrNull { it.double }!!.double
val normalizedFilteredSpectrum = ColumnTable.copy(filteredSpectrum)
.replaceColumn(NumassAnalyzer.COUNT_RATE_KEY) { it.getDouble(NumassAnalyzer.COUNT_RATE_KEY) / filteredNorm }
@ -114,6 +116,8 @@ fun main() {
group.add(DataPlot.plot("pileup", pileupSpectrum, AMPLITUDE_ADAPTER))
println("[$setName] Pileup spectrum integral: ${pileupSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumByDouble { it.double }}")
println("[$setName] Pileup spectrum integral: ${
pileupSpectrum.getColumn(NumassAnalyzer.COUNT_RATE_KEY).sumOf { it.double }
}")
}
}

Some files were not shown because too many files have changed in this diff Show More