Search in sources :

Example 86 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class BitVectorGeneratorNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
    NodeSettings internSettings = new NodeSettings(FILE_NAME);
    internSettings.addInt(INT_CFG_ROWS, m_nrOfProcessedRows);
    internSettings.addInt(INT_CFG_NR_ZEROS, m_totalNrOf0s);
    internSettings.addInt(INT_CFG_NR_ONES, m_totalNrOf1s);
    File f = new File(internDir, FILE_NAME);
    FileOutputStream fos = new FileOutputStream(f);
    internSettings.saveToXML(fos);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 87 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class TreeEnsembleRegressionLearnerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    File file;
    ExecutionMonitor sub;
    if (m_oldStyleEnsembleModel_deprecated != null) {
        // old workflow (<2.10) loaded and saved ...
        file = new File(nodeInternDir, INTERNAL_TREES_FILE);
        OutputStream out = new GZIPOutputStream(new FileOutputStream(file));
        sub = exec.createSubProgress(0.2);
        m_oldStyleEnsembleModel_deprecated.save(out, sub);
        out.close();
    }
    if (m_hiliteRowSample != null) {
        file = new File(nodeInternDir, INTERNAL_DATASAMPLE_FILE);
        sub = exec.createSubProgress(0.2);
        DataContainer.writeToZip(m_hiliteRowSample, file, sub);
    }
    if (m_viewMessage != null) {
        file = new File(nodeInternDir, INTERNAL_INFO_FILE);
        NodeSettings sets = new NodeSettings("ensembleData");
        sets.addString("view_warning", m_viewMessage);
        sets.saveToXML(new FileOutputStream(file));
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) File(java.io.File)

Example 88 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class SorterNodeModelTest method testSaveSettingsTo.

/**
 * Test method for {@link org.knime.base.node.preproc.sorter.SorterNodeModel#saveSettingsTo(...)}.
 */
@Test
public final void testSaveSettingsTo() throws InvalidSettingsException {
    Assert.assertFalse(m_settings.containsKey(SorterNodeModel.INCLUDELIST_KEY));
    Assert.assertFalse(m_settings.containsKey(SorterNodeModel.SORTORDER_KEY));
    Assert.assertFalse(m_settings.containsKey(SorterNodeModel.SORTINMEMORY_KEY));
    // save empty
    m_snm.saveSettingsTo(m_settings);
    // populate settings
    boolean[] sortOrder = { true, false };
    m_settings.addBooleanArray(SorterNodeModel.SORTORDER_KEY, sortOrder);
    String[] inclCols = { "TestCol1", "TestCol2" };
    m_settings.addStringArray(SorterNodeModel.INCLUDELIST_KEY, inclCols);
    boolean sortInMemory = false;
    m_settings.addBoolean(SorterNodeModel.SORTINMEMORY_KEY, sortInMemory);
    m_snm.validateSettings(m_settings);
    m_snm.loadValidatedSettingsFrom(m_settings);
    NodeSettings newsettings = new NodeSettings("Sorter");
    m_snm.saveSettingsTo(newsettings);
    boolean[] sortOrderTest = newsettings.getBooleanArray(SorterNodeModel.SORTORDER_KEY);
    Assert.assertTrue(sortOrderTest[0]);
    Assert.assertFalse(sortOrderTest[1]);
    Assert.assertEquals(2, sortOrderTest.length);
    String[] inclColsTest = newsettings.getStringArray(SorterNodeModel.INCLUDELIST_KEY);
    Assert.assertArrayEquals(inclCols, inclColsTest);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) Test(org.junit.Test)

Example 89 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class ConditionalBoxPlotNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    try {
        NodeSettings settings = new NodeSettings("conditionalBoxPlotInternals");
        settings.addInt("nrOfCols", m_statistics.size());
        int i = 0;
        for (DataColumnSpec spec : m_statistics.keySet()) {
            NodeSettings colSetting = (NodeSettings) settings.addConfig("col" + (i++));
            spec.save(colSetting);
        }
        if (m_numColSpec != null) {
            m_numColSpec.save(settings.addConfig("numColSpec"));
        }
        for (Map.Entry<DataColumnSpec, double[]> entry : m_statistics.entrySet()) {
            String colName = entry.getKey().getName();
            settings.addDoubleArray("stats" + colName, entry.getValue());
            Map<Double, Set<RowKey>> mildOutliers = m_mildOutliers.get(colName);
            double[] mild = new double[mildOutliers.size()];
            int mildIndex = 0;
            for (Map.Entry<Double, Set<RowKey>> mEnt : mildOutliers.entrySet()) {
                RowKey[] keys = mEnt.getValue().toArray(new RowKey[mEnt.getValue().size()]);
                String[] mildKeys = new String[keys.length];
                mild[mildIndex] = mEnt.getKey();
                for (int j = 0; j < keys.length; j++) {
                    mildKeys[j] = keys[j].getString();
                }
                settings.addStringArray("mildKeys" + colName + mildIndex, mildKeys);
                mildIndex++;
            }
            settings.addDoubleArray("mild" + colName, mild);
            Map<Double, Set<RowKey>> extremeOutliers = m_extremeOutliers.get(colName);
            double[] extr = new double[extremeOutliers.size()];
            int extrIndex = 0;
            for (Map.Entry<Double, Set<RowKey>> eEnt : extremeOutliers.entrySet()) {
                RowKey[] keys = eEnt.getValue().toArray(new RowKey[eEnt.getValue().size()]);
                String[] extrKeys = new String[keys.length];
                extr[extrIndex] = eEnt.getKey();
                for (int j = 0; j < keys.length; j++) {
                    extrKeys[j] = keys[j].getString();
                }
                settings.addStringArray("extremeKeys" + colName + extrIndex, extrKeys);
                extrIndex++;
            }
            settings.addDoubleArray("extreme" + colName, extr);
        }
        File f = new File(nodeInternDir, "conditionalBoxPlotInternals");
        FileOutputStream fos = new FileOutputStream(f);
        settings.saveToXML(fos);
        File dataFile = new File(nodeInternDir, "conditionalBoxPlotDataFile");
        DataContainer.writeToZip(m_dataArray, dataFile, exec);
    } catch (Exception e) {
        throw new IOException("Unable to save internals: " + e.getMessage(), e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) RowKey(org.knime.core.data.RowKey) IOException(java.io.IOException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) NodeSettings(org.knime.core.node.NodeSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Example 90 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class InteractiveHistogramDataModel method save2File.

/**
 * @param dataDir the data directory to write to
 * @param exec the {@link ExecutionMonitor}
 * @throws IOException if the file can't be created
 * @throws CanceledExecutionException if the process was canceled
 */
public void save2File(final File dataDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    final File settingFile = new File(dataDir, CFG_SETTING_FILE);
    final FileOutputStream os = new FileOutputStream(settingFile);
    final GZIPOutputStream dataOS = new GZIPOutputStream(os);
    final Config config = new NodeSettings(CFG_SETTING);
    final List<Color> rowColors = getRowColors();
    final ConfigWO colorColsConf = config.addConfig(CFG_COLOR_COLS);
    colorColsConf.addInt(CFG_ROW_COLOR_COUNTER, rowColors.size());
    int idx = 0;
    for (final Color color : rowColors) {
        colorColsConf.addInt(CFG_ROW_COLOR + idx++, color.getRGB());
    }
    config.saveToXML(dataOS);
    exec.checkCanceled();
    final File dataFile = new File(dataDir, CFG_DATA_FILE);
    DataContainer.writeToZip(m_data, dataFile, exec);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) Config(org.knime.core.node.config.Config) FileOutputStream(java.io.FileOutputStream) Color(java.awt.Color) ConfigWO(org.knime.core.node.config.ConfigWO) File(java.io.File)

Aggregations

NodeSettings (org.knime.core.node.NodeSettings)156 File (java.io.File)58 FileOutputStream (java.io.FileOutputStream)57 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)37 GZIPOutputStream (java.util.zip.GZIPOutputStream)27 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)17 Test (org.junit.Test)16 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)16 DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)16 IOException (java.io.IOException)14 OutputStream (java.io.OutputStream)12 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)11 BufferedOutputStream (java.io.BufferedOutputStream)9 Map (java.util.Map)8 RowKey (org.knime.core.data.RowKey)8 Config (org.knime.core.node.config.Config)8 LinkedHashMap (java.util.LinkedHashMap)7 DataTableSpec (org.knime.core.data.DataTableSpec)7 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)6 ArrayList (java.util.ArrayList)5