diff --git a/build.gradle.kts b/build.gradle.kts index 06d80994..a2a7f5b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,9 @@ plugins { - id("scientifik.mpp") version "0.2.0" apply false - id("scientifik.publish") version "0.2.0" apply false + id("scientifik.mpp") version "0.2.1" apply false + id("scientifik.publish") version "0.2.1" apply false } -val dataforgeVersion by extra("0.1.4-dev-4") +val dataforgeVersion by extra("0.1.4-dev-5") val bintrayRepo by extra("dataforge") val githubProject by extra("dataforge-core") diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ItemDescriptor.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ItemDescriptor.kt index 09e4d11e..0a25ff4d 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ItemDescriptor.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/descriptors/ItemDescriptor.kt @@ -32,13 +32,11 @@ sealed class ItemDescriptor(override val config: Config) : Specific { var info: String? by string() /** - * A list of tags for this item. Tags used to customize item usage + * Additional attributes of an item. For example validation and widget parameters * * @return */ - var tags: List by value { value -> - value?.list?.map { it.string } ?: emptyList() - } + var attributes by node() /** * True if the item is required @@ -54,7 +52,7 @@ sealed class ItemDescriptor(override val config: Config) : Specific { * * @author Alexander Nozik */ -class NodeDescriptor(config: Config) : ItemDescriptor(config){ +class NodeDescriptor(config: Config) : ItemDescriptor(config) { /** * True if the node is required @@ -68,7 +66,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config){ * * @return */ - var default: Meta? by node() + var default: Config? by node() /** * The list of value descriptors @@ -79,7 +77,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config){ } fun value(name: String, descriptor: ValueDescriptor) { - if(items.keys.contains(name)) error("The key $name already exists in descriptor") + if (items.keys.contains(name)) error("The key $name already exists in descriptor") val token = NameToken(VALUE_KEY, name) config[token] = descriptor.config } @@ -101,7 +99,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config){ fun node(name: String, descriptor: NodeDescriptor) { - if(items.keys.contains(name)) error("The key $name already exists in descriptor") + if (items.keys.contains(name)) error("The key $name already exists in descriptor") val token = NameToken(NODE_KEY, name) config[token] = descriptor.config } @@ -117,7 +115,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config){ companion object : Specification { -// const val ITEM_KEY = "item" + // const val ITEM_KEY = "item" const val NODE_KEY = "node" const val VALUE_KEY = "value" @@ -135,7 +133,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config){ * * @author Alexander Nozik */ -class ValueDescriptor(config: Config) : ItemDescriptor(config){ +class ValueDescriptor(config: Config) : ItemDescriptor(config) { /** diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/configDelegates.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/configDelegates.kt index 45b6b4d2..1dabd05b 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/configDelegates.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/configDelegates.kt @@ -105,7 +105,7 @@ inline fun > Configurable.enum(default: E, key: Name? = null /* Node delegates */ -fun Configurable.node(key: Name? = null) = MutableNodeDelegate(config, key) +fun Configurable.node(key: Name? = null): MutableNodeDelegate = MutableNodeDelegate(config, key) fun Configurable.spec(spec: Specification, key: Name? = null) = MutableMorphDelegate(config, key) { spec.wrap(it) } @@ -133,5 +133,5 @@ fun Configurable.doubleArray(key: Name? = null): ReadWriteDelegateWrapper Configurable.child(key: Name? = null, converter: (Meta) -> T) = +fun Configurable.node(key: Name? = null, converter: (Meta) -> T) = MutableMorphDelegate(config, key, converter) diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/metaDelegates.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/metaDelegates.kt index e9c19864..6bed5413 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/metaDelegates.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/metaDelegates.kt @@ -138,7 +138,7 @@ fun Meta.boolean(default: Boolean? = null, key: String? = null) = BooleanDelegat fun Meta.number(default: Number? = null, key: String? = null) = NumberDelegate(this, key, default) -fun Meta.child(key: String? = null) = ChildDelegate(this, key) { it } +fun Meta.node(key: String? = null) = ChildDelegate(this, key) { it } @JvmName("safeString") fun Meta.string(default: String, key: String? = null) = @@ -169,7 +169,7 @@ inline fun > Meta.enum(default: E, key: String? = null) = SafeEnumDelegate(this, key, default) { enumValueOf(it) } -fun Metoid.child(key: String? = null, converter: (Meta) -> T) = ChildDelegate(meta, key, converter) +fun Metoid.node(key: String? = null, converter: (Meta) -> T) = ChildDelegate(meta, key, converter) /* Read-write delegates */ @@ -337,12 +337,12 @@ class MutableSafeEnumvDelegate, E : Enum>( class MutableNodeDelegate>( val meta: M, private val key: Name? = null -) : ReadWriteProperty { - override fun getValue(thisRef: Any?, property: KProperty<*>): Meta? { +) : ReadWriteProperty { + override fun getValue(thisRef: Any?, property: KProperty<*>): M? { return meta[key ?: property.name.asName()]?.node } - override fun setValue(thisRef: Any?, property: KProperty<*>, value: Meta?) { + override fun setValue(thisRef: Any?, property: KProperty<*>, value: M?) { meta[key ?: property.name.asName()] = value } } diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt index f59c3d24..ff499888 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt @@ -19,20 +19,20 @@ class GenericTask( private val dataTransform: Workspace.() -> TaskModel.(DataNode) -> DataNode ) : Task { - private fun gather(workspace: Workspace, model: TaskModel): DataNode { - return DataNode.invoke(Any::class) { - model.dependencies.forEach { dep -> - update(dep.apply(workspace)) - } - } - } +// private fun gather(workspace: Workspace, model: TaskModel): DataNode { +// return DataNode.invoke(Any::class) { +// model.dependencies.forEach { dep -> +// update(dep.apply(workspace)) +// } +// } +// } override fun run(workspace: Workspace, model: TaskModel): DataNode { //validate model validate(model) // gather data - val input = gather(workspace, model) + val input = model.buildInput(workspace)// gather(workspace, model) //execute workspace.context.logger.info{"Starting task '$name' on ${model.target} with meta: \n${model.meta}"} diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt index 7f9cd976..f71f01a0 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt @@ -8,7 +8,6 @@ package hep.dataforge.workspace import hep.dataforge.data.DataFilter import hep.dataforge.data.DataTree import hep.dataforge.data.DataTreeBuilder -import hep.dataforge.data.dataSequence import hep.dataforge.meta.* import hep.dataforge.names.EmptyName import hep.dataforge.names.Name @@ -53,9 +52,8 @@ data class TaskModel( */ fun TaskModel.buildInput(workspace: Workspace): DataTree { return DataTreeBuilder(Any::class).apply { - dependencies.asSequence().flatMap { it.apply(workspace).dataSequence() }.forEach { (name, data) -> - //TODO add concise error on replacement - this[name] = data + dependencies.forEach { dep -> + update(dep.apply(workspace)) } }.build() } diff --git a/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt b/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt index f45f8720..3059cb29 100644 --- a/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt +++ b/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt @@ -35,6 +35,14 @@ class SimpleWorkspaceTest { } } + val filterTask = task("filterOne") { + model { + data("myData\\[12\\]") + } + pipe{ + it + } + } val square = task("square") { pipe { data -> @@ -150,4 +158,10 @@ class SimpleWorkspaceTest { val node = workspace.run("fullsquare") println(node.toMeta()) } + + @Test + fun testGather() { + val node = workspace.run("filterOne") + assertEquals(12, node.first()?.get()) + } } \ No newline at end of file