use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class CsvDecoder method decode.
@Override
public Map<TimeSeriesInfo<T>, TimeSeriesProcessor<T>> decode(InputStream in, List<TimeSeriesInfo<T>> seriesInfo) throws IOException, DecodingDataFromAdapterException {
try (Profiler ignored = Profiler.start("Building time series from csv data", logger::trace)) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, encoding))) {
CSVFormat csvFormat = CSVFormat.DEFAULT.withAllowMissingColumnNames(false).withFirstRecordAsHeader().withSkipHeaderRecord().withDelimiter(delimiter);
Iterable<CSVRecord> records = csvFormat.parse(reader);
Map<TimeSeriesInfo<T>, TimeSeriesProcessor<T>> series = new HashMap<>();
final AtomicLong nbpoints = new AtomicLong(0);
for (CSVRecord csvRecord : records) {
nbpoints.incrementAndGet();
ZonedDateTime timeStamp = dateParser.apply(csvRecord.get(0));
for (TimeSeriesInfo<T> info : seriesInfo) {
T val = numberParser.apply(csvRecord.get(info.getBinding().getLabel()));
XYChart.Data<ZonedDateTime, T> point = new XYChart.Data<>(timeStamp, val);
TimeSeriesProcessor<T> l = series.computeIfAbsent(info, k -> timeSeriesFactory.create());
l.addSample(point);
}
}
logger.trace(() -> String.format("Built %d series with %d samples each (%d total samples)", seriesInfo.size(), nbpoints.get(), seriesInfo.size() * nbpoints.get()));
return series;
}
}
}
use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class WorksheetController method plotChart.
private void plotChart(ChartViewPort<Double> viewPort, XYChartSelection<ZonedDateTime, Double> currentSelection, boolean forceRefresh) {
try (Profiler p = Profiler.start("Adding series to chart " + viewPort.getDataStore().getName(), logger::trace)) {
worksheetMaskerPane.setVisible(true);
AsyncTaskManager.getInstance().submit(() -> {
viewPort.getDataStore().fetchDataFromSources(currentSelection.getStartX(), currentSelection.getEndX(), forceRefresh);
return viewPort.getDataStore().getSeries().stream().filter(series -> {
if (series.getProcessor() == null) {
logger.warn("Series " + series.getDisplayName() + " does not contain any data to plot");
return false;
}
if (!series.isSelected()) {
logger.debug(() -> "Series " + series.getDisplayName() + " is not selected");
return false;
}
return true;
}).map(ts -> makeXYChartSeries(viewPort.getDataStore(), ts)).collect(Collectors.toList());
}, event -> {
if (!closed.get()) {
worksheetMaskerPane.setVisible(false);
viewPort.getChart().getData().setAll((Collection<? extends XYChart.Series<ZonedDateTime, Double>>) event.getSource().getValue());
// Force a redraw of the charts and their Y Axis considering their proper width.
new DelayedAction(() -> viewPort.getChart().resize(0.0, 0.0), Duration.millis(50)).submit();
}
}, event -> {
if (!closed.get()) {
worksheetMaskerPane.setVisible(false);
Dialogs.notifyException("Failed to retrieve data from source", event.getSource().getException(), root);
}
});
}
}
use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class WorksheetController method makeXYChartSeries.
private XYChart.Series<ZonedDateTime, Double> makeXYChartSeries(Chart<Double> currentChart, TimeSeriesInfo<Double> series) {
try (Profiler p = Profiler.start("Building XYChart.Series data for" + series.getDisplayName(), logger::trace)) {
XYChart.Series<ZonedDateTime, Double> newSeries = new XYChart.Series<>();
newSeries.getData().setAll(series.getProcessor().getData());
newSeries.nodeProperty().addListener((node, oldNode, newNode) -> {
if (newNode != null) {
switch(currentChart.getChartType()) {
case AREA:
case STACKED:
ObservableList<Node> children = ((Group) newNode).getChildren();
if (children != null && children.size() >= 1) {
Path stroke = (Path) children.get(1);
Path fill = (Path) children.get(0);
logger.trace(() -> "Setting color of series " + series.getBinding().getLabel() + " to " + series.getDisplayColor());
stroke.visibleProperty().bind(currentChart.showAreaOutlineProperty());
stroke.strokeWidthProperty().bind(currentChart.strokeWidthProperty());
stroke.strokeProperty().bind(series.displayColorProperty());
fill.fillProperty().bind(Bindings.createObjectBinding(() -> series.getDisplayColor().deriveColor(0.0, 1.0, 1.0, currentChart.getGraphOpacity()), series.displayColorProperty(), currentChart.graphOpacityProperty()));
}
break;
case SCATTER:
// TODO set colors to points
break;
case LINE:
Path stroke = (Path) newNode;
logger.trace(() -> "Setting color of series " + series.getBinding().getLabel() + " to " + series.getDisplayColor());
stroke.strokeWidthProperty().bind(currentChart.strokeWidthProperty());
stroke.strokeProperty().bind(series.displayColorProperty());
break;
default:
break;
}
}
});
return newSeries;
}
}
use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class WorksheetController method invalidate.
void invalidate(ChartViewPort<Double> viewPort, boolean dontPlot, boolean forceRefresh) {
try (Profiler p = Profiler.start("Refreshing chart " + getWorksheet().getName() + "\\" + viewPort.getDataStore().getName() + " (dontPlot=" + dontPlot + ")", logger::trace)) {
currentState.get(viewPort.getDataStore()).ifPresent(y -> {
XYChartSelection<ZonedDateTime, Double> currentSelection = y.asSelection();
logger.debug(() -> "currentSelection=" + (currentSelection == null ? "null" : currentSelection.toString()));
if (!dontPlot) {
plotChart(viewPort, currentSelection, forceRefresh);
}
});
}
}
use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class Binjr method start.
@Override
public void start(Stage primaryStage) throws Exception {
logger.info(() -> "Starting binjr");
FXMLLoader loader = new FXMLLoader(getClass().getResource("/views/MainView.fxml"));
Parent root = loader.load();
MainViewController mainViewController = loader.getController();
mainViewController.setParameters(getParameters());
primaryStage.setTitle("binjr");
StageAppearanceManager.getInstance().register(primaryStage);
try (Profiler p = Profiler.start("Set scene", logger::trace)) {
primaryStage.setScene(new Scene(root));
}
try (Profiler p = Profiler.start("show", logger::trace)) {
primaryStage.show();
}
SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null) {
splash.close();
}
}
Aggregations