Skip to content

Commit 55d632f

Browse files
committed
refactor: BenchmarkRecord and configuration_hash calculation
1 parent c8465a4 commit 55d632f

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

pysatl_cpd/benchmark/benchmark_executor.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
__license__ = "SPDX-License-Identifier: MIT"
1313

1414
import csv
15-
import hashlib
1615
import itertools
1716
import math
1817
import pickle
@@ -51,19 +50,19 @@ class BenchmarkRecord:
5150
"""
5251

5352
algorithm: str
54-
configuration_hash: str
53+
configuration_hash: int
5554
data: str
5655
threshold: float
5756
trace_path: str | None = None
5857

5958
@property
60-
def key(self) -> tuple[str, str, str, float]:
59+
def key(self) -> tuple[str, int, str, float]:
6160
"""
6261
Get the unique composite key for this benchmark run.
6362
6463
Returns
6564
-------
66-
tuple[str, str, str, float]
65+
tuple[str, int, str, float]
6766
A tuple containing (algorithm, configuration_hash, data, threshold)
6867
used for identifying the record in the registry.
6968
"""
@@ -122,7 +121,7 @@ def execute(self) -> list[tuple[BenchmarkRecord, OnlineDetectionTrace[Any]]]:
122121
the benchmark metadata record and the corresponding detection trace.
123122
"""
124123
results: list[tuple[BenchmarkRecord, OnlineDetectionTrace[Any]]] = []
125-
registry: dict[tuple[str, str, str, float], BenchmarkRecord] = {}
124+
registry: dict[tuple[str, int, str, float], BenchmarkRecord] = {}
126125
registry_path: Path | None = None
127126

128127
if self.__dump_dir is not None:
@@ -135,7 +134,7 @@ def execute(self) -> list[tuple[BenchmarkRecord, OnlineDetectionTrace[Any]]]:
135134
for row in reader:
136135
record = BenchmarkRecord(
137136
algorithm=row["algorithm"],
138-
configuration_hash=row["configuration_hash"],
137+
configuration_hash=int(row["configuration_hash"]),
139138
data=row["data"],
140139
threshold=float(row["threshold"]),
141140
trace_path=row["trace_path"] if row["trace_path"] else None,
@@ -144,7 +143,7 @@ def execute(self) -> list[tuple[BenchmarkRecord, OnlineDetectionTrace[Any]]]:
144143

145144
for (algorithm, thresholds), provider in itertools.product(self.__algorithms, self.__providers):
146145
algo_name = str(algorithm)
147-
config_hash = str(hashlib.md5(algo_name.encode("utf-8")).hexdigest()[:8])
146+
config_hash = hash(algorithm.configuration)
148147
data_name = provider.name
149148

150149
for threshold in thresholds:
@@ -161,7 +160,7 @@ def execute(self) -> list[tuple[BenchmarkRecord, OnlineDetectionTrace[Any]]]:
161160
continue
162161

163162
steps = list(self.__solver.run(algorithm, provider, threshold))
164-
trace = OnlineDetectionTrace.from_run(steps)
163+
trace = OnlineDetectionTrace.from_run(steps, algo_name, config_hash)
165164

166165
record = BenchmarkRecord(algo_name, config_hash, data_name, threshold, None)
167166

tests/unit/analysis/metrics/online/test_run_length_metric.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
__copyright__ = "Copyright (c) 2026 PySATL project"
99
__license__ = "SPDX-License-Identifier: MIT"
1010

11+
import warnings
12+
1113
import hypothesis.strategies as st
1214
import pytest
1315
from hypothesis import given
@@ -43,6 +45,7 @@ def test_run_length_metric_evaluate(
4345
"""
4446
Test the `evaluate` method for correct calculation of distances between detections.
4547
"""
48+
warnings.filterwarnings("ignore")
4649
metric: RunLengthMetric[MockOnlineDetectionTrace, MockLabeledData] = RunLengthMetric()
4750

4851
trace_mock = MockOnlineDetectionTrace(detected_change_points=detected)
@@ -74,6 +77,7 @@ def test_run_length_metric_invariants(detected: list[int]) -> None:
7477
"""
7578
Hypothesis property-based test for RunLengthMetric invariants.
7679
"""
80+
warnings.filterwarnings("ignore")
7781
metric: RunLengthMetric[MockOnlineDetectionTrace, MockLabeledData] = RunLengthMetric()
7882
trace = MockOnlineDetectionTrace(detected_change_points=detected)
7983
data = MockLabeledData(change_points=[])

0 commit comments

Comments
 (0)