muse2/input/process/
region.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Code for reading the process region CSV file
use super::define_process_id_getter;
use crate::input::region::{define_region_id_getter, read_regions_for_entity};
use crate::input::*;
use crate::region::RegionSelection;
use anyhow::Result;
use serde::Deserialize;
use std::collections::{HashMap, HashSet};
use std::path::Path;
use std::rc::Rc;

const PROCESS_REGIONS_FILE_NAME: &str = "process_regions.csv";

#[derive(PartialEq, Debug, Deserialize)]
struct ProcessRegion {
    process_id: String,
    region_id: String,
}
define_process_id_getter! {ProcessRegion}
define_region_id_getter! {ProcessRegion}

/// Read the process regions file.
///
/// # Arguments
///
/// * `model_dir` - Folder containing model configuration files
/// * `process_ids` - The possible valid process IDs
/// * `region_ids` - The possible valid region IDs
///
/// # Returns
///
/// A map of [`RegionSelection`]s, with the process ID as the key.
pub fn read_process_regions(
    model_dir: &Path,
    process_ids: &HashSet<Rc<str>>,
    region_ids: &HashSet<Rc<str>>,
) -> Result<HashMap<Rc<str>, RegionSelection>> {
    let file_path = model_dir.join(PROCESS_REGIONS_FILE_NAME);
    read_regions_for_entity::<ProcessRegion>(&file_path, process_ids, region_ids)
}