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;
}
}
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);
}
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()]));
}
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;
}
}
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();
}
Aggregations