-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/CO2_fitting_refinement' into 'master'
CO2 fitting algorithm refinement See merge request caimira/caimira!503
- Loading branch information
Showing
11 changed files
with
1,534 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import dataclasses | ||
import typing | ||
|
||
from caimira.models import CO2DataModel, Interval, IntPiecewiseConstant | ||
from .co2_model_generator import CO2FormData | ||
|
||
|
||
@dataclasses.dataclass | ||
class CO2ReportGenerator: | ||
|
||
def build_initial_plot( | ||
self, | ||
form: CO2FormData, | ||
) -> dict: | ||
''' | ||
Initial plot with the suggested ventilation state changes. | ||
This method receives the form input and returns the CO2 | ||
plot with the respective transition times. | ||
''' | ||
CO2model: CO2DataModel = form.build_model() | ||
|
||
occupancy_transition_times = list(CO2model.occupancy.transition_times) | ||
|
||
ventilation_transition_times: list = form.find_change_points() | ||
# The entire ventilation changes consider the initial and final occupancy state change | ||
all_vent_transition_times: list = sorted( | ||
[occupancy_transition_times[0]] + | ||
[occupancy_transition_times[-1]] + | ||
ventilation_transition_times) | ||
|
||
ventilation_plot: str = form.generate_ventilation_plot( | ||
ventilation_transition_times=all_vent_transition_times, | ||
occupancy_transition_times=occupancy_transition_times | ||
) | ||
|
||
context = { | ||
'CO2_plot': ventilation_plot, | ||
'transition_times': [round(el, 2) for el in all_vent_transition_times], | ||
} | ||
|
||
return context | ||
|
||
def build_fitting_results( | ||
self, | ||
form: CO2FormData, | ||
) -> dict: | ||
''' | ||
Final fitting results with the respective predictive CO2. | ||
This method receives the form input and returns the fitting results | ||
along with the CO2 plot with the predictive CO2. | ||
''' | ||
CO2model: CO2DataModel = form.build_model() | ||
|
||
# Ventilation times after user manipulation from the suggested ventilation state change times. | ||
ventilation_transition_times = list(CO2model.ventilation_transition_times) | ||
|
||
# The result of the following method is a dict with the results of the fitting | ||
# algorithm, namely the breathing rate and ACH values. It also returns the | ||
# predictive CO2 result based on the fitting results. | ||
context: typing.Dict = dict(CO2model.CO2_fit_params()) | ||
|
||
# Add the transition times and CO2 plot to the results. | ||
context['transition_times'] = ventilation_transition_times | ||
context['CO2_plot'] = form.generate_ventilation_plot(ventilation_transition_times=ventilation_transition_times[:-1], | ||
predictive_CO2=context['predictive_CO2']) | ||
|
||
return context | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.