Skip to content

Tidy prices module#1212

Open
tsmbland wants to merge 9 commits intomainfrom
prices_tidy
Open

Tidy prices module#1212
tsmbland wants to merge 9 commits intomainfrom
prices_tidy

Conversation

@tsmbland
Copy link
Collaborator

@tsmbland tsmbland commented Mar 19, 2026

Description

I think this is a bit tidier. Less repetitive at least. The main change is to break the core logic for cost-based price calculation into three re-usable function:

  • iter_existing_asset_max_prices: calculates prices from existing assets based on marginal/full cost, taking the max across assets
  • iter_candidate_asset_min_prices: calculates prices from candidate assets based on marginal/full cost, taking the min across assets, and skipping any prices already covered by existing assets
  • iter_existing_asset_average_prices: calculates prices from existing assets based on marginal/full cost, taking the average across assets

I've gone for the approach suggested by @alexdewar in #1196 of passing an optional annual activities map to signal the type of cost calculation, but also passing PricingStrategy as an argument just to be extra explicit.

There's still some similarity between these three functions, but I think they are are sufficiently different that any attempts to combine them further would probably be counterproductive.

Also:

  • removing some outdated references to shadow prices in the marginal/full cost calculations.
  • I've gone for something similar to what @alexdewar suggested in Add price strategies using load-weighted averaging #1205 about adding a type parameter to WeightedAverageAccumulator. I don't know if this is necessarily improvement so let me know what you think.
  • the file is getting quite big so I was thinking of maybe breaking it up to have a strategies submodule to store the core price calculation logic, but I haven't done this here

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc
  • Update release notes for the latest release if this PR adds a new feature or fixes a bug
    present in the previous release

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@tsmbland tsmbland changed the title Prices tidy Tidy prices module Mar 19, 2026
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 93.26923% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.74%. Comparing base (d904081) to head (95f2083).

Files with missing lines Patch % Lines
src/simulation/prices.rs 93.26% 11 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1212      +/-   ##
==========================================
+ Coverage   89.35%   89.74%   +0.39%     
==========================================
  Files          57       57              
  Lines        8263     8189      -74     
  Branches     8263     8189      -74     
==========================================
- Hits         7383     7349      -34     
+ Misses        582      542      -40     
  Partials      298      298              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tsmbland tsmbland requested a review from Copilot March 19, 2026 16:10
@tsmbland tsmbland marked this pull request as ready for review March 19, 2026 16:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors src/simulation/prices.rs to reduce duplication by extracting shared logic for cost-based price calculation into reusable helper iterators, and updates documentation/tests to remove outdated “shadow price” wording for marginal/full cost pricing.

Changes:

  • Extracts reusable helpers for computing selection-level prices from existing assets (max/average) and candidate assets (min).
  • Reworks marginal/full cost and average-price paths to use these helpers, then expands selection-level prices to time-slice prices.
  • Updates docstrings/tests terminology from “shadow price” to “price” where appropriate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Base automatically changed from average_prices to main March 20, 2026 11:21
Copilot AI review requested due to automatic review settings March 20, 2026 11:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors src/simulation/prices.rs to reduce repetition in cost-based pricing by extracting reusable iterator helpers for computing selection-level prices (max/avg over existing assets, min over candidates), while also cleaning up outdated “shadow price” references in docs/tests.

Changes:

  • Extracts shared pricing logic into iter_existing_asset_max_prices, iter_candidate_asset_min_prices, and iter_existing_asset_average_prices.
  • Rewires marginal/full cost pricing functions to use the new helpers and then expand selection-level prices back to per-timeslice entries.
  • Updates documentation/tests terminology from “shadow price” to “price” where the cost-based strategies use existing prices as inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tsmbland tsmbland requested review from Aurashk and alexdewar March 20, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants