Skip to content

Conversation

SakshiKekre
Copy link
Collaborator

@SakshiKekre SakshiKekre commented Oct 8, 2025

Fixes PolicyEngine/policyengine-app-v2#226

This PR

  • Adds output_json column to simulations table.
  • PATCH endpoint to store household calculation outputs for each simulation.
  • Works in conjunction with this PR in -app-v2.

Note: The production database schema has been modified using

mysql>   ALTER TABLE simulations
                  ADD COLUMN output_json JSON;

Copy link

codecov bot commented Oct 8, 2025

Codecov Report

❌ Patch coverage is 7.69231% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.19%. Comparing base (8e5ec93) to head (0422cdb).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
policyengine_api/routes/simulation_routes.py 10.00% 27 Missing ⚠️
policyengine_api/services/simulation_service.py 4.54% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2827      +/-   ##
==========================================
- Coverage   77.03%   75.19%   -1.85%     
==========================================
  Files          53       53              
  Lines        1903     1955      +52     
  Branches      243      252       +9     
==========================================
+ Hits         1466     1470       +4     
- Misses        387      435      +48     
  Partials       50       50              

☔ 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.

@SakshiKekre SakshiKekre force-pushed the fix/issue-226-household-simulation-outputs branch from 079d356 to 0422cdb Compare October 9, 2025 04:23
@SakshiKekre SakshiKekre requested a review from anth-volk October 9, 2025 05:16
@SakshiKekre SakshiKekre marked this pull request as ready for review October 9, 2025 05:16
Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

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

Thanks for this Sakshi! A couple nits; technically, if you don't want to add them and just want to merge, also feel free.

policy_id INT NOT NULL
policy_id INT NOT NULL,
-- output_json stores calculation results for household simulations only
-- For geography simulations, outputs are stored in report_outputs table
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can you say that it's for single-sim households (comparisons are still stored in report_outputs) and that for geo sims, it's because we don't have the API capability to calculate them separately?

policy_id INT NOT NULL,
-- output_json stores calculation results for household simulations only
-- For geography simulations, outputs are stored in report_outputs table
output_json JSON DEFAULT NULL
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Same as for initialise.sql

)

if not success:
raise BadRequest("No fields to update")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit, non-blocking: I think the message is wrong here maybe?

"""
print(f"Updating simulation {simulation_id} with output")
# Automatically update api_version on every update to latest
api_version: str = COUNTRY_PACKAGE_VERSIONS.get(country_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

accolade: Good catch, we do need this

@anth-volk anth-volk merged commit a24b1aa into master Oct 17, 2025
5 of 7 checks passed
@anth-volk anth-volk deleted the fix/issue-226-household-simulation-outputs branch October 17, 2025 23:49
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.

Fix household calculations to properly map a simulation run to a simulation record

2 participants