Skip to content
Merged
1 change: 1 addition & 0 deletions changelog.d/1166.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `POST /reports/without-run`, which finds or creates an economy, budget-window or household report and its simulations by the keys `POST /reports` uses, without creating a run or starting a calculation, for API v1's one-time migration of saved reports. `POST /reports/{report_id}/runs` now gives a budget window created this way its first window run, finding each year's simulations by key.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
SideDefinition,
SimulationDefinition,
WindowRerunYear,
WindowYearDefinition,
insert_household_report_rerun,
insert_report_rerun,
insert_report_rerun_with_cliffs,
Expand Down Expand Up @@ -137,25 +136,34 @@
from policyengine_simulation_persistence.keyed_economy_records import (
FoundEconomyReport,
FoundEconomySimulation,
FoundReportWithoutRun,
FoundSide,
KeyedEconomyReport,
KeyedEconomyReportWithoutRun,
KeyedEconomySimulation,
ProposedSide,
find_or_create_economy_report,
find_or_create_economy_report_without_run,
find_or_create_economy_simulation,
find_or_insert_report_run_cliffs,
)
from policyengine_simulation_persistence.keyed_household_records import (
FoundHouseholdReport,
KeyedHouseholdReport,
KeyedHouseholdReportWithoutRun,
find_or_create_household_report,
find_or_create_household_report_without_run,
)
from policyengine_simulation_persistence.keyed_window_records import (
FoundBudgetWindow,
FoundBudgetWindowWithoutRun,
FoundWindowYear,
KeyedBudgetWindow,
KeyedBudgetWindowWithoutRun,
KeyedWindowYear,
WindowYearDefinition,
find_or_create_budget_window,
find_or_create_budget_window_without_run,
)
from policyengine_simulation_persistence.orm_base import (
InputBase,
Expand Down Expand Up @@ -265,13 +273,15 @@
"EconomySimulationInputs",
"EconomySimulationState",
"FoundBudgetWindow",
"FoundBudgetWindowWithoutRun",
"FoundCliffCalculation",
"FoundCliffs",
"FoundEconomyReport",
"FoundEconomySimulation",
"FoundHouseholdReport",
"FoundReportRerun",
"FoundReportRun",
"FoundReportWithoutRun",
"FoundRow",
"FoundSide",
"FoundSimulationRun",
Expand All @@ -293,9 +303,12 @@
"InputBase",
"IntraDecileImpact",
"KeyedBudgetWindow",
"KeyedBudgetWindowWithoutRun",
"KeyedEconomyReport",
"KeyedEconomyReportWithoutRun",
"KeyedEconomySimulation",
"KeyedHouseholdReport",
"KeyedHouseholdReportWithoutRun",
"KeyedWindowYear",
"LaborSupplyDecileResponse",
"LaborSupplyResponse",
Expand Down Expand Up @@ -372,9 +385,12 @@
"fail_unstarted_simulation_run",
"find_joinable_report_run",
"find_or_create_budget_window",
"find_or_create_budget_window_without_run",
"find_or_create_economy_report",
"find_or_create_economy_report_without_run",
"find_or_create_economy_simulation",
"find_or_create_household_report",
"find_or_create_household_report_without_run",
"find_or_insert_cliff_calculations",
"find_or_insert_report",
"find_or_insert_report_run",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
)
from policyengine_simulation_persistence.keyed_window_records import (
FoundBudgetWindow,
WindowYearDefinition,
WindowYearToInsert,
insert_window_years,
stored_window_years,
Expand All @@ -82,7 +83,6 @@
ReportDefinition,
SideDefinition,
SimulationDefinition,
WindowYearDefinition,
read_report_definition,
read_simulation_definition,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@
)
from policyengine_simulation_persistence.keyed_economy_records import (
find_or_create_economy_report,
find_or_create_economy_report_without_run,
find_or_create_economy_simulation,
)
from policyengine_simulation_persistence.keyed_window_records import (
find_or_create_budget_window,
find_or_create_budget_window_without_run,
)
from policyengine_simulation_persistence.store_transactions import (
EconomyRecordOutcomeUnknownError,
Expand Down Expand Up @@ -90,12 +92,16 @@
from policyengine_simulation_persistence.keyed_economy_records import (
FoundEconomyReport,
FoundEconomySimulation,
FoundReportWithoutRun,
KeyedEconomyReport,
KeyedEconomyReportWithoutRun,
KeyedEconomySimulation,
)
from policyengine_simulation_persistence.keyed_window_records import (
FoundBudgetWindow,
FoundBudgetWindowWithoutRun,
KeyedBudgetWindow,
KeyedBudgetWindowWithoutRun,
)
from policyengine_simulation_persistence.shared_rows import (
FoundReportRun,
Expand Down Expand Up @@ -304,6 +310,31 @@ def find_or_create_budget_window(
lambda session: find_or_create_budget_window(session, window)
)

def find_or_create_report_without_run(
self, report: KeyedEconomyReportWithoutRun
) -> FoundReportWithoutRun:
"""Find the report and its simulations by key, or create them, with no run.

See ``find_or_create_economy_report_without_run``; raise as
``find_or_create_report`` does.
"""
return self._create(
lambda session: find_or_create_economy_report_without_run(session, report)
)

def find_or_create_budget_window_without_run(
self, window: KeyedBudgetWindowWithoutRun
) -> FoundBudgetWindowWithoutRun:
"""Find a window and each year's simulations by key, or create them.

It creates no window run. See
``find_or_create_budget_window_without_run``; raise as
``find_or_create_report`` does.
"""
return self._create(
lambda session: find_or_create_budget_window_without_run(session, window)
)

def find_or_create_simulation(
self, simulation: KeyedEconomySimulation
) -> FoundEconomySimulation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from policyengine_simulation_persistence.keyed_household_records import (
find_or_create_household_report,
find_or_create_household_report_without_run,
)
from policyengine_simulation_persistence.policy_reform import read_simulation_reform
from policyengine_simulation_persistence.store_transactions import (
Expand All @@ -61,9 +62,13 @@
from policyengine_simulation_persistence.household_job_records import (
StoredHousehold,
)
from policyengine_simulation_persistence.keyed_economy_records import (
FoundReportWithoutRun,
)
from policyengine_simulation_persistence.keyed_household_records import (
FoundHouseholdReport,
KeyedHouseholdReport,
KeyedHouseholdReportWithoutRun,
)
from policyengine_simulation_persistence.policy_reform import SimulationReform
from policyengine_simulation_persistence.shared_rows import FoundReportRun
Expand Down Expand Up @@ -193,6 +198,18 @@ def find_or_create_report(
lambda session: find_or_create_household_report(session, report)
)

def find_or_create_report_without_run(
self, report: KeyedHouseholdReportWithoutRun
) -> FoundReportWithoutRun:
"""Find the report and its simulations by key, or create them, with no run.

See ``find_or_create_household_report_without_run``; raise as
``find_or_create_report`` does.
"""
return self._create(
lambda session: find_or_create_household_report_without_run(session, report)
)

def create_report_rerun(self, rerun: NewHouseholdReportRerun) -> FoundReportRun:
"""Join a stored report's run on the re-run's versions, or create it.

Expand Down
Loading