API Documentation¶
Class List¶
mitschreiben.recording.Record |
This class can be used to record values during calculations. |
mitschreiben.table.Table |
A table consist of columns and rows. |
mitschreiben.formatting.DictTree |
A class to work with a dict whose keys are tuples as if this dict was a dictionary of dictionaries of dictionaries… |
Classes¶
-
class
mitschreiben.recording.
Record
[source]¶ Bases:
object
This class can be used to record values during calculations. The class can be called to do the actual recording. Moreover the class grants access to the record depending on the record level and finally it is a contextmanager to control whether to record or not.
The call “Record()” yields the Record-Object of the current scope of recording. Within each scope this object is unique.
The call
Record(key=value,key2=value2,...)
orRecord(keyval) [with keyval={key:value, key2:value2, ...}]
records the values with the given keys in the Record-Object. The actual keys will be concatenated keys depending on a stack of prefixes (see below). The Record-Object knows this stack and records{"former|keystack|key" : value}
.By default no value will be recorded unless the recording is started. This is can be done in two ways.
- Record is a contextmanager. A call looks like this:
Record(key=value) # No recording of key, value with Record() [as rec]: ... Record(key=value) # key, value is recorded Record(key=value) # No recording of key, value Thereby it is ensured to also stop the recording after the leaving the with environment.
- The call |Record().start()| enables recording whereas |Record().stop()| stops the recording
Record(key=value) # No recording of key, value Record().start() Record(key=value) # key, value is recorded Record().stop() Record(key=value) # No recording of key, value
There can be different scopes of recording by using the context management functionality of Record. As soon as the recording context is entered the level of record is incremented by one and a within this scope this Record-Object does not know what might have been recorded in an outer scope. When leaving the inner scope the Record-Object will be integrated in the Record-Object of the outer scope.
With |Record().entries| one access the dict containing the recorded keys and values.
Record makes use of two subclasses: Key and Prefix
Key is class that provides some convenience to add keys and obtain new keys, which are used as the keys of the of the |Record().entries|.
The keys may contain some information on the call stack when the class Prefix is used. As mentioned above, Record knows a prefix stack two record in which successive function call a value was recorded. A Prefix is added when a function is decorated with @Record.Prefix().
input
@Record.Prefix() def foo(obj): ... Record(key=value) with Record() as rec: foo(bar) print rec.entries
output
{"bar.foo|key":value}
-
class
Prefix
(prefix=None)[source]¶ Bases:
object
This decorator generates a key extension depending on the method it decorates and the object that is passed to that method. This class remembers which methods have been decorated.
-
is_started
¶ Returns a bool whether the Record is started or not. If False, Record(*args, **kwargs) has no effect.
-
entries
¶ returns a dictionary with Recordkeys and Values
-
to_csv_files
(path)[source]¶ creates csv files for the different levels of the record in the given path.
-
to_html_tables
(filename, path=None)[source]¶ creates a html structured like the levels of the graph (directory like) where the last two branch levels are made into a table
-
clear
()[source]¶ this method clears the entries of a Record instance. Since there is only one toplevel Record instance everything is recorded there during its lifetime.
-
class
mitschreiben.table.
Table
(default_value=None, name=None, left_upper=None)[source]¶ Bases:
object
A table consist of columns and rows. Each entry has a row and a column key.
-
rows_count
¶
-
cols_count
¶
-
-
class
mitschreiben.formatting.
DictTree
[source]¶ Bases:
dict
A class to work with a dict whose keys are tuples as if this dict was a dictionary of dictionaries of dictionaries… When trying to look up a value with key (=tuple) and this tuple is partially contained in other keys (=tuples) than a DictTree with only those truncated keys is returned.
-
toplevel_tables
(name)[source]¶ Return tables from the two uppermost layers of the DictTree. One of them is a true table and the other is a collection of values
-
to_tables
()[source]¶ Makes a table from each level within the DictTree and returns those tables stored in a new DictTree
-
pretty_print
()[source]¶ this function prints an alphabetically sorted tree in a directory-like structure.
-
as_tree_to_html
(filename, path=None)[source]¶ This function creates a html file that presents the dicttree in its tree structure.
-
as_tables_to_html
(filename, path=None)[source]¶ This functions creates a html file presenting the tree in tables
-