Spaces:
Sleeping
Sleeping
Sync app from GitHub Actions
Browse files- src/ui/app_factory.py +71 -1
- src/ui/theme.py +13 -3
- tests/unit/test_app_factory_audio_helpers.py +21 -0
src/ui/app_factory.py
CHANGED
|
@@ -1848,7 +1848,7 @@ def _advance_to_next_row_with_title(
|
|
| 1848 |
|
| 1849 |
safe_index = int(selected_index) + 1
|
| 1850 |
if safe_index >= len(normalized_rows):
|
| 1851 |
-
safe_index =
|
| 1852 |
safe_index = max(0, safe_index)
|
| 1853 |
audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
|
| 1854 |
audio_service=audio_service,
|
|
@@ -1863,6 +1863,59 @@ def _advance_to_next_row_with_title(
|
|
| 1863 |
return safe_index, audio_path, updated_cache_key, status, spectrogram_path, _spectrogram_title(species_name, confidence_value)
|
| 1864 |
|
| 1865 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1866 |
def _cleanup_selected_audio(audio_service: _AudioServiceProtocol, cache_key: str) -> tuple[str, str | None]:
|
| 1867 |
if not cache_key:
|
| 1868 |
return "No cached audio to clean", None
|
|
@@ -1939,6 +1992,8 @@ def _save_selected_validation_with_refresh(
|
|
| 1939 |
show_conflicts_only: bool,
|
| 1940 |
corrected_species: str | None = None,
|
| 1941 |
) -> tuple[str, str, str | None, list[list[object]], int, int, str, str]:
|
|
|
|
|
|
|
| 1942 |
selected_key = ""
|
| 1943 |
try:
|
| 1944 |
selected_key = _extract_detection_key(rows=rows, selected_index=selected_index)
|
|
@@ -1999,6 +2054,21 @@ def _save_selected_validation_with_refresh(
|
|
| 1999 |
else:
|
| 2000 |
conflict_key = ""
|
| 2001 |
pending_status_value = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2002 |
status = f"{save_status} | {page_status}"
|
| 2003 |
|
| 2004 |
return (
|
|
|
|
| 1848 |
|
| 1849 |
safe_index = int(selected_index) + 1
|
| 1850 |
if safe_index >= len(normalized_rows):
|
| 1851 |
+
safe_index = _first_pending_row_index(normalized_rows)
|
| 1852 |
safe_index = max(0, safe_index)
|
| 1853 |
audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
|
| 1854 |
audio_service=audio_service,
|
|
|
|
| 1863 |
return safe_index, audio_path, updated_cache_key, status, spectrogram_path, _spectrogram_title(species_name, confidence_value)
|
| 1864 |
|
| 1865 |
|
| 1866 |
+
def _first_pending_row_index(rows: object) -> int:
|
| 1867 |
+
normalized_rows = _normalize_rows(rows)
|
| 1868 |
+
for index, row in enumerate(normalized_rows):
|
| 1869 |
+
status_value = str(row[6] if len(row) > 6 else "pending").strip().lower()
|
| 1870 |
+
if status_value in {"", "pending"}:
|
| 1871 |
+
return index
|
| 1872 |
+
return 0
|
| 1873 |
+
|
| 1874 |
+
|
| 1875 |
+
def _first_pending_queue_page(
|
| 1876 |
+
queue_service: _QueueServiceProtocol,
|
| 1877 |
+
snapshot_reader: _ValidationReadRepositoryProtocol,
|
| 1878 |
+
project_slug: str,
|
| 1879 |
+
scientific_name: str,
|
| 1880 |
+
min_confidence: float,
|
| 1881 |
+
validator_filter: str,
|
| 1882 |
+
status_filter: str,
|
| 1883 |
+
updated_after: object,
|
| 1884 |
+
show_conflicts_only: bool,
|
| 1885 |
+
) -> tuple[list[list[object]], int, int] | None:
|
| 1886 |
+
normalized_status_filter = (status_filter or "all").strip().lower()
|
| 1887 |
+
if normalized_status_filter not in {"", "all", "pending"}:
|
| 1888 |
+
return None
|
| 1889 |
+
|
| 1890 |
+
requested_page = 1
|
| 1891 |
+
visited_pages: set[int] = set()
|
| 1892 |
+
while True:
|
| 1893 |
+
page_rows, _, actual_page = _page_to_table(
|
| 1894 |
+
service=queue_service,
|
| 1895 |
+
snapshot_reader=snapshot_reader,
|
| 1896 |
+
project_slug=project_slug,
|
| 1897 |
+
page=requested_page,
|
| 1898 |
+
scientific_name=scientific_name,
|
| 1899 |
+
min_confidence=min_confidence,
|
| 1900 |
+
validator_filter=validator_filter,
|
| 1901 |
+
status_filter=status_filter,
|
| 1902 |
+
updated_after=updated_after,
|
| 1903 |
+
show_conflicts_only=show_conflicts_only,
|
| 1904 |
+
)
|
| 1905 |
+
if actual_page in visited_pages:
|
| 1906 |
+
return None
|
| 1907 |
+
visited_pages.add(actual_page)
|
| 1908 |
+
|
| 1909 |
+
page_rows = _sort_rows_by_confidence_desc(page_rows)
|
| 1910 |
+
pending_index = _first_pending_row_index(page_rows)
|
| 1911 |
+
if page_rows:
|
| 1912 |
+
status_value = str(page_rows[pending_index][6] if len(page_rows[pending_index]) > 6 else "pending").strip().lower()
|
| 1913 |
+
if status_value in {"", "pending"}:
|
| 1914 |
+
return page_rows, actual_page, pending_index
|
| 1915 |
+
|
| 1916 |
+
requested_page = actual_page + 1
|
| 1917 |
+
|
| 1918 |
+
|
| 1919 |
def _cleanup_selected_audio(audio_service: _AudioServiceProtocol, cache_key: str) -> tuple[str, str | None]:
|
| 1920 |
if not cache_key:
|
| 1921 |
return "No cached audio to clean", None
|
|
|
|
| 1992 |
show_conflicts_only: bool,
|
| 1993 |
corrected_species: str | None = None,
|
| 1994 |
) -> tuple[str, str, str | None, list[list[object]], int, int, str, str]:
|
| 1995 |
+
prior_rows = _normalize_rows(rows)
|
| 1996 |
+
selected_was_last_row = bool(prior_rows) and int(selected_index) >= len(prior_rows) - 1
|
| 1997 |
selected_key = ""
|
| 1998 |
try:
|
| 1999 |
selected_key = _extract_detection_key(rows=rows, selected_index=selected_index)
|
|
|
|
| 2054 |
else:
|
| 2055 |
conflict_key = ""
|
| 2056 |
pending_status_value = ""
|
| 2057 |
+
if selected_was_last_row:
|
| 2058 |
+
first_pending_page = _first_pending_queue_page(
|
| 2059 |
+
queue_service=queue_service,
|
| 2060 |
+
snapshot_reader=snapshot_reader,
|
| 2061 |
+
project_slug=project_slug,
|
| 2062 |
+
scientific_name=scientific_name,
|
| 2063 |
+
min_confidence=min_confidence,
|
| 2064 |
+
validator_filter=validator_filter,
|
| 2065 |
+
status_filter=status_filter,
|
| 2066 |
+
updated_after=updated_after,
|
| 2067 |
+
show_conflicts_only=show_conflicts_only,
|
| 2068 |
+
)
|
| 2069 |
+
if first_pending_page is not None:
|
| 2070 |
+
refreshed_rows, refreshed_page, pending_index = first_pending_page
|
| 2071 |
+
refreshed_index = pending_index - 1
|
| 2072 |
status = f"{save_status} | {page_status}"
|
| 2073 |
|
| 2074 |
return (
|
src/ui/theme.py
CHANGED
|
@@ -593,7 +593,8 @@ body,
|
|
| 593 |
}
|
| 594 |
|
| 595 |
.bn-admin-access-panel,
|
| 596 |
-
.bn-admin-pending-panel
|
|
|
|
| 597 |
width: 100% !important;
|
| 598 |
}
|
| 599 |
|
|
@@ -604,10 +605,14 @@ body,
|
|
| 604 |
gap: 14px !important;
|
| 605 |
}
|
| 606 |
|
| 607 |
-
.column:has(> .bn-admin-access-panel):has(> .bn-admin-pending-panel) > :not(.bn-admin-access-panel):not(.bn-admin-pending-panel) {
|
| 608 |
grid-column: 1 / -1;
|
| 609 |
}
|
| 610 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
.bn-soft-action button,
|
| 612 |
button.bn-soft-action {
|
| 613 |
min-height: 42px !important;
|
|
@@ -831,7 +836,8 @@ select {
|
|
| 831 |
}
|
| 832 |
|
| 833 |
.bn-admin-access-panel,
|
| 834 |
-
.bn-admin-pending-panel
|
|
|
|
| 835 |
display: block !important;
|
| 836 |
width: 100% !important;
|
| 837 |
margin-left: 0 !important;
|
|
@@ -840,6 +846,10 @@ select {
|
|
| 840 |
.column:has(> .bn-admin-access-panel):has(> .bn-admin-pending-panel) {
|
| 841 |
grid-template-columns: 1fr;
|
| 842 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 843 |
}
|
| 844 |
|
| 845 |
@media (max-width: 560px) {
|
|
|
|
| 593 |
}
|
| 594 |
|
| 595 |
.bn-admin-access-panel,
|
| 596 |
+
.bn-admin-pending-panel,
|
| 597 |
+
.bn-admin-delete-panel {
|
| 598 |
width: 100% !important;
|
| 599 |
}
|
| 600 |
|
|
|
|
| 605 |
gap: 14px !important;
|
| 606 |
}
|
| 607 |
|
| 608 |
+
.column:has(> .bn-admin-access-panel):has(> .bn-admin-pending-panel) > :not(.bn-admin-access-panel):not(.bn-admin-pending-panel):not(.bn-admin-delete-panel) {
|
| 609 |
grid-column: 1 / -1;
|
| 610 |
}
|
| 611 |
|
| 612 |
+
.column:has(> .bn-admin-access-panel):has(> .bn-admin-pending-panel) > .bn-admin-delete-panel {
|
| 613 |
+
grid-column: 2;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
.bn-soft-action button,
|
| 617 |
button.bn-soft-action {
|
| 618 |
min-height: 42px !important;
|
|
|
|
| 836 |
}
|
| 837 |
|
| 838 |
.bn-admin-access-panel,
|
| 839 |
+
.bn-admin-pending-panel,
|
| 840 |
+
.bn-admin-delete-panel {
|
| 841 |
display: block !important;
|
| 842 |
width: 100% !important;
|
| 843 |
margin-left: 0 !important;
|
|
|
|
| 846 |
.column:has(> .bn-admin-access-panel):has(> .bn-admin-pending-panel) {
|
| 847 |
grid-template-columns: 1fr;
|
| 848 |
}
|
| 849 |
+
|
| 850 |
+
.column:has(> .bn-admin-access-panel):has(> .bn-admin-pending-panel) > .bn-admin-delete-panel {
|
| 851 |
+
grid-column: auto;
|
| 852 |
+
}
|
| 853 |
}
|
| 854 |
|
| 855 |
@media (max-width: 560px) {
|
tests/unit/test_app_factory_audio_helpers.py
CHANGED
|
@@ -471,6 +471,27 @@ def test_advance_to_next_row_wraps_after_last_selected_row() -> None:
|
|
| 471 |
assert title == "### Segment spectrogram"
|
| 472 |
|
| 473 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
def test_save_selected_validation_with_refresh_success() -> None:
|
| 475 |
audio_service = FakeAudioService()
|
| 476 |
validation_service = FakeValidationService()
|
|
|
|
| 471 |
assert title == "### Segment spectrogram"
|
| 472 |
|
| 473 |
|
| 474 |
+
def test_advance_to_next_row_wraps_to_first_pending_row() -> None:
|
| 475 |
+
service = FakeAudioService()
|
| 476 |
+
rows = [
|
| 477 |
+
["dkey_01", "audio_01", "sp", 0.9, 0.0, 1.0, "positive"],
|
| 478 |
+
["dkey_02", "audio_02", "sp", 0.8, 1.0, 2.0, "pending"],
|
| 479 |
+
["dkey_03", "audio_03", "sp", 0.7, 2.0, 3.0, "positive"],
|
| 480 |
+
]
|
| 481 |
+
|
| 482 |
+
selected_index, audio_path, cache_key, _, _, _ = _advance_to_next_row_with_title(
|
| 483 |
+
audio_service=service,
|
| 484 |
+
dataset_repo="org/dataset",
|
| 485 |
+
rows=rows,
|
| 486 |
+
selected_index=2,
|
| 487 |
+
cache_key="",
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
assert selected_index == 1
|
| 491 |
+
assert audio_path == "/tmp/audio_02.wav"
|
| 492 |
+
assert cache_key == "key:audio_02"
|
| 493 |
+
|
| 494 |
+
|
| 495 |
def test_save_selected_validation_with_refresh_success() -> None:
|
| 496 |
audio_service = FakeAudioService()
|
| 497 |
validation_service = FakeValidationService()
|