Search in sources :

Example 11 with ContainerTable

use of org.knime.core.data.container.ContainerTable in project knime-core by knime.

the class BoxPlotNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    try {
        File f = new File(nodeInternDir, FILE_NAME);
        FileInputStream fis = new FileInputStream(f);
        NodeSettingsRO settings = NodeSettings.loadFromXML(fis);
        m_statistics = new LinkedHashMap<DataColumnSpec, double[]>();
        m_mildOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        m_extremeOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        int nrOfCols = settings.getInt(CFG_NR_COLS);
        for (int i = 0; i < nrOfCols; i++) {
            NodeSettings subSetting = (NodeSettings) settings.getConfig(CFG_COL + i);
            DataColumnSpec spec = DataColumnSpec.load(subSetting);
            double[] stats = settings.getDoubleArray(CFG_STATS + spec.getName());
            m_statistics.put(spec, stats);
            loadOutliers(settings, spec);
        }
        File data = new File(nodeInternDir, ARRAY_FILE);
        ContainerTable table = DataContainer.readFromZip(data);
        m_array = new DefaultDataArray(table, 1, 2, exec);
    } catch (Exception e) {
        LOGGER.warn(e);
        throw new IOException(e.getMessage());
    }
}
Also used : RowKey(org.knime.core.data.RowKey) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable) 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) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with ContainerTable

use of org.knime.core.data.container.ContainerTable in project knime-core by knime.

the class ConditionalBoxPlotNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    try {
        File f = new File(nodeInternDir, "conditionalBoxPlotInternals");
        FileInputStream fis = new FileInputStream(f);
        NodeSettingsRO settings = NodeSettings.loadFromXML(fis);
        fis.close();
        m_statistics = new LinkedHashMap<DataColumnSpec, double[]>();
        m_mildOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        m_extremeOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        /* Load the numerical column spec if available.*/
        if (settings.containsKey("numColSpec")) {
            m_numColSpec = DataColumnSpec.load(settings.getConfig("numColSpec"));
        }
        int nrOfCols = settings.getInt("nrOfCols");
        for (int i = 0; i < nrOfCols; i++) {
            DataColumnSpec spec = DataColumnSpec.load(settings.getConfig("col" + i));
            String colName = spec.getName();
            double[] stats = settings.getDoubleArray("stats" + colName);
            m_statistics.put(spec, stats);
            double[] mild = settings.getDoubleArray("mild" + colName);
            Map<Double, Set<RowKey>> mildmap = new LinkedHashMap<Double, Set<RowKey>>();
            for (int j = 0; j < mild.length; j++) {
                Set<RowKey> set = new HashSet<RowKey>();
                String[] mildKeys = settings.getStringArray("mildKeys" + colName + j);
                for (int k = 0; k < mildKeys.length; k++) {
                    set.add(new RowKey(mildKeys[k]));
                }
                mildmap.put(mild[j], set);
            }
            m_mildOutliers.put(colName, mildmap);
            double[] extr = settings.getDoubleArray("extreme" + colName);
            Map<Double, Set<RowKey>> extrmap = new LinkedHashMap<Double, Set<RowKey>>();
            for (int j = 0; j < extr.length; j++) {
                Set<RowKey> set = new HashSet<RowKey>();
                String[] extrKeys = settings.getStringArray("extremeKeys" + colName + j);
                for (int k = 0; k < extrKeys.length; k++) {
                    set.add(new RowKey(extrKeys[k]));
                }
                extrmap.put(extr[j], set);
            }
            m_extremeOutliers.put(colName, extrmap);
        }
        File dataFile = new File(nodeInternDir, "conditionalBoxPlotDataFile");
        ContainerTable table = DataContainer.readFromZip(dataFile);
        m_dataArray = new DefaultDataArray(table, 1, 2, exec);
    } catch (Exception e) {
        throw new IOException("Unable to load internals: " + e.getMessage(), e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) RowKey(org.knime.core.data.RowKey) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) DataColumnSpec(org.knime.core.data.DataColumnSpec) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) File(java.io.File) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 13 with ContainerTable

use of org.knime.core.data.container.ContainerTable in project knime-core by knime.

the class InteractiveHistogramDataModel method loadFromFile.

/**
 * @param dataDir the data directory to read from
 * @param exec the {@link ExecutionMonitor}
 * @return the {@link InteractiveHistogramDataModel}
 * @throws IOException if the file is invalid
 * @throws InvalidSettingsException if a setting is invalid
 * @throws CanceledExecutionException if the process was canceled
 */
public static InteractiveHistogramDataModel loadFromFile(final File dataDir, final ExecutionMonitor exec) throws IOException, InvalidSettingsException, CanceledExecutionException {
    final File settingFile = new File(dataDir, CFG_SETTING_FILE);
    final FileInputStream is = new FileInputStream(settingFile);
    final GZIPInputStream inData = new GZIPInputStream(is);
    final ConfigRO config = NodeSettings.loadFromXML(inData);
    final ConfigRO colorColsConf = config.getConfig(CFG_COLOR_COLS);
    final int counter = colorColsConf.getInt(CFG_ROW_COLOR_COUNTER);
    final List<Color> rowColors = new ArrayList<Color>();
    for (int i = 0; i < counter; i++) {
        rowColors.add(new Color(colorColsConf.getInt(CFG_ROW_COLOR + i)));
    }
    exec.checkCanceled();
    final File dataFile = new File(dataDir, CFG_DATA_FILE);
    final ContainerTable table = DataContainer.readFromZip(dataFile);
    final int rowCount = table.getRowCount();
    final DefaultDataArray dataArray = new DefaultDataArray(table, 1, rowCount, exec);
    return new InteractiveHistogramDataModel(dataArray, rowColors);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) Color(java.awt.Color) ArrayList(java.util.ArrayList) ConfigRO(org.knime.core.node.config.ConfigRO) File(java.io.File) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable)

Example 14 with ContainerTable

use of org.knime.core.data.container.ContainerTable in project knime-core by knime.

the class InteractivePieDataModel method loadFromFile.

/**
 * @param dataDir the data directory to read from
 * @param exec {@link ExecutionMonitor}
 * @return the {@link InteractivePieDataModel}
 * @throws IOException if the file could not be read
 * @throws InvalidSettingsException if a setting wasn't present
 * @throws CanceledExecutionException if the operation was canceled
 */
public static InteractivePieDataModel loadFromFile(final File dataDir, final ExecutionMonitor exec) throws IOException, InvalidSettingsException, CanceledExecutionException {
    final File settingFile = new File(dataDir, CFG_SETTING_FILE);
    final FileInputStream is = new FileInputStream(settingFile);
    final GZIPInputStream inData = new GZIPInputStream(is);
    final ConfigRO config = NodeSettings.loadFromXML(inData);
    final boolean supportHiliting = config.getBoolean(CFG_HILITING);
    final boolean detailsAvailable = config.getBoolean(CFG_DETAILS);
    exec.checkCanceled();
    final File dataFile = new File(dataDir, CFG_DATA_FILE);
    final ContainerTable table = DataContainer.readFromZip(dataFile);
    final int rowCount = table.getRowCount();
    final DefaultDataArray dataArray = new DefaultDataArray(table, 1, rowCount, exec);
    return new InteractivePieDataModel(dataArray, detailsAvailable, supportHiliting);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) ConfigRO(org.knime.core.node.config.ConfigRO) File(java.io.File) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable)

Example 15 with ContainerTable

use of org.knime.core.data.container.ContainerTable in project knime-core by knime.

the class DefaultVisualizationNodeModel method loadInternals.

/**
 * Loads the converted {@link org.knime.base.node.util.DataArray}.
 *
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    File f = new File(nodeInternDir, FILE_NAME);
    ContainerTable table = DataContainer.readFromZip(f);
    m_input = new DefaultDataArray(table, 1, m_maxRows.getIntValue(), exec);
}
Also used : DefaultDataArray(org.knime.base.node.util.DefaultDataArray) File(java.io.File) ContainerTable(org.knime.core.data.container.ContainerTable)

Aggregations

ContainerTable (org.knime.core.data.container.ContainerTable)32 File (java.io.File)18 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)13 FileInputStream (java.io.FileInputStream)12 IOException (java.io.IOException)11 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 BufferedInputStream (java.io.BufferedInputStream)7 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)7 DataTable (org.knime.core.data.DataTable)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 Map (java.util.Map)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 ReferencedFile (org.knime.core.internal.ReferencedFile)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 Test (org.junit.Test)3 RowKey (org.knime.core.data.RowKey)3 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)3