Skip to content

Commit

Permalink
EC-84 transfer new data files for FHS and add accessors for evaporati…
Browse files Browse the repository at this point in the history
…ve losses data files

Co-authored-by: Rachel Howell <[email protected]>
  • Loading branch information
shieldo and rachowell committed Sep 19, 2024
1 parent 4ea9410 commit d56eb18
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/wrappers/future_homes_standard/future_homes_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use log::warn;
use serde::Deserialize;
use serde_json::{json, Number, Value};
use std::collections::{HashMap, HashSet};
use std::io::{BufReader, Cursor};
use std::io::{BufReader, Cursor, Read};
use std::iter::{repeat, zip};

const _EMIS_FACTOR_NAME: &str = "Emissions Factor kgCO2e/kWh";
Expand Down Expand Up @@ -105,6 +105,12 @@ lazy_static! {

factors
};
static ref EVAP_PROFILE_DATA: Vec<EvaporativeProfile> =
load_evaporative_profile(Cursor::new(include_str!("./evap_loss_profile.csv")))
.expect("Could not read evap_loss_profile.csv.");
static ref COLD_WATER_LOSS_PROFILE_DATA: Vec<EvaporativeProfile> =
load_evaporative_profile(Cursor::new(include_str!("./cold_water_loss_profile.csv")))
.expect("Could not read cold_water_loss_profile.csv");
}

#[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -756,6 +762,47 @@ fn create_water_heating_pattern(input: &mut InputForProcessing) -> anyhow::Resul
Ok(())
}

/// Load the daily evaporative profile from a CSV file.
///
/// This function reads a CSV file containing time-of-day factors for evaporative losses
/// for each day of the week. It constructs a dictionary mapping days of the week to
/// lists of evaporative loss factors.
///
/// Arguments:
///
/// * `file` - The name of the CSV file containing the evaporative profile data.
///
/// Returns:
/// dict: A dictionary with days of the week as keys and lists of float factors as values.
fn load_evaporative_profile(file: impl Read) -> anyhow::Result<Vec<EvaporativeProfile>> {
let mut profile_reader = Reader::from_reader(BufReader::new(file));

Ok(profile_reader
.deserialize()
.collect::<Result<Vec<EvaporativeProfile>, _>>()
.map_err(|_| anyhow!("Could not read evaporative profile file."))?)
}

#[derive(Debug, Deserialize)]
struct EvaporativeProfile {
#[serde(rename = "Half_hour")]
half_hour: usize,
#[serde(rename = "Mon")]
monday: f64,
#[serde(rename = "Tue")]
tuesday: f64,
#[serde(rename = "Wed")]
wednesday: f64,
#[serde(rename = "Thu")]
thursday: f64,
#[serde(rename = "Fri")]
friday: f64,
#[serde(rename = "Sat")]
saturday: f64,
#[serde(rename = "Sun")]
sunday: f64,
}

fn create_evaporative_losses(
input: &mut InputForProcessing,
total_floor_area: f64,
Expand Down

0 comments on commit d56eb18

Please sign in to comment.