diff --git a/build.gradle.kts b/build.gradle.kts index 26c568a..34aa5ed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } allprojects { - repositories{ + repositories { mavenLocal() maven("https://repo.kotlin.link") } @@ -12,8 +12,9 @@ allprojects { version = "0.1.0-dev-1" } -val dataforgeVersion by extra("0.5.2-dev-2") -val kmathVersion by extra("0.3.0-dev-15") +val dataforgeVersion by extra("0.5.2-dev-4") +val kmathVersion by extra("0.3.0-dev-17") +val plotlyVersion: String by extra("0.5.0") ksciencePublish{ git("https://mipt-npm.jetbrains.space/p/numass/code/numass/") diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..83b31b1 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenLocal() + maven("https://repo.kotlin.link") + mavenCentral() + gradlePluginPortal() +} + +dependencies { + api("com.squareup.wire:wire-gradle-plugin:3.7.1") + api("ru.mipt.npm:gradle-tools:0.10.8-kotlin-1.6.0") +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f371643..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/numass-analysis/build.gradle.kts b/numass-analysis/build.gradle.kts index fef9fbd..e30b106 100644 --- a/numass-analysis/build.gradle.kts +++ b/numass-analysis/build.gradle.kts @@ -1,19 +1,21 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") `maven-publish` } val dataforgeVersion: String by rootProject.extra +val kmathVersion: String by rootProject.extra kotlin.sourceSets { commonMain { dependencies { api(project(":numass-data-model")) api("space.kscience:tables-kt:0.1.1-dev-2") - api("space.kscience:kmath-complex:0.3.0-dev-17") - api("space.kscience:kmath-stat:0.3.0-dev-17") - api("space.kscience:kmath-histograms:0.3.0-dev-17") + api("space.kscience:kmath-complex:$kmathVersion") + api("space.kscience:kmath-stat:$kmathVersion") + api("space.kscience:kmath-histograms:$kmathVersion") } } } diff --git a/numass-data-model/build.gradle.kts b/numass-data-model/build.gradle.kts index 351bae7..985402b 100644 --- a/numass-data-model/build.gradle.kts +++ b/numass-data-model/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") `maven-publish` } @@ -11,7 +12,7 @@ kotlin.sourceSets { dependencies { api("space.kscience:dataforge-context:$dataforgeVersion") api("space.kscience:dataforge-data:$dataforgeVersion") - api("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1") + api("org.jetbrains.kotlinx:kotlinx-datetime:${ru.mipt.npm.gradle.KScienceVersions.dateTimeVersion}") } } jvmMain{ @@ -21,4 +22,8 @@ kotlin.sourceSets { } } +kscience{ + useSerialization() +} + diff --git a/numass-data-model/src/commonMain/kotlin/ru/inr/mass/data/api/HVEntry.kt b/numass-data-model/src/commonMain/kotlin/ru/inr/mass/data/api/HVEntry.kt new file mode 100644 index 0000000..52d7c55 --- /dev/null +++ b/numass-data-model/src/commonMain/kotlin/ru/inr/mass/data/api/HVEntry.kt @@ -0,0 +1,25 @@ +package ru.inr.mass.data.proto + +import kotlinx.datetime.Instant +import kotlinx.datetime.toInstant +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +public data class HVEntry(val timestamp: Instant, val value: Double, val channel: Int = 1) { + public companion object { + public fun readString(line: String): HVEntry { + val (timeStr, channelStr, valueStr) = line.split(' ') + return HVEntry((timeStr + "Z").toInstant(), valueStr.toDouble(), channelStr.toInt()) + } + } +} + +@Serializable +@JvmInline +public value class HVData(public val list: List) : Iterable { + override fun iterator(): Iterator = list.iterator() + + public companion object +} + diff --git a/numass-data-model/src/commonMain/kotlin/ru/inr/mass/data/api/NumassSet.kt b/numass-data-model/src/commonMain/kotlin/ru/inr/mass/data/api/NumassSet.kt index 15d9bbc..190e679 100644 --- a/numass-data-model/src/commonMain/kotlin/ru/inr/mass/data/api/NumassSet.kt +++ b/numass-data-model/src/commonMain/kotlin/ru/inr/mass/data/api/NumassSet.kt @@ -10,6 +10,8 @@ import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.long import space.kscience.dataforge.names.Name +import space.kscience.dataforge.names.NameToken +import space.kscience.dataforge.names.asName import space.kscience.dataforge.provider.Provider /** @@ -39,14 +41,15 @@ public interface NumassSet : Iterable, Provider { override val defaultTarget: String get() = NUMASS_POINT_TARGET override fun content(target: String): Map = if (target == NUMASS_POINT_TARGET) { - points.associateBy { Name.parse("point[${it.voltage}]") } + points.associateBy { NameToken("point", it.voltage.toString()).asName() } } else { super.content(target) } public companion object { //public const val DESCRIPTION_KEY = "info" - public const val NUMASS_POINT_TARGET: String = "point" + public const val NUMASS_POINT_TARGET: String = "numass.point" + public const val NUMASS_HV_TARGET: String = "numass.hv" } } diff --git a/numass-data-proto/build.gradle.kts b/numass-data-proto/build.gradle.kts index 742406f..9aa36ec 100644 --- a/numass-data-proto/build.gradle.kts +++ b/numass-data-proto/build.gradle.kts @@ -1,7 +1,7 @@ plugins { kotlin("jvm") id("ru.mipt.npm.gradle.common") - id("com.squareup.wire") version "3.5.0" + id("com.squareup.wire") `maven-publish` } diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/HVEntry.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/HVEntry.kt deleted file mode 100644 index ea08815..0000000 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/HVEntry.kt +++ /dev/null @@ -1,29 +0,0 @@ -package ru.inr.mass.data.proto - -import kotlinx.datetime.Instant -import kotlinx.datetime.toInstant -import space.kscience.dataforge.io.Envelope -import space.kscience.dataforge.meta.get -import space.kscience.dataforge.meta.string - -public data class HVEntry(val timestamp: Instant, val value: Double, val channel: Int = 1) { - public companion object { - public fun readString(line: String): HVEntry { - val (timeStr, channelStr, valueStr) = line.split(' ') - return HVEntry((timeStr + "Z").toInstant(), valueStr.toDouble(), channelStr.toInt()) - } - - public fun readEnvelope(envelope: Envelope): List { - check(envelope.meta["type"].string == "voltage") { "Expecting voltage type envelope" } - return buildList { - envelope.data?.read { - //Some problems with readLines - lines().forEach { str -> - add(readString(str)) - } - } - } - } - } -} - diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt index 4c068e5..50b616f 100644 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt +++ b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt @@ -2,6 +2,8 @@ package ru.inr.mass.data.proto import ru.inr.mass.data.api.NumassPoint import ru.inr.mass.data.api.NumassSet +import ru.inr.mass.data.api.NumassSet.Companion.NUMASS_HV_TARGET +import ru.inr.mass.data.api.readEnvelope import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.error import space.kscience.dataforge.context.logger @@ -10,6 +12,8 @@ import space.kscience.dataforge.io.io import space.kscience.dataforge.io.readEnvelopeFile import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.misc.DFExperimental +import space.kscience.dataforge.names.Name +import space.kscience.dataforge.names.asName import java.nio.file.Files import java.nio.file.Path import kotlin.io.path.* @@ -22,19 +26,20 @@ public class NumassDirectorySet internal constructor( ) : NumassSet { @OptIn(DFExperimental::class) - override val meta: Meta by lazy { - val metaFilePath = path / "meta" - if (metaFilePath.exists()) { - val envelope = context.io.readEnvelopeFile(metaFilePath) - envelope.meta - } else { - context.logger.warn { "Meta file does not exist for Numass set $metaFilePath" } - Meta.EMPTY + override val meta: Meta + get() { + val metaFilePath = path / "meta" + return if (metaFilePath.exists()) { + val envelope = context.io.readEnvelopeFile(metaFilePath) + envelope.meta + } else { + context.logger.warn { "Meta file does not exist for Numass set $metaFilePath" } + Meta.EMPTY + } } - } - override val points: List by lazy { - Files.list(path).filter { + override val points: List + get() = Files.list(path).filter { it.fileName.name.startsWith("p") }.map { pointPath -> try { @@ -44,18 +49,29 @@ public class NumassDirectorySet internal constructor( null } }.toList().filterNotNull() - } + @OptIn(DFExperimental::class) - public fun getHvData(): List? { + public fun getHvData(): HVData? { val hvFile = path / "voltage" return if (hvFile.exists()) { val envelope = context.io.readEnvelopeFile(hvFile) - HVEntry.readEnvelope(envelope) + HVData.readEnvelope(envelope) } else { null } } + + override fun content(target: String): Map = if (target == NUMASS_HV_TARGET) { + val hvData = getHvData() + if (hvData != null) { + mapOf("hv".asName() to hvData) + } else { + emptyMap() + } + } else super.content(target) + + public companion object } @OptIn(DFExperimental::class) @@ -68,8 +84,8 @@ public fun Context.readNumassPointFile(path: String): NumassPoint? = readNumassP @OptIn(ExperimentalPathApi::class) public fun Context.readNumassDirectory(path: Path): NumassDirectorySet { - if(!path.exists()) error("Path $path does not exist") - if(!path.isDirectory()) error("The path $path is not a directory") + if (!path.exists()) error("Path $path does not exist") + if (!path.isDirectory()) error("The path $path is not a directory") return NumassDirectorySet(this, path) } diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassProtoPlugin.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassProtoPlugin.kt index a6f8a61..f9a626b 100644 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassProtoPlugin.kt +++ b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassProtoPlugin.kt @@ -14,12 +14,10 @@ public class NumassProtoPlugin : AbstractPlugin() { public val io: IOPlugin by require(IOPlugin) override val tag: PluginTag get() = Companion.tag - override fun content(target: String): Map { - return if(target== EnvelopeFormatFactory.ENVELOPE_FORMAT_TYPE){ - mapOf(TaggedNumassEnvelopeFormat.name to TaggedNumassEnvelopeFormat) - } else{ - super.content(target) - } + override fun content(target: String): Map = if(target == EnvelopeFormatFactory.ENVELOPE_FORMAT_TYPE){ + mapOf(TaggedNumassEnvelopeFormat.name to TaggedNumassEnvelopeFormat) + } else{ + super.content(target) } public companion object : PluginFactory { diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt index 850cd67..f3f0507 100644 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt +++ b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/ProtoNumassPoint.kt @@ -41,7 +41,7 @@ import kotlin.time.Duration.Companion.nanoseconds */ internal class ProtoNumassPoint( override val meta: Meta, - private val protoBuilder: () -> Point, + protoBuilder: () -> Point, ) : NumassPoint { val point: Point by lazy(protoBuilder) @@ -80,7 +80,7 @@ internal class ProtoNumassPoint( override val framesCount: Long get() = point.channels.sumOf { channel -> channel.blocks.sumOf { block -> - block.frames.size ?: 0 + block.frames.size }.toLong() } diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/TaggedNumassEnvelopeFormat.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/TaggedNumassEnvelopeFormat.kt index 3621747..dd0020c 100644 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/TaggedNumassEnvelopeFormat.kt +++ b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/TaggedNumassEnvelopeFormat.kt @@ -112,7 +112,7 @@ internal class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeFo override fun invoke(meta: Meta, context: Context): EnvelopeFormat { val io = context.io - val metaFormatName = meta["name"].string?.let(Name::parse) ?: JsonMetaFormat.name + val metaFormatName = meta["name"].string?.let { Name.parse(it) } ?: JsonMetaFormat.name //Check if appropriate factory exists io.metaFormatFactories.find { it.name == metaFormatName } ?: error("Meta format could not be resolved") @@ -133,19 +133,17 @@ internal class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeFo return Tag(metaFormatKey, metaLength, dataLength) } - override fun peekFormat(io: IOPlugin, binary: Binary): EnvelopeFormat? { - return try { - binary.read { - val header = readRawString(30) - if (header.startsWith(START_SEQUENCE) && header.endsWith(END_SEQUENCE)) { - TaggedNumassEnvelopeFormat(io) - } else { - null - } + override fun peekFormat(io: IOPlugin, binary: Binary): EnvelopeFormat? = try { + binary.read { + val header = readRawString(30) + if (header.startsWith(START_SEQUENCE) && header.endsWith(END_SEQUENCE)) { + TaggedNumassEnvelopeFormat(io) + } else { + null } - } catch (ex: Exception) { - null } + } catch (ex: Exception) { + null } private val default by lazy { invoke() } diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/readHV.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/readHV.kt new file mode 100644 index 0000000..1a2dde0 --- /dev/null +++ b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/readHV.kt @@ -0,0 +1,20 @@ +package ru.inr.mass.data.api + +import ru.inr.mass.data.proto.HVData +import ru.inr.mass.data.proto.HVEntry +import ru.inr.mass.data.proto.lines +import space.kscience.dataforge.io.Envelope +import space.kscience.dataforge.meta.get +import space.kscience.dataforge.meta.string + +public fun HVData.Companion.readEnvelope(envelope: Envelope): HVData { + check(envelope.meta["type"].string == "voltage") { "Expecting voltage type envelope" } + return HVData(buildList { + envelope.data?.read { + //Some problems with readLines + lines().forEach { str -> + add(HVEntry.readString(str)) + } + } + }) +} \ No newline at end of file diff --git a/numass-data-proto/src/test/kotlin/ru/inr/mass/data/proto/TestNumassDirectory.kt b/numass-data-proto/src/test/kotlin/ru/inr/mass/data/proto/TestNumassDirectory.kt index 5cad5c6..ee29675 100644 --- a/numass-data-proto/src/test/kotlin/ru/inr/mass/data/proto/TestNumassDirectory.kt +++ b/numass-data-proto/src/test/kotlin/ru/inr/mass/data/proto/TestNumassDirectory.kt @@ -1,6 +1,10 @@ package ru.inr.mass.data.proto +import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Test +import ru.inr.mass.data.api.NumassPoint +import ru.inr.mass.data.api.ParentBlock import space.kscience.dataforge.context.Context import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.string @@ -14,8 +18,8 @@ class TestNumassDirectory { } @Test - fun testDirectoryRead() { - val dataPath = Path.of("src/test/resources", "testData/set_4") + fun testDanteRead() { + val dataPath = Path.of("src/test/resources", "testData/dante") val testSet = context.readNumassDirectory(dataPath) assertEquals("2018-04-13T22:01:46", testSet.meta["end_time"].string) assertEquals(ListValue.EMPTY, testSet.meta["comments"]?.value) @@ -24,4 +28,18 @@ class TestNumassDirectory { point22.flowBlocks() assertEquals("2018-04-13T21:56:09", point22.meta["end_time"].string) } + + @Test + fun testTQDCRead() = runBlocking { + val pointPath = Path.of("C:\\Users\\altavir\\Desktop\\p20211122173034(20s).dat") + val point: NumassPoint = context.readNumassPointFile(pointPath)!! + point.getChannels().forEach { (channel, block) -> + println("$channel: $block") + if(block is ParentBlock){ + block.flowBlocks().toList().forEach{ + println("\t${it.channel}:${it.eventsCount}") + } + } + } + } } \ No newline at end of file diff --git a/numass-data-proto/src/test/resources/testData/set_4/meta b/numass-data-proto/src/test/resources/testData/dante/meta similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/meta rename to numass-data-proto/src/test/resources/testData/dante/meta diff --git a/numass-data-proto/src/test/resources/testData/set_4/p0(10s)(HV1=18700) b/numass-data-proto/src/test/resources/testData/dante/p0(10s)(HV1=18700) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p0(10s)(HV1=18700) rename to numass-data-proto/src/test/resources/testData/dante/p0(10s)(HV1=18700) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p1(10s)(HV1=19015) b/numass-data-proto/src/test/resources/testData/dante/p1(10s)(HV1=19015) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p1(10s)(HV1=19015) rename to numass-data-proto/src/test/resources/testData/dante/p1(10s)(HV1=19015) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p10(10s)(HV1=18800) b/numass-data-proto/src/test/resources/testData/dante/p10(10s)(HV1=18800) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p10(10s)(HV1=18800) rename to numass-data-proto/src/test/resources/testData/dante/p10(10s)(HV1=18800) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p11(10s)(HV1=18700) b/numass-data-proto/src/test/resources/testData/dante/p11(10s)(HV1=18700) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p11(10s)(HV1=18700) rename to numass-data-proto/src/test/resources/testData/dante/p11(10s)(HV1=18700) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p12(10s)(HV1=18600) b/numass-data-proto/src/test/resources/testData/dante/p12(10s)(HV1=18600) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p12(10s)(HV1=18600) rename to numass-data-proto/src/test/resources/testData/dante/p12(10s)(HV1=18600) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p13(10s)(HV1=18400) b/numass-data-proto/src/test/resources/testData/dante/p13(10s)(HV1=18400) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p13(10s)(HV1=18400) rename to numass-data-proto/src/test/resources/testData/dante/p13(10s)(HV1=18400) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p14(10s)(HV1=18200) b/numass-data-proto/src/test/resources/testData/dante/p14(10s)(HV1=18200) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p14(10s)(HV1=18200) rename to numass-data-proto/src/test/resources/testData/dante/p14(10s)(HV1=18200) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p15(10s)(HV1=18000) b/numass-data-proto/src/test/resources/testData/dante/p15(10s)(HV1=18000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p15(10s)(HV1=18000) rename to numass-data-proto/src/test/resources/testData/dante/p15(10s)(HV1=18000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p16(10s)(HV1=17500) b/numass-data-proto/src/test/resources/testData/dante/p16(10s)(HV1=17500) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p16(10s)(HV1=17500) rename to numass-data-proto/src/test/resources/testData/dante/p16(10s)(HV1=17500) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p17(10s)(HV1=17000) b/numass-data-proto/src/test/resources/testData/dante/p17(10s)(HV1=17000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p17(10s)(HV1=17000) rename to numass-data-proto/src/test/resources/testData/dante/p17(10s)(HV1=17000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p18(10s)(HV1=18700) b/numass-data-proto/src/test/resources/testData/dante/p18(10s)(HV1=18700) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p18(10s)(HV1=18700) rename to numass-data-proto/src/test/resources/testData/dante/p18(10s)(HV1=18700) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p19(10s)(HV1=16500) b/numass-data-proto/src/test/resources/testData/dante/p19(10s)(HV1=16500) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p19(10s)(HV1=16500) rename to numass-data-proto/src/test/resources/testData/dante/p19(10s)(HV1=16500) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p2(10s)(HV1=19005) b/numass-data-proto/src/test/resources/testData/dante/p2(10s)(HV1=19005) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p2(10s)(HV1=19005) rename to numass-data-proto/src/test/resources/testData/dante/p2(10s)(HV1=19005) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p20(10s)(HV1=16000) b/numass-data-proto/src/test/resources/testData/dante/p20(10s)(HV1=16000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p20(10s)(HV1=16000) rename to numass-data-proto/src/test/resources/testData/dante/p20(10s)(HV1=16000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p21(10s)(HV1=15500) b/numass-data-proto/src/test/resources/testData/dante/p21(10s)(HV1=15500) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p21(10s)(HV1=15500) rename to numass-data-proto/src/test/resources/testData/dante/p21(10s)(HV1=15500) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p22(10s)(HV1=15000) b/numass-data-proto/src/test/resources/testData/dante/p22(10s)(HV1=15000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p22(10s)(HV1=15000) rename to numass-data-proto/src/test/resources/testData/dante/p22(10s)(HV1=15000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p23(10s)(HV1=14500) b/numass-data-proto/src/test/resources/testData/dante/p23(10s)(HV1=14500) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p23(10s)(HV1=14500) rename to numass-data-proto/src/test/resources/testData/dante/p23(10s)(HV1=14500) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p24(10s)(HV1=18700) b/numass-data-proto/src/test/resources/testData/dante/p24(10s)(HV1=18700) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p24(10s)(HV1=18700) rename to numass-data-proto/src/test/resources/testData/dante/p24(10s)(HV1=18700) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p25(10s)(HV1=14000) b/numass-data-proto/src/test/resources/testData/dante/p25(10s)(HV1=14000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p25(10s)(HV1=14000) rename to numass-data-proto/src/test/resources/testData/dante/p25(10s)(HV1=14000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p26(10s)(HV1=13500) b/numass-data-proto/src/test/resources/testData/dante/p26(10s)(HV1=13500) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p26(10s)(HV1=13500) rename to numass-data-proto/src/test/resources/testData/dante/p26(10s)(HV1=13500) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p27(10s)(HV1=13000) b/numass-data-proto/src/test/resources/testData/dante/p27(10s)(HV1=13000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p27(10s)(HV1=13000) rename to numass-data-proto/src/test/resources/testData/dante/p27(10s)(HV1=13000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p28(10s)(HV1=12500) b/numass-data-proto/src/test/resources/testData/dante/p28(10s)(HV1=12500) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p28(10s)(HV1=12500) rename to numass-data-proto/src/test/resources/testData/dante/p28(10s)(HV1=12500) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p29(10s)(HV1=12000) b/numass-data-proto/src/test/resources/testData/dante/p29(10s)(HV1=12000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p29(10s)(HV1=12000) rename to numass-data-proto/src/test/resources/testData/dante/p29(10s)(HV1=12000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p3(10s)(HV1=19000) b/numass-data-proto/src/test/resources/testData/dante/p3(10s)(HV1=19000) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p3(10s)(HV1=19000) rename to numass-data-proto/src/test/resources/testData/dante/p3(10s)(HV1=19000) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p30(10s)(HV1=18700) b/numass-data-proto/src/test/resources/testData/dante/p30(10s)(HV1=18700) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p30(10s)(HV1=18700) rename to numass-data-proto/src/test/resources/testData/dante/p30(10s)(HV1=18700) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p4(10s)(HV1=18995) b/numass-data-proto/src/test/resources/testData/dante/p4(10s)(HV1=18995) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p4(10s)(HV1=18995) rename to numass-data-proto/src/test/resources/testData/dante/p4(10s)(HV1=18995) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p5(10s)(HV1=18990) b/numass-data-proto/src/test/resources/testData/dante/p5(10s)(HV1=18990) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p5(10s)(HV1=18990) rename to numass-data-proto/src/test/resources/testData/dante/p5(10s)(HV1=18990) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p6(10s)(HV1=18700) b/numass-data-proto/src/test/resources/testData/dante/p6(10s)(HV1=18700) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p6(10s)(HV1=18700) rename to numass-data-proto/src/test/resources/testData/dante/p6(10s)(HV1=18700) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p7(10s)(HV1=18980) b/numass-data-proto/src/test/resources/testData/dante/p7(10s)(HV1=18980) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p7(10s)(HV1=18980) rename to numass-data-proto/src/test/resources/testData/dante/p7(10s)(HV1=18980) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p8(10s)(HV1=18950) b/numass-data-proto/src/test/resources/testData/dante/p8(10s)(HV1=18950) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p8(10s)(HV1=18950) rename to numass-data-proto/src/test/resources/testData/dante/p8(10s)(HV1=18950) diff --git a/numass-data-proto/src/test/resources/testData/set_4/p9(10s)(HV1=18900) b/numass-data-proto/src/test/resources/testData/dante/p9(10s)(HV1=18900) similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/p9(10s)(HV1=18900) rename to numass-data-proto/src/test/resources/testData/dante/p9(10s)(HV1=18900) diff --git a/numass-data-proto/src/test/resources/testData/set_4/scenario b/numass-data-proto/src/test/resources/testData/dante/scenario similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/scenario rename to numass-data-proto/src/test/resources/testData/dante/scenario diff --git a/numass-data-proto/src/test/resources/testData/set_4/voltage b/numass-data-proto/src/test/resources/testData/dante/voltage similarity index 100% rename from numass-data-proto/src/test/resources/testData/set_4/voltage rename to numass-data-proto/src/test/resources/testData/dante/voltage diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p0.df b/numass-data-proto/src/test/resources/testData/tqdc/p0.df new file mode 100644 index 0000000..ccb33f1 Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p0.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p1.df b/numass-data-proto/src/test/resources/testData/tqdc/p1.df new file mode 100644 index 0000000..f11d36e Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p1.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p2.df b/numass-data-proto/src/test/resources/testData/tqdc/p2.df new file mode 100644 index 0000000..f71fbd1 Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p2.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p3.df b/numass-data-proto/src/test/resources/testData/tqdc/p3.df new file mode 100644 index 0000000..fd7ad6c Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p3.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p4.df b/numass-data-proto/src/test/resources/testData/tqdc/p4.df new file mode 100644 index 0000000..a536407 Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p4.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p5.df b/numass-data-proto/src/test/resources/testData/tqdc/p5.df new file mode 100644 index 0000000..7520233 Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p5.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p6.df b/numass-data-proto/src/test/resources/testData/tqdc/p6.df new file mode 100644 index 0000000..1fdb9a7 Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p6.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p7.df b/numass-data-proto/src/test/resources/testData/tqdc/p7.df new file mode 100644 index 0000000..28852ae Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p7.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p8.df b/numass-data-proto/src/test/resources/testData/tqdc/p8.df new file mode 100644 index 0000000..e5350d0 Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p8.df differ diff --git a/numass-data-proto/src/test/resources/testData/tqdc/p9.df b/numass-data-proto/src/test/resources/testData/tqdc/p9.df new file mode 100644 index 0000000..4d902be Binary files /dev/null and b/numass-data-proto/src/test/resources/testData/tqdc/p9.df differ diff --git a/numass-data-server/build.gradle.kts b/numass-data-server/build.gradle.kts new file mode 100644 index 0000000..66db8e0 --- /dev/null +++ b/numass-data-server/build.gradle.kts @@ -0,0 +1,51 @@ +plugins { + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") + `maven-publish` +} + +val visionForgeVersion = "0.2.0-dev-24" + +kotlin { + js{ + browser { + webpackTask { + this.outputFileName = "js/numass-web.js" + } + } + binaries.executable() + } + + afterEvaluate { + val jsBrowserDistribution by tasks.getting + + tasks.getByName("jvmProcessResources") { + dependsOn(jsBrowserDistribution) + afterEvaluate { + from(jsBrowserDistribution) + } + } + } + + sourceSets { + commonMain { + dependencies { + implementation(project(":numass-data-model")) + implementation("space.kscience:visionforge-plotly:$visionForgeVersion") + } + } + jvmMain { + dependencies { + implementation(project(":numass-data-proto")) + implementation("space.kscience:visionforge-server:$visionForgeVersion") + } + } + + } +} + +kscience{ + useSerialization { + json() + } +} diff --git a/numass-data-server/src/commonMain/kotlin/ru/inr/mass/data/server/NumassCommonPlugin.kt b/numass-data-server/src/commonMain/kotlin/ru/inr/mass/data/server/NumassCommonPlugin.kt new file mode 100644 index 0000000..8f0556b --- /dev/null +++ b/numass-data-server/src/commonMain/kotlin/ru/inr/mass/data/server/NumassCommonPlugin.kt @@ -0,0 +1,40 @@ +package ru.inr.mass.data.server + +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import kotlinx.serialization.modules.subclass +import space.kscience.dataforge.context.Context +import space.kscience.dataforge.context.PluginFactory +import space.kscience.dataforge.context.PluginTag +import space.kscience.dataforge.meta.Meta +import space.kscience.visionforge.Vision +import space.kscience.visionforge.VisionBase +import space.kscience.visionforge.VisionGroupBase +import space.kscience.visionforge.VisionPlugin +import space.kscience.visionforge.plotly.PlotlyPlugin +import kotlin.reflect.KClass + +public class NumassCommonPlugin(meta: Meta) : VisionPlugin(meta) { + override val tag: PluginTag get() = Companion.tag + + public val plotlyPlugin: PlotlyPlugin by require(PlotlyPlugin) + + override val visionSerializersModule: SerializersModule get() = numassSerializersModule + + public companion object : PluginFactory { + override val tag: PluginTag = PluginTag("numass.common", "ru.inr.mass") + override val type: KClass = NumassCommonPlugin::class + override fun invoke(meta: Meta, context: Context): NumassCommonPlugin = NumassCommonPlugin() + + private val numassSerializersModule = SerializersModule { + polymorphic(Vision::class) { + subclass(VisionBase.serializer()) + subclass(VisionGroupBase.serializer()) + subclass(VisionOfNumassHv.serializer()) + subclass(VisionOfNumassPoint.serializer()) + subclass(VisionOfNumassHv.serializer()) + subclass(VisionOfNumassSet.serializer()) + } + } + } +} \ No newline at end of file diff --git a/numass-data-server/src/commonMain/kotlin/ru/inr/mass/data/server/VisionOfNumassPoint.kt b/numass-data-server/src/commonMain/kotlin/ru/inr/mass/data/server/VisionOfNumassPoint.kt new file mode 100644 index 0000000..0739976 --- /dev/null +++ b/numass-data-server/src/commonMain/kotlin/ru/inr/mass/data/server/VisionOfNumassPoint.kt @@ -0,0 +1,66 @@ +package ru.inr.mass.data.server + +import kotlinx.coroutines.flow.collect +import kotlinx.serialization.Serializable +import ru.inr.mass.data.api.NumassBlock +import ru.inr.mass.data.api.NumassPoint +import ru.inr.mass.data.api.NumassSet +import ru.inr.mass.data.api.NumassSet.Companion.NUMASS_HV_TARGET +import ru.inr.mass.data.proto.HVData +import ru.inr.mass.data.proto.HVEntry +import space.kscience.dataforge.meta.Meta +import space.kscience.dataforge.names.NameToken +import space.kscience.dataforge.provider.top +import space.kscience.visionforge.VisionBase +import space.kscience.visionforge.VisionGroupBase + + +public typealias SimpleAmplitudeSpectrum = Map + +private suspend fun NumassBlock.simpleAmplitudeSpectrum(): SimpleAmplitudeSpectrum { + val res = mutableMapOf() + events.collect { + res[it.amplitude] = (res[it.amplitude] ?: 0U) + 1U + } + return res +} + +@Serializable +public class VisionOfNumassPoint( + public val pointMeta: Meta, + public val index: Int, + public val voltage: Double, + public val spectra: Map, +) : VisionBase() + +public suspend fun NumassPoint.toVision(): VisionOfNumassPoint = VisionOfNumassPoint( + meta, + index, + voltage, + getChannels().entries.associate { (k, v) -> + k.toString() to v.simpleAmplitudeSpectrum() + } +) + +@Serializable +public class VisionOfNumassHv(public val hv: HVData) : VisionBase(), Iterable { + override fun iterator(): Iterator = hv.iterator() +} + +private val VisionOfNumassPoint.token: NameToken get() = NameToken("point", index.toString()) + +@Serializable +public class VisionOfNumassSet(public val points: List) : VisionBase() { +// init { +// points.forEach { +// //childrenInternal[it.token] = it +// } +// +// } +} + +public suspend fun NumassSet.toVision(): VisionOfNumassSet = VisionOfNumassSet(points.map { it.toVision() }).apply { + this@toVision.top(NUMASS_HV_TARGET).forEach { (key, hv) -> + // set(key, VisionOfNumassHv(hv)) + } +} diff --git a/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/NumassJsPlugin.kt b/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/NumassJsPlugin.kt new file mode 100644 index 0000000..dd85906 --- /dev/null +++ b/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/NumassJsPlugin.kt @@ -0,0 +1,76 @@ +package ru.inr.mass.data.server + +import kotlinx.html.dom.append +import kotlinx.html.js.* +import org.w3c.dom.Element +import space.kscience.dataforge.context.AbstractPlugin +import space.kscience.dataforge.context.Context +import space.kscience.dataforge.context.PluginFactory +import space.kscience.dataforge.context.PluginTag +import space.kscience.dataforge.meta.Meta +import space.kscience.plotly.models.LineShape +import space.kscience.plotly.models.ScatterMode +import space.kscience.plotly.plot +import space.kscience.plotly.scatter +import space.kscience.visionforge.ElementVisionRenderer +import space.kscience.visionforge.Vision +import kotlin.reflect.KClass + +public class NumassJsPlugin : AbstractPlugin(), ElementVisionRenderer { + public val numassCommon: NumassCommonPlugin by require(NumassCommonPlugin) + private val plotly = numassCommon.plotlyPlugin + + override val tag: PluginTag get() = Companion.tag + + override fun rateVision(vision: Vision): Int = when (vision) { + is VisionOfNumassHv, is VisionOfNumassPoint, is VisionOfNumassSet -> ElementVisionRenderer.DEFAULT_RATING + else -> ElementVisionRenderer.ZERO_RATING + } + + override fun render(element: Element, vision: Vision, meta: Meta) { + when (vision) { + is VisionOfNumassHv -> element.append { + h1 { +"HV" } + //TODO add title + table { + th { + td { +"Time" } + td { +"Value" } + td { +"channel" } + } + vision.forEach { entry -> + tr { + td { +entry.timestamp.toString() } + td { +entry.value.toString() } + td { +entry.channel.toString() } + } + } + } + } + is VisionOfNumassPoint -> element.append { + h1{ +"Point"} + plot { + vision.spectra.forEach { (channel, spectrum) -> + scatter { + name = channel + mode = ScatterMode.lines + line { + shape = LineShape.hv + } + x.numbers = spectrum.keys.map { it.toInt() } + y.numbers = spectrum.values.map { it.toInt() } + } + } + } + } + is VisionOfNumassSet -> {} + } + } + + + public companion object : PluginFactory { + override val tag: PluginTag = PluginTag("numass.js", "ru.inr.mass") + override val type: KClass = NumassJsPlugin::class + override fun invoke(meta: Meta, context: Context): NumassJsPlugin = NumassJsPlugin() + } +} \ No newline at end of file diff --git a/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/jsMain.kt b/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/jsMain.kt new file mode 100644 index 0000000..5a3850b --- /dev/null +++ b/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/jsMain.kt @@ -0,0 +1,10 @@ +package ru.inr.mass.data.server + +import space.kscience.dataforge.misc.DFExperimental +import space.kscience.visionforge.runVisionClient + + +@DFExperimental +public fun main(): Unit = runVisionClient { + plugin(NumassJsPlugin) +} \ No newline at end of file diff --git a/numass-data-server/src/jvmMain/kotlin/ru/inr/mass/data/server/demo.kt b/numass-data-server/src/jvmMain/kotlin/ru/inr/mass/data/server/demo.kt new file mode 100644 index 0000000..4365abf --- /dev/null +++ b/numass-data-server/src/jvmMain/kotlin/ru/inr/mass/data/server/demo.kt @@ -0,0 +1,53 @@ +package ru.inr.mass.data.server + +import kotlinx.coroutines.runBlocking +import kotlinx.html.div +import kotlinx.html.h1 +import ru.inr.mass.data.api.NumassPoint +import ru.inr.mass.data.proto.NumassProtoPlugin +import ru.inr.mass.data.proto.readNumassPointFile +import space.kscience.dataforge.context.Context +import space.kscience.visionforge.three.server.close +import space.kscience.visionforge.three.server.serve +import space.kscience.visionforge.three.server.show +import space.kscience.visionforge.visionManager +import java.nio.file.Path + + +public fun main() { + val context = Context("Numass") { + plugin(NumassProtoPlugin) + plugin(NumassCommonPlugin) + } + + val pointPath = Path.of("C:\\Users\\altavir\\Desktop\\p20211122173034(20s).dat") + val point: NumassPoint = context.readNumassPointFile(pointPath)!! + + val visionOfNumass = runBlocking { + point.toVision() + } + + val server = context.visionManager.serve { + //use client library + useNumassWeb() + //use css + //useCss("css/styles.css") + page { + div("flex-column") { + h1 { +"Satellite detector demo" } + //vision(visionOfNumass) + } + } + } + + server.show() + + + println("Enter 'exit' to close server") + while (readLine() != "exit") { + // + } + + server.close() + +} \ No newline at end of file diff --git a/numass-data-server/src/jvmMain/kotlin/ru/inr/mass/data/server/serverExtensions.kt b/numass-data-server/src/jvmMain/kotlin/ru/inr/mass/data/server/serverExtensions.kt new file mode 100644 index 0000000..97706e2 --- /dev/null +++ b/numass-data-server/src/jvmMain/kotlin/ru/inr/mass/data/server/serverExtensions.kt @@ -0,0 +1,32 @@ +package ru.inr.mass.data.server + +import space.kscience.dataforge.context.Context +import space.kscience.dataforge.misc.DFExperimental +import space.kscience.visionforge.html.HtmlVisionFragment +import space.kscience.visionforge.html.ResourceLocation +import space.kscience.visionforge.html.page +import space.kscience.visionforge.html.scriptHeader +import space.kscience.visionforge.makeFile +import space.kscience.visionforge.three.server.VisionServer +import space.kscience.visionforge.three.server.useScript +import java.awt.Desktop +import java.nio.file.Path + + +public fun VisionServer.useNumassWeb(): Unit { + useScript("js/numass-web.js") +} + +@DFExperimental +public fun Context.makeNumassWebFile( + content: HtmlVisionFragment, + path: Path? = null, + title: String = "VisionForge Numass page", + resourceLocation: ResourceLocation = ResourceLocation.SYSTEM, + show: Boolean = true, +): Unit { + val actualPath = page(title, content = content).makeFile(path) { actualPath -> + mapOf("numassWeb" to scriptHeader("js/numass-web.js", resourceLocation, actualPath)) + } + if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI()) +} diff --git a/numass-workspace/build.gradle.kts b/numass-workspace/build.gradle.kts index 07f0fec..b5ab348 100644 --- a/numass-workspace/build.gradle.kts +++ b/numass-workspace/build.gradle.kts @@ -1,7 +1,6 @@ plugins { kotlin("jvm") id("ru.mipt.npm.gradle.common") - id("com.github.johnrengelman.shadow") version "6.1.0" `maven-publish` } @@ -10,7 +9,7 @@ kotlin { } val dataforgeVersion: String by rootProject.extra -val plotlyVersion: String by rootProject.extra("0.4.0") +val plotlyVersion: String by rootProject.extra val kmathVersion: String by rootProject.extra dependencies { diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2020_12.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2020_12.kt index 9802148..0c5e533 100644 --- a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2020_12.kt +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2020_12.kt @@ -14,7 +14,7 @@ suspend fun main() { operator?.startsWith("Vas") ?: false } - filtered.flow().collect { + filtered.flowData().collect { println(it) } } \ No newline at end of file diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/NumassPlugin.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/NumassPlugin.kt index 7e6fc4d..374172f 100644 --- a/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/NumassPlugin.kt +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/NumassPlugin.kt @@ -1,25 +1,11 @@ package ru.inr.mass.workspace -import ru.inr.mass.data.analysis.SmartAnalyzer -import ru.inr.mass.data.api.NumassSet import ru.inr.mass.data.proto.NumassProtoPlugin import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.PluginFactory import space.kscience.dataforge.context.PluginTag -import space.kscience.dataforge.data.select import space.kscience.dataforge.meta.Meta -import space.kscience.dataforge.meta.boolean -import space.kscience.dataforge.meta.descriptors.MetaDescriptor -import space.kscience.dataforge.meta.descriptors.value -import space.kscience.dataforge.meta.get -import space.kscience.dataforge.meta.toMutableMeta -import space.kscience.dataforge.names.Name -import space.kscience.dataforge.tables.Table -import space.kscience.dataforge.values.Value -import space.kscience.dataforge.values.ValueType import space.kscience.dataforge.workspace.WorkspacePlugin -import space.kscience.dataforge.workspace.pipeFrom -import space.kscience.dataforge.workspace.task import kotlin.reflect.KClass class NumassPlugin : WorkspacePlugin() { @@ -27,40 +13,40 @@ class NumassPlugin : WorkspacePlugin() { val numassProtoPlugin by require(NumassProtoPlugin) - val select by task( - descriptor = MetaDescriptor { - info = "Select data from workspace data pool" - value("forward", ValueType.BOOLEAN) { - info = "Select only forward or only backward sets" - } - } - ) { - val forward = meta["forward"]?.boolean - val filtered = workspace.data.select { _, meta -> - when (forward) { - true -> meta["iteration_info.reverse"]?.boolean?.not() ?: false - false -> meta["iteration_info.reverse"]?.boolean ?: false - else -> true - } - } - - emit(Name.EMPTY, filtered) - } - - val analyze by task>( - MetaDescriptor { - info = "Count the number of events for each voltage and produce a table with the results" - } - ) { - pipeFrom(select) { set, name, meta -> - val res = SmartAnalyzer.analyzeSet(set, meta["analyzer"] ?: Meta.EMPTY) - val outputMeta = meta.toMutableMeta().apply { - "data" put set.meta - } - // context.output.render(res, stage = "numass.analyze", name = name, meta = outputMeta) - res - } - } +// val select by task( +// descriptor = MetaDescriptor { +// info = "Select data from workspace data pool" +// value("forward", ValueType.BOOLEAN) { +// info = "Select only forward or only backward sets" +// } +// } +// ) { +// val forward = meta["forward"]?.boolean +// val filtered = workspace.data.select { _, meta -> +// when (forward) { +// true -> meta["iteration_info.reverse"]?.boolean?.not() ?: false +// false -> meta["iteration_info.reverse"]?.boolean ?: false +// else -> true +// } +// } +// +// emit(Name.EMPTY, filtered) +// } +// +// val analyze by task>( +// MetaDescriptor { +// info = "Count the number of events for each voltage and produce a table with the results" +// } +// ) { +// pipeFrom(select) { set, name, meta -> +// val res = SmartAnalyzer.analyzeSet(set, meta["analyzer"] ?: Meta.EMPTY) +// val outputMeta = meta.toMutableMeta().apply { +// "data" put set.meta +// } +// // context.output.render(res, stage = "numass.analyze", name = name, meta = outputMeta) +// res +// } +// } companion object : PluginFactory { override val tag: PluginTag = PluginTag("numass", "ru.mipt.npm") diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt index 6ee9cea..5ff2565 100644 --- a/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/workspace/plots.kt @@ -3,7 +3,7 @@ package ru.inr.mass.workspace import kotlinx.html.h1 import kotlinx.html.h2 import ru.inr.mass.data.api.NumassPoint -import ru.inr.mass.data.proto.HVEntry +import ru.inr.mass.data.proto.HVData import ru.inr.mass.data.proto.NumassDirectorySet import space.kscience.dataforge.values.asValue import space.kscience.dataforge.values.double @@ -42,7 +42,7 @@ fun Plot.amplitudeSpectrum( /** * Generate a plot from hv data */ -fun Plot.hvData(data: List): Trace = scatter { +fun Plot.hvData(data: HVData): Trace = scatter { x.strings = data.map { it.timestamp.toString() } y.numbers = data.map { it.value } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 3df4d32..fefa4b8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,30 +1,16 @@ -pluginManagement { +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") +enableFeaturePreview("VERSION_CATALOGS") + +dependencyResolutionManagement { repositories { + mavenLocal() maven("https://repo.kotlin.link") mavenCentral() - gradlePluginPortal() - mavenLocal() } - val toolsVersion = "0.10.7" - val kotlinVersion = "1.6.0" - - plugins { - id("ru.mipt.npm.gradle.project") version toolsVersion - id("ru.mipt.npm.gradle.mpp") version toolsVersion - id("ru.mipt.npm.gradle.jvm") version toolsVersion - id("ru.mipt.npm.gradle.js") version toolsVersion - kotlin("jvm") version kotlinVersion - kotlin("js") version kotlinVersion - } - - resolutionStrategy { - eachPlugin { - if (requested.id.id == "com.squareup.wire") { - // For some reason, Gradle does a lookup on the wrong coordinates: - // 'com.squareup.wire:com.squareup.wire.gradle.plugin' instead of the one below. - useModule("com.squareup.wire:wire-gradle-plugin:${requested.version}") - } + versionCatalogs { + create("npm") { + from("ru.mipt.npm:version-catalog:0.10.8-kotlin-1.6.0") } } } @@ -33,6 +19,7 @@ include( ":numass-data-model", ":numass-analysis", ":numass-data-proto", + //":numass-data-server", ":numass-workspace", ":numass-model" )