Using Names instead of Strings wherever possible

This commit is contained in:
Alexander Nozik 2017-11-05 22:10:29 +03:00
parent 52afce60b6
commit fd5b177b30
17 changed files with 152 additions and 33 deletions

View File

@ -15,6 +15,8 @@ allprojects{
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url "http://dl.bintray.com/kotlin/ktor" }
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
}
// tasks.withType(JavaCompile) {

View File

@ -69,7 +69,7 @@ class BoardView : View("Numass control board", ImageView(dfIcon)) {
if (storage is FileStorage) {
"Path: " + storage.dataDir;
} else {
"Name: " + storage.fullPath
"Name: " + storage.fullName
}
}
})

View File

@ -77,8 +77,8 @@ class MspViewConnection() : DeviceViewConnection<MspDevice>(), DeviceListener, N
val basePlotConfig = MetaBuilder("plotFrame")
.setNode(MetaBuilder("yAxis")
.setValue("type", "log")
.setValue("axisTitle", "partial pressure")
.setValue("axisUnits", "mbar")
.setValue("title", "partial pressure")
.setValue("units", "mbar")
)
.setValue("xAxis.type", "time")

View File

@ -99,8 +99,8 @@ class VacCollectorViewConnection : DeviceViewConnection<VacCollectorDevice>() {
"xAxis.type" to "time"
node("yAxis") {
"type" to "log"
"axisTitle" to "presure"
"axisUnits" to "mbar"
"title" to "presure"
"units" to "mbar"
}
}
right {

View File

@ -25,9 +25,9 @@ public class NumassDataFactory extends DataFactory<NumassSet> {
@Override
protected void fill(DataTree.Builder<NumassSet> builder, Context context, Meta meta) {
NumassStorage storage = new NumassStorage(context,meta);
StorageUtils.loaderStream(storage).forEach(pair -> {
if (pair.getValue() instanceof NumassSet) {
builder.putStatic(pair.getKey(), (NumassSet) pair.getValue());
StorageUtils.loaderStream(storage).forEach(loader -> {
if (loader instanceof NumassSet) {
builder.putStatic(loader.getFullName().toUnescaped(), (NumassSet) loader);
}
});
}

View 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"
}
}

View File

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

View File

@ -29,7 +29,7 @@ import hep.dataforge.plots.data.XYFunctionPlot;
import hep.dataforge.stat.fit.FitResult;
import hep.dataforge.stat.fit.FitState;
import hep.dataforge.stat.models.XYModel;
import hep.dataforge.tables.NavigablePointSource;
import hep.dataforge.tables.NavigableValuesSource;
import hep.dataforge.tables.XYAdapter;
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"));
NavigablePointSource data = input.getData();
NavigableValuesSource data = input.getData();
if (!(state.getModel() instanceof XYModel)) {
context.getChronicle(name).reportError("The fit model should be instance of XYModel for this action. Action failed!");
return input;

View File

@ -104,7 +104,7 @@ public class NumassIO extends BasicIOManager {
}
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);
registry.add(out);
return out;

View File

@ -16,7 +16,7 @@
package inr.numass.models;
import hep.dataforge.io.IOUtils;
import hep.dataforge.tables.PointSource;
import hep.dataforge.tables.ValuesSource;
import hep.dataforge.values.Values;
import java.io.InputStream;
@ -31,7 +31,7 @@ public class FSS {
private double norm;
public FSS(InputStream stream) {
PointSource data = IOUtils.readColumnedData(stream, "E", "P");
ValuesSource data = IOUtils.readColumnedData(stream, "E", "P");
norm = 0;
for (Values dp : data) {
es.add(dp.getDouble("E"));

View File

@ -20,15 +20,12 @@ import hep.dataforge.context.Context;
import hep.dataforge.data.DataNode;
import hep.dataforge.io.ColumnedDataReader;
import hep.dataforge.meta.Meta;
import hep.dataforge.tables.PointSource;
import hep.dataforge.tables.Table;
import hep.dataforge.tables.ValuesSource;
import hep.dataforge.values.Values;
import org.apache.commons.math3.analysis.UnivariateFunction;
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.nio.file.Files;
import java.nio.file.Path;
@ -55,7 +52,7 @@ public class TransmissionInterpolator implements UnivariateFunction {
public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation,
String xName, String yName, int nSmooth, double w, double border) throws InterruptedException {
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);
}

View File

@ -72,8 +72,8 @@ class TimeAnalyzerAction : OneToOneAction<NumassPoint, Table>() {
histPlot.configure {
node("xAxis") {
"axisTitle" to "delay"
"axisUnits" to "us"
"title" to "delay"
"units" to "us"
}
node("yAxis") {
"type" to "log"

View File

@ -36,13 +36,13 @@ class AmplitudeView(
private val frame: PlotFrame = JFreeChartFrame().configure {
"title" to "Detector response plot"
node("xAxis") {
"axisTitle" to "ADC"
"axisUnits" to "channels"
"title" to "ADC"
"units" to "channels"
}
node("yAxis") {
"axisTitle" to "count rate"
"axisUnits" to "Hz"
"title" to "count rate"
"units" to "Hz"
}
"legend.show" to false
}

View File

@ -22,9 +22,9 @@ import tornadofx.*
class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon)) {
private val frame: PlotFrame = JFreeChartFrame().configure {
"xAxis.axisTitle" to "time"
"xAxis.title" to "time"
"xAxis.type" to "time"
"yAxis.axisTitle" to "HV"
"yAxis.title" to "HV"
}
private val container = PlotContainer(frame);

View File

@ -40,10 +40,10 @@ class SpectrumView(
) : View(title = "Numass spectrum plot", icon = ImageView(dfIcon)) {
private val frame: PlotFrame = JFreeChartFrame().configure {
"xAxis.axisTitle" to "U"
"xAxis.axisUnits" to "V"
"yAxis.axisTitle" to "count rate"
"yAxis.axisUnits" to "Hz"
"xAxis.title" to "U"
"xAxis.units" to "V"
"yAxis.title" to "count rate"
"yAxis.units" to "Hz"
//"legend.show" to false
}
private val container = PlotContainer(frame);

View File

@ -228,7 +228,7 @@ class StorageView(private val context: Context = Global.instance()) : View(title
private fun buildContainer(content: Any, parent: Container): Container {
return when (content) {
is Storage -> {
Container(content.fullPath, content)
Container(content.fullName.toString(), content)
}
is NumassSet -> {
val id = if (content is NumassDataLoader) {
@ -236,13 +236,13 @@ class StorageView(private val context: Context = Global.instance()) : View(title
} else {
content.name
}
Container(id, content)
Container(id.toString(), content)
}
is NumassPoint -> {
Container("${parent.id}/${content.voltage}".replace(".", "_"), content)
}
is Loader -> {
Container(content.path, content);
Container(content.path.toString(), content);
}
else -> throw IllegalArgumentException("Unknown content type: ${content::class.java}");
}

View File

@ -13,6 +13,7 @@ include ":numass-core"
include ":numass-client"
include ":numass-server"
include ":numass-server"
include ":numass-kserver"
include ":numass-test"
//
include ":numass-viewer"