- Updated `config.yaml` to change the advice storage table from `advice` to `advisories` and adjusted the `thinking_budget` from 11264 to 9216. - Modified `README.md` to reflect the new `advisories` table in the advisory generation process. - Refactored SQL queries in `batch.py`, `job.py`, and `advice_context.py` to align with the new table structure. - Enhanced the advice generation logic in `advice.py` to accommodate changes in the data model, including updates to the JSON structure for advice output. - Updated relevant functions and documentation to ensure consistency across the codebase regarding the new advisory schema.
126 lines
4.0 KiB
Python
126 lines
4.0 KiB
Python
"""Unit tests for INCUBAZPRIMARIA model_value rounding and labels."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from decimal import Decimal
|
|
|
|
from pipeline.stages.disease import (
|
|
_DayRecords,
|
|
_format_model_value,
|
|
_incub_label,
|
|
_resolve_day_fase,
|
|
)
|
|
|
|
|
|
class FormatModelValueTests(unittest.TestCase):
|
|
def test_long_float_rounds_to_two_decimals(self) -> None:
|
|
self.assertEqual(_format_model_value(40.123456789), "40.12")
|
|
|
|
def test_long_decimal_rounds_to_two_decimals(self) -> None:
|
|
self.assertEqual(_format_model_value(Decimal("40.123456789")), "40.12")
|
|
|
|
def test_trailing_zeros_stripped(self) -> None:
|
|
self.assertEqual(_format_model_value(40.30), "40.3")
|
|
self.assertEqual(_format_model_value(40.0), "40")
|
|
self.assertEqual(_format_model_value(Decimal("40.10")), "40.1")
|
|
|
|
def test_none_and_empty_return_none(self) -> None:
|
|
self.assertIsNone(_format_model_value(None))
|
|
self.assertIsNone(_format_model_value(" "))
|
|
|
|
def test_non_numeric_passthrough(self) -> None:
|
|
self.assertEqual(_format_model_value("n/a"), "n/a")
|
|
|
|
|
|
class IncubLabelTests(unittest.TestCase):
|
|
def test_picks_max_raw_value_then_rounds_suffix(self) -> None:
|
|
self.assertEqual(
|
|
_incub_label([
|
|
("INCUBAZPRIMARIA", 40.12),
|
|
("INCUBAZPRIMARIA", 40.129),
|
|
("INCUBAZPRIMARIA", 39.99),
|
|
]),
|
|
"INCUBAZPRIMARIA_40.13",
|
|
)
|
|
|
|
def test_keeps_index_of_winning_row(self) -> None:
|
|
self.assertEqual(
|
|
_incub_label([("INCUBAZPRIMARIA2", 80.7)]),
|
|
"INCUBAZPRIMARIA2_80.7",
|
|
)
|
|
|
|
def test_higher_percentage_beats_higher_index(self) -> None:
|
|
self.assertEqual(
|
|
_incub_label([
|
|
("INCUBAZPRIMARIA2", 40),
|
|
("INCUBAZPRIMARIA1", 90),
|
|
]),
|
|
"INCUBAZPRIMARIA1_90",
|
|
)
|
|
|
|
def test_tie_keeps_higher_index(self) -> None:
|
|
self.assertEqual(
|
|
_incub_label([
|
|
("INCUBAZPRIMARIA1", 80.7),
|
|
("INCUBAZPRIMARIA2", 80.7),
|
|
]),
|
|
"INCUBAZPRIMARIA2_80.7",
|
|
)
|
|
|
|
def test_missing_index_loses_tie(self) -> None:
|
|
self.assertEqual(
|
|
_incub_label([
|
|
("INCUBAZPRIMARIA", 40),
|
|
("INCUBAZPRIMARIA2", 40),
|
|
]),
|
|
"INCUBAZPRIMARIA2_40",
|
|
)
|
|
|
|
def test_space_or_underscore_is_not_an_index(self) -> None:
|
|
self.assertEqual(
|
|
_incub_label([("INCUBAZPRIMARIA 2", 40), ("INCUBAZPRIMARIA_2", 30)]),
|
|
"INCUBAZPRIMARIA_40",
|
|
)
|
|
|
|
def test_empty_or_non_numeric_falls_back(self) -> None:
|
|
self.assertEqual(_incub_label([]), "INCUBAZPRIMARIA")
|
|
self.assertEqual(
|
|
_incub_label([("INCUBAZPRIMARIA", None), ("INCUBAZPRIMARIA2", "n/a")]),
|
|
"INCUBAZPRIMARIA",
|
|
)
|
|
|
|
def test_day_keeps_each_index_and_fase5(self) -> None:
|
|
records = _DayRecords(
|
|
descriptions={"INCUBAZPRIMARIA1", "INCUBAZPRIMARIA2", "FASE5", "FASE2"},
|
|
incub_rows=[
|
|
("INCUBAZPRIMARIA1", 90),
|
|
("INCUBAZPRIMARIA2", 40),
|
|
],
|
|
)
|
|
self.assertEqual(
|
|
_resolve_day_fase(records),
|
|
["INCUBAZPRIMARIA1_90", "INCUBAZPRIMARIA2_40", "FASE5"],
|
|
)
|
|
|
|
def test_incubation_only_keeps_highest_value_per_index(self) -> None:
|
|
records = _DayRecords(
|
|
descriptions={"INCUBAZPRIMARIA2"},
|
|
incub_rows=[
|
|
("INCUBAZPRIMARIA2", 40),
|
|
("INCUBAZPRIMARIA2", 80.7),
|
|
],
|
|
)
|
|
self.assertEqual(_resolve_day_fase(records), ["INCUBAZPRIMARIA2_80.7"])
|
|
|
|
def test_fase2_without_incubation(self) -> None:
|
|
records = _DayRecords(descriptions={"FASE2"})
|
|
self.assertEqual(_resolve_day_fase(records), ["FASE2"])
|
|
|
|
def test_empty_day_is_none(self) -> None:
|
|
self.assertIsNone(_resolve_day_fase(_DayRecords()))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|