vis_tools.CSVReport module

CVSReport.py

This class is a simple Python wrapper for csv report files.

Usage::

report = CSVReport(path.combine(my_dir, “ReportEventRecorder.csv”)) print report

class vis_tools.CSVReport.CSVReport(file_path='', verbose=False)[source]

Bases: object

Class to hold DTK CSV report data.

The class is constructed with the path to the report file in question. Thereafter the public data members source_file and rows may be used to directly access the resultant Python representation of the file.

Additionally, since CSVReport implements __len__ and __iter__, the report object can be treated like a list, e.g.:

row = report[10]    # Obtain the 11th row
Public members:

The following data members are publicly exposed.

source_file (str): A copy of the file_path that was used to construct the CSVReport object.

rows (array): Array of Python objects made from the input file lines.

header (array): Array of field names read from top of CSV file.

make_series(name, time_field, data_field)[source]

Make a Highcharts-compatible series object from CSV rows.

Returns:

Object for use as a Highcharts data series.

Return type:

obj

Parameters:
  • name (str) – The name that is put into the output series structure.

  • time_field (str) – The column name for the column representing time.

  • data_field (str) – The column name for teh data (Y) value.

Raises:

Data access exceptions.

read_partial(file_path, row_count)[source]

Read the first row_count rows off a CSV.

To do a partial read of a CSV report, create a CSVReport with the default constructor, then call read_partial to read as many rows as desired. E.g.:

report = CSVReport()
report.read_partial(my_csv_file_path, 100)
print report.rows[10]
Returns:

None.

Parameters:
  • file_path (str) – File path of CSV report.

  • row_count – The number of rows to read.

Raises:

I/O, csv exceptions.

missing_columns(column_list)[source]

Confirms that a given set of columns exists in a CSVReport.

This function can be used to verify the presence of a set of (presumably required) fields in a CSVReport. Typical usage is:

if (rpt.missing_columns(["Time", "Node_ID"]) is None)
    # All require columns present, so carry on
Returns:

List of columns from column_list that are not present, or None if all columns are present.

Parameters:

column_list (list) – Columns to be tested for.