EventLogic is a lightweight library for performing logical operations on event-style or timestamp data. Logical operations on event-style data are commonplace in many fields. This library seeks to provide a generalized framework and methods for dealing with this data.
Project description
Description
EventLogic is a lightweight library for performing logical operations on event-style or timestamp data. Logical operations on event-style data are commonplace in many fields. This library seeks to provide a generalized framework and methods for dealing with this data.
Installation
EventLogic can be installed with pip.
pip install --upgrade pip
pip install eventlogic
Examples
There are 9 flavors of event interactions:
| Case | Events |
|---|---|
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 |
Usage
The Event class represents an event with a start (on) and end (off) time. It supports various logical operations:
| Operation Class | Symbols |
|---|---|
| Comparison Operators | >, <, >=, <=, ==, != |
| Logical Operators | &, |, ^ |
| Containment | in, not in |
Creating an Event
from eventlogic import Event
event = Event(on=1, off=5)
Event Duration
duration = event.duration() # Returns the duration of the event
Copying an Event
event_copy = event.copy()
Event Existence
exists = event.exists() # Checks if the event is defined
Comparison Operators
If we look at case 1:
from eventlogic import Event
a = Event(3,4)
b = Event(1,2)
a > b # True
a < b # False
Logical Operations
event1 = Event(on=1, off=5)
event2 = Event(on=4, off=6)
Intersection
intersection = event1 & event2 # Returns (4,5)
Union
union = event1 | event2 # Returns [(1,6)]
xor
xor = event1 ^ event2 # Returns ((1,4), (5,6))
Containment Operators
If we look at case 9:
from eventlogic import Event
a = Event(3,4)
b = Event(2,5)
a in b # True
a not in b # False
Working with numpy.datetime64
import numpy as np
from eventlogic import Event
a = Event(np.datetime64('2023-01-01T12:00'), np.datetime64('2023-01-01T14:00'))
b = Event(np.datetime64('2023-01-01T13:00'), np.datetime64('2023-01-01T15:00'))
print(a & b) # (2023-01-01T13:00,2023-01-01T14:00)
print(a | b) # [(2023-01-01T12:00,2023-01-01T15:00)]
print(a > b) # False
print(a < b) # False
Event Container
The Events class allows for handling multiple events at once.
from eventlogic import Event, Events
events = Events([Event(1, 2), Event(3, 4), Event(5, 6)])
print(len(events)) # 3
print(events) # [(1,2), (3,4), (5,6)]
And importantly, the creation of Events from numpy arrays (including datetime!).
import numpy as np
from eventlogic import Events
ons = np.array([1,3,5])
offs = np.array([2,4,6])
events = Events.from_arrays(ons,offs)
print(len(events)) # 3
print(events) # [(1,2), (3,4), (5,6)]
Merging Events
merged_events = events.merge(threshold=0.5)
print(merged_events)
Filtering Events by Duration
filtered_events = events.duration_filter(lower_bound=0.5, upper_bound=2.0)
print(filtered_events)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eventlogic-0.1.12.tar.gz.
File metadata
- Download URL: eventlogic-0.1.12.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4979b42d5f933cd28bc20a187c7ae8d0d6569d85519071f21af5b44aa42137cf
|
|
| MD5 |
e71b2cc45136726e28598d9e16af012f
|
|
| BLAKE2b-256 |
8d451db4403e2a8cdf99517a5973cceaf88cb7d440247821a3ecdfb45b43f3d1
|
File details
Details for the file eventlogic-0.1.12-py3-none-any.whl.
File metadata
- Download URL: eventlogic-0.1.12-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
468a1dee53103b2bfa219b7de59594351b802011cf02a3595ca460c450d0c20c
|
|
| MD5 |
5335592a14c25246dbaad3972ce47ef4
|
|
| BLAKE2b-256 |
29698f1a89b43fea15c456d4f3190ae21951586fc2edce890e60a03e27fd2396
|