From e5368b97026f698cfcbcc08f22e826c2b61e6820 Mon Sep 17 00:00:00 2001 From: Charlotte Avery Date: Mon, 24 Jun 2024 14:55:47 +0100 Subject: [PATCH] Normalise the SBR score --- .../calculate_sbr_score.py | 8 ++++- tests/test_sbr_calculator.py | 31 ++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/smart_building_rating_calculator/calculate_sbr_score.py b/src/smart_building_rating_calculator/calculate_sbr_score.py index e054546..2946a7d 100644 --- a/src/smart_building_rating_calculator/calculate_sbr_score.py +++ b/src/smart_building_rating_calculator/calculate_sbr_score.py @@ -106,4 +106,10 @@ def sbr_score( integrated_control_sys, ) sbr_val, sbr, flex_archetype = get_sbr_scores(user_inputs) - return sbr_val, sbr, flex_archetype + + # Normalise score between 0 & 100 + min_sbr = -3.0 + max_sbr = 27.75 + sbr_normalised = 100 * (sbr_val - min_sbr) / (max_sbr - min_sbr) + + return sbr_normalised, sbr, flex_archetype diff --git a/tests/test_sbr_calculator.py b/tests/test_sbr_calculator.py index 20b3d50..4644c1b 100644 --- a/tests/test_sbr_calculator.py +++ b/tests/test_sbr_calculator.py @@ -1,4 +1,7 @@ -from src.smart_building_rating_calculator.calculate_sbr_score import get_sbr_scores +from src.smart_building_rating_calculator.calculate_sbr_score import ( + get_sbr_scores, + sbr_score, +) from src.smart_building_rating_calculator.flex_archetype import FlexArchetype from src.smart_building_rating_calculator.inputs import ( BatterySize, @@ -16,6 +19,8 @@ class TestScoreCalculators: + """Test the scoring calculations using the results in the SBR excel sheet created by ESC""" + def test_smartest_home(self): user_inputs = UserInputs( smart_meter=True, @@ -247,8 +252,9 @@ def no_smart_meter(self): assert flex_archetype == FlexArchetype.LOW_TECH_FLEXER -# Test all combinations of get_sbr_scores inputs def test_all_combinations(): + """Test all combinations of get_sbr_scores inputs""" + scores = [] for smart_meter in [True, False]: for smart_ev_charger in [True, False]: for charger_power in EVChargerPower: @@ -315,8 +321,21 @@ def test_all_combinations(): sbr_val, sbr, flex_archetype, - ) = get_sbr_scores( - user_inputs + ) = sbr_score( + smart_meter, + smart_ev_charger, + charger_power, + smart_v2g_enabled, + home_battery, + battery_size, + solar_pv, + pv_inverter_size, + electric_heating, + heating_source, + hot_water_source, + secondary_heating, + secondary_hot_water, + integrated_control_sys, ) assert isinstance( @@ -328,3 +347,7 @@ def test_all_combinations(): flex_archetype, str, ) + scores.append(sbr_val) + + assert min(scores) == 0.0 + assert max(scores) == 100.0