Logging the right experimental data is a tedious task. You do not only have to consider how much data to collect, but also in what format to store the data. The ExperimentLogger class is designed to make it easy to log different variables with different data types straight to a (My)SQL database. Below you will find information on how the class is constructed and on how to put it to full use.
To use the ExperimentLogger class, you do the following:
- Instantiate an ExperimentLogger object, like so
- Pass the log(Object ... fields) method of the ExperimentLogger object any number of arguments. For instance:
The ExperimentLogger will then check whether the database table exists or not. There are two scenarios:
- The table does not exist.
The ExperimentLogger will create a new table with as many columns as the number of arguments passed to the log method and then continue to log the objects to the table.
- The table exists.
The ExperimentLogger wil check whether the number of columns equals the number of objects passed to the log method and check whether the data types of the objects match the data types in the columns (in order). If either check fails, an Exception is thrown. Otherwise, it will continue to log.
|A note on conversion|
The ExperimentLogger's log(Object ... fields) method will take any object as a parameter and will then convert the Java data type to a SQL datatype on the basis of the outcome of a sequence of instanceof statements. For instance, an int Object returns true to instanceof Integer and will therefore be logged as an INTEGER SQL data type; a String will be logged as a VARCHAR(255).
By using a wrapper class, you can predefine a sequence of variables that will be logged with each log statement.
By calling this log method, your log statement will be recorded, together with a time stamp and the gameId as well as the pin, perGameId, chip sets and positions of each player at that moment. To create your own Wrapper class, all you need is a constructor that instantiates the ExperimentLogger and a log method like the above.
In your configuration file, you now simply instantiate an instance of the Wrapper class and call the Wrapper's log method to log to MySQL.
|For more information...|
For more examples of how to use a Wrapper class, please take a look at edu.harvard.eecs.airg.coloredtrails.shared.ExampleExperimentLoggerWrapper.java.