Baby Language Lab Scripts
A collection of data processing tools.
 All Classes Namespaces Files Functions Variables Pages
parsers.reliability2_parser.Reliability2Parser Class Reference

This class parses information from an ADEX-exported csv file, for use in the Reliability2 program. More...

Inheritance diagram for parsers.reliability2_parser.Reliability2Parser:

Public Member Functions

def __init__
 Constructor. More...
 
def close
 This method closes the file that the parser is reading. More...
 
def parse
 Reads the csv file and organizes the information according to environment, activity, and used/unused. More...
 
def get_acts_list
 Provides a list of all unique activities in the file. More...
 
def get_envs_list
 Provides a list of all unique environments in the file. More...
 
def locate_wavfile
 Attempts to locate a particular wav file in a given folder hierarchy. More...
 
def pick_rows
 Picks a set of blocks from the csv file, for a given check2 object. More...
 
def have_enough_blocks
 Checks to see if we have enough blocks in a csv file to satisfy the requirements for a given Check2 object. More...
 

Static Public Member Functions

def get_row_timestamp
 Returns a timestamp string that uniquely identifies a row. More...
 
def get_child_code
 Returns the child code for a give row. More...
 

Public Attributes

 csv_file
 
 reader
 
 envs
 
 acts
 
 parse_dict
 

Detailed Description

This class parses information from an ADEX-exported csv file, for use in the Reliability2 program.

It provides tools to obtain a list of the possible activity and environment categories present in the file, and to pick a given number of segments that belong to a specific environment-activity group. The csv file this class operates upon should contain the usual ADEX columns (but with one 5 minute block per row rather than one segment per row - you can set this up using an option in ADEX), in addition to two columns called "Activity" and "environment". Environment is the type of daycare in which the recording took place (eg. "home", "home daycare", or "daycare centre"). This generally stays the same for all 5 minute blocks in a csv file (though it need not). Activity is something the child is engaged in like "mealtime", "playtime - organized", "naptime", etc., and often differs every couple of blocks (depending on the attention span of the child :)

Definition at line 21 of file reliability2_parser.py.

Constructor & Destructor Documentation

def parsers.reliability2_parser.Reliability2Parser.__init__ (   self,
  filename 
)

Constructor.

Parameters
self
filename(string) path to the csv file to read.

Definition at line 25 of file reliability2_parser.py.

Member Function Documentation

def parsers.reliability2_parser.Reliability2Parser.close (   self)

This method closes the file that the parser is reading.

It should always be called when you are done with a parser instance.

Parameters
self

Definition at line 46 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.get_acts_list (   self)

Provides a list of all unique activities in the file.

Parameters
self
Returns
(list) list of strings, one for each unique activity

Definition at line 100 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.get_child_code (   row)
static

Returns the child code for a give row.

Parameters
row(list) the row of the csv file from which to extract the child code
Returns
(string) a child code in the format "C_yyyymmdd" - for example, "C002_20091231"

Definition at line 204 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.get_envs_list (   self)

Provides a list of all unique environments in the file.

Parameters
self
Returns
(list) list of strings, one for each unique environment

Definition at line 106 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.get_row_timestamp (   row,
  row_offset_sec 
)
static

Returns a timestamp string that uniquely identifies a row.

Parameters
row(list) the row of the csv file for which to generate a timestamp string
row_offset_sec(float) the absolute start time of the row. You cannot use the "Elapsed_Time" column value for this - it may restart several times in the same file. Instead, you should use an accumulator variable that calculates the absolute start time of each row as you loop through the csv file. See parse() for an example.
Returns
(string) a timestamp string in the format "yyyy mm dd accum_sec"

Definition at line 193 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.have_enough_blocks (   self,
  check2,
  include_used 
)

Checks to see if we have enough blocks in a csv file to satisfy the requirements for a given Check2 object.

The check2 object has properties that tell the parser which environment-activitiy categories to pick from, and how many blocks to pick for each.

Parameters
self
check2(Check2) the Check2 instance for which we are counting blocks.
include_used(boolean) By default, this method only counts blocks from the parser's 'unused' category (see parse()). If this is set to True, then the method assumes that the same block may be picked more than once.
Returns
(2-tuple) the first element is a boolean that is True if we have enough blocks to satisfy all requirements for the check2 object, False otherwise. The second element is a string (with newlines such that it is formatted as a three column table) that indicates how many blocks for each type of environment-activity pair are available in the csv file. This is suitable for printing to the UI in the event that there are not enough of one category (lets them know which category is short).

Definition at line 222 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.locate_wavfile (   self,
  wav_filename,
  root_dir 
)

Attempts to locate a particular wav file in a given folder hierarchy.

Returns the path if it's found.

Parameters
self
wav_filename(string) the name of the wav file to search for (this should not contain any path information - just the bare filename, eg. "C001a_20090708.wav")
root_dir(string) the full path to the root directory of the folder hierarchy to search for the wav file
Returns
(string) the full path to the located wav file (including the wav filename itself), or None if the wav file could not be found in the hierarchy

Definition at line 114 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.parse (   self)

Reads the csv file and organizes the information according to environment, activity, and used/unused.

The info is placed into the organized parse_dict dictionary described in the constructor.

Parameters
self

Definition at line 52 of file reliability2_parser.py.

def parsers.reliability2_parser.Reliability2Parser.pick_rows (   self,
  check2,
  alt_wav_locate_fcn,
  include_used 
)

Picks a set of blocks from the csv file, for a given check2 object.

The check2 object has properties that tell the parser which environment-activitiy categories to pick from, and how many blocks to pick for each. It is possible that there are not enough blocks of a particular category in the csv file. You can check this before calling this method, by calling the have_enough_blocks() method. If there are not enough blocks of a given type, and this method is still called anyway, it will return as many blocks as exist for each requested category.

Parameters
self
check2(Check2) the Check2 instance for which we are picking blocks.
alt_wav_locate_fcn(function) allows you to specify a custom search function that returns the path to the wav file, if the default locator method in this class (locate_wavfile()) cannot find it. This param was added to allow calling code to pass in a function that opens a "browse file" dialog box, so that the user can select the file manually if the code can't find it. The function is passed the name of the wav file we are looking for. If this custom search function also fails to return a path, an exception is raised.
include_used(boolean) By default, this method only picks blocks from the parser's 'unused' category (see parse()). If this is set to True, then the same block may be picked more than once.
Returns
(list) returns a list of Test2 objects, one for each block. If there were not enough blocks of a requested environment-activity type, this list will be too short. Please call the have_enough_blocks() method first to make sure you have enough blocks of each type.

Definition at line 151 of file reliability2_parser.py.

Member Data Documentation

parsers.reliability2_parser.Reliability2Parser.acts

Definition at line 33 of file reliability2_parser.py.

parsers.reliability2_parser.Reliability2Parser.csv_file

Definition at line 26 of file reliability2_parser.py.

parsers.reliability2_parser.Reliability2Parser.envs

Definition at line 30 of file reliability2_parser.py.

parsers.reliability2_parser.Reliability2Parser.parse_dict

Definition at line 40 of file reliability2_parser.py.

parsers.reliability2_parser.Reliability2Parser.reader

Definition at line 27 of file reliability2_parser.py.


The documentation for this class was generated from the following file: