fix column matcher false-positive on shared table prefixes; round float durations for int columns
This commit is contained in:
@@ -139,9 +139,23 @@ class ColumnMatcher:
|
|||||||
if normalized_source == unprefixed_target:
|
if normalized_source == unprefixed_target:
|
||||||
return _UNPREFIXED, "unprefixed"
|
return _UNPREFIXED, "unprefixed"
|
||||||
# Not every field has a table prefix (`hemoglobina_g_dl`), so words
|
# Not every field has a table prefix (`hemoglobina_g_dl`), so words
|
||||||
# are compared against both the full and the unprefixed name.
|
# are compared against both the full and the unprefixed name. When
|
||||||
|
# the target *does* have real content beyond its prefix ("eeg" in
|
||||||
|
# "eeg_estudio"), that prefix is dropped from the full-name words
|
||||||
|
# first: every column in the table shares it, so a source word
|
||||||
|
# matching only that (e.g. "eeg_id" ~ "eeg_estudio", both just
|
||||||
|
# carrying "eeg") is not real evidence of a relationship. When the
|
||||||
|
# target has no content beyond its prefix (it isn't really a
|
||||||
|
# "prefix_field" name, e.g. "hemoglobina_g_dl"), nothing is dropped.
|
||||||
|
unprefixed_target_words = _words(unprefixed_target)
|
||||||
|
prefix_token = normalized_target.split("_", 1)[0]
|
||||||
|
target_words_full = (
|
||||||
|
[w for w in _words(normalized_target) if w != prefix_token]
|
||||||
|
if unprefixed_target_words
|
||||||
|
else _words(normalized_target)
|
||||||
|
)
|
||||||
source_words = _words(normalized_source)
|
source_words = _words(normalized_source)
|
||||||
words = max(_word_score(source_words, _words(normalized_target)), _word_score(source_words, _words(unprefixed_target)))
|
words = max(_word_score(source_words, target_words_full), _word_score(source_words, unprefixed_target_words))
|
||||||
if words >= _WORD_FLOOR:
|
if words >= _WORD_FLOOR:
|
||||||
# 0.5..0.7 by word overlap, plus a tiny whole-string tiebreak so
|
# 0.5..0.7 by word overlap, plus a tiny whole-string tiebreak so
|
||||||
# "fecha_reporte" prefers bx_fecha_reporte over another one-word overlap.
|
# "fecha_reporte" prefers bx_fecha_reporte over another one-word overlap.
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ def optional_str(v: Any) -> Any:
|
|||||||
return text or None
|
return text or None
|
||||||
|
|
||||||
|
|
||||||
|
def rounded_int(v: Any) -> Any:
|
||||||
|
"""A minutes/count field stored as an `int` column, whose source may
|
||||||
|
report a float (e.g. a duration measured to tenths of a minute)."""
|
||||||
|
if v is None or (isinstance(v, str) and v.strip() == ""):
|
||||||
|
return None
|
||||||
|
return round(float(v))
|
||||||
|
|
||||||
|
|
||||||
_DAY_FIRST_FORMATS = ("%d/%m/%Y", "%d-%m-%Y", "%d.%m.%Y", "%Y/%m/%d")
|
_DAY_FIRST_FORMATS = ("%d/%m/%Y", "%d-%m-%Y", "%d.%m.%Y", "%Y/%m/%d")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from core.tea.enums import (
|
|||||||
TipoGrafoelemento,
|
TipoGrafoelemento,
|
||||||
)
|
)
|
||||||
from webapi.imports.schemas.base import ImportSchema
|
from webapi.imports.schemas.base import ImportSchema
|
||||||
from webapi.imports.schemas.coercion import edf_file, Catalog, CatalogValue, coerce_date, optional_str
|
from webapi.imports.schemas.coercion import edf_file, Catalog, CatalogValue, coerce_date, optional_str, rounded_int
|
||||||
|
|
||||||
_FUENTE_INTERPRETACION_EEG_CATALOG = Catalog(FuenteInterpretacionEeg)
|
_FUENTE_INTERPRETACION_EEG_CATALOG = Catalog(FuenteInterpretacionEeg)
|
||||||
_ESTADO_REGISTRO_EEG_CATALOG = Catalog(EstadoRegistroEeg)
|
_ESTADO_REGISTRO_EEG_CATALOG = Catalog(EstadoRegistroEeg)
|
||||||
@@ -84,6 +84,11 @@ class EegEstudioImportSchema(ImportSchema):
|
|||||||
def _coerce_dates(cls, v):
|
def _coerce_dates(cls, v):
|
||||||
return coerce_date(v)
|
return coerce_date(v)
|
||||||
|
|
||||||
|
@field_validator("eeg_duracion_min", mode="before")
|
||||||
|
@classmethod
|
||||||
|
def _coerce_duracion_min(cls, v):
|
||||||
|
return rounded_int(v)
|
||||||
|
|
||||||
@field_validator("eeg_estudio", mode="before")
|
@field_validator("eeg_estudio", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def _valid_edf(cls, v):
|
def _valid_edf(cls, v):
|
||||||
|
|||||||
Reference in New Issue
Block a user