Actions to kotlin. Actions cleanup
This commit is contained in:
parent
05fc2d1fb9
commit
c8da91b39f
@ -1,176 +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;
|
|
||||||
|
|
||||||
import hep.dataforge.actions.ActionUtils;
|
|
||||||
import hep.dataforge.context.Context;
|
|
||||||
import hep.dataforge.context.Global;
|
|
||||||
import hep.dataforge.io.MetaFileReader;
|
|
||||||
import hep.dataforge.meta.Meta;
|
|
||||||
import org.apache.commons.cli.*;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.filechooser.FileFilter;
|
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static inr.numass.Numass.printDescription;
|
|
||||||
import static java.util.Locale.setDefault;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
setDefault(Locale.US);
|
|
||||||
|
|
||||||
Context context = Numass.buildContext();
|
|
||||||
run(context, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void run(Context context, String[] args) throws Exception {
|
|
||||||
if(context == null){
|
|
||||||
context = Global.INSTANCE;
|
|
||||||
}
|
|
||||||
Logger logger = LoggerFactory.getLogger("numass-main");
|
|
||||||
|
|
||||||
Options options = prepareOptions();
|
|
||||||
CommandLineParser parser = new DefaultParser();
|
|
||||||
CommandLine line;
|
|
||||||
try {
|
|
||||||
// parse the command line arguments
|
|
||||||
line = parser.parse(options, args);
|
|
||||||
} catch (ParseException exp) {
|
|
||||||
// oops, something went wrong
|
|
||||||
logger.error("Command line error. Reason: " + exp.getMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.hasOption("l")) {
|
|
||||||
printDescription(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String cfgPath;
|
|
||||||
|
|
||||||
if (args.length == 0) {
|
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
|
||||||
formatter.printHelp("java -jar DataReader.jar [OPTIONS]", options);
|
|
||||||
System.out.println("Trying to use default config location...");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.hasOption("c")) {
|
|
||||||
cfgPath = line.getOptionValue("c");
|
|
||||||
if (cfgPath == null) {
|
|
||||||
logger.info("Configutation path not provided.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
java.nio.file.Path configFile = context.getRootDir().resolve(cfgPath);
|
|
||||||
|
|
||||||
if (!Files.exists(configFile)) {
|
|
||||||
throw new FileNotFoundException("Configuration file not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
Meta config = MetaFileReader.Companion.read(configFile);
|
|
||||||
|
|
||||||
context.setValue(Context.ROOT_DIRECTORY_CONTEXT_KEY, configFile.getParent().toString());
|
|
||||||
|
|
||||||
applyCLItoContext(line, context);
|
|
||||||
|
|
||||||
ActionUtils.runConfig(context, config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void applyCLItoContext(CommandLine line, Context context) throws FileNotFoundException {
|
|
||||||
File workDir = new File(context.getString(Context.ROOT_DIRECTORY_CONTEXT_KEY));
|
|
||||||
|
|
||||||
if (line.hasOption("h")) {
|
|
||||||
workDir = new File(line.getOptionValue("h"));
|
|
||||||
context.setValue(Context.ROOT_DIRECTORY_CONTEXT_KEY, workDir.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.hasOption("d")) {
|
|
||||||
String dataPath = line.getOptionValue("d");
|
|
||||||
File dataDir = new File(dataPath);
|
|
||||||
if (!dataDir.isAbsolute()) {
|
|
||||||
dataDir = new File(workDir, dataPath);
|
|
||||||
}
|
|
||||||
if (dataDir.exists() && dataDir.isDirectory()) {
|
|
||||||
context.setValue(Context.DATA_DIRECTORY_CONTEXT_KEY, dataDir.getAbsolutePath());
|
|
||||||
} else {
|
|
||||||
throw new FileNotFoundException("Data directory not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.hasOption("o")) {
|
|
||||||
String outPath = line.getOptionValue("o");
|
|
||||||
File outDir = new File(outPath);
|
|
||||||
if (!outDir.isAbsolute()) {
|
|
||||||
outDir = new File(workDir, outPath);
|
|
||||||
}
|
|
||||||
if (!outDir.exists()) {
|
|
||||||
outDir.mkdirs();
|
|
||||||
}
|
|
||||||
context.setValue(Context.WORK_DIRECTORY_CONTEXT_KEY, outDir.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Options prepareOptions() {
|
|
||||||
Options options = new Options();
|
|
||||||
|
|
||||||
options.addOption("c", "config", true, "Configuration file path. "
|
|
||||||
+ "If this option is not present, than workbench is launched and all other parameters are ignored.");
|
|
||||||
options.addOption("h", "home", true,
|
|
||||||
"Working directory (by default the working directory is the directory where config file is placed)");
|
|
||||||
options.addOption("d", "data", true, "Data directory (absolute or relative to working directory)");
|
|
||||||
options.addOption("o", "output", true, "Output directory (absolute or relative to working directory)");
|
|
||||||
options.addOption("l", "list", false, "List of available actions");
|
|
||||||
options.addOption("lc", "list-color", false, "List of available actions with ANSI coloring");
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getFilePathFromDialog(String homeDir) throws FileNotFoundException {
|
|
||||||
//TODO переместить в IOManager
|
|
||||||
|
|
||||||
JFrame frame = new JFrame("Chose a configuration file");
|
|
||||||
JFileChooser fc = new JFileChooser(homeDir);
|
|
||||||
FileFilter xmlFilter = new FileNameExtensionFilter("XML files", "XML", "xml");
|
|
||||||
// fc.addChoosableFileFilter(xmlFilter);
|
|
||||||
|
|
||||||
fc.setFileFilter(xmlFilter);
|
|
||||||
|
|
||||||
int returnVal = fc.showOpenDialog(frame);
|
|
||||||
File file;
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
file = fc.getSelectedFile();
|
|
||||||
frame.dispose();
|
|
||||||
return file.getAbsolutePath();
|
|
||||||
} else {
|
|
||||||
frame.dispose();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -15,14 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.actions.ActionUtils;
|
|
||||||
import hep.dataforge.context.Context;
|
import hep.dataforge.context.Context;
|
||||||
import hep.dataforge.data.DataNode;
|
|
||||||
import hep.dataforge.io.ColumnedDataReader;
|
import hep.dataforge.io.ColumnedDataReader;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import hep.dataforge.tables.Table;
|
|
||||||
import hep.dataforge.tables.ValuesSource;
|
|
||||||
import hep.dataforge.values.Values;
|
import hep.dataforge.values.Values;
|
||||||
|
import kotlin.NotImplementedError;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
|
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
|
||||||
|
|
||||||
@ -51,9 +48,11 @@ public class TransmissionInterpolator implements UnivariateFunction {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation,
|
public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation,
|
||||||
String xName, String yName, int nSmooth, double w, double border) throws InterruptedException {
|
String xName, String yName, int nSmooth, double w, double border) throws InterruptedException {
|
||||||
DataNode<Table> node = ActionUtils.runConfig(context, actionAnnotation);
|
|
||||||
ValuesSource data = node.getData().get();
|
throw new NotImplementedError();
|
||||||
return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
|
// DataNode<Table> node = ActionUtils.runConfig(context, actionAnnotation);
|
||||||
|
// ValuesSource data = node.getData().get();
|
||||||
|
// return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnivariateFunction func;
|
UnivariateFunction func;
|
||||||
|
@ -259,8 +259,7 @@ class NumassPlugin : BasicPlugin() {
|
|||||||
} else if (an.hasMeta("transBuildAction")) {
|
} else if (an.hasMeta("transBuildAction")) {
|
||||||
val transBuild = an.getMeta("transBuildAction")
|
val transBuild = an.getMeta("transBuildAction")
|
||||||
try {
|
try {
|
||||||
return TransmissionInterpolator.fromAction(context,
|
return TransmissionInterpolator.fromAction(context, transBuild, transXName, transYName, nSmooth, w, stitchBorder)
|
||||||
transBuild, transXName, transYName, nSmooth, w, stitchBorder)
|
|
||||||
} catch (ex: InterruptedException) {
|
} catch (ex: InterruptedException) {
|
||||||
throw RuntimeException("Transmission builder failed")
|
throw RuntimeException("Transmission builder failed")
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ object AnalyzeDataAction : OneToOneAction<NumassSet, Table>() {
|
|||||||
val analyzer = NumassAnalyzer.DEFAULT_ANALYZER
|
val analyzer = NumassAnalyzer.DEFAULT_ANALYZER
|
||||||
val res = analyzer.analyzeSet(input, inputMeta)
|
val res = analyzer.analyzeSet(input, inputMeta)
|
||||||
|
|
||||||
push(context, name, NumassUtils.wrap(res, inputMeta))
|
render(context, name, NumassUtils.wrap(res, inputMeta))
|
||||||
// output(context, name) { stream -> NumassUtils.write(stream, inputMeta, res) }
|
// output(context, name) { stream -> NumassUtils.write(stream, inputMeta, res) }
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -43,5 +43,5 @@ class CachedPoint(val point: NumassPoint) : NumassPoint by point {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CachedSet(set: NumassSet) : NumassSet by set {
|
class CachedSet(set: NumassSet) : NumassSet by set {
|
||||||
override val points: List<CachedPoint> = set.points.map { CachedPoint(it) }
|
override val points: List<CachedPoint> by lazy { set.points.map { CachedPoint(it) } }
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,8 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
|
|||||||
runLater { container.progress = -1.0 }
|
runLater { container.progress = -1.0 }
|
||||||
runGoal("hvData[${change.key}]") {
|
runGoal("hvData[${change.key}]") {
|
||||||
change.valueAdded.getHvData()
|
change.valueAdded.getHvData()
|
||||||
} ui {table->
|
} ui { table ->
|
||||||
if(table!= null) {
|
if (table != null) {
|
||||||
((frame[change.key] as? DataPlot)
|
((frame[change.key] as? DataPlot)
|
||||||
?: DataPlot(change.key, adapter = Adapters.buildXYAdapter("timestamp", "value")).also { frame.add(it) })
|
?: DataPlot(change.key, adapter = Adapters.buildXYAdapter("timestamp", "value")).also { frame.add(it) })
|
||||||
.fillData(table)
|
.fillData(table)
|
||||||
|
@ -102,7 +102,9 @@ class StorageView(val storage: Storage) : View(title = "Numass storage", icon =
|
|||||||
//isShowRoot = false
|
//isShowRoot = false
|
||||||
root = TreeItem(Container(storage.name, storage))
|
root = TreeItem(Container(storage.name, storage))
|
||||||
root.isExpanded = true
|
root.isExpanded = true
|
||||||
lazyPopulate(leafCheck = { !it.value.hasChildren }) { it.value.children }
|
lazyPopulate(leafCheck = { !it.value.hasChildren }) {
|
||||||
|
it.value.children
|
||||||
|
}
|
||||||
cellFormat { value ->
|
cellFormat { value ->
|
||||||
when (value.content) {
|
when (value.content) {
|
||||||
is Storage -> {
|
is Storage -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user