Search in sources :

Example 1 with SpreadsheetExportJob

use of org.csstudio.trends.databrowser3.export.SpreadsheetExportJob in project org.csstudio.display.builder by kasemir.

the class ExportTest method speadsheetExport.

/**
 * Export channels in a spreadsheet
 *  @throws Exception on error
 */
@Test
public void speadsheetExport() throws Exception {
    final Model model = getTestModel();
    final ExportJob export = new SpreadsheetExportJob(model, model.getStartTime(), model.getEndTime(), Source.RAW_ARCHIVE, 10, new ValueWithInfoFormatter(Style.Exponential, 3), "/tmp/sheet.dat", this);
    export.run(new SysoutProgressMonitor());
}
Also used : Model(org.csstudio.trends.databrowser3.model.Model) Test(org.junit.Test)

Example 2 with SpreadsheetExportJob

use of org.csstudio.trends.databrowser3.export.SpreadsheetExportJob in project org.csstudio.display.builder by kasemir.

the class ExportView method startExportJob.

/**
 * Start export job with parameters from GUI
 */
private void startExportJob() {
    if (model == null)
        return;
    // Determine start/end time
    final Instant start_time, end_time;
    if (use_plot_times.getSelection()) {
        start_time = model.getStartTime();
        end_time = model.getEndTime();
    } else {
        try {
            final StartEndTimeParser times = new StartEndTimeParser(start.getText(), end.getText());
            start_time = times.getStart().toInstant();
            end_time = times.getEnd().toInstant();
        } catch (final Exception ex) {
            handleExportError(ex);
            return;
        }
    }
    // Determine source: Plot, archive, ...
    final Source source;
    int optimize_parameter = -1;
    if (source_raw.getSelection())
        source = Source.RAW_ARCHIVE;
    else if (source_opt.getSelection()) {
        source = Source.OPTIMIZED_ARCHIVE;
        try {
            optimize_parameter = Integer.parseInt(optimize.getText());
        } catch (Exception ex) {
            MessageDialog.openError(optimize.getShell(), Messages.Error, Messages.ExportOptimizeCountError);
            return;
        }
    } else if (source_lin.getSelection()) {
        source = Source.LINEAR_INTERPOLATION;
        try {
            optimize_parameter = (int) (SecondsParser.parseSeconds(linear.getText()) + 0.5);
            if (optimize_parameter < 1)
                optimize_parameter = 1;
        } catch (Exception ex) {
            MessageDialog.openError(linear.getShell(), Messages.Error, Messages.ExportLinearIntervalError);
            return;
        }
    } else
        source = Source.PLOT;
    // Get remaining export parameters
    final String filename = this.filename.getText().trim();
    if (filename.equalsIgnoreCase(Messages.ExportDefaultFilename)) {
        MessageDialog.openConfirm(optimize.getShell(), Messages.Error, Messages.ExportEnterFilenameError);
        this.filename.setFocus();
        return;
    }
    if (new File(filename).exists()) {
        if (!MessageDialog.openConfirm(optimize.getShell(), Messages.ExportFileExists, NLS.bind(Messages.ExportFileExistsFmt, filename)))
            return;
    }
    // Construct appropriate export job
    final Job export;
    if (type_matlab.getSelection()) {
        if (// $NON-NLS-1$
        filename.endsWith(".m"))
            export = new MatlabScriptExportJob(model, start_time, end_time, source, optimize_parameter, filename, this);
        else if (// $NON-NLS-1$
        filename.endsWith(".mat"))
            export = new MatlabFileExportJob(model, start_time, end_time, source, optimize_parameter, filename, this);
        else {
            MessageDialog.openError(type_matlab.getShell(), Messages.Error, Messages.ExportMatlabFilenameError);
            return;
        }
    } else {
        // Spreadsheet file export
        final Style style;
        if (format_decimal.getSelection())
            style = Style.Decimal;
        else if (format_expo.getSelection())
            style = Style.Exponential;
        else
            style = Style.Default;
        final int precision;
        if (style == Style.Default)
            // Not used
            precision = 0;
        else {
            try {
                precision = Integer.parseInt(format_digits.getText().trim());
            } catch (Exception ex) {
                MessageDialog.openError(optimize.getShell(), Messages.Error, Messages.ExportDigitsError);
                return;
            }
        }
        final ValueFormatter formatter;
        if (sev_stat.getSelection())
            formatter = new ValueWithInfoFormatter(style, precision);
        else
            formatter = new ValueFormatter(style, precision);
        formatter.useMinMaxColumn(minMaxAllowed() && min_max_col.getSelection());
        if (tabular.getSelection())
            export = new SpreadsheetExportJob(model, start_time, end_time, source, optimize_parameter, formatter, filename, this);
        else
            export = new PlainExportJob(model, start_time, end_time, source, optimize_parameter, formatter, filename, this);
    }
    export.schedule();
}
Also used : Instant(java.time.Instant) MatlabScriptExportJob(org.csstudio.trends.databrowser3.export.MatlabScriptExportJob) Source(org.csstudio.trends.databrowser3.export.Source) StartEndTimeParser(org.csstudio.apputil.time.StartEndTimeParser) SpreadsheetExportJob(org.csstudio.trends.databrowser3.export.SpreadsheetExportJob) MatlabFileExportJob(org.csstudio.trends.databrowser3.export.MatlabFileExportJob) Style(org.csstudio.archive.vtype.Style) ValueWithInfoFormatter(org.csstudio.trends.databrowser3.export.ValueWithInfoFormatter) PlainExportJob(org.csstudio.trends.databrowser3.export.PlainExportJob) SpreadsheetExportJob(org.csstudio.trends.databrowser3.export.SpreadsheetExportJob) MatlabScriptExportJob(org.csstudio.trends.databrowser3.export.MatlabScriptExportJob) Job(org.eclipse.core.runtime.jobs.Job) MatlabFileExportJob(org.csstudio.trends.databrowser3.export.MatlabFileExportJob) ValueFormatter(org.csstudio.trends.databrowser3.export.ValueFormatter) File(java.io.File) PlainExportJob(org.csstudio.trends.databrowser3.export.PlainExportJob)

Aggregations

File (java.io.File)1 Instant (java.time.Instant)1 StartEndTimeParser (org.csstudio.apputil.time.StartEndTimeParser)1 Style (org.csstudio.archive.vtype.Style)1 MatlabFileExportJob (org.csstudio.trends.databrowser3.export.MatlabFileExportJob)1 MatlabScriptExportJob (org.csstudio.trends.databrowser3.export.MatlabScriptExportJob)1 PlainExportJob (org.csstudio.trends.databrowser3.export.PlainExportJob)1 Source (org.csstudio.trends.databrowser3.export.Source)1 SpreadsheetExportJob (org.csstudio.trends.databrowser3.export.SpreadsheetExportJob)1 ValueFormatter (org.csstudio.trends.databrowser3.export.ValueFormatter)1 ValueWithInfoFormatter (org.csstudio.trends.databrowser3.export.ValueWithInfoFormatter)1 Model (org.csstudio.trends.databrowser3.model.Model)1 Job (org.eclipse.core.runtime.jobs.Job)1 Test (org.junit.Test)1