/*
	Minimal application that reads data into variables and registers them with a 
	VariableOrganizer, then creates subsets and displays descriptive statistics
	for them.
	lobsterman 01/04/24
*/

import JavaGrinders.*;

public class DataHandlingDemo3 {

	// first define variables and the VariableOrganizer used to coordinate them
	static integerVariable theInts;
	static numberVariable theDoubles;
	static VariableOrganizer myOrganizer;
	
	public static void partitionSet() throws Exception {
	// subdivide the data set by selecting sets of cases (i.e., rows) based on
	// its value in the Variable "theInts"
	theDoubles.saveSelectedRows();
	for (int i = 5; i <= 10; i=i+5) {
		// select the subset of data that matches the condition
			theDoubles.restoreSelectedRows();
			myOrganizer.selectBelow(theInts,i,false);
		// list descriptive stats for the variable
			theDoubles.listDescriptives(null);
		}
	}

	public static void main(String args[]) {
	try {
        // define and contruct a Parser for a DataFile with a given name.
        // Note, for this to work you need to place this file in the same
        // harddisk directory as your project. If no name is provided then
        // a standard filechooser dialog box will pop up allowing you to
        // select a file from your hard disk.
        DataFileParser myParser = new DataFileParser("../../DataFiles/Test.txt");
        // now construct a VariableOrganizer from the Parser
        myOrganizer = new VariableOrganizer(myParser);
        // contruct variables and register them with the VariableOrganizer 
        theInts = new integerVariable("xInteger",myOrganizer);
        theDoubles = new numberVariable("yDouble",myOrganizer);
        // now fill them with data from the internal array of the Parser 
        theInts.fillWithParser(myParser,0);
        theDoubles.fillWithParser(myParser,1);
        partitionSet(); // then perform an analysis on subsets
	} catch (Throwable e) { System.err.println(e); }
	}
}
