From 84632682a84da56063621cb5491d6cc3ba8af3f9 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Wed, 29 Jan 2025 12:24:48 +1100 Subject: [PATCH] Add general `Simulation.calculate` method Fixes #78 --- changelog_entry.yaml | 4 ++++ policyengine/simulation.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29b..0c434d91 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: minor + changes: + added: + - General `calculate` method. diff --git a/policyengine/simulation.py b/policyengine/simulation.py index 65f8bad9..09036e7b 100644 --- a/policyengine/simulation.py +++ b/policyengine/simulation.py @@ -307,6 +307,26 @@ def _data_handle_cps_special_case(self): ) self.data = Dataset.from_file(self.data, "2023") + def calculate( + self, + ) -> ( + SingleEconomy + | EconomyComparison + | SingleHousehold + | HouseholdComparison + ): + """Calculate the default output statistics for the simulation type.""" + if self.options.scope == "macro": + if self.is_comparison: + return self.calculate_economy_comparison() + else: + return self.calculate_single_economy() + elif self.options.scope == "household": + if self.is_comparison: + return self.calculate_household_comparison() + else: + return self.calculate_single_household() + def calculate_economy_comparison(self) -> EconomyComparison: """Calculate comparison statistics between two economic scenarios.""" return calculate_economy_comparison(self)