Search in sources :

Example 1 with Profiler

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;
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) TimeSeriesInfo(eu.fthevenet.binjr.data.workspace.TimeSeriesInfo) HashMap(java.util.HashMap) TimeSeriesProcessor(eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor) AtomicLong(java.util.concurrent.atomic.AtomicLong) Profiler(eu.fthevenet.util.logging.Profiler) ZonedDateTime(java.time.ZonedDateTime) BufferedReader(java.io.BufferedReader) XYChart(javafx.scene.chart.XYChart) CSVFormat(org.apache.commons.csv.CSVFormat) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 2 with Profiler

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);
            }
        });
    }
}
Also used : TimeRangePicker(eu.fthevenet.util.javafx.controls.TimeRangePicker) HPos(javafx.geometry.HPos) Pos(javafx.geometry.Pos) BindingManager(eu.fthevenet.util.javafx.bindings.BindingManager) Initializable(javafx.fxml.Initializable) DoubleBinding(javafx.beans.binding.DoubleBinding) javafx.scene.layout(javafx.scene.layout) Dialogs(eu.fthevenet.binjr.dialogs.Dialogs) CacheHint(javafx.scene.CacheHint) javafx.scene.control(javafx.scene.control) URL(java.net.URL) ZonedDateTime(java.time.ZonedDateTime) NoAdapterFoundException(eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException) Side(javafx.geometry.Side) InvalidationListener(javafx.beans.InvalidationListener) ColorTableCell(eu.fthevenet.util.javafx.controls.ColorTableCell) MaskerPane(org.controlsfx.control.MaskerPane) ListChangeListener(javafx.collections.ListChangeListener) ImageIO(javax.imageio.ImageIO) eu.fthevenet.binjr.data.workspace(eu.fthevenet.binjr.data.workspace) DelayedAction(eu.fthevenet.util.javafx.controls.DelayedAction) USE_COMPUTED_SIZE(javafx.scene.layout.Region.USE_COMPUTED_SIZE) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) ReadOnlyDoubleProperty(javafx.beans.property.ReadOnlyDoubleProperty) AsyncTaskManager(eu.fthevenet.binjr.data.async.AsyncTaskManager) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) DataAdapter(eu.fthevenet.binjr.data.adapters.DataAdapter) Duration(javafx.util.Duration) Logger(org.apache.logging.log4j.Logger) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) javafx.scene.chart(javafx.scene.chart) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) ObservableList(javafx.collections.ObservableList) Path(javafx.scene.shape.Path) Profiler(eu.fthevenet.util.logging.Profiler) java.util(java.util) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Bindings(javafx.beans.binding.Bindings) Function(java.util.function.Function) Supplier(java.util.function.Supplier) VPos(javafx.geometry.VPos) FXMLLoader(javafx.fxml.FXMLLoader) GlobalPreferences(eu.fthevenet.binjr.preferences.GlobalPreferences) TextAlignment(javafx.scene.text.TextAlignment) Chart(eu.fthevenet.binjr.data.workspace.Chart) DecimalFormatTableCellFactory(eu.fthevenet.util.javafx.controls.DecimalFormatTableCellFactory) Color(javafx.scene.paint.Color) javafx.scene.input(javafx.scene.input) Node(javafx.scene.Node) Property(javafx.beans.property.Property) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) eu.fthevenet.util.javafx.charts(eu.fthevenet.util.javafx.charts) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) DateTimeFormatter(java.time.format.DateTimeFormatter) SwingFXUtils(javafx.embed.swing.SwingFXUtils) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) LogManager(org.apache.logging.log4j.LogManager) Profiler(eu.fthevenet.util.logging.Profiler) ZonedDateTime(java.time.ZonedDateTime) DelayedAction(eu.fthevenet.util.javafx.controls.DelayedAction)

Example 3 with Profiler

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;
    }
}
Also used : Path(javafx.scene.shape.Path) Group(javafx.scene.Group) Profiler(eu.fthevenet.util.logging.Profiler) ZonedDateTime(java.time.ZonedDateTime) Node(javafx.scene.Node)

Example 4 with Profiler

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);
            }
        });
    }
}
Also used : Profiler(eu.fthevenet.util.logging.Profiler) ZonedDateTime(java.time.ZonedDateTime)

Example 5 with Profiler

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();
    }
}
Also used : MainViewController(eu.fthevenet.binjr.controllers.MainViewController) Profiler(eu.fthevenet.util.logging.Profiler) Parent(javafx.scene.Parent) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader)

Aggregations

Profiler (eu.fthevenet.util.logging.Profiler)8 ZonedDateTime (java.time.ZonedDateTime)5 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Parent (javafx.scene.Parent)2 Scene (javafx.scene.Scene)2 MainViewController (eu.fthevenet.binjr.controllers.MainViewController)1 DataAdapter (eu.fthevenet.binjr.data.adapters.DataAdapter)1 TimeSeriesBinding (eu.fthevenet.binjr.data.adapters.TimeSeriesBinding)1 AsyncTaskManager (eu.fthevenet.binjr.data.async.AsyncTaskManager)1 NoAdapterFoundException (eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException)1 TimeSeriesProcessor (eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor)1 eu.fthevenet.binjr.data.workspace (eu.fthevenet.binjr.data.workspace)1 Chart (eu.fthevenet.binjr.data.workspace.Chart)1 TimeSeriesInfo (eu.fthevenet.binjr.data.workspace.TimeSeriesInfo)1 Dialogs (eu.fthevenet.binjr.dialogs.Dialogs)1 GlobalPreferences (eu.fthevenet.binjr.preferences.GlobalPreferences)1 BindingManager (eu.fthevenet.util.javafx.bindings.BindingManager)1 eu.fthevenet.util.javafx.charts (eu.fthevenet.util.javafx.charts)1