Skip to content

Interpolate between two scenarios #1684

@louispt1

Description

@louispt1

@aaccensi I had a go at refining the changes required for interpolation:

Description

Refactor the interpolation setup to support interpolating between two scenarios (a start scenario and an end scenario) rather than from default values to a scenario. This enables creating intermediate-year scenarios between two user-defined scenarios.


Current Behavior

  • Interpolates from default start values → original scenario values
  • Uses input.start_value_for(@scenario) as the baseline

Proposed Improvement

  • Interpolates from start_scenario values → end_scenario values
  • Validates both scenarios have the same area_code

Implementation Ideas

1. Modify Scenario::YearInterpolator Class:

a. Update the initializer and call method:
- Add optional start_scenario parameter
- Store as instance variable

  def self.call(scenario, year, current_user = nil, start_scenario = nil)
    new(scenario, year, current_user, start_scenario).run
  end

  def initialize(scenario, year, current_user, start_scenario = nil)
    @scenario = scenario
    @year = year
    @current_user = current_user
    @start_scenario = start_scenario
  end

b. Update validation to validate start scenario - add to validate!, add a validate_start_scenario!
c. Update interpolation logic:

  • Modify interpolate_input_collection to calculate years correctly
  • Modify interpolate_input to use start_scenario values when available ( I think we can fall back to dataset values for now if the start scenario is not given)

2. Modify Api::V3::ScenariosController#interpolate

 a. Accept optional start_scenario_id parameter
 b. Update permitted parameters

3. Tests and documentation

  • Write tests for changes
  • Document changes to the interpolation endpoint

Further enhancements

Outlined above is a MVP for these changes - if we want to go further, we could introduce a batch interpolation endpoint which accepts multiple target years in a single request to make multiple interpolated scenarios at once and enforces a 6 scenario limit.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions