c3acdf6c12
Port the reference vocabulary and priority order into NOTE_WORDS triples. Match prefixes at word starts and words at both boundaries, normalize ñ to n after the existing accent normalization, and reject whole-word closing notes. Keep note_intervals, window_note, mask, EXCLUDED and MASKED unchanged. Ported 32 logic cases: 22 recognized texts, nine negative texts and the closing-note interval case. Did not port test_igual_que_la_libreria_eeg, as explicitly required: it imports and compares against the external eeg library rather than testing the local logic. The interval case omits the am.MODULE.version assertion because this implementation has no annotation library MODULE or corresponding version API. Internal choices: - Keep the existing next-with-default expression for first-match selection. - Use the reference ordered list and END, _pattern and PATTERNS structure, compiling one expression per state at module import. - Use Ruff's multiline formatting for the vocabulary and invented fixtures. - Adapt interval fixtures to the existing tuple input/output shapes and calculate the asserted interval end as onset plus duration. Validation from the worktree root with the main checkout's virtualenv: - ruff check models: passed. - ruff format --check models: passed, 54 files already formatted. - lint-imports: passed, two contracts kept and none broken. - pytest models/tests/test_tea_notes.py: 32 passed. - pytest test_eeg_reasons.py, test_tea_training_source.py, test_tea_job.py and test_tea_preview.py under models/tests: 24 passed, seven warnings. This regression run used flock heavy.lock and nice -n 10. - Reference vocabulary and unchanged interval/masking AST checks: passed. - git diff --check: passed. Python checks used PYTHONPATH=Core:Persistance:models:WebApi:synthetic to resolve this worktree instead of the virtualenv's editable main checkout.
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
import pytest
|
|
|
|
from models.tea.eeg.sleep import note_intervals, note_state
|
|
|
|
VERDADEROS = [
|
|
("Ojos cerrados", "eyes_closed"),
|
|
("OC", "eyes_closed"),
|
|
("oc 10 s", "eyes_closed"),
|
|
("Cierra los ojos", "eyes_closed"),
|
|
("Eyes closed", "eyes_closed"),
|
|
("Ojos abiertos", "eyes_open"),
|
|
("OA", "eyes_open"),
|
|
("Sueño", "sleep"),
|
|
("SUEÑO", "sleep"),
|
|
("dormida", "sleep"),
|
|
("Fase II", "sleep"),
|
|
("N2", "sleep"),
|
|
("Asleep", "sleep"),
|
|
("Fótica 6 Hz", "photic"),
|
|
("Photic 12 Hz", "photic"),
|
|
("HV", "hyperventilation"),
|
|
("Hiperventilación", "hyperventilation"),
|
|
("Despierto", "awake"),
|
|
("Llora", "crying"),
|
|
("Movimiento", "movement"),
|
|
("Biberón", "feeding"),
|
|
("come", "feeding"),
|
|
]
|
|
FALSOS = [
|
|
"foco",
|
|
"Boca abierta",
|
|
"Mov. local",
|
|
"Doctor",
|
|
"Toalla",
|
|
"comentario del técnico",
|
|
"Recolocar electrodo",
|
|
"Photic: Off",
|
|
"Fin de fótica",
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("texto, estado", VERDADEROS)
|
|
def test_estado_reconocido(texto, estado):
|
|
assert note_state(texto) == estado
|
|
|
|
|
|
@pytest.mark.parametrize("texto", FALSOS)
|
|
def test_sin_falso_positivo(texto):
|
|
assert note_state(texto) is None
|
|
|
|
|
|
def test_intervalos_no_abren_estado_con_nota_de_cierre():
|
|
notas = [
|
|
(0.0, 0.0, "Photic 6 Hz"),
|
|
(20.0, 0.0, "Photic: Off"),
|
|
(100.0, 0.0, "foco"),
|
|
]
|
|
iv = note_intervals(notas, 300.0)
|
|
assert [state for _, _, state in iv] == ["photic", "unmarked"]
|
|
assert iv[0][0] + iv[0][1] == 60.0
|