diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 0f68794b..15646c00 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -30,7 +30,7 @@ from backend.app.db.connection import db_engine from model_data.optimiser.GainOptimiser import GainOptimiser from model_data.optimiser.CostOptimiser import CostOptimiser -from model_data.utils import epc_to_sap_lower_bound +from backend.app.utils import epc_to_sap_lower_bound from model_data.optimiser.optimiser_functions import prepare_input_measures # TODO: This is placeholder until data is stored in DB diff --git a/backend/app/utils.py b/backend/app/utils.py index a3eac3f2..bc052e74 100644 --- a/backend/app/utils.py +++ b/backend/app/utils.py @@ -65,3 +65,55 @@ def generate_api_key(): # Generate a 40 character long api key api_key = ''.join(secrets.choice(characters) for _ in range(40)) return api_key + + +def sap_to_epc(sap_points: int): + """ + Simple utility function to convert SAP points to EPC rating. + :param sapPoints: numerical value of SAP points, typically between 0 and 100 + :return: + """ + + if sap_points <= 0 or sap_points > 100: + raise ValueError("SAP points should be between 1 and 100.") + + if sap_points > 91: + return "A" + elif sap_points > 80: + return "B" + elif sap_points > 69: + return "C" + elif sap_points > 55: + return "D" + elif sap_points > 39: + return "E" + elif sap_points > 21: + return "F" + else: + return "G" + + +def epc_to_sap_lower_bound(epc: str): + """ + Given an EPC rating, returns the lower bound SAP score required + to hit that EPC rating + :param epc: EPC rating, between A and G + :return: + """ + + if epc == "A": + return 92 + elif epc == "B": + return 81 + elif epc == "C": + return 70 + elif epc == "D": + return 56 + elif epc == "E": + return 40 + elif epc == "F": + return 22 + elif epc == "G": + return 1 + else: + raise ValueError("EPC rating should be between A and G") diff --git a/model_data/utils.py b/model_data/utils.py index a59699da..744914a4 100644 --- a/model_data/utils.py +++ b/model_data/utils.py @@ -24,57 +24,3 @@ def correct_spelling(text): corrected_text = ' '.join(corrected_words) return corrected_text - - -def sap_to_epc(sap_points: int): - """ - Simple utility function to convert SAP points to EPC rating. - :param sapPoints: numerical value of SAP points, typically between 0 and 100 - :return: - """ - - if sap_points <= 0 or sap_points > 100: - raise ValueError("SAP points should be between 1 and 100.") - - if sap_points > 91: - return "A" - elif sap_points > 80: - return "B" - elif sap_points > 69: - return "C" - elif sap_points > 55: - return "D" - elif sap_points > 39: - return "E" - elif sap_points > 21: - return "F" - else: - return "G" - - -def epc_to_sap_lower_bound(epc: str): - """ - Given an EPC rating, returns the lower bound SAP score required - to hit that EPC rating - :param epc: EPC rating, between A and G - :return: - """ - - if epc == "A": - return 92 - elif epc == "B": - return 81 - elif epc == "C": - return 70 - elif epc == "D": - return 56 - elif epc == "E": - return 40 - elif epc == "F": - return 22 - elif epc == "G": - return 1 - else: - raise ValueError("EPC rating should be between A and G") - -