From c72ba2c7b8529b4d759af2aa4e2be986539c2f9e Mon Sep 17 00:00:00 2001 From: hannesdiedrich Date: Mon, 4 Mar 2024 09:14:37 +0100 Subject: [PATCH 1/3] FE-478: Increase number of digits for rounding the results for the UI --- gsy_framework/utils.py | 2 +- tests/test_bills.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gsy_framework/utils.py b/gsy_framework/utils.py index 2413465b..8cdf13ee 100644 --- a/gsy_framework/utils.py +++ b/gsy_framework/utils.py @@ -344,7 +344,7 @@ def get_area_uuid_name_mapping(area_dict, results): def round_floats_for_ui(number): """Round the given number using the scale required by the UI.""" - return round(number, 3) + return round(number, 5) def round_prices_to_cents(number): diff --git a/tests/test_bills.py b/tests/test_bills.py index a7c9f9ce..a23f349e 100644 --- a/tests/test_bills.py +++ b/tests/test_bills.py @@ -152,7 +152,7 @@ def test_round_results_for_ui(self): uuid_results["2345"]["pv"]["sold"] = 0.987 uuid_results["6789"]["earned"] = 12 results = self.bills._round_results_for_ui(uuid_results) - assert results["1234"]["house1"]["bought"] == 0.123 - assert results["1234"]["house2"]["sold"] == 0.988 + assert results["1234"]["house1"]["bought"] == 0.12346 + assert results["1234"]["house2"]["sold"] == 0.98765 assert results["2345"]["pv"]["sold"] == 0.987 assert results["6789"]["earned"] == 12 From 1b3b0c34425a5f5968ced3a09c27f9407a52d75f Mon Sep 17 00:00:00 2001 From: hannesdiedrich Date: Mon, 4 Mar 2024 09:15:55 +0100 Subject: [PATCH 2/3] FE-478: fix pylint errors --- tests/test_bills.py | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/tests/test_bills.py b/tests/test_bills.py index a23f349e..308453de 100644 --- a/tests/test_bills.py +++ b/tests/test_bills.py @@ -7,6 +7,7 @@ class TestBills(unittest.TestCase): + # pylint: disable=protected-access def setUp(self): self.bills = MarketEnergyBills() @@ -17,11 +18,11 @@ def tearDown(self): @property def _empty_bills(self): return { - 'bought': 0.0, 'sold': 0.0, 'spent': 0.0, 'earned': 0.0, 'total_energy': 0.0, - 'total_cost': 0.0, 'market_fee': 0.0, 'type': 'Area' + "bought": 0.0, "sold": 0.0, "spent": 0.0, "earned": 0.0, "total_energy": 0.0, + "total_cost": 0.0, "market_fee": 0.0, "type": "Area" } - def create_empty_results_with_children(self, uuid_or_name_list): + def _create_empty_results_with_children(self, uuid_or_name_list): result_dict = {k: self._empty_bills for k in ACCUMULATED_KEYS_LIST} result_dict.update({u: self._empty_bills for u in uuid_or_name_list}) return result_dict @@ -41,12 +42,12 @@ def test_swap_children_uuids_to_names(self): {"name": "house2", "uuid": house2_uuid, "parent_uuid": grid_uuid, "children": [ {"name": "pv2", "uuid": pv2_uuid, "parent_uuid": house2_uuid, "children": []}, ]} - ] - } + ] + } uuid_results = { - grid_uuid: self.create_empty_results_with_children([house1_uuid, house2_uuid]), - house1_uuid: self.create_empty_results_with_children([pv_uuid, load_uuid]), - house2_uuid: self.create_empty_results_with_children([pv2_uuid]), + grid_uuid: self._create_empty_results_with_children([house1_uuid, house2_uuid]), + house1_uuid: self._create_empty_results_with_children([pv_uuid, load_uuid]), + house2_uuid: self._create_empty_results_with_children([pv2_uuid]), pv_uuid: self._empty_bills, load_uuid: self._empty_bills, pv2_uuid: self._empty_bills, @@ -66,9 +67,9 @@ def test_restore_area_results_state(self): load_uuid = str(uuid4()) pv2_uuid = str(uuid4()) name_results = { - grid_uuid: self.create_empty_results_with_children(["house1", "house2"]), - house1_uuid: self.create_empty_results_with_children(["pv", "load"]), - house2_uuid: self.create_empty_results_with_children(["pv2"]), + grid_uuid: self._create_empty_results_with_children(["house1", "house2"]), + house1_uuid: self._create_empty_results_with_children(["pv", "load"]), + house2_uuid: self._create_empty_results_with_children(["pv2"]), pv_uuid: self._empty_bills, load_uuid: self._empty_bills, pv2_uuid: self._empty_bills, @@ -81,14 +82,15 @@ def test_restore_area_results_state(self): {"name": "house2", "uuid": house2_uuid, "parent_uuid": grid_uuid, "children": [ {"name": "pv2", "uuid": pv2_uuid, "parent_uuid": house2_uuid, "children": []}, ]} - ] - } + ] + } self.bills.restore_area_results_state(area_dict, name_results[grid_uuid]) assert_dicts_identical(self.bills.bills_redis_results[grid_uuid], name_results[grid_uuid]) assert_dicts_identical(self.bills.bills_results["grid"], name_results[grid_uuid]) assert_dicts_identical(self.bills.current_raw_bills[grid_uuid], - self.create_empty_results_with_children([house1_uuid, house2_uuid])) + self._create_empty_results_with_children( + [house1_uuid, house2_uuid])) self.bills.restore_area_results_state(area_dict["children"][0], name_results[house1_uuid]) @@ -96,7 +98,7 @@ def test_restore_area_results_state(self): name_results[house1_uuid]) assert_dicts_identical(self.bills.bills_results["house1"], name_results[house1_uuid]) assert_dicts_identical(self.bills.current_raw_bills[house1_uuid], - self.create_empty_results_with_children([pv_uuid, load_uuid])) + self._create_empty_results_with_children([pv_uuid, load_uuid])) self.bills.restore_area_results_state(area_dict["children"][1]["children"][0], name_results[pv2_uuid]) @@ -119,12 +121,12 @@ def test_bills_local_format(self): {"name": "house2", "uuid": house2_uuid, "parent_uuid": grid_uuid, "children": [ {"name": "pv2", "uuid": pv2_uuid, "parent_uuid": house2_uuid, "children": []}, ]} - ] - } + ] + } uuid_results = { - grid_uuid: self.create_empty_results_with_children(["house1", "house2"]), - house1_uuid: self.create_empty_results_with_children(["pv", "load"]), - house2_uuid: self.create_empty_results_with_children(["pv2"]), + grid_uuid: self._create_empty_results_with_children(["house1", "house2"]), + house1_uuid: self._create_empty_results_with_children(["pv", "load"]), + house2_uuid: self._create_empty_results_with_children(["pv2"]), pv_uuid: self._empty_bills, load_uuid: self._empty_bills, pv2_uuid: self._empty_bills, @@ -139,9 +141,9 @@ def test_bills_local_format(self): def test_round_results_for_ui(self): uuid_results = { - "1234": self.create_empty_results_with_children(["house1", "house2"]), - "2345": self.create_empty_results_with_children(["pv", "load"]), - "3456": self.create_empty_results_with_children(["pv2"]), + "1234": self._create_empty_results_with_children(["house1", "house2"]), + "2345": self._create_empty_results_with_children(["pv", "load"]), + "3456": self._create_empty_results_with_children(["pv2"]), "4567": self._empty_bills, "5678": self._empty_bills, "6789": self._empty_bills, From 66b686a6f05b0cc8cd251124a1946a80086eaf61 Mon Sep 17 00:00:00 2001 From: hannesdiedrich Date: Mon, 4 Mar 2024 09:23:15 +0100 Subject: [PATCH 3/3] FE-478: Fix tests --- tests/test_sim_results/test_cumulative_bills.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_sim_results/test_cumulative_bills.py b/tests/test_sim_results/test_cumulative_bills.py index 64880a77..a77686c9 100644 --- a/tests/test_sim_results/test_cumulative_bills.py +++ b/tests/test_sim_results/test_cumulative_bills.py @@ -59,9 +59,9 @@ def test_update_cumulative_bills_works(self): # Equals to penalty_energy * PV_PENALTY_RATE / 100.0 assert self._bills.cumulative_bills[seller_uuid]["penalties"] == 0.12 * 0.5 # Equals to the trade price since the PV is the seller - assert self._bills.cumulative_bills[seller_uuid]["earned"] == 0.002 + assert self._bills.cumulative_bills[seller_uuid]["earned"] == 0.0019 # Equals to penalties - earned - assert isclose(self._bills.cumulative_bills[seller_uuid]["total"], 0.06-0.002) + assert isclose(self._bills.cumulative_bills[seller_uuid]["total"], 0.06 - 0.0019) assert self._bills.cumulative_bills[buyer_uuid]["name"] == buyer_name # Equal to the energy_requirement_kWh (consumption not bought) @@ -69,6 +69,6 @@ def test_update_cumulative_bills_works(self): # Equals to penalty_energy * LOAD_PENALTY_RATE / 100.0 assert self._bills.cumulative_bills[buyer_uuid]["penalties"] == 0.05 * 0.5 # Equals to the trade price since the Load is the buyer - assert self._bills.cumulative_bills[buyer_uuid]["spent_total"] == 0.002 + assert self._bills.cumulative_bills[buyer_uuid]["spent_total"] == 0.0021 # Equals to penalties + spent - assert isclose(self._bills.cumulative_bills[buyer_uuid]["total"], 0.027) + assert isclose(self._bills.cumulative_bills[buyer_uuid]["total"], 0.0271)