jrrribeiro commited on
Commit
d7a6f4f
·
1 Parent(s): c4b2cd0

feat(ui): use native date picker for updated-after filter

Browse files
README.md CHANGED
@@ -62,3 +62,4 @@ Estrutura base criada por projeto/dataset:
62
  - Sprint 3 (UX conflito++++): atalhos teclado para validacao rapida (1=positivo 2=negativo 3=indeterminado 4=pular R=reaplicar)
63
  - Sprint 3 (UX conflito+++++): operacoes em lote para aprovar/rejeitar todos os conflitos em uma unica acao
64
  - Sprint 3 (UX conflito++++++): filtros avancados por validador, status e data de atualizacao em toda a navegacao
 
 
62
  - Sprint 3 (UX conflito++++): atalhos teclado para validacao rapida (1=positivo 2=negativo 3=indeterminado 4=pular R=reaplicar)
63
  - Sprint 3 (UX conflito+++++): operacoes em lote para aprovar/rejeitar todos os conflitos em uma unica acao
64
  - Sprint 3 (UX conflito++++++): filtros avancados por validador, status e data de atualizacao em toda a navegacao
65
+ - Sprint 3 (UX conflito+++++++): filtro de data com seletor nativo (DateTime sem hora) para reduzir erros de digitacao
src/ui/app_factory.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import tempfile
3
- from datetime import datetime
4
  from pathlib import Path
5
  from typing import Protocol
6
 
@@ -105,7 +105,7 @@ def _page_to_table(
105
  min_confidence: float,
106
  validator_filter: str = "",
107
  status_filter: str = "all",
108
- updated_after: str = "",
109
  conflict_detection_key: str = "",
110
  show_conflicts_only: bool = False,
111
  ):
@@ -122,7 +122,24 @@ def _page_to_table(
122
 
123
  normalized_status_filter = status_filter.strip().lower() if status_filter else "all"
124
  normalized_validator_filter = validator_filter.strip().lower()
125
- updated_after_date = updated_after.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  rows = [
128
  [
@@ -151,23 +168,19 @@ def _page_to_table(
151
  rows = [row for row in rows if str(row[6]).strip().lower() == normalized_status_filter]
152
 
153
  if updated_after_date:
154
- try:
155
- cutoff_date = datetime.strptime(updated_after_date, "%Y-%m-%d").date()
156
- filtered_rows: list[list[object]] = []
157
- for row in rows:
158
- snapshot_item = snapshot.get(str(row[0]), {})
159
- updated_at_value = str(snapshot_item.get("updated_at", "")).strip()
160
- if not updated_at_value:
161
- continue
162
- try:
163
- item_date = datetime.fromisoformat(updated_at_value.replace("Z", "+00:00")).date()
164
- if item_date >= cutoff_date:
165
- filtered_rows.append(row)
166
- except ValueError:
167
- continue
168
- rows = filtered_rows
169
- except ValueError:
170
- pass
171
 
172
  if show_conflicts_only:
173
  rows = [row for row in rows if str(row[8]) == "CONFLICT"]
@@ -359,7 +372,7 @@ def _save_selected_validation_with_refresh(
359
  min_confidence: float,
360
  validator_filter: str,
361
  status_filter: str,
362
- updated_after: str,
363
  show_conflicts_only: bool,
364
  ) -> tuple[str, str, str | None, list[list[object]], int, int, str, str]:
365
  selected_key = ""
@@ -451,7 +464,7 @@ def _reapply_last_conflict_validation_with_refresh(
451
  min_confidence: float,
452
  validator_filter: str,
453
  status_filter: str,
454
- updated_after: str,
455
  show_conflicts_only: bool,
456
  ) -> tuple[str, str, str | None, list[list[object]], int, int, str, str]:
457
  if not pending_status_value:
@@ -517,7 +530,7 @@ def _batch_validate_conflicts(
517
  min_confidence: float,
518
  validator_filter: str,
519
  status_filter: str,
520
- updated_after: str,
521
  ) -> tuple[str, str, str | None, list[list[object]], int]:
522
  """Apply the same validation status to all visible conflicts in the table."""
523
  validator_name = validator.strip()
@@ -597,7 +610,7 @@ def _batch_reapply_all_pending(
597
  min_confidence: float,
598
  validator_filter: str,
599
  status_filter: str,
600
- updated_after: str,
601
  ) -> tuple[str, str, str | None, list[list[object]], int]:
602
  """Reapply all pending validations (stored conflicts) with current version."""
603
  if not pending_statuses:
@@ -678,7 +691,7 @@ def create_app() -> gr.Blocks:
678
  choices=["all", "pending", "positive", "negative", "uncertain", "skip"],
679
  value="all",
680
  )
681
- updated_after_filter = gr.Textbox(label="Atualizado a partir de (YYYY-MM-DD)", placeholder="Ex: 2026-03-25")
682
 
683
  with gr.Row():
684
  prev_btn = gr.Button("Pagina anterior")
@@ -767,7 +780,7 @@ def create_app() -> gr.Blocks:
767
  confidence: float,
768
  validator_filter_value: str,
769
  status_filter_value: str,
770
- updated_after_value: str,
771
  only_conflicts: bool,
772
  ):
773
  return _page_to_table(
@@ -789,7 +802,7 @@ def create_app() -> gr.Blocks:
789
  confidence: float,
790
  validator_filter_value: str,
791
  status_filter_value: str,
792
- updated_after_value: str,
793
  only_conflicts: bool,
794
  ):
795
  return refresh(
@@ -808,7 +821,7 @@ def create_app() -> gr.Blocks:
808
  confidence: float,
809
  validator_filter_value: str,
810
  status_filter_value: str,
811
- updated_after_value: str,
812
  only_conflicts: bool,
813
  ):
814
  return refresh(
 
1
  import gradio as gr
2
  import tempfile
3
+ from datetime import date, datetime
4
  from pathlib import Path
5
  from typing import Protocol
6
 
 
105
  min_confidence: float,
106
  validator_filter: str = "",
107
  status_filter: str = "all",
108
+ updated_after: object = None,
109
  conflict_detection_key: str = "",
110
  show_conflicts_only: bool = False,
111
  ):
 
122
 
123
  normalized_status_filter = status_filter.strip().lower() if status_filter else "all"
124
  normalized_validator_filter = validator_filter.strip().lower()
125
+ updated_after_date: date | None = None
126
+ if updated_after is not None:
127
+ if isinstance(updated_after, datetime):
128
+ updated_after_date = updated_after.date()
129
+ elif isinstance(updated_after, date):
130
+ updated_after_date = updated_after
131
+ elif isinstance(updated_after, (int, float)):
132
+ updated_after_date = datetime.fromtimestamp(float(updated_after)).date()
133
+ else:
134
+ updated_after_text = str(updated_after).strip()
135
+ if updated_after_text:
136
+ try:
137
+ updated_after_date = datetime.strptime(updated_after_text, "%Y-%m-%d").date()
138
+ except ValueError:
139
+ try:
140
+ updated_after_date = datetime.fromisoformat(updated_after_text.replace("Z", "+00:00")).date()
141
+ except ValueError:
142
+ updated_after_date = None
143
 
144
  rows = [
145
  [
 
168
  rows = [row for row in rows if str(row[6]).strip().lower() == normalized_status_filter]
169
 
170
  if updated_after_date:
171
+ filtered_rows: list[list[object]] = []
172
+ for row in rows:
173
+ snapshot_item = snapshot.get(str(row[0]), {})
174
+ updated_at_value = str(snapshot_item.get("updated_at", "")).strip()
175
+ if not updated_at_value:
176
+ continue
177
+ try:
178
+ item_date = datetime.fromisoformat(updated_at_value.replace("Z", "+00:00")).date()
179
+ if item_date >= updated_after_date:
180
+ filtered_rows.append(row)
181
+ except ValueError:
182
+ continue
183
+ rows = filtered_rows
 
 
 
 
184
 
185
  if show_conflicts_only:
186
  rows = [row for row in rows if str(row[8]) == "CONFLICT"]
 
372
  min_confidence: float,
373
  validator_filter: str,
374
  status_filter: str,
375
+ updated_after: object,
376
  show_conflicts_only: bool,
377
  ) -> tuple[str, str, str | None, list[list[object]], int, int, str, str]:
378
  selected_key = ""
 
464
  min_confidence: float,
465
  validator_filter: str,
466
  status_filter: str,
467
+ updated_after: object,
468
  show_conflicts_only: bool,
469
  ) -> tuple[str, str, str | None, list[list[object]], int, int, str, str]:
470
  if not pending_status_value:
 
530
  min_confidence: float,
531
  validator_filter: str,
532
  status_filter: str,
533
+ updated_after: object,
534
  ) -> tuple[str, str, str | None, list[list[object]], int]:
535
  """Apply the same validation status to all visible conflicts in the table."""
536
  validator_name = validator.strip()
 
610
  min_confidence: float,
611
  validator_filter: str,
612
  status_filter: str,
613
+ updated_after: object,
614
  ) -> tuple[str, str, str | None, list[list[object]], int]:
615
  """Reapply all pending validations (stored conflicts) with current version."""
616
  if not pending_statuses:
 
691
  choices=["all", "pending", "positive", "negative", "uncertain", "skip"],
692
  value="all",
693
  )
694
+ updated_after_filter = gr.DateTime(label="Atualizado a partir de", include_time=False, type="string")
695
 
696
  with gr.Row():
697
  prev_btn = gr.Button("Pagina anterior")
 
780
  confidence: float,
781
  validator_filter_value: str,
782
  status_filter_value: str,
783
+ updated_after_value: object,
784
  only_conflicts: bool,
785
  ):
786
  return _page_to_table(
 
802
  confidence: float,
803
  validator_filter_value: str,
804
  status_filter_value: str,
805
+ updated_after_value: object,
806
  only_conflicts: bool,
807
  ):
808
  return refresh(
 
821
  confidence: float,
822
  validator_filter_value: str,
823
  status_filter_value: str,
824
+ updated_after_value: object,
825
  only_conflicts: bool,
826
  ):
827
  return refresh(
tests/unit/test_app_factory_audio_helpers.py CHANGED
@@ -1,4 +1,5 @@
1
  from dataclasses import dataclass
 
2
  from pathlib import Path
3
 
4
  import pandas as pd
@@ -384,6 +385,21 @@ def test_page_to_table_filters_by_updated_after() -> None:
384
  assert rows[0][0] == "dkey_01"
385
 
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  def test_find_detection_row_index() -> None:
388
  rows = [["dkey_00", "audio_00"], ["dkey_01", "audio_01"]]
389
 
 
1
  from dataclasses import dataclass
2
+ from datetime import date
3
  from pathlib import Path
4
 
5
  import pandas as pd
 
385
  assert rows[0][0] == "dkey_01"
386
 
387
 
388
+ def test_page_to_table_filters_by_updated_after_date_object() -> None:
389
+ rows, _, _ = _page_to_table(
390
+ service=FakeQueueService(),
391
+ snapshot_reader=FakeSnapshotReader(),
392
+ project_slug="demo-project",
393
+ page=1,
394
+ scientific_name="",
395
+ min_confidence=0.0,
396
+ updated_after=date(2026, 3, 24),
397
+ )
398
+
399
+ assert len(rows) == 1
400
+ assert rows[0][0] == "dkey_01"
401
+
402
+
403
  def test_find_detection_row_index() -> None:
404
  rows = [["dkey_00", "audio_00"], ["dkey_01", "audio_01"]]
405