Cache update

This commit is contained in:
Alexander Nozik 2017-10-23 19:57:40 +03:00
parent edfa40ccdb
commit ec844b7f5c
6 changed files with 70 additions and 152 deletions

View File

@ -34,6 +34,10 @@ dependencies {
compile "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal') compile "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal')
compile "hep.dataforge:kmath" compile "hep.dataforge:kmath"
compile "hep.dataforge:kodex-fx" compile "hep.dataforge:kodex-fx"
// https://mvnrepository.com/artifact/org.ehcache/ehcache
compile group: 'org.ehcache', name: 'ehcache', version: '3.4.0'
} }
task repl(dependsOn: classes, type: JavaExec) { task repl(dependsOn: classes, type: JavaExec) {

View File

@ -61,18 +61,18 @@ class NumassPlugin : BasicPlugin() {
val actions = context.pluginManager().getOrLoad(ActionManager::class.java) val actions = context.pluginManager().getOrLoad(ActionManager::class.java)
actions.attach(context) actions.attach(context)
actions.putTask(NumassTableFilterTask::class.java)
actions.putTask(NumassFitScanTask::class.java) actions.putTask(NumassFitScanTask::class.java)
actions.putTask(NumassFitScanSummaryTask::class.java) actions.putTask(NumassFitScanSummaryTask::class.java)
actions.putTask(NumassFitTask::class.java)
actions.putTask(NumassFitSummaryTask::class.java) actions.putTask(NumassFitSummaryTask::class.java)
actions.put(selectDataTask) actions.put(selectTask)
actions.put(analyzeTask) actions.put(analyzeTask)
actions.put(mergeTask) actions.put(mergeTask)
actions.put(mergeEmptyTask) actions.put(mergeEmptyTask)
actions.put(monitorTableTask) actions.put(monitorTableTask)
actions.put(subtractEmptyTask) actions.put(subtractEmptyTask)
actions.put(transformTask) actions.put(transformTask)
actions.put(filterTask)
actions.put(fitTask)
} }
private fun loadMath(math: MathPlugin) { private fun loadMath(math: MathPlugin) {
@ -281,7 +281,8 @@ class NumassPlugin : BasicPlugin() {
* @param height * @param height
* @return * @return
*/ */
@JvmOverloads fun displayJFreeChart(title: String, width: Double = 800.0, height: Double = 600.0, meta: Meta = Meta.empty()): JFreeChartFrame { @JvmOverloads
fun displayJFreeChart(title: String, width: Double = 800.0, height: Double = 600.0, meta: Meta = Meta.empty()): JFreeChartFrame {
val frame = JFreeChartFrame(meta) val frame = JFreeChartFrame(meta)
frame.configureValue("title", title) frame.configureValue("title", title)
PlotContainer.display(frame, title, width, height) PlotContainer.display(frame, title, width, height)

View File

@ -30,6 +30,7 @@ import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.tables.ListTable import hep.dataforge.tables.ListTable
import hep.dataforge.tables.Table import hep.dataforge.tables.Table
import hep.dataforge.tables.ValueMap import hep.dataforge.tables.ValueMap
import hep.dataforge.values.ValueType
import hep.dataforge.values.Values import hep.dataforge.values.Values
import inr.numass.data.api.NumassAnalyzer import inr.numass.data.api.NumassAnalyzer
import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassPoint
@ -221,3 +222,19 @@ fun subtract(context: Context, merge: Table, empty: Table): Table {
return builder.build() return builder.build()
} }
fun Values.unbox(): Map<String, Any?> {
val res = HashMap<String, Any?>()
for (field in this.names) {
val value = this.getValue(field)
val obj: Any? = when (value.type) {
ValueType.BOOLEAN -> value.booleanValue()
ValueType.NUMBER -> value.doubleValue()
ValueType.STRING -> value.stringValue()
ValueType.TIME -> value.timeValue()
ValueType.NULL -> null
}
res.put(field, obj)
}
return res
}

View File

@ -1,61 +0,0 @@
/*
* Copyright 2015 Alexander Nozik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.tasks
import hep.dataforge.actions.Action
import hep.dataforge.actions.ActionUtils
import hep.dataforge.data.DataNode
import hep.dataforge.meta.Meta
import hep.dataforge.plotfit.PlotFitResultAction
import hep.dataforge.stat.fit.FitAction
import hep.dataforge.stat.fit.FitResult
import hep.dataforge.tables.Table
import hep.dataforge.workspace.tasks.SingleActionTask
import hep.dataforge.workspace.tasks.TaskModel
/**
* Created by darksnake on 16-Sep-16.
*/
class NumassFitTask : SingleActionTask<Table, FitResult>() {
override fun getName(): String {
return "fit"
}
override fun gatherNode(data: DataNode<*>): DataNode<Table> {
return data.checked(Table::class.java)
}
override fun validate(model: TaskModel) {
if (model.meta().isEmpty) {
throw RuntimeException("Fit element not found in model")
}
}
override fun getAction(model: TaskModel): Action<Table, FitResult> {
val action = FitAction()
return if (model.meta().getBoolean("frame", false)) {
ActionUtils.compose(action, PlotFitResultAction())
} else {
action
}
}
override fun buildModel(model: TaskModel.Builder, meta: Meta) {
model.dependsOn("filter", meta);
}
}

View File

@ -1,77 +0,0 @@
package inr.numass.tasks
import hep.dataforge.actions.Action
import hep.dataforge.actions.OneToOneAction
import hep.dataforge.context.Context
import hep.dataforge.data.DataNode
import hep.dataforge.description.TypedActionDef
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.Meta
import hep.dataforge.tables.Table
import hep.dataforge.tables.TableTransform
import hep.dataforge.values.ValueType
import hep.dataforge.values.Values
import hep.dataforge.workspace.tasks.SingleActionTask
import hep.dataforge.workspace.tasks.TaskModel
import inr.numass.data.api.NumassPoint
import inr.numass.utils.ExpressionUtils
import java.util.*
/**
* Created by darksnake on 13-Aug-16.
*/
class NumassTableFilterTask : SingleActionTask<Table, Table>() {
override fun getName(): String {
return "filter"
}
override fun gatherNode(data: DataNode<*>): DataNode<Table> {
return data.checked(Table::class.java)
}
override fun buildModel(model: TaskModel.Builder, meta: Meta) {
if (meta.hasMeta("empty")) {
model.dependsOn("dif", meta)
} else {
model.dependsOn("transform", meta)
}
}
override fun getAction(model: TaskModel): Action<Table, Table> {
return FilterTableAction()
}
@TypedActionDef(name = "filterTable", inputType = Table::class, outputType = Table::class)
private inner class FilterTableAction : OneToOneAction<Table, Table>() {
override fun execute(context: Context, name: String, input: Table, inputMeta: Laminate): Table {
if (inputMeta.hasValue("from") || inputMeta.hasValue("to")) {
val uLo = inputMeta.getDouble("from", 0.0)!!
val uHi = inputMeta.getDouble("to", java.lang.Double.POSITIVE_INFINITY)!!
getLogger(context, inputMeta).debug("Filtering finished")
return TableTransform.filter(input, NumassPoint.HV_KEY, uLo, uHi)
} else if (inputMeta.hasValue("condition")) {
return TableTransform.filter(input) { ExpressionUtils.condition(inputMeta.getString("condition"), unbox(it)) }
} else {
throw RuntimeException("No filtering condition specified")
}
}
}
private fun unbox(dp: Values): Map<String, Any?> {
val res = HashMap<String, Any?>()
for (field in dp.names) {
val value = dp.getValue(field)
val obj: Any? = when (value.type) {
ValueType.BOOLEAN -> value.booleanValue()
ValueType.NUMBER -> value.doubleValue()
ValueType.STRING -> value.stringValue()
ValueType.TIME -> value.timeValue()
ValueType.NULL -> null
}
res.put(field, obj)
}
return res
}
}

View File

@ -14,8 +14,11 @@ import hep.dataforge.meta.MetaUtils
import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.data.DataPlot import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.stat.fit.FitAction
import hep.dataforge.stat.fit.FitResult
import hep.dataforge.tables.ListTable import hep.dataforge.tables.ListTable
import hep.dataforge.tables.Table import hep.dataforge.tables.Table
import hep.dataforge.tables.TableTransform
import hep.dataforge.tables.XYAdapter import hep.dataforge.tables.XYAdapter
import hep.dataforge.values.ValueType import hep.dataforge.values.ValueType
import inr.numass.NumassUtils import inr.numass.NumassUtils
@ -24,10 +27,13 @@ import inr.numass.actions.MergeDataAction.MERGE_NAME
import inr.numass.actions.TransformDataAction import inr.numass.actions.TransformDataAction
import inr.numass.addSetMarkers import inr.numass.addSetMarkers
import inr.numass.data.analyzers.SmartAnalyzer import inr.numass.data.analyzers.SmartAnalyzer
import inr.numass.data.api.NumassPoint
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
import inr.numass.subtract import inr.numass.subtract
import inr.numass.unbox
import inr.numass.utils.ExpressionUtils
val selectDataTask = task("select") { val selectTask = task("select") {
model { meta -> model { meta ->
data("*") data("*")
configure(meta.getMetaOrEmpty("data")) configure(meta.getMetaOrEmpty("data"))
@ -40,7 +46,7 @@ val selectDataTask = task("select") {
@ValueDef(name = "showPlot", type = arrayOf(ValueType.BOOLEAN), info = "Show plot after complete") @ValueDef(name = "showPlot", type = arrayOf(ValueType.BOOLEAN), info = "Show plot after complete")
val monitorTableTask = task("monitor") { val monitorTableTask = task("monitor") {
model { meta -> model { meta ->
dependsOn("select", meta) dependsOn(selectTask, meta)
configure(meta.getMetaOrEmpty("analyzer")) configure(meta.getMetaOrEmpty("analyzer"))
} }
join<NumassSet, Table> { join<NumassSet, Table> {
@ -90,7 +96,7 @@ val monitorTableTask = task("monitor") {
val analyzeTask = task("analyze") { val analyzeTask = task("analyze") {
model { meta -> model { meta ->
dependsOn("select", meta); dependsOn(selectTask, meta);
configure(MetaUtils.optEither(meta, "analyzer", "prepare").orElse(Meta.empty())) configure(MetaUtils.optEither(meta, "analyzer", "prepare").orElse(Meta.empty()))
} }
pipe<NumassSet, Table> { pipe<NumassSet, Table> {
@ -106,7 +112,7 @@ val analyzeTask = task("analyze") {
val mergeTask = task("merge") { val mergeTask = task("merge") {
model { meta -> model { meta ->
dependsOn("analyze", meta) dependsOn(analyzeTask, meta)
configure(meta.getMetaOrEmpty("merge")) configure(meta.getMetaOrEmpty("merge"))
} }
action<Table, Table>(MergeDataAction()) action<Table, Table>(MergeDataAction())
@ -123,7 +129,7 @@ val mergeEmptyTask = task("empty") {
.removeNode("empty") .removeNode("empty")
.setNode("data", meta.getMeta("empty")) .setNode("data", meta.getMeta("empty"))
.setValue("merge." + MERGE_NAME, meta.getString("merge." + MERGE_NAME, "") + "_empty"); .setValue("merge." + MERGE_NAME, meta.getString("merge." + MERGE_NAME, "") + "_empty");
dependsOn("merge", newMeta) dependsOn(mergeTask, newMeta)
} }
transform<Table, Table> { data -> transform<Table, Table> { data ->
val builder = DataSet.builder(Table::class.java) val builder = DataSet.builder(Table::class.java)
@ -137,8 +143,8 @@ val mergeEmptyTask = task("empty") {
val subtractEmptyTask = task("dif") { val subtractEmptyTask = task("dif") {
model { meta -> model { meta ->
dependsOn("merge", meta, "data") dependsOn(mergeTask, meta, "data")
dependsOn("empty", meta, "empty") dependsOn(mergeEmptyTask, meta, "empty")
} }
transform<Table, Table> { data -> transform<Table, Table> { data ->
val builder = DataTree.builder(Table::class.java) val builder = DataTree.builder(Table::class.java)
@ -167,14 +173,42 @@ val transformTask = task("transform") {
model { meta -> model { meta ->
if (meta.hasMeta("merge")) { if (meta.hasMeta("merge")) {
if (meta.hasMeta("empty")) { if (meta.hasMeta("empty")) {
dependsOn("dif", meta) dependsOn(subtractEmptyTask, meta)
} else { } else {
dependsOn("merge", meta); dependsOn(mergeTask, meta);
} }
} else { } else {
dependsOn("analyze", meta); dependsOn(analyzeTask, meta);
} }
configure(MetaUtils.optEither(meta, "transform", "prepare").orElse(Meta.empty())) configure(MetaUtils.optEither(meta, "transform", "prepare").orElse(Meta.empty()))
} }
action<Table, Table>(TransformDataAction()); action<Table, Table>(TransformDataAction());
} }
val filterTask = task("filter") {
model { meta ->
dependsOn(transformTask, meta)
}
pipe<Table, Table> {
result { data ->
if (meta.hasValue("from") || meta.hasValue("to")) {
val uLo = meta.getDouble("from", 0.0)!!
val uHi = meta.getDouble("to", java.lang.Double.POSITIVE_INFINITY)!!
this.log.report("Filtering finished")
TableTransform.filter(data, NumassPoint.HV_KEY, uLo, uHi)
} else if (meta.hasValue("condition")) {
TableTransform.filter(data) { ExpressionUtils.condition(meta.getString("condition"), it.unbox()) }
} else {
throw RuntimeException("No filtering condition specified")
}
}
}
}
val fitTask = task("fit") {
model { meta ->
dependsOn(filterTask, meta)
configure(meta.getMeta("fit"))
}
action<Table, FitResult>(FitAction())
}