Directory and file accessors
This commit is contained in:
parent
ddbd9bf3cd
commit
e52924a5e2
@ -2,13 +2,19 @@ plugins {
|
|||||||
id("ru.mipt.npm.project")
|
id("ru.mipt.npm.project")
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "ru.inr.mass"
|
allprojects {
|
||||||
version = "0.1.0-SHAPSHOT"
|
group = "ru.inr.mass"
|
||||||
|
version = "0.1.0-SHAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
val dataforgeVersion by extra("0.3.0-dev")
|
val dataforgeVersion by extra("0.3.0-dev-1")
|
||||||
|
|
||||||
val spaceRepo by extra("https://maven.pkg.jetbrains.space/mipt-npm/p/numass/maven")
|
|
||||||
|
|
||||||
apiValidation{
|
apiValidation{
|
||||||
validationDisabled = true
|
validationDisabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val vcs by project.extra("https://mipt-npm.jetbrains.space/p/numass/code/numass/")
|
||||||
|
|
||||||
|
ksciencePublish{
|
||||||
|
spaceRepo = "https://maven.pkg.jetbrains.space/mipt-npm/p/numass/maven"
|
||||||
|
}
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -3,6 +3,10 @@ plugins {
|
|||||||
id("ru.mipt.npm.kscience")
|
id("ru.mipt.npm.kscience")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kscience{
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
|
||||||
val dataforgeVersion: String by rootProject.extra
|
val dataforgeVersion: String by rootProject.extra
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package ru.inr.mass.data.api
|
package ru.inr.mass.data.api
|
||||||
|
|
||||||
import hep.dataforge.context.Named
|
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.meta.get
|
import hep.dataforge.meta.get
|
||||||
import hep.dataforge.meta.long
|
import hep.dataforge.meta.long
|
||||||
@ -13,14 +12,13 @@ import hep.dataforge.names.Name
|
|||||||
import hep.dataforge.names.toName
|
import hep.dataforge.names.toName
|
||||||
import hep.dataforge.provider.Provider
|
import hep.dataforge.provider.Provider
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A single set of numass points previously called file.
|
* A single set of numass measurements together with metadata.
|
||||||
*
|
*
|
||||||
* @author [Alexander Nozik](mailto:altavir@gmail.com)
|
* @author [Alexander Nozik](mailto:altavir@gmail.com)
|
||||||
*/
|
*/
|
||||||
public interface NumassSet : Named, Iterable<NumassPoint>, Provider {
|
public interface NumassSet : Iterable<NumassPoint>, Provider {
|
||||||
|
|
||||||
public val meta: Meta
|
public val meta: Meta
|
||||||
|
|
||||||
@ -32,7 +30,9 @@ public interface NumassSet : Named, Iterable<NumassPoint>, Provider {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public val startTime: Instant
|
public val startTime: Instant
|
||||||
get() = meta[NumassPoint.START_TIME_KEY].long?.let { Instant.ofEpochMilli(it) } ?: firstPoint.startTime
|
get() = meta[NumassPoint.START_TIME_KEY].long?.let {
|
||||||
|
Instant.ofEpochMilli(it)
|
||||||
|
} ?: firstPoint.startTime
|
||||||
|
|
||||||
//suspend fun getHvData(): Table?
|
//suspend fun getHvData(): Table?
|
||||||
|
|
||||||
@ -44,9 +44,9 @@ public interface NumassSet : Named, Iterable<NumassPoint>, Provider {
|
|||||||
override val defaultTarget: String get() = NUMASS_POINT_PROVIDER_KEY
|
override val defaultTarget: String get() = NUMASS_POINT_PROVIDER_KEY
|
||||||
|
|
||||||
override fun content(target: String): Map<Name, Any> {
|
override fun content(target: String): Map<Name, Any> {
|
||||||
return if(target == NUMASS_POINT_PROVIDER_KEY){
|
return if (target == NUMASS_POINT_PROVIDER_KEY) {
|
||||||
points.associate { "point[${it.voltage}]".toName() to it }
|
points.associateBy { "point[${it.voltage}]".toName() }
|
||||||
}else {
|
} else {
|
||||||
super.content(target)
|
super.content(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import com.google.protobuf.gradle.*
|
import com.google.protobuf.gradle.proto
|
||||||
|
import com.google.protobuf.gradle.protobuf
|
||||||
|
import com.google.protobuf.gradle.protoc
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
@ -7,6 +9,10 @@ plugins {
|
|||||||
id("com.google.protobuf") version "0.8.14"
|
id("com.google.protobuf") version "0.8.14"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kscience{
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
|
||||||
val dataforgeVersion: String by rootProject.extra
|
val dataforgeVersion: String by rootProject.extra
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package ru.inr.mass.data.proto
|
||||||
|
|
||||||
|
import hep.dataforge.context.Context
|
||||||
|
import hep.dataforge.context.logger
|
||||||
|
import hep.dataforge.io.io
|
||||||
|
import hep.dataforge.io.readEnvelopeFile
|
||||||
|
import hep.dataforge.meta.Meta
|
||||||
|
import ru.inr.mass.data.api.NumassPoint
|
||||||
|
import ru.inr.mass.data.api.NumassSet
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.io.path.ExperimentalPathApi
|
||||||
|
import kotlin.io.path.div
|
||||||
|
import kotlin.io.path.exists
|
||||||
|
import kotlin.io.path.isDirectory
|
||||||
|
import kotlin.streams.toList
|
||||||
|
|
||||||
|
@OptIn(ExperimentalPathApi::class)
|
||||||
|
public class NumassDirectorySet internal constructor(
|
||||||
|
public val context: Context,
|
||||||
|
public val path: Path,
|
||||||
|
) : NumassSet {
|
||||||
|
|
||||||
|
override val meta: Meta by lazy {
|
||||||
|
val metaFilePath = path / "meta"
|
||||||
|
if (metaFilePath.exists()) {
|
||||||
|
val envelope = context.io.readEnvelopeFile(path) ?: error("Envelope could not be read from $path")
|
||||||
|
envelope.meta
|
||||||
|
} else {
|
||||||
|
Meta.EMPTY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val points: List<NumassPoint> by lazy<List<NumassPoint>> {
|
||||||
|
Files.list(path).filter { it.fileName.startsWith("p") }.map { path ->
|
||||||
|
try {
|
||||||
|
context.readNumassFile(path)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
context.logger.error(e) { "Error reading Numass point file $path" }
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}.toList().filterNotNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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")
|
||||||
|
return NumassDirectorySet(this, path)
|
||||||
|
}
|
@ -9,7 +9,7 @@ import hep.dataforge.meta.Meta
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
public class NumassProtoPlugin : AbstractPlugin() {
|
public class NumassProtoPlugin : AbstractPlugin() {
|
||||||
val io by require(IOPlugin)
|
public val io: IOPlugin by require(IOPlugin)
|
||||||
override val tag: PluginTag get() = Companion.tag
|
override val tag: PluginTag get() = Companion.tag
|
||||||
|
|
||||||
public companion object : PluginFactory<NumassProtoPlugin> {
|
public companion object : PluginFactory<NumassProtoPlugin> {
|
||||||
|
@ -16,10 +16,7 @@
|
|||||||
|
|
||||||
package ru.inr.mass.data.proto
|
package ru.inr.mass.data.proto
|
||||||
|
|
||||||
import hep.dataforge.context.Context
|
|
||||||
import hep.dataforge.io.Envelope
|
import hep.dataforge.io.Envelope
|
||||||
import hep.dataforge.io.io
|
|
||||||
import hep.dataforge.io.readEnvelopeFile
|
|
||||||
import hep.dataforge.meta.*
|
import hep.dataforge.meta.*
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
@ -30,7 +27,6 @@ import ru.inr.mass.data.api.*
|
|||||||
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.file.Path
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.zip.Inflater
|
import java.util.zip.Inflater
|
||||||
@ -76,7 +72,6 @@ public class ProtoNumassPoint(
|
|||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get valid data stream utilizing compression if it is present
|
* Get valid data stream utilizing compression if it is present
|
||||||
*/
|
*/
|
||||||
@ -114,24 +109,10 @@ public class ProtoNumassPoint(
|
|||||||
}
|
}
|
||||||
return proto?.let { ProtoNumassPoint(envelope.meta) { it } }
|
return proto?.let { ProtoNumassPoint(envelope.meta) { it } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun fromFile(context: Context, path: Path): ProtoNumassPoint? {
|
|
||||||
val envelope = context.io.readEnvelopeFile(path) ?: error("Envelope could not be read from $path")
|
|
||||||
return fromEnvelope(envelope)
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun fromFile(context: Context, path: String): ProtoNumassPoint? {
|
|
||||||
return fromFile(context,Path.of(path))
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun ofEpochNanos(nanos: Long): Instant {
|
|
||||||
val seconds = Math.floorDiv(nanos, 1e9.toInt().toLong())
|
|
||||||
val reminder = (nanos % 1e9).toInt()
|
|
||||||
return Instant.ofEpochSecond(seconds, reminder.toLong())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class ProtoBlock(
|
public class ProtoBlock(
|
||||||
override val channel: Int,
|
override val channel: Int,
|
||||||
private val block: NumassProto.Point.Channel.Block,
|
private val block: NumassProto.Point.Channel.Block,
|
||||||
@ -139,7 +120,7 @@ public class ProtoBlock(
|
|||||||
) : NumassBlock {
|
) : NumassBlock {
|
||||||
|
|
||||||
override val startTime: Instant
|
override val startTime: Instant
|
||||||
get() = ProtoNumassPoint.ofEpochNanos(block.time)
|
get() = epochNanoTime(block.time)
|
||||||
|
|
||||||
override val length: Duration = when {
|
override val length: Duration = when {
|
||||||
block.length > 0 -> Duration.ofNanos(block.length)
|
block.length > 0 -> Duration.ofNanos(block.length)
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package ru.inr.mass.data.proto
|
||||||
|
|
||||||
|
import hep.dataforge.context.Context
|
||||||
|
import hep.dataforge.io.io
|
||||||
|
import hep.dataforge.io.readEnvelopeFile
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
public fun Context.readNumassFile(path: Path): ProtoNumassPoint? {
|
||||||
|
val envelope = io.readEnvelopeFile(path) ?: error("Envelope could not be read from $path")
|
||||||
|
return ProtoNumassPoint.fromEnvelope(envelope)
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun Context.readNumassFile(path: String): ProtoNumassPoint? = readNumassFile(Path.of(path))
|
@ -0,0 +1,10 @@
|
|||||||
|
package ru.inr.mass.data.proto
|
||||||
|
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
|
|
||||||
|
internal fun epochNanoTime(nanos: Long): Instant {
|
||||||
|
val seconds = Math.floorDiv(nanos, 1e9.toInt().toLong())
|
||||||
|
val reminder = (nanos % 1e9).toInt()
|
||||||
|
return Instant.ofEpochSecond(seconds, reminder.toLong())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user