-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidation_controller.py
More file actions
96 lines (81 loc) · 3.29 KB
/
validation_controller.py
File metadata and controls
96 lines (81 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""Validation Controller for PEtab GUI.
This module contains the ValidationController class, which handles all model
validation operations, including:
- PEtab model consistency checking
- Validation error logging and reporting
- Invalid cell management
"""
import logging
from ..utils import CaptureLogHandler
from .utils import filtered_error
class ValidationController:
"""Controller for model validation.
Handles validation of PEtab models and reports errors to the user through
the logging system. Manages the PEtab lint process and coordinates
validation results with the model's invalid cell tracking.
Attributes
----------
main : MainController
Reference to the main controller for access to models, views, and
other controllers.
model : PEtabModel
The PEtab model being validated.
logger : LoggerController
The logger for user feedback.
"""
def __init__(self, main_controller):
"""Initialize the ValidationController.
Parameters
----------
main_controller : MainController
The main controller instance.
"""
self.main = main_controller
self.model = main_controller.model
self.logger = main_controller.logger
def check_model(self):
"""Check the consistency of the model and log the results.
Runs the PEtab linter to validate the model structure, data, and
consistency. Captures and reports all validation messages, and
resets invalid cell markers if validation passes.
Notes
-----
Uses PEtab's built-in validation through `model.test_consistency()`.
Captures log messages from the PEtab linter for display to the user.
"""
capture_handler = CaptureLogHandler()
logger_lint = logging.getLogger("petab.v1.lint")
logger_vis = logging.getLogger("petab.v1.visualize.lint")
logger_lint.addHandler(capture_handler)
logger_vis.addHandler(capture_handler)
try:
# Run the consistency check
failed = self.model.test_consistency()
# Process captured logs
if capture_handler.records:
captured_output = "<br> ".join(
capture_handler.get_formatted_messages()
)
self.logger.log_message(
f"Captured petab lint logs:<br>"
f" {captured_output}",
color="purple",
)
# Log the consistency check result
if not failed:
self.logger.log_message(
"PEtab problem has no errors.", color="green"
)
for model in self.model.pandas_models.values():
model.reset_invalid_cells()
else:
self.logger.log_message(
"PEtab problem has errors.", color="red"
)
except Exception as e:
msg = f"PEtab linter failed at some point: {filtered_error(e)}"
self.logger.log_message(msg, color="red")
finally:
# Always remove the capture handler
logger_lint.removeHandler(capture_handler)
logger_vis.removeHandler(capture_handler)