-
Notifications
You must be signed in to change notification settings - Fork 3
Make Process commission year a RangeInclusive
#1010
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
Changes from all commits
014bdad
53bb216
695912f
7c60f55
9929945
0ca440b
55fe6aa
fa927e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ enum LimitType { | |
| /// * `model_dir` - Folder containing model configuration files | ||
| /// * `processes` - Map of processes | ||
| /// * `time_slice_info` - Information about seasons and times of day | ||
| /// * `base_year` - First milestone year of simulation | ||
| /// * `milestone_years` - Milestone years of simulation | ||
| /// | ||
| /// # Returns | ||
| /// | ||
|
|
@@ -85,15 +85,15 @@ pub fn read_process_availabilities( | |
| model_dir: &Path, | ||
| processes: &ProcessMap, | ||
| time_slice_info: &TimeSliceInfo, | ||
| base_year: u32, | ||
| milestone_years: &[u32], | ||
| ) -> Result<HashMap<ProcessID, ProcessActivityLimitsMap>> { | ||
| let file_path = model_dir.join(PROCESS_AVAILABILITIES_FILE_NAME); | ||
| let process_availabilities_csv = read_csv(&file_path)?; | ||
| read_process_availabilities_from_iter( | ||
| process_availabilities_csv, | ||
| processes, | ||
| time_slice_info, | ||
| base_year, | ||
| milestone_years, | ||
| ) | ||
| .with_context(|| input_err_msg(&file_path)) | ||
| } | ||
|
|
@@ -105,7 +105,7 @@ pub fn read_process_availabilities( | |
| /// * `iter` - Iterator of raw process availability records | ||
| /// * `processes` - Map of processes | ||
| /// * `time_slice_info` - Information about seasons and times of day | ||
| /// * `base_year` - First milestone year of simulation | ||
| /// * `milestone_years` - Milestone years of simulation | ||
| /// | ||
| /// # Returns | ||
| /// | ||
|
|
@@ -115,7 +115,7 @@ fn read_process_availabilities_from_iter<I>( | |
| iter: I, | ||
| processes: &ProcessMap, | ||
| time_slice_info: &TimeSliceInfo, | ||
| base_year: u32, | ||
| milestone_years: &[u32], | ||
| ) -> Result<HashMap<ProcessID, ProcessActivityLimitsMap>> | ||
| where | ||
| I: Iterator<Item = ProcessAvailabilityRaw>, | ||
|
|
@@ -137,9 +137,9 @@ where | |
| })?; | ||
|
|
||
| // Get years | ||
| let process_years = &process.years; | ||
| let process_years: Vec<u32> = process.years.clone().collect(); | ||
| let record_years = | ||
| parse_year_str(&record.commission_years, process_years).with_context(|| { | ||
| parse_year_str(&record.commission_years, &process_years).with_context(|| { | ||
| format!("Invalid year for process {id}. Valid years are {process_years:?}") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably fine, although this could be a lot of years which will make for a long message. Maybe better to give the range of years rather than the full list? I also wonder if
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about this, but
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm good point. I'd say it's best as it is then |
||
| })?; | ||
|
|
||
|
|
@@ -162,7 +162,7 @@ where | |
| } | ||
| } | ||
|
|
||
| validate_activity_limits_maps(&map, processes, time_slice_info, base_year)?; | ||
| validate_activity_limits_maps(&map, processes, time_slice_info, milestone_years)?; | ||
|
|
||
| Ok(map) | ||
| } | ||
|
|
@@ -172,15 +172,15 @@ fn validate_activity_limits_maps( | |
| all_availabilities: &HashMap<ProcessID, ProcessActivityLimitsMap>, | ||
| processes: &ProcessMap, | ||
| time_slice_info: &TimeSliceInfo, | ||
| base_year: u32, | ||
| milestone_years: &[u32], | ||
| ) -> Result<()> { | ||
| for (process_id, process) in processes { | ||
| // A map of maps: the outer map is keyed by region and year; the inner one by time slice | ||
| let map_for_process = all_availabilities | ||
| .get(process_id) | ||
| .with_context(|| format!("Missing availabilities for process {process_id}"))?; | ||
|
|
||
| check_missing_milestone_years(process, map_for_process, base_year)?; | ||
| check_missing_milestone_years(process, map_for_process, milestone_years)?; | ||
| check_missing_time_slices(process, map_for_process, time_slice_info)?; | ||
| } | ||
|
|
||
|
|
@@ -195,13 +195,12 @@ fn validate_activity_limits_maps( | |
| fn check_missing_milestone_years( | ||
| process: &Process, | ||
| map_for_process: &ProcessActivityLimitsMap, | ||
| base_year: u32, | ||
| milestone_years: &[u32], | ||
| ) -> Result<()> { | ||
| let process_milestone_years = process | ||
| .years | ||
| .iter() | ||
| .copied() | ||
| .filter(|&year| year >= base_year); | ||
| .clone() | ||
| .filter(|year| milestone_years.contains(year)); | ||
| let mut missing = Vec::new(); | ||
| for (region_id, year) in iproduct!(&process.regions, process_milestone_years) { | ||
| if !map_for_process.contains_key(&(region_id.clone(), year)) { | ||
|
|
@@ -227,7 +226,7 @@ fn check_missing_time_slices( | |
| time_slice_info: &TimeSliceInfo, | ||
| ) -> Result<()> { | ||
| let mut missing = Vec::new(); | ||
| for (region_id, &year) in iproduct!(&process.regions, &process.years) { | ||
| for (region_id, year) in iproduct!(&process.regions, process.years.clone()) { | ||
| if let Some(map_for_region_year) = map_for_process.get(&(region_id.clone(), year)) { | ||
| // There are at least some entries for this region/year combo; check if there are | ||
| // any time slices not covered | ||
|
|
||
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.
I like this block a lot, but aren't we already doing these checks elsewhere?
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.
Yes, sort of, when building the commodity graph for the model. I just thought it made sense to catch issues even earlier, when processing the file. Happy to remove it if you think it is redundant, but I don't think it does any harm.