RePast
v. 2.0

uchicago.src.sim.analysis
Class DataRecorder

java.lang.Object
  |
  +--uchicago.src.sim.analysis.DataRecorder
All Implemented Interfaces:
SimEventListener

public class DataRecorder
extends Object
implements SimEventListener

The primary means of recording data during a simulation. The recorded data is drawn from objects in the simulation via the DataSources added with DataRecorder's addObjectDataSource method.


Field Summary
protected  SimData data
           
protected  Hashtable dynParams
           
protected  SimModel model
           
protected  Vector sources
           
 
Constructor Summary
DataRecorder(String fileName, SimModel model)
          Constructs a DataRecorder using the specified file name and model.
DataRecorder(String fileName, SimModel model, boolean isBatch)
          Deprecated.  
DataRecorder(String fileName, SimModel model, boolean isBatch, String headerComment)
          Deprecated.  
DataRecorder(String fileName, SimModel model, String headerComment)
          Constructs a DataRecorder using the specified file name, model, and headerComment.
 
Method Summary
 void addNumericDataSource(String name, NumericDataSource s)
          Adds a NumericDataSource to this DataRecorder with the specified name.
 void addNumericDataSource(String name, NumericDataSource s, int maxIntegerDigits, int maxFractionDigits)
          Adds a NumericDataSource to this DataRecorder with the specified name, and specified number of integral and fractional digits.
 void addObjectDataSource(String name, DataSource s)
          Adds a DataSource to this DataRecorder with the specified name.
 void createAverageDataSource(String name, ArrayList feedFrom, String methodName)
          Creates an average data source from a specified list using a method with the specified name.
 void createAverageDataSource(String name, ArrayList feedFrom, String methodName, int maxIntegerDigits, int maxFractionDigits)
          Creates an average data source from a specified list using a method with the specified name.
 void createNumericDataSource(String name, Object feedFrom, String methodName)
          Creates a NumericDataSource using the specified object and the specified method name.
 void createNumericDataSource(String name, Object feedFrom, String methodName, int maxIntegerDigits, int maxFractionDigits)
          Creates a NumericDataSource using the specified object and the specified method name.
 void createObjectDataSource(String name, Object feedFrom, String methodName)
          Creates a DataSource using the specified object and the specified method name.
 void record()
          Records the data for the current tick in tabular format.
 void setDelimiter(String delim)
          Sets the tabular data delimiter to the specified string.
 void simEventPerformed(SimEvent evt)
           
 void write()
          Writes the recorded data out to a file in tabular format.
 void writeEnd()
          Writes any ending matter to the file.
 void writeToFile()
          Writes the recorded data out to a file in tabular format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected SimData data

sources

protected Vector sources

model

protected SimModel model

dynParams

protected Hashtable dynParams
Constructor Detail

DataRecorder

public DataRecorder(String fileName,
                    SimModel model)
Constructs a DataRecorder using the specified file name and model. Defaults to non-batch mode.

Parameters:
fileName - the file to which the data is recorded
model - the model from which the data is drawn. The relevant model parameters (set/get parameters, rng seed) are written to the header of the file.

DataRecorder

public DataRecorder(String fileName,
                    SimModel model,
                    boolean isBatch)
Deprecated.  

Constructs a DataRecorder using the specified file name, model, and mode.

Parameters:
fileName - the file to which the data is recorded
model - the model from which the data is drawn. The relevant model parameters (set/get parameters, rng seed) are written to the header of the file
isBatch - whether this model is run in batch mode

DataRecorder

public DataRecorder(String fileName,
                    SimModel model,
                    String headerComment)
Constructs a DataRecorder using the specified file name, model, and headerComment.

Parameters:
fileName - the file to which the data is recorded
model - the model from which the data is drawn. The relevant model parameters (set/get parameters, rng seed) are written to the header of the file
headerComment - a comment to prepend to the file header information

DataRecorder

public DataRecorder(String fileName,
                    SimModel model,
                    boolean isBatch,
                    String headerComment)
Deprecated.  

Constructs a DataRecorder using the specified file name, model, and mode.

Parameters:
fileName - the file to which the data is recorded
model - the model from which the data is drawn. The relevant model parameters (set/get parameters, rng seed) are written to the header of the file
isBatch - whether this model is run in batch mode
headerComment - a comment to prepend to the file header information
Method Detail

setDelimiter

public void setDelimiter(String delim)
Sets the tabular data delimiter to the specified string. The default is ",".

Parameters:
delim - the new delimiter.

addNumericDataSource

public void addNumericDataSource(String name,
                                 NumericDataSource s,
                                 int maxIntegerDigits,
                                 int maxFractionDigits)
Adds a NumericDataSource to this DataRecorder with the specified name, and specified number of integral and fractional digits. The NumericDataSource generates the data to be recorded.

Specify a maxIntegerDigits of less than 0 to avoid rounding and truncating the integeral portion of the number. Similarly, specify a maxFractionDigits of less than 0 to avoid rounding and truncating the fractional portion of the number.

Note that the number is rounded if necessary when trucated. For example, with a maxFactionDigits of 2, the number 99.555 becomes 99.56.

Parameters:
name - the name of the data (e.g. Number of Agents)
s - the source of the data
maxIntegerDigits - the maximum number of digits before the decimal point. A value of -1 will record all the digits.
maxFractionDigits - the maximum number of digits after the decimal point. A value of -1 will record all the digits.

addNumericDataSource

public void addNumericDataSource(String name,
                                 NumericDataSource s)
Adds a NumericDataSource to this DataRecorder with the specified name. The NumericDataSource generates the data to be recorded.

Parameters:
name - the name of the data (e.g. Number of Agents)
s - the source of the data

createObjectDataSource

public void createObjectDataSource(String name,
                                   Object feedFrom,
                                   String methodName)
Creates a DataSource using the specified object and the specified method name. Whenever DataRecorder.record is called, the method of this name is called on this object and the result is recorded.

Note the specified method must return an Object, that is, anything but void or a primitive. The method must be public.

Parameters:
name - the name for this data source. This corresponds to the column name when this object is written out to the file
feedFrom - the object on which to call the method
methodName - the name of the method to call

createNumericDataSource

public void createNumericDataSource(String name,
                                    Object feedFrom,
                                    String methodName,
                                    int maxIntegerDigits,
                                    int maxFractionDigits)
Creates a NumericDataSource using the specified object and the specified method name. Whenever DataRecorder.record is called, the method of this name is called on this object and the result is recorded.

Note the specified method must explicity return a double, that is, the return value of the method signature must be a double (e.g. public double ...). The method must be public.

Parameters:
name - the name for this data source. This corresponds to the column name when this object is written out to the file
feedFrom - the object on which to call the method
methodName - the name of the method to call
maxIntegerDigits - the maximum number of digits before the decimal point. A value of -1 will record all the digits.
maxFractionDigits - the maximum number of digits after the decimal point. A value of -1 will record all the digits.

createNumericDataSource

public void createNumericDataSource(String name,
                                    Object feedFrom,
                                    String methodName)
Creates a NumericDataSource using the specified object and the specified method name. Whenever DataRecorder.record is called, the method of this name is called on this object and the result is recorded.

Note the specified method must explicity return a double, that is, the return value of the method signature must be a double (e.g. public double ...). The method must be public.

Parameters:
name - the name for this data source. This corresponds to the column name when this object is written out to the file
feedFrom - the object on which to call the method
methodName - the name of the method to call

addObjectDataSource

public void addObjectDataSource(String name,
                                DataSource s)
Adds a DataSource to this DataRecorder with the specified name. The DataSource generates the data that is to be recorded.

Parameters:
name - the name of the data to be recorded
s - the DataSource for the data to be recorded

createAverageDataSource

public void createAverageDataSource(String name,
                                    ArrayList feedFrom,
                                    String methodName)
Creates an average data source from a specified list using a method with the specified name. Whenever DataRecorder.record is called, this method is called on all the objects in the list, the resulting values are averaged, and this average is recorded.

Parameters:
name - the name for this data source. This corresponds to the column name when this object is written out to the file
feedFrom - the list of object on which to call the method
methodName - the name of the method to call. This method should return some sub class of java.lang.Number

createAverageDataSource

public void createAverageDataSource(String name,
                                    ArrayList feedFrom,
                                    String methodName,
                                    int maxIntegerDigits,
                                    int maxFractionDigits)
Creates an average data source from a specified list using a method with the specified name. Whenever DataRecorder.record is called, this method is called on all the objects in the list, the resulting values are averaged, and this average is recorded.

Parameters:
name - the name for this data source. This corresponds to the column name when this object is written out to the file
feedFrom - the list of object on which to call the method
methodName - the name of the method to call. This method should return some sub class of java.lang.Number

record

public void record()
Records the data for the current tick in tabular format. Each tick is a row, and each column is the name of the data source.


writeToFile

public void writeToFile()
Writes the recorded data out to a file in tabular format. This also does a flush on the data itself (i.e. the data is no longer stored by repast and exists only in the file). Identical to write().


write

public void write()
Writes the recorded data out to a file in tabular format. This also does a flush on the data itself (i.e. the data is no longer stored by repast and exists only in the file). Identical to writeToFile().


writeEnd

public void writeEnd()
Writes any ending matter to the file. Used internally during a batch run to write the ending time of the entire batch. A model would not typically call this method.


simEventPerformed

public void simEventPerformed(SimEvent evt)
Specified by:
simEventPerformed in interface SimEventListener

RePast
v. 2.0

Bug reports and feature requests to RePast