Coverage for backend/django/diagnostics/methods/get_solver_rule_findings.py: 100%
17 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-06-23 21:51 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-06-23 21:51 +0000
1from django.db.models.manager import BaseManager
2from diagnostics.models.DiagnosticsResult import DiagnosticsResult
3from core.auxiliary.models import Flowsheet
4from diagnostics.rules.engine import RuleFinding
5from typing import Generator
8def format_results(diagnostics_results: list[DiagnosticsResult]) -> list[RuleFinding]:
9 """
10 Convert DiagnosticsResult objects to RuleFinding format expected by the frontend.
11 """
12 findings: list[RuleFinding] = []
13 for result in diagnostics_results:
14 simulation_object = result.propertyValue.get_simulation_object() if result.propertyValue else None
15 findings.append(
16 RuleFinding(
17 propertyId=result.propertyValue.id if result.propertyValue else None,
18 propertyKey=result.propertyValue.property.key if result.propertyValue else None,
19 componentName= simulation_object.componentName if simulation_object else None,
20 componentId=simulation_object.id if simulation_object else None,
21 severity=result.severity,
22 description=result.message,
23 title="",
24 )
25 )
27 return findings
29def get_object_rule_findings(object_id: int) -> list[RuleFinding]:
30 """
31 Fetch the latest diagnostics results for a specific SimulationObject and convert them to RuleFinding format.
32 """
33 diagnostics_results = DiagnosticsResult.objects.filter(
34 propertyValue__property__set__simulationObject_id=object_id).all()
36 return format_results(list(diagnostics_results))
38def get_flowsheet_rule_findings(flowsheet_id: int) -> list[RuleFinding]:
40 """
41 Fetch the latest diagnostics results for the flowsheet and convert them to RuleFinding format.
42 """
43 diagnostics_results = DiagnosticsResult.objects.filter(
44 flowsheet_id=flowsheet_id).all()
46 return format_results(list(diagnostics_results))