working on numass viewer improvement

This commit is contained in:
darksnake 2016-09-22 17:02:23 +03:00
parent 1177bdfa6c
commit 92ff3b5215
6 changed files with 129 additions and 71 deletions

View File

@ -100,7 +100,7 @@ public class NumassRootHandler implements Handler {
}
private void renderLoader(Context ctx, StringBuilder b, Loader loader) {
String href = "/storage?path=" + loader.getPath();
String href = "/storage?path=" + loader.getFullPath();
b.append(String.format("<p><a href=\"%s\">%s</a> (%s)</p>", href, loader.getName(), loader.getType()));
}
}

View File

@ -311,7 +311,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
public boolean isReversed() {
//TODO replace by meta tag in later revisions
return SetDirectionUtility.isReversed(getPath(), n -> {
return SetDirectionUtility.isReversed(getFullPath(), n -> {
List<Envelope> points = getPoints();
if (getPoints().size() >= 2) {
return readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta()));

View File

@ -59,8 +59,8 @@ public class MainViewerController implements Initializable {
@FXML
private Button loadDirectoryButton;
private MspViewController mspController;
@FXML
private AnchorPane mspPlotPane;
// @FXML
// private AnchorPane mspContainer;
//main pane views
@FXML
private AnchorPane numassLoaderViewContainer;
@ -181,7 +181,7 @@ public class MainViewerController implements Initializable {
callback.setProgressToMax();
});
mspController = new MspViewController(getContext(), mspPlotPane);
mspController = new MspViewController(getContext(), mspTab);
mspController.fillMspData(root);
pressuresTab.getContent().setVisible(false);

View File

@ -21,7 +21,6 @@ package inr.numass.viewer;
* and open the template in the editor.
*/
import hep.dataforge.computation.ProgressCallback;
import hep.dataforge.context.Context;
import hep.dataforge.names.Name;
import hep.dataforge.plots.PlotUtils;
@ -36,11 +35,17 @@ import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.values.Value;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Tab;
import javafx.scene.layout.AnchorPane;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
@ -50,27 +55,27 @@ import java.util.stream.StreamSupport;
*/
public class MspViewController {
private final AnchorPane mspPlotPane;
private final Context context;
@FXML
private AnchorPane mspPlotPane;
public MspViewController(Context context, AnchorPane mspPlotPane) {
public MspViewController(Context context, Tab mspTab) {
this.context = context;
this.mspPlotPane = mspPlotPane;
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/MspView.fxml"));
loader.setController(this);
try {
loader.load();
} catch (IOException e) {
throw new Error(e);
}
mspTab.setContent(loader.getRoot());
// this.mspPlotPane = mspContainer;
}
/**
* update detector pane with new data
*/
private void updateMspPane(DynamicPlottableSet mspData) {
// MetaBuilder plotMeta = new MetaBuilder("plot")
// .setNode(new MetaBuilder("xAxis")
// .setValue("axisTitle", "time")
// .setValue("type", "time"))
// .setNode(new MetaBuilder("yAxis")
// .setValue("axisTitle", "partial pressure")
// .setValue("axisUnits", "mbar")
// .setValue("type", "log")
// );
JFreeChartFrame frame = new JFreeChartFrame();
PlotUtils.setYAxis(frame, "partial pressure", "mbar", "log");
frame.getConfig().setValue("yAxis.range.lower", 1e-10);
@ -81,66 +86,122 @@ public class MspViewController {
.sorted((DynamicPlottable o1, DynamicPlottable o2)
-> Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl));
Platform.runLater(() -> {
mspPlotPane.getChildren().clear();
PlotContainer container = PlotContainer.anchorTo(mspPlotPane);
container.setPlot(frame);
});
}
public void fillMspData(Storage rootStorage) {
if (rootStorage != null) {
context.taskManager().submit("viewer.msp.fill", (ProgressCallback callback) -> {
// callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")");
callback.updateTitle("Load msp data (" + rootStorage.getName() + ")");
public List<PointLoader> listMspLoaders(Storage rootStorage) {
return StorageUtils.loaderStream(rootStorage)
.filter(pair -> Name.of(pair.getKey()).getLast().toString().startsWith("msp"))
.map(pair -> pair.getValue())
.filter(loader -> PointLoader.POINT_LOADER_TYPE.equals(loader.getType()))
.map(loader -> (PointLoader) loader)
.collect(Collectors.toList());
}
List<DataPoint> mspData = new ArrayList<>();
StorageUtils.loaderStream(rootStorage)
.filter(pair -> pair.getValue() instanceof PointLoader)
.filter(pair -> Name.of(pair.getKey()).getLast().toString().startsWith("msp"))
.map(pair -> pair.getValue())
.filter(loader -> PointLoader.POINT_LOADER_TYPE.equals(loader.getType()))
.forEach(loader -> {
try {
PointLoader mspLoader = (PointLoader) loader;
mspLoader.open();
callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
DataPoint last = null;
for (DataPoint dp : mspLoader) {
mspData.add(dp);
last = dp;
}
if (last != null) {
mspData.add(terminatorPoint(last));
}
} catch (Exception ex) {
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
}
});
callback.updateMessage("Loading msp data finished");
// return mspData;
// List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
if (!mspData.isEmpty()) {
DynamicPlottableSet plottables = new DynamicPlottableSet();
for (DataPoint point : mspData) {
for (String name : point.names()) {
if (!name.equals("timestamp")) {
if (!plottables.hasPlottable(name)) {
plottables.addPlottable(new DynamicPlottable(name, name));
public void plotData(List<PointLoader> loaders) {
DynamicPlottableSet plottables = new DynamicPlottableSet();
loaders.stream()
.flatMap(loader -> getLoaderData(loader))
.distinct()
.forEach(point -> {
for (String name : point.names()) {
if (!name.equals("timestamp")) {
if (!plottables.hasPlottable(name)) {
plottables.addPlottable(new DynamicPlottable(name, name));
}
}
}
plottables.put(point);
}
plottables.put(point);
}
);
updateMspPane(plottables);
}
updateMspPane(plottables);
}
});
private Stream<DataPoint> getLoaderData(PointLoader loader) {
try {
loader.open();
List<DataPoint> points = new ArrayList<>();
// callback.updateMessage("Loading mass spectrometer data from " + loader.getName());
DataPoint last = null;
for (DataPoint dp : loader) {
points.add(dp);
last = dp;
}
if (last != null) {
points.add(terminatorPoint(last));
}
return points.stream();
} catch (Exception ex) {
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
return Stream.empty();
}
}
public void fillMspData(Storage rootStorage) {
plotData(listMspLoaders(rootStorage));
}
// public void fillMspData(Storage rootStorage) {
// if (rootStorage != null) {
// context.taskManager().submit("viewer.msp.fill", (ProgressCallback callback) -> {
// // callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")");
//
// callback.updateTitle("Load msp data (" + rootStorage.getName() + ")");
//
// List<DataPoint> mspData = new ArrayList<>();
//
// StorageUtils.loaderStream(rootStorage)
// .filter(pair -> pair.getValue() instanceof PointLoader)
// .filter(pair -> Name.of(pair.getKey()).getLast().toString().startsWith("msp"))
// .map(pair -> pair.getValue())
// .filter(loader -> PointLoader.POINT_LOADER_TYPE.equals(loader.getType()))
// .forEach(loader -> {
// try {
// PointLoader mspLoader = (PointLoader) loader;
// mspLoader.open();
// callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
// DataPoint last = null;
// for (DataPoint dp : mspLoader) {
// mspData.add(dp);
// last = dp;
// }
// if (last != null) {
// mspData.add(terminatorPoint(last));
// }
// } catch (Exception ex) {
// LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
// }
// });
// callback.updateMessage("Loading msp data finished");
//// return mspData;
//// List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
//
// if (!mspData.isEmpty()) {
// DynamicPlottableSet plottables = new DynamicPlottableSet();
//
// for (DataPoint point : mspData) {
// for (String name : point.names()) {
// if (!name.equals("timestamp")) {
// if (!plottables.hasPlottable(name)) {
// plottables.addPlottable(new DynamicPlottable(name, name));
// }
// }
// }
// plottables.put(point);
// }
//
// updateMspPane(plottables);
// }
// });
// }
// }
/**
* Create a null value point to terminate msp series
*

View File

@ -73,7 +73,7 @@ limitations under the License.
</Tab>
<Tab fx:id="mspTab" closable="false" text="Mass-spectrum">
<content>
<AnchorPane fx:id="mspPlotPane" prefHeight="200.0" prefWidth="200.0" />
<AnchorPane fx:id="mspContainer" prefHeight="200.0" prefWidth="200.0"/>
</content>
</Tab>
<Tab fx:id="pressuresTab" closable="false" text="Pressures">

View File

@ -16,13 +16,10 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.viewer.MspViewController">
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" id="AnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="180.0"
prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.76-ea"
fx:controller="inr.numass.viewer.MspViewController">
<children>
<BorderPane layoutX="401.0" layoutY="270.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<center>