-
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 'bugfix/API_refinement' into 'master'
REST API refinement See merge request caimira/caimira!508
- Loading branch information
Showing
11 changed files
with
50 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 4.17.2 (September 19, 2024) | ||
|
||
## Features Added | ||
- Initial commit with changelog file. | ||
- New project layout architecture. | ||
- Added CAiMIRA REST API features. | ||
|
||
## Bug Fixes | ||
- Virus and CO2 routes and controllers. |
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
23 changes: 12 additions & 11 deletions
23
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
import typing | ||
|
||
from caimira.calculator.validators.co2.co2_validator import CO2FormData | ||
from caimira.calculator.store.data_registry import DataRegistry | ||
from caimira.calculator.models.models import CO2DataModel | ||
|
||
|
||
def generate_form_obj(form_data, data_registry): | ||
def generate_form_obj(form_data: typing.Dict, data_registry: DataRegistry) -> CO2FormData: | ||
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_model(form_obj: CO2FormData) -> CO2DataModel: | ||
return form_obj.build_model() | ||
|
||
|
||
def generate_report(model): | ||
def generate_report(model: CO2DataModel) -> typing.Dict: | ||
return dict(model.CO2_fit_params()) | ||
|
||
|
||
def submit_CO2_form(form_data): | ||
data_registry = DataRegistry() | ||
def submit_CO2_form(form_data: typing.Dict) -> typing.Dict: | ||
data_registry: DataRegistry = 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) | ||
form_obj: CO2FormData = generate_form_obj(form_data=form_data, data_registry=data_registry) | ||
model: CO2DataModel = generate_model(form_obj=form_obj) | ||
report_data: typing.Dict = generate_report(model=model) | ||
|
||
return report_data |
26 changes: 13 additions & 13 deletions
26
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 |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import concurrent.futures | ||
import functools | ||
import typing | ||
|
||
from caimira.calculator.validators.virus.virus_validator import VirusFormData | ||
from caimira.calculator.store.data_registry import DataRegistry | ||
from caimira.calculator.models.models import ExposureModel | ||
import caimira.calculator.report.virus_report_data as rg | ||
|
||
|
||
def generate_form_obj(form_data, data_registry): | ||
def generate_form_obj(form_data: typing.Dict, data_registry: DataRegistry) -> VirusFormData: | ||
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): | ||
def generate_report(form_obj: VirusFormData, report_generation_parallelism: typing.Optional[int]) -> typing.Dict: | ||
return rg.calculate_report_data( | ||
form=form_obj, | ||
executor_factory=functools.partial( | ||
concurrent.futures.ThreadPoolExecutor, None, # TODO define report_parallelism | ||
concurrent.futures.ThreadPoolExecutor, | ||
report_generation_parallelism, | ||
), | ||
) | ||
|
||
|
||
def submit_virus_form(form_data): | ||
data_registry = DataRegistry | ||
def submit_virus_form(form_data: typing.Dict, report_generation_parallelism: typing.Optional[int]) -> typing.Dict: | ||
data_registry: DataRegistry = DataRegistry() | ||
|
||
form_obj: VirusFormData = generate_form_obj(form_data=form_data, data_registry=data_registry) | ||
report_data: typing.Dict = generate_report(form_obj=form_obj, report_generation_parallelism=report_generation_parallelism) | ||
|
||
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) | ||
# Handle model representation | ||
if report_data['model']: report_data['model'] = repr(report_data['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
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
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