Skip to main content

Weave multiple streams of intervals into combinations

Project description

eventweave

Eventweave is a lightweight Python utility that groups overlapping events into chronological combinations. It is useful for temporal reasoning and event sourcing, allowing you to analyze and visualize the relationships between events that occur simultaneously.

Features

  • Accepts any iterable of events with user-defined start and end times
  • Yields sets of events that are simultaneously active at some point in time
  • Handles edge cases for back-to-back, non-overlapping intervals
  • Supports atomic events that start and end at the same time
  • Runs in O(n log n) time and O(n) space

Installation

This project is self-contained with no dependencies beyond the Python standard library.

You can install it using pip:

python -m pip install eventweave

Supported for Python 3.13 and above.

Example Usage

Define your events and a key function:

>>> from eventweave import interweave
>>>
>>> events = [
...     ("A", (1, 4)),
...     ("B", (2, 5)),
...     ("C", (5, 6)),
... ]
>>>
>>> def key(event):
...     return event[1]

Use interweave to iterate over overlapping combinations:

>>> result = list(interweave(events, key))
>>> expected = [
...     {('A', (1, 4))},
...     {('A', (1, 4)), ('B', (2, 5))},
...     {('B', (2, 5))},
...     {('C', (5, 6))},
... ]
>>> assert result == expected

Clarification of Overlapping Events

If one event ends at time T and another begins at time T, they are not considered overlapping. The model assumes the starting event ends just after T to preserve strict separation of events that merely touch.

Instantaneous events - where the start and end times are the same - are considered to be active exactly at this point in time. If an event E starts and ends at time T, it will overlap with any other event that ends at T. However, it will not overlap with any event that starts at T, due to the rule above.

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

eventweave-0.4.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

eventweave-0.4.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file eventweave-0.4.0.tar.gz.

File metadata

  • Download URL: eventweave-0.4.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for eventweave-0.4.0.tar.gz
Algorithm Hash digest
SHA256 052415391762a3e666997fa447b5e31a9bec97eb903448cad86736fd6da49991
MD5 e2489fb7a87324baf5d9835e2edd0689
BLAKE2b-256 fbedd1623ecc2ed984db8ce59a75f93497ccfea3023d3e9fe7ecd23de77ef9f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for eventweave-0.4.0.tar.gz:

Publisher: python-publish.yml on MaxG87/eventweave

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eventweave-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: eventweave-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for eventweave-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8aef577bdcf55f51413284eca0cfb39888af75a0cd5f95005ee62254b3f81702
MD5 980003c4657173f4edcc939a41b81517
BLAKE2b-256 6e8659e14eaa16096c3546cbceedd816095d83dcb7406e7ddcbcdbbf86714dc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for eventweave-0.4.0-py3-none-any.whl:

Publisher: python-publish.yml on MaxG87/eventweave

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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