Search in sources :

Example 1 with TimeSeriesData

use of edu.cmu.tetrad.data.TimeSeriesData in project tetrad by cmu-phil.

the class LoadTimeSeriesDataAction method loadTimeSeriesDataSet.

/**
 * Method loadDataSet_TabDelim
 */
private void loadTimeSeriesDataSet() {
    // select a file to load using the file chooser
    JFileChooser chooser = getJFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.showOpenDialog(this.editor);
    // get the file
    File file = chooser.getSelectedFile();
    Preferences.userRoot().put("fileSaveLocation", file.getParent());
    try {
        BufferedReader in = new BufferedReader(new FileReader(file));
        String line;
        StringTokenizer st;
        // read in variable name and set up DataSet.
        List<Node> variables = new LinkedList<>();
        st = new StringTokenizer(in.readLine());
        while (st.hasMoreTokens()) {
            String name = st.nextToken();
            ContinuousVariable var = new ContinuousVariable(name);
            variables.add(var);
        }
        DataSet dataSet = new ColtDataSet(0, variables);
        int row = -1;
        while ((line = in.readLine()) != null) {
            int col = -1;
            st = new StringTokenizer(line);
            while (st.hasMoreTokens()) {
                String literal = st.nextToken();
                if (literal.length() == 0) {
                    continue;
                }
                dataSet.setObject(row, ++col, literal);
            }
        }
        TimeSeriesData dataSet3 = new TimeSeriesData(dataSet.getDoubleData(), dataSet.getVariableNames());
        editor.getDataWrapper().setDataModel(dataSet3);
        firePropertyChange("modelChanged", null, null);
        editor.reset();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) StringTokenizer(java.util.StringTokenizer) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) TimeSeriesData(edu.cmu.tetrad.data.TimeSeriesData)

Aggregations

ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)1 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)1 DataSet (edu.cmu.tetrad.data.DataSet)1 TimeSeriesData (edu.cmu.tetrad.data.TimeSeriesData)1 Node (edu.cmu.tetrad.graph.Node)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 LinkedList (java.util.LinkedList)1 StringTokenizer (java.util.StringTokenizer)1