process-intelligence 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- process_intelligence-0.1.0/LICENSE +21 -0
- process_intelligence-0.1.0/PKG-INFO +12 -0
- process_intelligence-0.1.0/README.md +2 -0
- process_intelligence-0.1.0/process_intelligence.egg-info/PKG-INFO +12 -0
- process_intelligence-0.1.0/process_intelligence.egg-info/SOURCES.txt +16 -0
- process_intelligence-0.1.0/process_intelligence.egg-info/dependency_links.txt +1 -0
- process_intelligence-0.1.0/process_intelligence.egg-info/requires.txt +3 -0
- process_intelligence-0.1.0/process_intelligence.egg-info/top_level.txt +2 -0
- process_intelligence-0.1.0/setup.cfg +4 -0
- process_intelligence-0.1.0/setup.py +13 -0
- process_intelligence-0.1.0/src/__init__.py +1 -0
- process_intelligence-0.1.0/src/config.py +10 -0
- process_intelligence-0.1.0/src/models.py +68 -0
- process_intelligence-0.1.0/tests/test_helpers.py +62 -0
- process_intelligence-0.1.0/tests/test_models.py +65 -0
- process_intelligence-0.1.0/utils/__init__.py +1 -0
- process_intelligence-0.1.0/utils/helpers.py +45 -0
- process_intelligence-0.1.0/utils/logger.py +29 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Process Intelligence Research
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: process-intelligence
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A sample process intelligence Python project.
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Provides-Extra: dev
|
|
8
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
Dynamic: provides-extra
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: process-intelligence
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A sample process intelligence Python project.
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Provides-Extra: dev
|
|
8
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
Dynamic: provides-extra
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
process_intelligence.egg-info/PKG-INFO
|
|
5
|
+
process_intelligence.egg-info/SOURCES.txt
|
|
6
|
+
process_intelligence.egg-info/dependency_links.txt
|
|
7
|
+
process_intelligence.egg-info/requires.txt
|
|
8
|
+
process_intelligence.egg-info/top_level.txt
|
|
9
|
+
src/__init__.py
|
|
10
|
+
src/config.py
|
|
11
|
+
src/models.py
|
|
12
|
+
tests/test_helpers.py
|
|
13
|
+
tests/test_models.py
|
|
14
|
+
utils/__init__.py
|
|
15
|
+
utils/helpers.py
|
|
16
|
+
utils/logger.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="process-intelligence",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="A sample process intelligence Python project.",
|
|
7
|
+
packages=find_packages(exclude=["tests*"]),
|
|
8
|
+
python_requires=">=3.10",
|
|
9
|
+
install_requires=[],
|
|
10
|
+
extras_require={
|
|
11
|
+
"dev": ["pytest>=7.0"],
|
|
12
|
+
},
|
|
13
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# src package
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Data models for the application."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class Event:
|
|
10
|
+
"""Represents a process event."""
|
|
11
|
+
|
|
12
|
+
event_id: str
|
|
13
|
+
name: str
|
|
14
|
+
timestamp: datetime
|
|
15
|
+
resource: Optional[str] = None
|
|
16
|
+
attributes: dict = field(default_factory=dict)
|
|
17
|
+
|
|
18
|
+
def to_dict(self) -> dict:
|
|
19
|
+
return {
|
|
20
|
+
"event_id": self.event_id,
|
|
21
|
+
"name": self.name,
|
|
22
|
+
"timestamp": self.timestamp.isoformat(),
|
|
23
|
+
"resource": self.resource,
|
|
24
|
+
"attributes": self.attributes,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class Case:
|
|
30
|
+
"""Represents a process case (trace)."""
|
|
31
|
+
|
|
32
|
+
case_id: str
|
|
33
|
+
events: List[Event] = field(default_factory=list)
|
|
34
|
+
|
|
35
|
+
def add_event(self, event: Event) -> None:
|
|
36
|
+
self.events.append(event)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def duration(self) -> Optional[float]:
|
|
40
|
+
if len(self.events) < 2:
|
|
41
|
+
return None
|
|
42
|
+
start = min(e.timestamp for e in self.events)
|
|
43
|
+
end = max(e.timestamp for e in self.events)
|
|
44
|
+
return (end - start).total_seconds()
|
|
45
|
+
|
|
46
|
+
def __len__(self) -> int:
|
|
47
|
+
return len(self.events)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class ProcessLog:
|
|
52
|
+
"""Collection of cases forming a process event log."""
|
|
53
|
+
|
|
54
|
+
log_id: str
|
|
55
|
+
cases: List[Case] = field(default_factory=list)
|
|
56
|
+
|
|
57
|
+
def add_case(self, case: Case) -> None:
|
|
58
|
+
self.cases.append(case)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def num_events(self) -> int:
|
|
62
|
+
return sum(len(c) for c in self.cases)
|
|
63
|
+
|
|
64
|
+
def get_case(self, case_id: str) -> Optional[Case]:
|
|
65
|
+
for case in self.cases:
|
|
66
|
+
if case.case_id == case_id:
|
|
67
|
+
return case
|
|
68
|
+
return None
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Tests for utils.helpers."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from utils.helpers import generate_id, format_duration, flatten, compute_checksum, chunk_list
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestGenerateId:
|
|
8
|
+
def test_returns_string(self):
|
|
9
|
+
assert isinstance(generate_id(), str)
|
|
10
|
+
|
|
11
|
+
def test_prefix_included(self):
|
|
12
|
+
uid = generate_id("evt")
|
|
13
|
+
assert uid.startswith("evt-")
|
|
14
|
+
|
|
15
|
+
def test_unique_ids(self):
|
|
16
|
+
ids = {generate_id() for _ in range(100)}
|
|
17
|
+
assert len(ids) == 100
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestFormatDuration:
|
|
21
|
+
def test_seconds_only(self):
|
|
22
|
+
assert format_duration(45.0) == "45.0s"
|
|
23
|
+
|
|
24
|
+
def test_minutes_and_seconds(self):
|
|
25
|
+
assert format_duration(125.0) == "2m 5s"
|
|
26
|
+
|
|
27
|
+
def test_hours_and_minutes(self):
|
|
28
|
+
assert format_duration(3661.0) == "1h 1m"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TestFlatten:
|
|
32
|
+
def test_already_flat(self):
|
|
33
|
+
assert flatten([1, 2, 3]) == [1, 2, 3]
|
|
34
|
+
|
|
35
|
+
def test_nested(self):
|
|
36
|
+
assert flatten([[1, 2], [3, [4, 5]]]) == [1, 2, 3, 4, 5]
|
|
37
|
+
|
|
38
|
+
def test_empty(self):
|
|
39
|
+
assert flatten([]) == []
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class TestComputeChecksum:
|
|
43
|
+
def test_deterministic(self):
|
|
44
|
+
assert compute_checksum("hello") == compute_checksum("hello")
|
|
45
|
+
|
|
46
|
+
def test_different_inputs(self):
|
|
47
|
+
assert compute_checksum("foo") != compute_checksum("bar")
|
|
48
|
+
|
|
49
|
+
def test_length(self):
|
|
50
|
+
assert len(compute_checksum("test")) == 64
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class TestChunkList:
|
|
54
|
+
def test_even_split(self):
|
|
55
|
+
assert chunk_list([1, 2, 3, 4], 2) == [[1, 2], [3, 4]]
|
|
56
|
+
|
|
57
|
+
def test_uneven_split(self):
|
|
58
|
+
assert chunk_list([1, 2, 3], 2) == [[1, 2], [3]]
|
|
59
|
+
|
|
60
|
+
def test_invalid_size(self):
|
|
61
|
+
with pytest.raises(ValueError):
|
|
62
|
+
chunk_list([1, 2], 0)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Tests for src.models."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from datetime import datetime, timedelta
|
|
5
|
+
from src.models import Event, Case, ProcessLog
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def make_event(name: str, offset_hours: int = 0) -> Event:
|
|
9
|
+
return Event(
|
|
10
|
+
event_id=f"evt-{offset_hours}",
|
|
11
|
+
name=name,
|
|
12
|
+
timestamp=datetime(2024, 1, 1, offset_hours),
|
|
13
|
+
resource="Alice",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestEvent:
|
|
18
|
+
def test_to_dict_keys(self):
|
|
19
|
+
event = make_event("Start", 0)
|
|
20
|
+
d = event.to_dict()
|
|
21
|
+
assert set(d.keys()) == {"event_id", "name", "timestamp", "resource", "attributes"}
|
|
22
|
+
|
|
23
|
+
def test_to_dict_timestamp_is_string(self):
|
|
24
|
+
event = make_event("Start", 1)
|
|
25
|
+
assert isinstance(event.to_dict()["timestamp"], str)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TestCase:
|
|
29
|
+
def test_add_event_increases_length(self):
|
|
30
|
+
case = Case(case_id="case-001")
|
|
31
|
+
assert len(case) == 0
|
|
32
|
+
case.add_event(make_event("A", 0))
|
|
33
|
+
assert len(case) == 1
|
|
34
|
+
|
|
35
|
+
def test_duration_none_for_single_event(self):
|
|
36
|
+
case = Case(case_id="case-002")
|
|
37
|
+
case.add_event(make_event("A", 0))
|
|
38
|
+
assert case.duration is None
|
|
39
|
+
|
|
40
|
+
def test_duration_calculated_correctly(self):
|
|
41
|
+
case = Case(case_id="case-003")
|
|
42
|
+
case.add_event(make_event("A", 0))
|
|
43
|
+
case.add_event(make_event("B", 2))
|
|
44
|
+
assert case.duration == pytest.approx(2 * 3600)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TestProcessLog:
|
|
48
|
+
def test_num_events(self):
|
|
49
|
+
log = ProcessLog(log_id="log-001")
|
|
50
|
+
for i in range(3):
|
|
51
|
+
case = Case(case_id=f"case-{i}")
|
|
52
|
+
case.add_event(make_event("X", i))
|
|
53
|
+
case.add_event(make_event("Y", i + 1))
|
|
54
|
+
log.add_case(case)
|
|
55
|
+
assert log.num_events == 6
|
|
56
|
+
|
|
57
|
+
def test_get_case_existing(self):
|
|
58
|
+
log = ProcessLog(log_id="log-002")
|
|
59
|
+
case = Case(case_id="target")
|
|
60
|
+
log.add_case(case)
|
|
61
|
+
assert log.get_case("target") is case
|
|
62
|
+
|
|
63
|
+
def test_get_case_missing(self):
|
|
64
|
+
log = ProcessLog(log_id="log-003")
|
|
65
|
+
assert log.get_case("nope") is None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# utils package
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Miscellaneous helper utilities."""
|
|
2
|
+
|
|
3
|
+
import uuid
|
|
4
|
+
import hashlib
|
|
5
|
+
from typing import Any, List
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def generate_id(prefix: str = "") -> str:
|
|
9
|
+
"""Return a short unique identifier with an optional prefix."""
|
|
10
|
+
uid = uuid.uuid4().hex[:8]
|
|
11
|
+
return f"{prefix}-{uid}" if prefix else uid
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def format_duration(seconds: float) -> str:
|
|
15
|
+
"""Convert a duration in seconds to a human-readable string."""
|
|
16
|
+
if seconds < 60:
|
|
17
|
+
return f"{seconds:.1f}s"
|
|
18
|
+
minutes, secs = divmod(seconds, 60)
|
|
19
|
+
if minutes < 60:
|
|
20
|
+
return f"{int(minutes)}m {int(secs)}s"
|
|
21
|
+
hours, mins = divmod(minutes, 60)
|
|
22
|
+
return f"{int(hours)}h {int(mins)}m"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def flatten(nested: List[Any]) -> List[Any]:
|
|
26
|
+
"""Recursively flatten a nested list."""
|
|
27
|
+
result: List[Any] = []
|
|
28
|
+
for item in nested:
|
|
29
|
+
if isinstance(item, list):
|
|
30
|
+
result.extend(flatten(item))
|
|
31
|
+
else:
|
|
32
|
+
result.append(item)
|
|
33
|
+
return result
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def compute_checksum(data: str) -> str:
|
|
37
|
+
"""Return the SHA-256 hex digest of the given string."""
|
|
38
|
+
return hashlib.sha256(data.encode()).hexdigest()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def chunk_list(lst: List[Any], size: int) -> List[List[Any]]:
|
|
42
|
+
"""Split *lst* into consecutive chunks of *size* elements."""
|
|
43
|
+
if size <= 0:
|
|
44
|
+
raise ValueError("Chunk size must be a positive integer.")
|
|
45
|
+
return [lst[i : i + size] for i in range(0, len(lst), size)]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Lightweight logging wrapper."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_logger(name: str, level: str = "INFO") -> logging.Logger:
|
|
8
|
+
"""Return a configured :class:`logging.Logger` instance.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
name:
|
|
13
|
+
Logger name, typically ``__name__``.
|
|
14
|
+
level:
|
|
15
|
+
Logging level as a string (e.g. ``"DEBUG"``, ``"INFO"``).
|
|
16
|
+
"""
|
|
17
|
+
logger = logging.getLogger(name)
|
|
18
|
+
if not logger.handlers:
|
|
19
|
+
handler = logging.StreamHandler(sys.stdout)
|
|
20
|
+
formatter = logging.Formatter(
|
|
21
|
+
fmt="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
22
|
+
datefmt="%Y-%m-%dT%H:%M:%S",
|
|
23
|
+
)
|
|
24
|
+
handler.setFormatter(formatter)
|
|
25
|
+
logger.addHandler(handler)
|
|
26
|
+
|
|
27
|
+
numeric_level = getattr(logging, level.upper(), logging.INFO)
|
|
28
|
+
logger.setLevel(numeric_level)
|
|
29
|
+
return logger
|