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/receiver labels.
Methods
__call__
(generator)Replaces all sender and receiver values by integer keys. make_id
(generator)Replaces all sender and receiver values by integer keys.
-
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.
expand_sender_events
(generator, directed=True)[source]¶ Expands sender events from each sender to each other sender
The functions uses an iterator of events and creates for every sender-sender combination a new event.
Parameters: generator : iterable or single event
Events
directed : boolean
If true generates A->B and B->A
-
dynamix.events.tools.
jitter_equal
(generator, interval=(-1, 1))[source]¶ Adds noise to the event time.
This functions adds an equal distributed noise in the given interval to the time of the events.
Parameters: generator : iterable or single event
Events
interval : tuple or list
2 element tuple with min and max jitter
Notes
Events could be out of order after adding jitter.
-
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.
random
() → x in the interval [0, 1).¶
-
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.
sort
(generator, window_size=5.0)[source]¶ Sorts events in an event stream.
Elements of an generator will be sorted in the given time window size.
Parameters: generator : iterable or single event
Events
window_size : int or float
time window size
Notes
Events would be delayed until next event with timedelta > window_size arrives.
-
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], 'receiver': [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, 'receiver': 2} True
-
dynamix.events.tools.
throttle
(generator, factor=1.0)[source]¶ Throttles event processing
The events will be repressed until the passing time from the first event to the current one is at least factor times the event time between the first event and the current one.
Parameters: generator : iterable or single event
Events
factor : float
factor of time delay, default 1.0
Notes
The time will be interpreted as seconds.
Twitter - Stream¶
Creates Events from Twitter.com
-
class
dynamix.events.twitter.
TwitterEvents
(auth)[source]¶ Twitter api wrapper
Attributes
auth Methods
hashtags
([limit, min_tags, search_tags])Generates events from Twitter Hashtags. mentions
([limit])Generates events from Twitter mentions. raw_tweets
()Iterator for basic tweet stream. user_activities
([limit])Generates events from Twitter Tweets. Generates events from Twitter Hashtags.
Every tweet with hashtags generates an event with sender is a list of all containing hashtags and receiver not set.
Parameters: limit : int or None
Limits the result size. Default is None - no limit.
min_tags : int
Minimum number of hashtags (excluding search tags)
search_tags : list of strings or string
List of hashtags. At least one hashtag must be in the tweet