Report class¶
- class araucaria.main.report.Report(name=None, sep=2, sdigits=5, marker='=')[source]¶
Report class.
Stores user-defined information for print to
sys.stdout
.- Parameters
Example
>>> from araucaria import Report >>> report = Report() >>> type(report) <class 'araucaria.main.report.Report'> >>> report.sep 2 >>> report.sdigits 5 >>> report.marker '='
- set_columns(names)[source]¶
Sets parameters for each printed column.
Example
>>> from araucaria import Report >>> report = Report() >>> names = ['Name', 'Description'] >>> report.set_columns(names) >>> report.names ['Name', 'Description']
- add_row(row)[source]¶
Adds a row of content to the report.
Content can be accesed through the
self.content
attribute.- Parameters
row (
list
) – List with values for each column in a single report row.- Return type
- Returns
- Raises
AttributeError – If
names
has not been set withset_columns()
.TypeError – If
row
is not a list.IndexError – If the length of
row
is different than the length ofnames
given inset_columns()
.
Example
>>> from araucaria import Report >>> report = Report() >>> names = ['Name', 'Description'] >>> report.set_columns(names) >>> report.add_row(['filename 1', 'a single scan']) >>> report.content array(['filename 1', 'a single scan'], dtype=object)
- add_midrule(marker='-')[source]¶
Adds a midrule to the report.
Example
>>> from araucaria import Report >>> report = Report() >>> names = ['Name', 'Description'] >>> report.set_columns(names) >>> report.add_midrule() >>> report.content array(['-', '-'], dtype=object)
- get_cols(names=['all'], astype=<class 'object'>)[source]¶
Returns columns of the report by name.
- Parameters
- Return type
- Returns
Array with the requested columns.
- Raises
ValueError – If
names
does not contain valid column names.
Example
>>> import random >>> from araucaria import Report >>> random.seed(1111) >>> report = Report() >>> names = ['Name', 'Value'] >>> report.set_columns(names) >>> for i in range(1,4): ... report.add_row(['filename %s'% i, random.random()]) >>> col = report.get_cols(names=['Value',]) >>> print(col) ['0.2176' '0.34438' '0.64225']
>>> # returning column as float >>> col = report.get_cols(names=['Value',], astype=float) >>> print(col) [0.2176 0.34438 0.64225] >>> print(col.dtype) float64
- get_rows(index=['all'], astype=<class 'object'>)[source]¶
Returns rows of the report by index.
- Parameters
- Return type
- Returns
Array with the requested rows.
Example
>>> import random >>> from araucaria import Report >>> random.seed(1111) >>> report = Report() >>> names = ['Name', 'Value'] >>> report.set_columns(names) >>> for i in range(1,4): ... report.add_row(['filename %s'% i, random.random()]) >>> row = report.get_rows(index=[1,]) >>> print(row) ['filename 2' '0.34438']
- show(header=True, endrule=True, print_report=True)[source]¶
Returns the formatted report.
- Parameters
- Return type
- Returns
Formatted report. Returned only if
print_report=False
.
Example
>>> import random >>> from araucaria import Report >>> random.seed(1111) >>> report = Report() >>> names = ['Name', 'Value'] >>> report.set_columns(names) >>> for i in range(1,4): ... report.add_row(['filename %s'% i, random.random()]) >>> report.show() ===================== Name Value ===================== filename 1 0.2176 filename 2 0.34438 filename 3 0.64225 =====================