Upgraded plugin and added test for data gathering in workspace.

This commit is contained in:
Alexander Nozik 2019-10-09 19:10:37 +03:00
parent 156a43d4bf
commit 23a2d29e84
7 changed files with 42 additions and 32 deletions

View File

@ -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")

View File

@ -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<String> 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<NodeDescriptor> {
// 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) {
/**

View File

@ -105,7 +105,7 @@ inline fun <reified E : Enum<E>> 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<Config> = MutableNodeDelegate(config, key)
fun <T : Specific> Configurable.spec(spec: Specification<T>, key: Name? = null) =
MutableMorphDelegate(config, key) { spec.wrap(it) }
@ -133,5 +133,5 @@ fun Configurable.doubleArray(key: Name? = null): ReadWriteDelegateWrapper<Value?
?: doubleArrayOf()
}
fun <T : Configurable> Configurable.child(key: Name? = null, converter: (Meta) -> T) =
fun <T : Configurable> Configurable.node(key: Name? = null, converter: (Meta) -> T) =
MutableMorphDelegate(config, key, converter)

View File

@ -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 <reified E : Enum<E>> Meta.enum(default: E, key: String? = null) =
SafeEnumDelegate(this, key, default) { enumValueOf(it) }
fun <T : Metoid> Metoid.child(key: String? = null, converter: (Meta) -> T) = ChildDelegate(meta, key, converter)
fun <T : Metoid> Metoid.node(key: String? = null, converter: (Meta) -> T) = ChildDelegate(meta, key, converter)
/* Read-write delegates */
@ -337,12 +337,12 @@ class MutableSafeEnumvDelegate<M : MutableMeta<M>, E : Enum<E>>(
class MutableNodeDelegate<M : MutableMeta<M>>(
val meta: M,
private val key: Name? = null
) : ReadWriteProperty<Any?, Meta?> {
override fun getValue(thisRef: Any?, property: KProperty<*>): Meta? {
) : ReadWriteProperty<Any?, M?> {
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
}
}

View File

@ -19,20 +19,20 @@ class GenericTask<R : Any>(
private val dataTransform: Workspace.() -> TaskModel.(DataNode<Any>) -> DataNode<R>
) : Task<R> {
private fun gather(workspace: Workspace, model: TaskModel): DataNode<Any> {
return DataNode.invoke(Any::class) {
model.dependencies.forEach { dep ->
update(dep.apply(workspace))
}
}
}
// private fun gather(workspace: Workspace, model: TaskModel): DataNode<Any> {
// return DataNode.invoke(Any::class) {
// model.dependencies.forEach { dep ->
// update(dep.apply(workspace))
// }
// }
// }
override fun run(workspace: Workspace, model: TaskModel): DataNode<R> {
//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}"}

View File

@ -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<Any> {
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()
}

View File

@ -35,6 +35,14 @@ class SimpleWorkspaceTest {
}
}
val filterTask = task<Int>("filterOne") {
model {
data("myData\\[12\\]")
}
pipe<Int>{
it
}
}
val square = task<Int>("square") {
pipe<Int> { 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())
}
}