-
Notifications
You must be signed in to change notification settings - Fork 1
Store agent objectives as a map #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors agent objectives by changing their representation from a vector to a map keyed by milestone year, simplifying objective lookups and validation logic. Key changes include updating the CSV parsing logic to handle string year representations, refactoring objective validations to populate an AgentObjectiveMap, and adapting related tests and structures accordingly.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/input/agent/objective.rs | Updated CSV parsing and validation for agent objectives; replaced vector with map. |
src/input/agent/commodity_portion.rs | Adjusted tests to construct AgentObjectiveMap instead of a vector. |
src/input/agent.rs | Updated agent creation and tests to reflect the new objectives representation. |
src/agent.rs | Revised documentation and type definitions to use AgentObjectiveMap. |
Comments suppressed due to low confidence (1)
src/input/agent/objective.rs:83
- The error message does not properly interpolate the variables 'agent_id' and 'year'. Consider using '{}' placeholders and providing the variables as arguments to ensure the message displays the correct values.
ensure!(agent_objectives.contains_key(year), "Agent {agent_id} is missing objectives for year {year}");
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #543 +/- ##
==========================================
- Coverage 92.84% 92.49% -0.35%
==========================================
Files 37 37
Lines 4274 4173 -101
Branches 4274 4173 -101
==========================================
- Hits 3968 3860 -108
- Misses 149 153 +4
- Partials 157 160 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I'm fine with this. Keep the code simple for now. I'd say delete |
We just need to make sure we keep in the back of our minds that multiple objectives will be added at some point in the future, and do things in a way that makes that as easy as possible when the time comes |
I meant to mark this as draft before... anyway, this is ready for review now whenever you are. |
Description
As we're only currently supporting the "single" objective type (and likely won't support anything else for the forseeable future) I was able to write this in a more simplified way than planned. I've written a check to disable the other objective types for now.
I'm opening this as draft because this might not be uncontroversial 😛. I haven't added commodity IDs as keys to the map yet (#542) because I wanted to run this by you before building on top of it, plus I think it can wait till later anyway.
Instead of a
HashMap<u32, Vec<AgentObjective>>
, I've gone withHashMap<u32, ObjectiveType>
, as a) we will only have one objective per year and b) that objective won't have any additional parameters. Writing things this way made the validation checks simpler and it should be slightly simpler to use too.Now the
check_agent_objectives
function is unused outside of the unit tests. I'd be inclined to delete it with the tests for now (we can leave a note somewhere saying we've done this) -- but it's also probably pretty harmless so we could just leave it.If you're happy with all this, I was planning on refactoring the tests a bit to use
rstest
fixtures, like elsewhere.Closes #506.
Type of change
Key checklist
$ cargo test
$ cargo doc
Further checks