-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracted CO2 logic to a dedicated route
- Loading branch information
Showing
16 changed files
with
692 additions
and
682 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
26 changes: 26 additions & 0 deletions
26
caimira/src/caimira/api/controller/co2_report_controller.py
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,26 @@ | ||
from caimira.calculator.validators.co2.co2_validator import CO2FormData | ||
from caimira.calculator.store.data_registry import DataRegistry | ||
|
||
|
||
def generate_form_obj(form_data, data_registry): | ||
return CO2FormData.from_dict(form_data=form_data, data_registry=data_registry) | ||
|
||
|
||
def generate_model(form_obj, data_registry): | ||
sample_size = data_registry.monte_carlo['sample_size'] | ||
return form_obj.build_model(sample_size=sample_size) | ||
|
||
|
||
def generate_report(model): | ||
return dict(model.CO2_fit_params()) | ||
|
||
|
||
def submit_CO2_form(form_data): | ||
data_registry = DataRegistry() | ||
|
||
form_obj = generate_form_obj( | ||
form_data=form_data, data_registry=data_registry) | ||
model = generate_model(form_obj=form_obj, data_registry=data_registry) | ||
report_data = generate_report(model=model) | ||
|
||
return report_data |
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
caimira/src/caimira/api/controller/virus_report_controller.py
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,38 @@ | ||
import concurrent.futures | ||
import functools | ||
|
||
from caimira.calculator.validators.virus.virus_validator import VirusFormData | ||
from caimira.calculator.store.data_registry import DataRegistry | ||
import caimira.calculator.report.virus_report_data as rg | ||
|
||
|
||
def generate_form_obj(form_data, data_registry): | ||
return VirusFormData.from_dict( | ||
form_data=form_data, | ||
data_registry=data_registry, | ||
) | ||
|
||
|
||
def generate_model(form_obj, data_registry): | ||
sample_size = data_registry.monte_carlo['sample_size'] | ||
return form_obj.build_model(sample_size=sample_size) | ||
|
||
|
||
def generate_report_results(form_obj, model): | ||
return rg.calculate_report_data( | ||
form=form_obj, | ||
model=model, | ||
executor_factory=functools.partial( | ||
concurrent.futures.ThreadPoolExecutor, None, # TODO define report_parallelism | ||
), | ||
) | ||
|
||
|
||
def submit_virus_form(form_data): | ||
data_registry = DataRegistry | ||
|
||
form_obj = generate_form_obj(form_data=form_data, data_registry=data_registry) | ||
model = generate_model(form_obj=form_obj, data_registry=data_registry) | ||
report_data = generate_report_results(form_obj=form_obj, model=model) | ||
|
||
return report_data |
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,60 @@ | ||
from caimira.calculator.validators.co2.co2_validator import CO2FormData | ||
from caimira.calculator.models.models import CO2DataModel | ||
|
||
|
||
def build_initial_plot( | ||
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( | ||
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 = 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.