Skip to content

Commit

Permalink
EC-264 Update part of calc_final_rates to 0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
kpinakula committed Feb 10, 2025
1 parent 9835b16 commit a7b2b78
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/wrappers/future_homes_standard/fhs_compliance_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ impl TryFrom<&HashMap<CalculationKey, CalculationResultsWithContext<'_>>>
&dwelling_fhs_results.results.energy_export,
&dwelling_fhs_results.results.results_end_user,
dwelling_fhs_results.results.timestep_array.len(),
),
)?,
target_final_rates: calc_final_rates(
notional_fhs_results.context.input,
&notional_fhs_results.results.energy_import,
&notional_fhs_results.results.energy_export,
&notional_fhs_results.results.results_end_user,
notional_fhs_results.results.timestep_array.len(),
),
)?,
dwelling_fabric_energy_efficiency: calc_fabric_energy_efficiency(
dwelling_fhs_fee_results.results.space_heat_demand_total(),
dwelling_fhs_fee_results.results.space_cool_demand_total(),
Expand Down
51 changes: 34 additions & 17 deletions src/wrappers/future_homes_standard/future_homes_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub fn apply_fhs_postprocessing(
energy_export,
results_end_user,
no_of_timesteps,
);
)?;

// Write results to output files
write_postproc_file(output, "emissions", emis_results, no_of_timesteps)?;
Expand All @@ -290,7 +290,7 @@ pub(super) fn calc_final_rates(
energy_export: &IndexMap<ArrayString<64>, Vec<f64>>,
results_end_user: &ResultsEndUser,
number_of_timesteps: usize,
) -> FinalRates {
) -> anyhow::Result<FinalRates> {
// Add unmet demand to list of EnergySupply objects

// For each EnergySupply object:
Expand Down Expand Up @@ -370,19 +370,36 @@ pub(super) fn calc_final_rates(
};

// Calculate energy imported and associated emissions/PE
supply_emis_result.import = energy_import[&KeyString::from(&energy_supply_key).unwrap()]
.iter()
.map(|x| x * emis_factor_import_export[0])
.collect::<Vec<_>>();
supply_emis_oos_result.import = energy_import
[&KeyString::from(&energy_supply_key).unwrap()]
.iter()
.map(|x| x * emis_oos_factor_import_export[0])
.collect::<Vec<_>>();
supply_pe_result.import = energy_import[&KeyString::from(&energy_supply_key).unwrap()]
.iter()
.map(|x| x * pe_factor_import_export[0])
.collect::<Vec<_>>();
if fuel_code == FuelType::Electricity {
let energy_supply_key = &KeyString::from(&energy_supply_key).unwrap();
supply_emis_result.import = apply_energy_factor_series(
energy_import[energy_supply_key].clone(),
emis_factor_import_export.clone(),
)?;
supply_emis_oos_result.import = apply_energy_factor_series(
energy_import[energy_supply_key].clone(),
emis_oos_factor_import_export.clone(),
)?;
supply_pe_result.import = apply_energy_factor_series(
energy_import[energy_supply_key].clone(),
pe_factor_import_export.clone(),
)?;
} else {
supply_emis_result.import = energy_import
[&KeyString::from(&energy_supply_key).unwrap()]
.iter()
.map(|x| x * emis_factor_import_export[0])
.collect::<Vec<_>>();
supply_emis_oos_result.import = energy_import
[&KeyString::from(&energy_supply_key).unwrap()]
.iter()
.map(|x| x * emis_oos_factor_import_export[0])
.collect::<Vec<_>>();
supply_pe_result.import = energy_import[&KeyString::from(&energy_supply_key).unwrap()]
.iter()
.map(|x| x * pe_factor_import_export[0])
.collect::<Vec<_>>();
}

// If there is any export, Calculate energy exported and associated emissions/PE
// Note that by convention, exported energy is negative
Expand Down Expand Up @@ -531,13 +548,13 @@ pub(super) fn calc_final_rates(
.sum::<f64>()
/ tfa;

FinalRates {
Ok(FinalRates {
emission_rate: total_emissions_rate,
primary_energy_rate: total_pe_rate,
emissions_results: emis_results,
emissions_out_of_scope_results: emis_oos_results,
primary_energy_results: pe_results,
}
})
}

pub(super) struct FinalRates {
Expand Down

0 comments on commit a7b2b78

Please sign in to comment.