Using Names instead of Strings wherever possible
This commit is contained in:
parent
52afce60b6
commit
fd5b177b30
@ -15,6 +15,8 @@ allprojects{
|
|||||||
jcenter()
|
jcenter()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url "https://jitpack.io" }
|
maven { url "https://jitpack.io" }
|
||||||
|
maven { url "http://dl.bintray.com/kotlin/ktor" }
|
||||||
|
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
|
||||||
}
|
}
|
||||||
|
|
||||||
// tasks.withType(JavaCompile) {
|
// tasks.withType(JavaCompile) {
|
||||||
|
@ -69,7 +69,7 @@ class BoardView : View("Numass control board", ImageView(dfIcon)) {
|
|||||||
if (storage is FileStorage) {
|
if (storage is FileStorage) {
|
||||||
"Path: " + storage.dataDir;
|
"Path: " + storage.dataDir;
|
||||||
} else {
|
} else {
|
||||||
"Name: " + storage.fullPath
|
"Name: " + storage.fullName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -77,8 +77,8 @@ class MspViewConnection() : DeviceViewConnection<MspDevice>(), DeviceListener, N
|
|||||||
val basePlotConfig = MetaBuilder("plotFrame")
|
val basePlotConfig = MetaBuilder("plotFrame")
|
||||||
.setNode(MetaBuilder("yAxis")
|
.setNode(MetaBuilder("yAxis")
|
||||||
.setValue("type", "log")
|
.setValue("type", "log")
|
||||||
.setValue("axisTitle", "partial pressure")
|
.setValue("title", "partial pressure")
|
||||||
.setValue("axisUnits", "mbar")
|
.setValue("units", "mbar")
|
||||||
)
|
)
|
||||||
.setValue("xAxis.type", "time")
|
.setValue("xAxis.type", "time")
|
||||||
|
|
||||||
|
@ -99,8 +99,8 @@ class VacCollectorViewConnection : DeviceViewConnection<VacCollectorDevice>() {
|
|||||||
"xAxis.type" to "time"
|
"xAxis.type" to "time"
|
||||||
node("yAxis") {
|
node("yAxis") {
|
||||||
"type" to "log"
|
"type" to "log"
|
||||||
"axisTitle" to "presure"
|
"title" to "presure"
|
||||||
"axisUnits" to "mbar"
|
"units" to "mbar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
right {
|
right {
|
||||||
|
@ -25,9 +25,9 @@ public class NumassDataFactory extends DataFactory<NumassSet> {
|
|||||||
@Override
|
@Override
|
||||||
protected void fill(DataTree.Builder<NumassSet> builder, Context context, Meta meta) {
|
protected void fill(DataTree.Builder<NumassSet> builder, Context context, Meta meta) {
|
||||||
NumassStorage storage = new NumassStorage(context,meta);
|
NumassStorage storage = new NumassStorage(context,meta);
|
||||||
StorageUtils.loaderStream(storage).forEach(pair -> {
|
StorageUtils.loaderStream(storage).forEach(loader -> {
|
||||||
if (pair.getValue() instanceof NumassSet) {
|
if (loader instanceof NumassSet) {
|
||||||
builder.putStatic(pair.getKey(), (NumassSet) pair.getValue());
|
builder.putStatic(loader.getFullName().toUnescaped(), (NumassSet) loader);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
28
numass-kserver/build.gradle
Normal file
28
numass-kserver/build.gradle
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
plugins {
|
||||||
|
id "com.github.johnrengelman.shadow" version "2.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
|
||||||
|
description = 'kodex/ktor based server'
|
||||||
|
|
||||||
|
//mainClassName = "inr.numass.server.ServerRunner"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile "hep.dataforge:kodex-server"
|
||||||
|
compile "hep.dataforge:dataforge-storage"
|
||||||
|
compile project(":numass-core")
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
javaParameters = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
experimental {
|
||||||
|
coroutines "enable"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package inr.numass.server
|
||||||
|
|
||||||
|
import hep.dataforge.context.Context
|
||||||
|
import hep.dataforge.meta.Meta
|
||||||
|
import hep.dataforge.providers.Path
|
||||||
|
import hep.dataforge.server.*
|
||||||
|
import hep.dataforge.storage.api.TableLoader
|
||||||
|
import hep.dataforge.storage.commons.StorageManager
|
||||||
|
import hep.dataforge.storage.commons.StorageUtils
|
||||||
|
import hep.dataforge.values.Value
|
||||||
|
import io.ktor.application.ApplicationCall
|
||||||
|
import io.ktor.application.call
|
||||||
|
import io.ktor.http.ContentType
|
||||||
|
import io.ktor.response.respondText
|
||||||
|
import io.ktor.routing.get
|
||||||
|
import javax.json.JsonObjectBuilder
|
||||||
|
|
||||||
|
|
||||||
|
private suspend fun ApplicationCall.error(type: String, message: String) {
|
||||||
|
this.respondText(ContentType("application", "json")) {
|
||||||
|
jsonObject {
|
||||||
|
add("status", "ERROR")
|
||||||
|
add("type", type)
|
||||||
|
add("message", message)
|
||||||
|
}.render()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun ApplicationCall.json(json: suspend JsonObjectBuilder.() -> Unit) {
|
||||||
|
this.respondText(ContentType("application", "json")) {
|
||||||
|
jsonObject(json).add("status", "OK").render()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class StorageInterceptorBuilder : InterceptorBuilder {
|
||||||
|
override fun build(context: Context, meta: Meta): ServerInterceptor {
|
||||||
|
val storageManager = context.getFeature(StorageManager::class.java);
|
||||||
|
val storage = storageManager.buildStorage(meta);
|
||||||
|
return ServerInterceptor("storage") {
|
||||||
|
get("listStorage") {
|
||||||
|
val path = call.request.queryParameters["path"] ?: ""
|
||||||
|
val shelf = storage.optShelf(path)
|
||||||
|
if (shelf.isPresent) {
|
||||||
|
call.json {
|
||||||
|
val loaders = jsonArray();
|
||||||
|
for (loader in StorageUtils.loaderStream(shelf.get())) {
|
||||||
|
loaders.add(jsonObject {
|
||||||
|
add("name", loader.name)
|
||||||
|
add("path", loader.path.toString())
|
||||||
|
add("type", loader.type)
|
||||||
|
add("meta", loader.laminate.asJson())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
add("loaders", loaders)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
call.error("storage.shelfNotFound", "The shelf with path '$path' not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get("getPlotData") {
|
||||||
|
val path = call.request.queryParameters["path"]
|
||||||
|
if (path == null) {
|
||||||
|
call.error("storage.missingParameter", "Missing request parameter 'path'")
|
||||||
|
} else {
|
||||||
|
val loaderObject = storage.provide(Path.of(path))
|
||||||
|
if (loaderObject.isPresent) {
|
||||||
|
val loader = loaderObject.get();
|
||||||
|
if (loader is TableLoader) {
|
||||||
|
val from = Value.of(call.request.queryParameters["from"] ?: "")
|
||||||
|
val to = Value.of(call.request.queryParameters["to"] ?: "")
|
||||||
|
val maxItems = (call.request.queryParameters.get("maxItems") ?: "1000").toInt()
|
||||||
|
call.json {
|
||||||
|
add("path", loader.path.toString())
|
||||||
|
val data = jsonArray()
|
||||||
|
for (point in loader.index.pull(from, to, maxItems)) {
|
||||||
|
data.add(point.asJson())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
call.error("storage.incorrectLoaderType", "Loader $path is not a TableLoader")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
call.error("storage.loaderNotFound", "Can't find TableLoader with path = '$path'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -29,7 +29,7 @@ import hep.dataforge.plots.data.XYFunctionPlot;
|
|||||||
import hep.dataforge.stat.fit.FitResult;
|
import hep.dataforge.stat.fit.FitResult;
|
||||||
import hep.dataforge.stat.fit.FitState;
|
import hep.dataforge.stat.fit.FitState;
|
||||||
import hep.dataforge.stat.models.XYModel;
|
import hep.dataforge.stat.models.XYModel;
|
||||||
import hep.dataforge.tables.NavigablePointSource;
|
import hep.dataforge.tables.NavigableValuesSource;
|
||||||
import hep.dataforge.tables.XYAdapter;
|
import hep.dataforge.tables.XYAdapter;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -48,7 +48,7 @@ public class PlotFitResultAction extends OneToOneAction<FitResult, FitResult> {
|
|||||||
|
|
||||||
FitState state = input.optState().orElseThrow(()->new UnsupportedOperationException("Can't work with fit result not containing state, sorry! Will fix it later"));
|
FitState state = input.optState().orElseThrow(()->new UnsupportedOperationException("Can't work with fit result not containing state, sorry! Will fix it later"));
|
||||||
|
|
||||||
NavigablePointSource data = input.getData();
|
NavigableValuesSource data = input.getData();
|
||||||
if (!(state.getModel() instanceof XYModel)) {
|
if (!(state.getModel() instanceof XYModel)) {
|
||||||
context.getChronicle(name).reportError("The fit model should be instance of XYModel for this action. Action failed!");
|
context.getChronicle(name).reportError("The fit model should be instance of XYModel for this action. Action failed!");
|
||||||
return input;
|
return input;
|
||||||
|
@ -104,7 +104,7 @@ public class NumassIO extends BasicIOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String dirName = String.join(File.separator, tokens);
|
String dirName = String.join(File.separator, tokens);
|
||||||
String fileName = name.removeNameSpace().toString() + getExtension(type);
|
String fileName = name.toString() + getExtension(type);
|
||||||
OutputStream out = buildOut(getWorkDirectory(), dirName, fileName);
|
OutputStream out = buildOut(getWorkDirectory(), dirName, fileName);
|
||||||
registry.add(out);
|
registry.add(out);
|
||||||
return out;
|
return out;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.io.IOUtils;
|
import hep.dataforge.io.IOUtils;
|
||||||
import hep.dataforge.tables.PointSource;
|
import hep.dataforge.tables.ValuesSource;
|
||||||
import hep.dataforge.values.Values;
|
import hep.dataforge.values.Values;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -31,7 +31,7 @@ public class FSS {
|
|||||||
private double norm;
|
private double norm;
|
||||||
|
|
||||||
public FSS(InputStream stream) {
|
public FSS(InputStream stream) {
|
||||||
PointSource data = IOUtils.readColumnedData(stream, "E", "P");
|
ValuesSource data = IOUtils.readColumnedData(stream, "E", "P");
|
||||||
norm = 0;
|
norm = 0;
|
||||||
for (Values dp : data) {
|
for (Values dp : data) {
|
||||||
es.add(dp.getDouble("E"));
|
es.add(dp.getDouble("E"));
|
||||||
|
@ -20,15 +20,12 @@ import hep.dataforge.context.Context;
|
|||||||
import hep.dataforge.data.DataNode;
|
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.PointSource;
|
|
||||||
import hep.dataforge.tables.Table;
|
import hep.dataforge.tables.Table;
|
||||||
|
import hep.dataforge.tables.ValuesSource;
|
||||||
import hep.dataforge.values.Values;
|
import hep.dataforge.values.Values;
|
||||||
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;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -55,7 +52,7 @@ public class TransmissionInterpolator implements UnivariateFunction {
|
|||||||
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);
|
DataNode<Table> node = ActionUtils.runConfig(context, actionAnnotation);
|
||||||
PointSource data = node.getData().get();
|
ValuesSource data = node.getData().get();
|
||||||
return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
|
return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@ class TimeAnalyzerAction : OneToOneAction<NumassPoint, Table>() {
|
|||||||
|
|
||||||
histPlot.configure {
|
histPlot.configure {
|
||||||
node("xAxis") {
|
node("xAxis") {
|
||||||
"axisTitle" to "delay"
|
"title" to "delay"
|
||||||
"axisUnits" to "us"
|
"units" to "us"
|
||||||
}
|
}
|
||||||
node("yAxis") {
|
node("yAxis") {
|
||||||
"type" to "log"
|
"type" to "log"
|
||||||
|
@ -36,13 +36,13 @@ class AmplitudeView(
|
|||||||
private val frame: PlotFrame = JFreeChartFrame().configure {
|
private val frame: PlotFrame = JFreeChartFrame().configure {
|
||||||
"title" to "Detector response plot"
|
"title" to "Detector response plot"
|
||||||
node("xAxis") {
|
node("xAxis") {
|
||||||
"axisTitle" to "ADC"
|
"title" to "ADC"
|
||||||
"axisUnits" to "channels"
|
"units" to "channels"
|
||||||
|
|
||||||
}
|
}
|
||||||
node("yAxis") {
|
node("yAxis") {
|
||||||
"axisTitle" to "count rate"
|
"title" to "count rate"
|
||||||
"axisUnits" to "Hz"
|
"units" to "Hz"
|
||||||
}
|
}
|
||||||
"legend.show" to false
|
"legend.show" to false
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ import tornadofx.*
|
|||||||
class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon)) {
|
class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon)) {
|
||||||
|
|
||||||
private val frame: PlotFrame = JFreeChartFrame().configure {
|
private val frame: PlotFrame = JFreeChartFrame().configure {
|
||||||
"xAxis.axisTitle" to "time"
|
"xAxis.title" to "time"
|
||||||
"xAxis.type" to "time"
|
"xAxis.type" to "time"
|
||||||
"yAxis.axisTitle" to "HV"
|
"yAxis.title" to "HV"
|
||||||
}
|
}
|
||||||
private val container = PlotContainer(frame);
|
private val container = PlotContainer(frame);
|
||||||
|
|
||||||
|
@ -40,10 +40,10 @@ class SpectrumView(
|
|||||||
) : View(title = "Numass spectrum plot", icon = ImageView(dfIcon)) {
|
) : View(title = "Numass spectrum plot", icon = ImageView(dfIcon)) {
|
||||||
|
|
||||||
private val frame: PlotFrame = JFreeChartFrame().configure {
|
private val frame: PlotFrame = JFreeChartFrame().configure {
|
||||||
"xAxis.axisTitle" to "U"
|
"xAxis.title" to "U"
|
||||||
"xAxis.axisUnits" to "V"
|
"xAxis.units" to "V"
|
||||||
"yAxis.axisTitle" to "count rate"
|
"yAxis.title" to "count rate"
|
||||||
"yAxis.axisUnits" to "Hz"
|
"yAxis.units" to "Hz"
|
||||||
//"legend.show" to false
|
//"legend.show" to false
|
||||||
}
|
}
|
||||||
private val container = PlotContainer(frame);
|
private val container = PlotContainer(frame);
|
||||||
|
@ -228,7 +228,7 @@ class StorageView(private val context: Context = Global.instance()) : View(title
|
|||||||
private fun buildContainer(content: Any, parent: Container): Container {
|
private fun buildContainer(content: Any, parent: Container): Container {
|
||||||
return when (content) {
|
return when (content) {
|
||||||
is Storage -> {
|
is Storage -> {
|
||||||
Container(content.fullPath, content)
|
Container(content.fullName.toString(), content)
|
||||||
}
|
}
|
||||||
is NumassSet -> {
|
is NumassSet -> {
|
||||||
val id = if (content is NumassDataLoader) {
|
val id = if (content is NumassDataLoader) {
|
||||||
@ -236,13 +236,13 @@ class StorageView(private val context: Context = Global.instance()) : View(title
|
|||||||
} else {
|
} else {
|
||||||
content.name
|
content.name
|
||||||
}
|
}
|
||||||
Container(id, content)
|
Container(id.toString(), content)
|
||||||
}
|
}
|
||||||
is NumassPoint -> {
|
is NumassPoint -> {
|
||||||
Container("${parent.id}/${content.voltage}".replace(".", "_"), content)
|
Container("${parent.id}/${content.voltage}".replace(".", "_"), content)
|
||||||
}
|
}
|
||||||
is Loader -> {
|
is Loader -> {
|
||||||
Container(content.path, content);
|
Container(content.path.toString(), content);
|
||||||
}
|
}
|
||||||
else -> throw IllegalArgumentException("Unknown content type: ${content::class.java}");
|
else -> throw IllegalArgumentException("Unknown content type: ${content::class.java}");
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ include ":numass-core"
|
|||||||
include ":numass-client"
|
include ":numass-client"
|
||||||
include ":numass-server"
|
include ":numass-server"
|
||||||
include ":numass-server"
|
include ":numass-server"
|
||||||
|
include ":numass-kserver"
|
||||||
include ":numass-test"
|
include ":numass-test"
|
||||||
//
|
//
|
||||||
include ":numass-viewer"
|
include ":numass-viewer"
|
||||||
|
Loading…
Reference in New Issue
Block a user