Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip duration plots for single duration #74

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions audbcards/core/datacard.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def file_duration_distribution(self) -> str:
under ``<dataset-name>/<dataset-name>-file-durations.png``
and displayed
between the minimum and maximum values.
If all duration values are the same,
no distribution plot is created.

"""
min_ = 0
Expand All @@ -149,6 +151,12 @@ def file_duration_distribution(self) -> str:
if len(durations) > 0:
min_ = np.min(durations)
max_ = np.max(durations)

# Skip creating a distribution plot,
# if all durations are the same
if min_ == max_:
ChristianGeng marked this conversation as resolved.
Show resolved Hide resolved
return f"{max_:.1f} {unit}"

distribution_str = f"{min_:.1f} {unit} .. {max_:.1f} {unit}"

# Save distribution plot
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/rendered_templates/bare_db.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ channel
sampling rate
bit depth
duration 0 days 00:00:00
files 0, duration distribution: 0.0 s .. 0.0 s
files 0, duration distribution: 0.0 s
repository `data-local <.../data-local/bare_db>`__
published 2023-04-05 by author
============= ======================
2 changes: 1 addition & 1 deletion tests/test_data/rendered_templates/minimal_db.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ channel 1
sampling rate 8000
bit depth 16
duration 0 days 00:00:00.100000
files 1, duration distribution: 0.1 s .. 0.1 s
files 1, duration distribution: 0.1 s
repository `data-local <.../data-local/minimal_db>`__
published 2023-04-05 by author
============= ======================
Expand Down
14 changes: 9 additions & 5 deletions tests/test_datacard.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,21 @@ def test_datacard_file_duration_distribution(
f"{db.name}-file-durations.png",
)
assert not os.path.exists(image_file)
expected_distribution_str = f"{expected_min:.1f} s .. {expected_max:.1f} s"
if expected_min == expected_max:
expected_distribution_str = f"{expected_max:.1f} s"
ChristianGeng marked this conversation as resolved.
Show resolved Hide resolved
else:
expected_distribution_str = f"{expected_min:.1f} s .. {expected_max:.1f} s"
assert expected_distribution_str == distribution_str

# Set sphinx src and build dir and execute again
datacard.sphinx_build_dir = build_dir
datacard.sphinx_src_dir = src_dir
distribution_str = datacard.file_duration_distribution
assert os.path.exists(image_file)
expected_distribution_str = (
f"{expected_min:.1f} s |{db.name}-file-durations| {expected_max:.1f} s"
)
if expected_min != expected_max:
assert os.path.exists(image_file)
expected_distribution_str = (
f"{expected_min:.1f} s |{db.name}-file-durations| {expected_max:.1f} s"
)
assert expected_distribution_str == distribution_str


Expand Down
Loading