-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Description
Problem
The refactored policyengine.py replaced the old region: str parameter with filter_field/filter_value on the Simulation model but only implemented row filtering. The weight replacement logic used for UK parliamentary constituencies and local authorities was lost. UK constituencies are defined with filter_field="household_weight" which doesn't work with the row-filter implementation.
Proposed solution
Introduce a RegionScopingStrategy abstraction with two concrete implementations:
RowFilterStrategy: Filters dataset rows by matching a household-level variable (used for UK countries, US places)WeightReplacementStrategy: Downloads pre-computed weight matrices from GCS and replaceshousehold_weightin the dataset (used for UK constituencies and local authorities)
Changes
- New
scoping_strategy.pymodule withRegionScopingStrategybase class,RowFilterStrategy,WeightReplacementStrategy, andScopingStrategydiscriminated union type - Updated
RegionandSimulationmodels withscoping_strategyfield - Updated UK and US model
run()methods to use strategy pattern - Updated UK region registry (constituencies + local authorities use
WeightReplacementStrategy, countries useRowFilterStrategy) - Updated US region registry (places use
RowFilterStrategy) - Comprehensive tests for strategy serialization, application, and model integration
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels