Search in sources :

Example 16 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class SpreadsheetExportJob method performExport.

/**
 * {@inheritDoc}
 */
@Override
protected void performExport(final IProgressMonitor monitor, final PrintStream out) throws Exception {
    // Item header
    for (ModelItem item : model.getItems()) printItemInfo(out, item);
    out.println();
    // Spreadsheet Header
    out.print("# " + Messages.TimeColumn);
    for (ModelItem item : model.getItems()) out.print(Messages.Export_Delimiter + item.getName() + " " + formatter.getHeader());
    out.println();
    // Create speadsheet interpolation
    final List<ValueIterator> iters = new ArrayList<>();
    for (ModelItem item : model.getItems()) {
        monitor.subTask(NLS.bind("Fetching data for {0}", item.getName()));
        iters.add(createValueIterator(item));
    }
    final SpreadsheetIterator sheet = new SpreadsheetIterator(iters.toArray(new ValueIterator[iters.size()]));
    // Dump the spreadsheet lines
    long line_count = 0;
    while (sheet.hasNext() && !monitor.isCanceled()) {
        final Instant time = sheet.getTime();
        final VType[] line = sheet.next();
        out.print(TimestampHelper.format(time));
        for (int i = 0; i < line.length; ++i) out.print(Messages.Export_Delimiter + formatter.format(line[i]));
        out.println();
        ++line_count;
        if ((line_count % PROGRESS_UPDATE_LINES) == 0)
            monitor.subTask(NLS.bind("Wrote {0} samples", line_count));
        if (monitor.isCanceled())
            break;
    }
}
Also used : VType(org.diirt.vtype.VType) SpreadsheetIterator(org.csstudio.archive.reader.SpreadsheetIterator) Instant(java.time.Instant) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) ValueIterator(org.csstudio.archive.reader.ValueIterator)

Example 17 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class ExportJob method printItemInfo.

/**
 * Print info about item
 *  @param out PrintStream for output
 *  @param item ModelItem
 */
protected void printItemInfo(final PrintStream out, final ModelItem item) {
    out.println(comment + "Channel: " + item.getName());
    // If display name differs from PV, show the _resolved_ version
    if (!item.getName().equals(item.getDisplayName()))
        out.println(comment + "Name   : " + item.getResolvedDisplayName());
    if (item instanceof PVItem) {
        final PVItem pv = (PVItem) item;
        out.println(comment + "Archives:");
        final ArchiveDataSource[] archives = pv.getArchiveDataSources();
        for (int i = 0; i < archives.length; ++i) {
            out.println(comment + (i + 1) + ") " + archives[i].getName());
            out.println(comment + "   URL: " + archives[i].getUrl());
            out.println(comment + "   Key: " + archives[i].getKey());
        }
    }
    out.println(comment);
}
Also used : ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 18 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class ExportJob method createValueIterator.

/**
 * @param item ModelItem
 *  @return ValueIterator for samples in the item
 *  @throws Exception on error
 */
protected ValueIterator createValueIterator(final ModelItem item) throws Exception {
    if (source == Source.PLOT || !(item instanceof PVItem))
        return new ModelSampleIterator(item, start, end);
    // Start ValueIterator for each sub-archive
    final ArchiveDataSource[] archives = ((PVItem) item).getArchiveDataSources();
    final List<ValueIterator> iters = new ArrayList<>();
    Exception error = null;
    for (ArchiveDataSource archive : archives) {
        // Create reader, remember to close it when done
        final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(archive.getUrl());
        archive_readers.add(reader);
        // Create ValueIterator
        try {
            ValueIterator iter;
            if (source == Source.OPTIMIZED_ARCHIVE && optimize_parameter > 1)
                iter = reader.getOptimizedValues(archive.getKey(), item.getName(), start, end, (int) optimize_parameter);
            else {
                iter = reader.getRawValues(archive.getKey(), item.getName(), start, end);
                if (source == Source.LINEAR_INTERPOLATION && optimize_parameter >= 1)
                    iter = new LinearValueIterator(iter, TimeDuration.ofSeconds(optimize_parameter));
            }
            iters.add(iter);
        } catch (Exception ex) {
            Logger.getLogger(getClass().getName()).log(Level.FINE, "Export error for " + item.getName(), ex);
            if (error == null)
                error = ex;
        }
    }
    // If none of the iterators work out, report the first error that we found
    if (iters.isEmpty() && error != null)
        throw error;
    // Return a merging iterator
    return new MergingValueIterator(iters.toArray(new ValueIterator[iters.size()]));
}
Also used : ArchiveReader(org.csstudio.archive.reader.ArchiveReader) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) ValueIterator(org.csstudio.archive.reader.ValueIterator) MergingValueIterator(org.csstudio.archive.reader.MergingValueIterator) LinearValueIterator(org.csstudio.archive.reader.LinearValueIterator) MergingValueIterator(org.csstudio.archive.reader.MergingValueIterator) PVItem(org.csstudio.trends.databrowser3.model.PVItem) LinearValueIterator(org.csstudio.archive.reader.LinearValueIterator)

Example 19 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class PlainExportJob method performExport.

/**
 * {@inheritDoc}
 */
@Override
protected void performExport(final IProgressMonitor monitor, final PrintStream out) throws Exception {
    int count = 0;
    for (ModelItem item : model.getItems()) {
        // Item header
        if (count > 0)
            out.println();
        printItemInfo(out, item);
        // Get data
        monitor.subTask(NLS.bind("Fetching data for {0}", item.getName()));
        final ValueIterator values = createValueIterator(item);
        // Dump all values
        out.println(comment + Messages.TimeColumn + Messages.Export_Delimiter + formatter.getHeader());
        long line_count = 0;
        while (values.hasNext() && !monitor.isCanceled()) {
            final VType value = values.next();
            final String time = TimestampHelper.format(VTypeHelper.getTimestamp(value));
            out.println(time + Messages.Export_Delimiter + formatter.format(value));
            ++line_count;
            if (++line_count % PROGRESS_UPDATE_LINES == 0)
                monitor.subTask(NLS.bind("{0}: Wrote {1} samples", item.getName(), line_count));
        }
        ++count;
    }
}
Also used : VType(org.diirt.vtype.VType) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) ValueIterator(org.csstudio.archive.reader.ValueIterator)

Example 20 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class XMLPersistence method write.

/**
 * Write XML formatted Model content.
 *  @param model Model to write
 *  @param out OutputStream, will NOT be closed when done.
 */
public void write(final Model model, final OutputStream out) {
    final PrintWriter writer = new PrintWriter(out);
    XMLWriter.header(writer);
    XMLWriter.start(writer, 0, TAG_DATABROWSER);
    writer.println();
    XMLWriter.XML(writer, 1, TAG_TITLE, model.getTitle().orElse(""));
    XMLWriter.XML(writer, 1, TAG_SAVE_CHANGES, model.shouldSaveChanges());
    // Visibility of toolbar and legend
    XMLWriter.XML(writer, 1, TAG_SHOW_LEGEND, model.isLegendVisible());
    XMLWriter.XML(writer, 1, TAG_SHOW_TOOLBAR, model.isToolbarVisible());
    // Time axis
    XMLWriter.XML(writer, 1, TAG_GRID, model.isGridVisible());
    XMLWriter.XML(writer, 1, TAG_SCROLL, model.isScrollEnabled());
    XMLWriter.XML(writer, 1, TAG_UPDATE_PERIOD, model.getUpdatePeriod());
    XMLWriter.XML(writer, 1, TAG_SCROLL_STEP, model.getScrollStep().getSeconds());
    XMLWriter.XML(writer, 1, TAG_START, model.getStartSpec());
    XMLWriter.XML(writer, 1, TAG_END, model.getEndSpec());
    XMLWriter.XML(writer, 1, TAG_ARCHIVE_RESCALE, model.getArchiveRescale().name());
    writeColor(writer, 1, TAG_BACKGROUND, model.getPlotBackground());
    XMLWriter.XML(writer, 1, TAG_TITLE_FONT, SWTMediaPool.getFontDescription(model.getTitleFont()));
    XMLWriter.XML(writer, 1, TAG_LABEL_FONT, SWTMediaPool.getFontDescription(model.getLabelFont()));
    XMLWriter.XML(writer, 1, TAG_SCALE_FONT, SWTMediaPool.getFontDescription(model.getScaleFont()));
    XMLWriter.XML(writer, 1, TAG_LEGEND_FONT, SWTMediaPool.getFontDescription(model.getLegendFont()));
    // Value axes
    XMLWriter.start(writer, 1, TAG_AXES);
    writer.println();
    for (AxisConfig axis : model.getAxes()) axis.write(writer);
    XMLWriter.end(writer, 1, TAG_AXES);
    writer.println();
    // Annotations
    XMLWriter.start(writer, 1, TAG_ANNOTATIONS);
    writer.println();
    for (AnnotationInfo annotation : model.getAnnotations()) annotation.write(writer);
    XMLWriter.end(writer, 1, TAG_ANNOTATIONS);
    writer.println();
    // PVs (Formulas)
    XMLWriter.start(writer, 1, TAG_PVLIST);
    writer.println();
    for (ModelItem item : model.getItems()) item.write(writer);
    XMLWriter.end(writer, 1, TAG_PVLIST);
    writer.println();
    XMLWriter.end(writer, 0, TAG_DATABROWSER);
    writer.flush();
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) PrintWriter(java.io.PrintWriter) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo)

Aggregations

ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)23 ArrayList (java.util.ArrayList)12 PVItem (org.csstudio.trends.databrowser3.model.PVItem)10 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)7 VType (org.diirt.vtype.VType)6 Instant (java.time.Instant)5 ValueIterator (org.csstudio.archive.reader.ValueIterator)5 Model (org.csstudio.trends.databrowser3.model.Model)4 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)4 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)3 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)3 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 PrintWriter (java.io.PrintWriter)2 InputItem (org.csstudio.apputil.ui.formula.InputItem)2 TraceType (org.csstudio.javafx.rtplot.TraceType)2 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)2 RequestType (org.csstudio.trends.databrowser3.model.RequestType)2 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)2