Updated kotlin to 1.2.40
This commit is contained in:
parent
8a45cc4517
commit
1a9309fd21
16
build.gradle
16
build.gradle
@ -1,9 +1,9 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = "1.2.31"
|
ext.kotlin_version = "1.2.40"
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
maven {
|
maven {
|
||||||
url "https://dl.bintray.com/kotlin/kotlin-eap"
|
url = "https://dl.bintray.com/kotlin/kotlin-eap"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ buildscript {
|
|||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allprojects{
|
allprojects {
|
||||||
apply plugin: 'idea'
|
apply plugin: 'idea'
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: "kotlin"
|
apply plugin: "kotlin"
|
||||||
@ -25,12 +25,12 @@ allprojects{
|
|||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
//maven { url "https://jitpack.io" }
|
maven { url = "https://jitpack.io" }
|
||||||
maven { url "http://dl.bintray.com/kotlin/ktor" }
|
maven { url = "http://dl.bintray.com/kotlin/ktor" }
|
||||||
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
|
maven { url = "https://dl.bintray.com/kotlin/kotlinx" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies{
|
dependencies {
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.+'
|
testCompile group: 'junit', name: 'junit', version: '4.+'
|
||||||
@ -45,7 +45,7 @@ allprojects{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTestKotlin{
|
compileTestKotlin {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "1.8"
|
jvmTarget = "1.8"
|
||||||
javaParameters = true
|
javaParameters = true
|
||||||
|
@ -102,7 +102,7 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable {
|
|||||||
*/
|
*/
|
||||||
private data class BoardState(val num: Int, var meta: Meta? = null)
|
private data class BoardState(val num: Int, var meta: Meta? = null)
|
||||||
|
|
||||||
private val boards = (0..chainLength).map { BoardState(it) }
|
private val boards = (0 until chainLength).map { BoardState(it) }
|
||||||
|
|
||||||
|
|
||||||
fun open() {
|
fun open() {
|
||||||
|
@ -33,7 +33,7 @@ import inr.numass.data.channel
|
|||||||
import kotlinx.coroutines.experimental.runBlocking
|
import kotlinx.coroutines.experimental.runBlocking
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val client = DanteClient("192.168.111.120", 7)
|
val client = DanteClient("192.168.111.120", 8)
|
||||||
client.open()
|
client.open()
|
||||||
val meta = buildMeta {
|
val meta = buildMeta {
|
||||||
"gain" to 1.0
|
"gain" to 1.0
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package inr.numass.data
|
package inr.numass.data
|
||||||
|
|
||||||
import hep.dataforge.io.envelopes.Envelope
|
import hep.dataforge.io.envelopes.Envelope
|
||||||
import hep.dataforge.kodex.nullable
|
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.meta.MetaBuilder
|
import hep.dataforge.meta.MetaBuilder
|
||||||
import inr.numass.data.api.*
|
import inr.numass.data.api.*
|
||||||
@ -63,16 +62,16 @@ val Envelope.dataStream: InputStream
|
|||||||
this.data.stream
|
this.data.stream
|
||||||
}
|
}
|
||||||
|
|
||||||
val NumassBlock.channel: Int?
|
val NumassBlock.channel: Int
|
||||||
get() = if (this is ProtoBlock) {
|
get() = if (this is ProtoBlock) {
|
||||||
this.channel
|
this.channel
|
||||||
} else {
|
} else {
|
||||||
this.meta.optValue("channel").map { it.getInt() }.nullable
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun NumassBlock.transformChain(transform: (NumassEvent, NumassEvent) -> Pair<Short, Long>?): NumassBlock {
|
fun NumassBlock.transformChain(transform: (NumassEvent, NumassEvent) -> Pair<Short, Long>?): NumassBlock {
|
||||||
return SimpleBlock(this.startTime, this.length, this.meta) { owner ->
|
return SimpleBlock(this.startTime, this.length) { owner ->
|
||||||
this.events.asSequence()
|
this.events.asSequence()
|
||||||
.sortedBy { it.timeOffset }
|
.sortedBy { it.timeOffset }
|
||||||
.zipWithNext(transform)
|
.zipWithNext(transform)
|
||||||
@ -82,7 +81,7 @@ fun NumassBlock.transformChain(transform: (NumassEvent, NumassEvent) -> Pair<Sho
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun NumassBlock.filterChain(condition: (NumassEvent, NumassEvent) -> Boolean): NumassBlock {
|
fun NumassBlock.filterChain(condition: (NumassEvent, NumassEvent) -> Boolean): NumassBlock {
|
||||||
return SimpleBlock(this.startTime, this.length, this.meta) { owner ->
|
return SimpleBlock(this.startTime, this.length) { owner ->
|
||||||
this.events.asSequence()
|
this.events.asSequence()
|
||||||
.sortedBy { it.timeOffset }
|
.sortedBy { it.timeOffset }
|
||||||
.zipWithNext().filter { condition.invoke(it.first, it.second) }.map { it.second }.asIterable()
|
.zipWithNext().filter { condition.invoke(it.first, it.second) }.map { it.second }.asIterable()
|
||||||
@ -90,13 +89,13 @@ fun NumassBlock.filterChain(condition: (NumassEvent, NumassEvent) -> Boolean): N
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun NumassBlock.filter(condition: (NumassEvent) -> Boolean): NumassBlock {
|
fun NumassBlock.filter(condition: (NumassEvent) -> Boolean): NumassBlock {
|
||||||
return SimpleBlock(this.startTime, this.length, this.meta) { owner ->
|
return SimpleBlock(this.startTime, this.length) { owner ->
|
||||||
this.events.asSequence().filter(condition).asIterable()
|
this.events.asSequence().filter(condition).asIterable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NumassBlock.transform(transform: (NumassEvent) -> OrphanNumassEvent): NumassBlock {
|
fun NumassBlock.transform(transform: (NumassEvent) -> OrphanNumassEvent): NumassBlock {
|
||||||
return SimpleBlock(this.startTime, this.length, this.meta) { owner ->
|
return SimpleBlock(this.startTime, this.length) { owner ->
|
||||||
this.events.asSequence()
|
this.events.asSequence()
|
||||||
.map { transform(it).adopt(owner) }
|
.map { transform(it).adopt(owner) }
|
||||||
.asIterable()
|
.asIterable()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package inr.numass.data.api
|
package inr.numass.data.api
|
||||||
|
|
||||||
import hep.dataforge.meta.Meta
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -10,7 +9,7 @@ import java.util.stream.Stream
|
|||||||
* A block constructed from a set of other blocks. Internal blocks are not necessary subsequent. Blocks are automatically sorted.
|
* A block constructed from a set of other blocks. Internal blocks are not necessary subsequent. Blocks are automatically sorted.
|
||||||
* Created by darksnake on 16.07.2017.
|
* Created by darksnake on 16.07.2017.
|
||||||
*/
|
*/
|
||||||
class MetaBlock(blocks: Collection<NumassBlock>, override val meta: Meta = Meta.empty()) : NumassBlock {
|
class MetaBlock(blocks: Collection<NumassBlock>) : NumassBlock {
|
||||||
|
|
||||||
private val blocks = TreeSet(Comparator.comparing<NumassBlock, Instant>{ it.startTime })
|
private val blocks = TreeSet(Comparator.comparing<NumassBlock, Instant>{ it.startTime })
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package inr.numass.data.api
|
package inr.numass.data.api
|
||||||
|
|
||||||
import hep.dataforge.meta.Meta
|
|
||||||
import hep.dataforge.meta.Metoid
|
|
||||||
import inr.numass.data.channel
|
import inr.numass.data.channel
|
||||||
import kotlinx.coroutines.experimental.runBlocking
|
import kotlinx.coroutines.experimental.runBlocking
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
@ -21,7 +19,7 @@ import java.util.stream.Stream
|
|||||||
*/
|
*/
|
||||||
class NumassEvent(val amp: Short, val timeOffset: Long, val owner: NumassBlock) : Serializable {
|
class NumassEvent(val amp: Short, val timeOffset: Long, val owner: NumassBlock) : Serializable {
|
||||||
|
|
||||||
val channel: Int?
|
val channel: Int
|
||||||
get() = owner.channel
|
get() = owner.channel
|
||||||
|
|
||||||
val time: Instant
|
val time: Instant
|
||||||
@ -36,7 +34,7 @@ class NumassEvent(val amp: Short, val timeOffset: Long, val owner: NumassBlock)
|
|||||||
*
|
*
|
||||||
* Created by darksnake on 06-Jul-17.
|
* Created by darksnake on 06-Jul-17.
|
||||||
*/
|
*/
|
||||||
interface NumassBlock : Metoid {
|
interface NumassBlock {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The absolute start time of the block
|
* The absolute start time of the block
|
||||||
@ -80,7 +78,6 @@ val OrphanNumassEvent.amp: Short
|
|||||||
class SimpleBlock(
|
class SimpleBlock(
|
||||||
override val startTime: Instant,
|
override val startTime: Instant,
|
||||||
override val length: Duration,
|
override val length: Duration,
|
||||||
override val meta: Meta = Meta.empty(),
|
|
||||||
producer: suspend (NumassBlock) -> Iterable<NumassEvent>) : NumassBlock, Serializable {
|
producer: suspend (NumassBlock) -> Iterable<NumassEvent>) : NumassBlock, Serializable {
|
||||||
|
|
||||||
private val eventList = runBlocking { producer(this@SimpleBlock).toList()}
|
private val eventList = runBlocking { producer(this@SimpleBlock).toList()}
|
||||||
|
@ -2,6 +2,7 @@ package inr.numass.data.api
|
|||||||
|
|
||||||
import hep.dataforge.io.envelopes.Envelope
|
import hep.dataforge.io.envelopes.Envelope
|
||||||
import hep.dataforge.meta.Metoid
|
import hep.dataforge.meta.Metoid
|
||||||
|
import inr.numass.data.channel
|
||||||
import inr.numass.data.storage.ClassicNumassPoint
|
import inr.numass.data.storage.ClassicNumassPoint
|
||||||
import inr.numass.data.storage.ProtoNumassPoint
|
import inr.numass.data.storage.ProtoNumassPoint
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
@ -45,7 +46,7 @@ interface NumassPoint : Metoid, NumassBlock {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
override val startTime: Instant
|
override val startTime: Instant
|
||||||
get() = meta.optValue(START_TIME_KEY).map<Instant> { it.getTime() }.orElseGet { firstBlock.startTime }
|
get() = meta.optValue(START_TIME_KEY).map<Instant> { it.time }.orElseGet { firstBlock.startTime }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the length key of meta or calculate length as a sum of block lengths. The latter could be a bit slow
|
* Get the length key of meta or calculate length as a sum of block lengths. The latter could be a bit slow
|
||||||
@ -53,10 +54,7 @@ interface NumassPoint : Metoid, NumassBlock {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
override val length: Duration
|
override val length: Duration
|
||||||
get() = Duration.ofNanos(
|
get() = Duration.ofNanos(blocks.filter{it.channel == 0}.mapToLong { it -> it.length.toNanos() }.sum())
|
||||||
meta.optValue(LENGTH_KEY).map<Long> { it.getLong() }
|
|
||||||
.orElseGet { blocks.mapToLong { it -> it.length.toNanos() }.sum() }
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all events it all blocks as a single sequence
|
* Get all events it all blocks as a single sequence
|
||||||
|
@ -49,8 +49,7 @@ class ClassicNumassPoint(private val envelope: Envelope) : NumassPoint {
|
|||||||
//TODO split blocks using meta
|
//TODO split blocks using meta
|
||||||
private inner class ClassicBlock(
|
private inner class ClassicBlock(
|
||||||
override val startTime: Instant,
|
override val startTime: Instant,
|
||||||
override val length: Duration,
|
override val length: Duration) : NumassBlock, Iterable<NumassEvent> {
|
||||||
override val meta: Meta = Meta.empty()) : NumassBlock, Iterable<NumassEvent> {
|
|
||||||
|
|
||||||
override val events: Stream<NumassEvent>
|
override val events: Stream<NumassEvent>
|
||||||
get() = StreamSupport.stream(this.spliterator(), false)
|
get() = StreamSupport.stream(this.spliterator(), false)
|
||||||
|
@ -3,9 +3,7 @@ package inr.numass.data.storage
|
|||||||
import hep.dataforge.context.Context
|
import hep.dataforge.context.Context
|
||||||
import hep.dataforge.context.Global
|
import hep.dataforge.context.Global
|
||||||
import hep.dataforge.io.envelopes.Envelope
|
import hep.dataforge.io.envelopes.Envelope
|
||||||
import hep.dataforge.kodex.buildMeta
|
|
||||||
import hep.dataforge.kodex.toList
|
import hep.dataforge.kodex.toList
|
||||||
import hep.dataforge.meta.Laminate
|
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import inr.numass.data.NumassProto
|
import inr.numass.data.NumassProto
|
||||||
import inr.numass.data.api.NumassBlock
|
import inr.numass.data.api.NumassBlock
|
||||||
@ -26,7 +24,9 @@ import java.util.stream.Stream
|
|||||||
* Protobuf based numass point
|
* Protobuf based numass point
|
||||||
* Created by darksnake on 09.07.2017.
|
* Created by darksnake on 09.07.2017.
|
||||||
*/
|
*/
|
||||||
class ProtoNumassPoint(val proto: NumassProto.Point, override val meta: Meta) : NumassPoint {
|
class ProtoNumassPoint(override val meta: Meta, protoBuilder: () -> NumassProto.Point) : NumassPoint {
|
||||||
|
|
||||||
|
val proto: NumassProto.Point by lazy(protoBuilder)
|
||||||
|
|
||||||
override val blocks: Stream<NumassBlock>
|
override val blocks: Stream<NumassBlock>
|
||||||
get() = proto.channelsList.stream()
|
get() = proto.channelsList.stream()
|
||||||
@ -47,16 +47,25 @@ class ProtoNumassPoint(val proto: NumassProto.Point, override val meta: Meta) :
|
|||||||
super.startTime
|
super.startTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val length: Duration
|
||||||
|
get() = if (meta.hasValue("acquisition_time")) {
|
||||||
|
Duration.ofMillis((meta.getDouble("acquisition_time") * 1000).toLong())
|
||||||
|
} else {
|
||||||
|
super.length
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun readFile(path: Path): ProtoNumassPoint {
|
fun readFile(path: Path): ProtoNumassPoint {
|
||||||
return fromEnvelope(NumassFileEnvelope.open(path, true))
|
return fromEnvelope(NumassFileEnvelope.open(path, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromEnvelope(envelope: Envelope): ProtoNumassPoint {
|
fun fromEnvelope(envelope: Envelope): ProtoNumassPoint {
|
||||||
val proto = envelope.dataStream.use {
|
return ProtoNumassPoint(envelope.meta){
|
||||||
|
envelope.dataStream.use {
|
||||||
NumassProto.Point.parseFrom(it)
|
NumassProto.Point.parseFrom(it)
|
||||||
}
|
}
|
||||||
return ProtoNumassPoint(proto, envelope.meta)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readFile(path: String, context: Context = Global): ProtoNumassPoint {
|
fun readFile(path: String, context: Context = Global): ProtoNumassPoint {
|
||||||
@ -71,20 +80,15 @@ class ProtoNumassPoint(val proto: NumassProto.Point, override val meta: Meta) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, parent: NumassBlock? = null) : NumassBlock {
|
class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, val parent: NumassPoint? = null) : NumassBlock {
|
||||||
override val meta: Meta by lazy {
|
|
||||||
val blockMeta = buildMeta {
|
|
||||||
"channel" to channel
|
|
||||||
}
|
|
||||||
return@lazy parent?.let { Laminate(blockMeta, parent.meta) } ?: blockMeta
|
|
||||||
}
|
|
||||||
|
|
||||||
override val startTime: Instant
|
override val startTime: Instant
|
||||||
get() = ProtoNumassPoint.ofEpochNanos(block.time)
|
get() = ProtoNumassPoint.ofEpochNanos(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)
|
||||||
meta.hasValue("acquisition_time") -> Duration.ofMillis((meta.getDouble("acquisition_time") * 1000).toLong())
|
parent?.meta?.hasValue("acquisition_time") ?: false ->
|
||||||
|
Duration.ofMillis((parent!!.meta.getDouble("acquisition_time") * 1000).toLong())
|
||||||
else -> {
|
else -> {
|
||||||
LoggerFactory.getLogger(javaClass).error("No length information on block. Trying to infer from first and last events")
|
LoggerFactory.getLogger(javaClass).error("No length information on block. Trying to infer from first and last events")
|
||||||
val times = events.map { it.timeOffset }.toList()
|
val times = events.map { it.timeOffset }.toList()
|
||||||
|
@ -87,6 +87,17 @@ class StorageView(private val context: Context = Global) : View(title = "Numass
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val children: List<Container>? by lazy {
|
||||||
|
when (content) {
|
||||||
|
is Storage -> (content.shelves().sorted() + content.loaders().sorted()).map { buildContainer(it, this) }
|
||||||
|
is NumassSet -> content.points.map { buildContainer(it, this) }.toList().sortedBy { it.id }
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasChildren: Boolean
|
||||||
|
get() = (content is Storage) || (content is NumassPoint)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val root = borderpane {
|
override val root = borderpane {
|
||||||
@ -153,6 +164,15 @@ class StorageView(private val context: Context = Global) : View(title = "Numass
|
|||||||
}
|
}
|
||||||
runLater { statusBar.progress = 0.0 }
|
runLater { statusBar.progress = 0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
lazyPopulate( leafCheck = { it.value.hasChildren }) {
|
||||||
|
runLater { statusBar.progress = -1.0 }
|
||||||
|
it.value.children.also {
|
||||||
|
runLater { statusBar.progress = 0.0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cellFormat { value ->
|
cellFormat { value ->
|
||||||
|
Loading…
Reference in New Issue
Block a user