From 5b7494c52bf2f0c2b753b42294ac0be439129f03 Mon Sep 17 00:00:00 2001 From: unexcellent <> Date: Tue, 29 Oct 2024 08:51:39 +0100 Subject: [PATCH] refactor: remove stats module --- raillabel/__init__.py | 2 +- raillabel/stats/__init__.py | 5 -- raillabel/stats/generate_timespan.py | 36 ---------- .../stats/test_generate_timespan.py | 71 ------------------- 4 files changed, 1 insertion(+), 113 deletions(-) delete mode 100644 raillabel/stats/__init__.py delete mode 100644 raillabel/stats/generate_timespan.py delete mode 100644 tests/test_raillabel/stats/test_generate_timespan.py diff --git a/raillabel/__init__.py b/raillabel/__init__.py index 40dfb0a..7b613eb 100644 --- a/raillabel/__init__.py +++ b/raillabel/__init__.py @@ -3,7 +3,7 @@ """Devkit for working with recorded and annotated train ride data from DB.""" from importlib import metadata -from . import _util, format, stats +from . import _util, format from .exceptions import * from .filter.filter import filter from .format import Scene diff --git a/raillabel/stats/__init__.py b/raillabel/stats/__init__.py deleted file mode 100644 index d6fb143..0000000 --- a/raillabel/stats/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright DB InfraGO AG and contributors -# SPDX-License-Identifier: Apache-2.0 -"""Statsmodule provides statistics.""" - -from .generate_timespan import generate_timespan diff --git a/raillabel/stats/generate_timespan.py b/raillabel/stats/generate_timespan.py deleted file mode 100644 index 44853d7..0000000 --- a/raillabel/stats/generate_timespan.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright DB InfraGO AG and contributors -# SPDX-License-Identifier: Apache-2.0 - -import typing as t -from decimal import Decimal - -from ..format import Scene - - -def generate_timespan(scene: Scene) -> t.Tuple[t.Optional[Decimal], t.Optional[Decimal]]: - """Return start and end timestamp of the scene. - - Parameters - ---------- - scene: raillabel.format.Scene - Scene the timespan should be based off. - - Returns - ------- - decimal.Decimal or None - Start timestamp of the scene. Is None if the scene has no frames. - decimal.Decimal or None - End timestamp of the scene. Is None if the scene has no frames. - """ - start_timestamp = None - end_timestamp = None - - for frame in scene.frames.values(): - - if start_timestamp == None or frame.timestamp < start_timestamp: - start_timestamp = frame.timestamp - - if end_timestamp == None or frame.timestamp > end_timestamp: - end_timestamp = frame.timestamp - - return (start_timestamp, end_timestamp) diff --git a/tests/test_raillabel/stats/test_generate_timespan.py b/tests/test_raillabel/stats/test_generate_timespan.py deleted file mode 100644 index a9e0236..0000000 --- a/tests/test_raillabel/stats/test_generate_timespan.py +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright DB InfraGO AG and contributors -# SPDX-License-Identifier: Apache-2.0 - -import os -import sys -from pathlib import Path - -import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent)) - -import raillabel - -# == Fixtures ============================ - -@pytest.fixture -def metadata() -> raillabel.format.Metadata: - return raillabel.format.Metadata(schema_version="1.0.0") - -# == Tests ============================ - -def test_simple_timespan(metadata): - scene = raillabel.Scene( - metadata=metadata, - frames={ - 0: raillabel.format.Frame( - uid=0, - timestamp=100 - ), - 1: raillabel.format.Frame( - uid=1, - timestamp=105 - ), - 2: raillabel.format.Frame( - uid=0, - timestamp=110 - ), - } - ) - - assert raillabel.stats.generate_timespan(scene) == (100, 110) - -def test_unordered_timspan(metadata): - scene = raillabel.Scene( - metadata=metadata, - frames={ - 0: raillabel.format.Frame( - uid=0, - timestamp=110 - ), - 1: raillabel.format.Frame( - uid=1, - timestamp=100 - ), - } - ) - - assert raillabel.stats.generate_timespan(scene) == (100, 110) - -def test_empty_timespan(metadata): - scene = raillabel.Scene( - metadata=metadata, - frames={} - ) - - assert raillabel.stats.generate_timespan(scene) == (None, None) - - -if __name__ == "__main__": - os.system("clear") - pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])