Move CSV-related code to src/input/ (batch 1)#290
Conversation
5c24c33 to
04d4f43
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #290 +/- ##
==========================================
- Coverage 95.17% 95.15% -0.03%
==========================================
Files 13 19 +6
Lines 2529 2619 +90
Branches 2529 2619 +90
==========================================
+ Hits 2407 2492 +85
- Misses 47 50 +3
- Partials 75 77 +2 ☔ View full report in Codecov by Sentry. |
tsmbland
left a comment
There was a problem hiding this comment.
Looks good! Definitely an improvement. I might have some more comments when everything is done about privacy of functions/structs/objects, but for now everything looks fine.
src/input/agent.rs
Outdated
| const AGENT_REGIONS_FILE_NAME: &str = "agent_regions.csv"; | ||
|
|
||
| #[derive(Debug, Deserialize, PartialEq)] | ||
| struct AgentRegion { |
There was a problem hiding this comment.
This struct should be in the main agent module, no? Since presumably other parts of the code will want to reference this outside the input module
There was a problem hiding this comment.
Actually, just realised that this data is stored as RegionSelection, so I take that back
Still, I think this AgentRegion stuff belongs in its own file in the input.agent module. Might have saved me some confusion
There was a problem hiding this comment.
Sure. I've made a separate submodule for it and a little wrapper function around the generic read_regions_for_entity we use.
| agent_id: String, | ||
| /// The region to which an agent belongs. | ||
| region_id: String, | ||
| impl<'de> Deserialize<'de> for SearchSpace { |
There was a problem hiding this comment.
I kind of think all this deserializing (here and elsewhere) should be part of the input module, and the final struct just stores the already-deserialized object. Does that make sense?
There was a problem hiding this comment.
I did consider this, and Rust does let you separate methods from data structures in this way, but I think to make this work, we'd need a glob import in src/agent.rs (i.e. use crate::input::agent::*;) to get the Deserialize trait for SearchSpace, which we need (struct Agent can't be made Deserialize otherwise). On balance, I'm not sure it's worth it, so I think I'll leave it as is for now.
|
Thanks for the review @tsmbland! And merry Christmas 🎄 |
Description
This PR is the first batch of changes for #281. I've split up the following files, putting their contents into submodules under
inputinstead:region.rsagent.rsasset.rscommodity.rsIn most cases, it made sense to split things into further submodules (e.g. there is a separate
input::commodity::costmodule for dealing withcommodity_costs.csv). Forassets.rs, I moved the CSV-related code to a submodule underinput::agentand incorporated the remainder intoagent.rs.region.rsnow only has one silly little struct in it, so it probably doesn't deserve its own.rsfile, but I thought I'd leave it there for now.No functional changes intended.
Closes #287. Closes #282. Closes #283. Closes #284.
Type of change
Key checklist
$ cargo test$ cargo docFurther checks