Run 2021_11 reader

This commit is contained in:
Alexander Nozik 2021-12-07 18:52:48 +03:00
parent 6b988f2849
commit c73ada2c51
6 changed files with 81 additions and 12 deletions

View File

@ -12,7 +12,7 @@ allprojects {
version = "0.1.0-dev-1" version = "0.1.0-dev-1"
} }
val dataforgeVersion by extra("0.5.2-dev-4") val dataforgeVersion by extra("0.5.2")
val kmathVersion by extra("0.3.0-dev-17") val kmathVersion by extra("0.3.0-dev-17")
val plotlyVersion: String by extra("0.5.0") val plotlyVersion: String by extra("0.5.0")

View File

@ -11,5 +11,5 @@ repositories {
dependencies { dependencies {
api("com.squareup.wire:wire-gradle-plugin:3.7.1") api("com.squareup.wire:wire-gradle-plugin:3.7.1")
api("ru.mipt.npm:gradle-tools:0.10.8-kotlin-1.6.0") api("ru.mipt.npm:gradle-tools:0.10.7")
} }

View File

@ -12,6 +12,7 @@ kotlin.sourceSets {
commonMain { commonMain {
dependencies { dependencies {
api(project(":numass-data-model")) api(project(":numass-data-model"))
api("space.kscience:dataforge-io:$dataforgeVersion")
api("space.kscience:tables-kt:0.1.1-dev-2") api("space.kscience:tables-kt:0.1.1-dev-2")
api("space.kscience:kmath-complex:$kmathVersion") api("space.kscience:kmath-complex:$kmathVersion")
api("space.kscience:kmath-stat:$kmathVersion") api("space.kscience:kmath-stat:$kmathVersion")

View File

@ -30,6 +30,7 @@ import space.kscience.dataforge.meta.*
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.InputStream import java.io.InputStream
import java.nio.ByteOrder
import java.util.zip.Inflater import java.util.zip.Inflater
import kotlin.time.Duration import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.milliseconds
@ -46,11 +47,19 @@ internal class ProtoNumassPoint(
val point: Point by lazy(protoBuilder) val point: Point by lazy(protoBuilder)
override fun flowBlocks() = point.channels.flatMap { channel -> override fun flowBlocks(): Flow<ProtoNumassBlock> {
channel.blocks val frameByteOrder = if (meta["tqdc"] != null) {
.map { block -> ProtoNumassBlock(channel.id.toInt(), block, this) } ByteOrder.LITTLE_ENDIAN
.sortedBy { it.startTime } } else {
}.asFlow() ByteOrder.BIG_ENDIAN
}
return point.channels.flatMap { channel ->
channel.blocks
.map { block -> ProtoNumassBlock(channel.id.toInt(), block, this, frameByteOrder) }
.sortedBy { it.startTime }
}.asFlow()
}
override suspend fun getChannels(): Map<Int, NumassBlock> = override suspend fun getChannels(): Map<Int, NumassBlock> =
point.channels.groupBy { it.id.toInt() }.mapValues { entry -> point.channels.groupBy { it.id.toInt() }.mapValues { entry ->
@ -120,10 +129,12 @@ internal class ProtoNumassPoint(
} }
public fun fromEnvelope(envelope: Envelope): ProtoNumassPoint? { public fun fromEnvelope(envelope: Envelope): ProtoNumassPoint? {
val proto = envelope.useData { if (envelope.data == null) return null
Point.ADAPTER.decode(it) return ProtoNumassPoint(envelope.meta) {
envelope.useData {
Point.ADAPTER.decode(it)
} ?: error("Data is empty")
} }
return proto?.let { ProtoNumassPoint(envelope.meta) { it } }
} }
} }
} }
@ -133,6 +144,7 @@ public class ProtoNumassBlock(
override val channel: Int, override val channel: Int,
private val block: Point.Channel.Block, private val block: Point.Channel.Block,
private val parent: NumassPoint? = null, private val parent: NumassPoint? = null,
private val frameByteOrder: ByteOrder = ByteOrder.BIG_ENDIAN,
) : NumassBlock { ) : NumassBlock {
override val startTime: Instant override val startTime: Instant
@ -176,7 +188,9 @@ public class ProtoNumassBlock(
} }
private fun ByteString.toShortArray(): ShortArray { private fun ByteString.toShortArray(): ShortArray {
val shortBuffer = asByteBuffer().asShortBuffer() val shortBuffer = asByteBuffer().apply {
order(frameByteOrder)
}.asShortBuffer()
return if (shortBuffer.hasArray()) { return if (shortBuffer.hasArray()) {
shortBuffer.array() shortBuffer.array()
} else { } else {

View File

@ -0,0 +1,54 @@
package ru.inr.mass.scripts
import kotlinx.coroutines.flow.toList
import kotlinx.html.code
import kotlinx.html.h2
import kotlinx.html.p
import kotlinx.serialization.json.Json
import ru.inr.mass.workspace.readNumassDirectory
import space.kscience.dataforge.io.JsonMetaFormat
import space.kscience.dataforge.io.toString
import space.kscience.dataforge.meta.MetaSerializer
import space.kscience.plotly.*
suspend fun main() {
//val repo: DataTree<NumassDirectorySet> = readNumassRepository("D:\\Work\\numass-data\\")
val directory = readNumassDirectory("D:\\Work\\numass-data\\set_3\\")
val point = directory.points.first()
val frames = point.frames.toList()
Plotly.page {
p { +"${frames.size} frames" }
h2 { +"Random frames" }
plot {
val random = kotlin.random.Random(1234)
repeat(10) {
val frame = frames.random(random)
scatter {
y.numbers = frame.signal.map { it.toUShort().toInt() - Short.MAX_VALUE }
}
}
}
h2 { +"Analysis" }
plot {
histogram {
name="max"
x.numbers = frames.map { frame -> frame.signal.maxOf { it.toUShort().toInt() - Short.MAX_VALUE } }
}
histogram {
name="max-min"
xbins{
size = 2.0
}
x.numbers = frames.map { frame ->
frame.signal.maxOf { it.toUShort().toInt() - Short.MAX_VALUE } -
frame.signal.minOf { it.toUShort().toInt() - Short.MAX_VALUE }
}
}
}
h2 { +"Meta" }
p { +Json.encodeToString(MetaSerializer, point.meta) }
}.makeFile()
}

View File

@ -10,7 +10,7 @@ dependencyResolutionManagement {
versionCatalogs { versionCatalogs {
create("npm") { create("npm") {
from("ru.mipt.npm:version-catalog:0.10.8-kotlin-1.6.0") from("ru.mipt.npm:version-catalog:0.10.7")
} }
} }
} }