Event Management

This modules provides methods for event handling.

Every event is an dictionary in the following form:

event = {
    "time": [a float value],
    "sender": [a single sender (int or str) or a list of senders],
    "receiver": [a single receiver (int or str) or a list of receivers] (optional),
}

Tools

This file provides tools for event handling.

class dynamix.events.tools.MakeID[source]

Converter object for sender/reciever labels.

Methods

make_id(generator)[source]

Replaces all sender and receiver values by integer keys.

Parameters:

generator : iterable or single event

Events

dynamix.events.tools.event_to_string(event)[source]

Converts the Event-Dictionary into a string representation.

Parameters:

event : dict

Event in dict representation

Returns:

line : str

String representation of the event

Notes

Example:

>>> event_to_string({"time":1,"sender":[1,2,3],"receiver":[4,5,6]})
'1;1,2,3;4,5,6'

>>> event_to_string({"time":1,"sender":[1,2,3]})
'1;1,2,3'

>>> event_to_string({"time":1,"sender":1,"receiver":2})
'1;1;2'
dynamix.events.tools.load(filename)[source]

Loads events from file

Parameters:

filename : str

Filename which is used to load the data.

dynamix.events.tools.make_lists(event)[source]

Converts all sender and receiver literals into lists

dynamix.events.tools.make_literals(event)[source]

Converts all sender and receiver lists into literals if they contain only one element

dynamix.events.tools.save(generator, filename)[source]

Saves events to file

Parameters:

generator : iterable or single event

Events

filename : str

Filename which is used to save the file.

dynamix.events.tools.simplify(generator)[source]

Simplifies the compact representation with multiple sender and receivers.

The functions uses an iterator of events and creates for every sender-receiver combination a new event.

Parameters:

generator : iterable or single event

Events

dynamix.events.tools.string_to_event(string)[source]

Converts the string representation of an event into the dictionary representation.

Parameters:

string : str

Event in string representation

Returns:

event : dict

Dictionary representation of the event

Notes

Example:

>>> event = string_to_event('1;1,2,3;4,5,6')
>>> event ==  {'time': 1, 'sender': [1, 2, 3], 'reciever': [4, 5, 6]}
True

>>> event = string_to_event('1;1,2,3')
>>> event == {'time': 1, 'sender': [1, 2, 3]}
True

>>> event = string_to_event('1;1;2')
>>> event == {'time': 1, 'sender': 1, 'reciever': 2}
True