Skip to main content

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 Case 1 Image
2 Case 2 Image
3 Case 3 Image
4 Case 4 Image
5 Case 5 Image
6 Case 6 Image
7 Case 7 Image
8 Case 8 Image
9 Case 9 Image

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eventlogic-0.1.11.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eventlogic-0.1.11-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file eventlogic-0.1.11.tar.gz.

File metadata

  • Download URL: eventlogic-0.1.11.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.15

File hashes

Hashes for eventlogic-0.1.11.tar.gz
Algorithm Hash digest
SHA256 a8efdaf7f729f415ea8ce7b5f9e7858498f8b54dcca598e2a9986fbf0de38e4e
MD5 4afd1b9868c00ee0f0f2271fd102d557
BLAKE2b-256 988c6df2adb1649ad3a8f8e7994c1f9438799faa999c5574dbcdeebbd3372e6e

See more details on using hashes here.

File details

Details for the file eventlogic-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: eventlogic-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.15

File hashes

Hashes for eventlogic-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a645c7f13f9ee134c575d9b0cef079375223f7af05b0ef51e87980bd1b7d6e75
MD5 e740969344e2a7590ecab487083496cc
BLAKE2b-256 f3b5e4663c218ecf2cf263c9c673d2bc9627e0317adfcbb9c748633b1915935c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page