Skip to content

Commit 6e89b39

Browse files
committed
Add helper methods to get flow costs
1 parent 0cd3aa1 commit 6e89b39

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

src/process.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Processes are used for converting between different commodities. The data structures in this
22
//! module are used to represent these conversions along with the associated costs.
3-
use crate::commodity::{Commodity, CommodityID};
3+
use crate::commodity::{BalanceType, Commodity, CommodityID};
44
use crate::id::define_id_type;
55
use crate::region::RegionID;
66
use crate::time_slice::TimeSliceID;
@@ -98,6 +98,41 @@ pub struct ProcessFlow {
9898
pub is_pac: bool,
9999
}
100100

101+
impl ProcessFlow {
102+
/// Get the cost for this flow with the given parameters.
103+
///
104+
/// This includes cost per unit flow and levies/incentives, if any.
105+
pub fn get_total_cost(&self, region_id: &RegionID, year: u32, time_slice: &TimeSliceID) -> f64 {
106+
let cost_per_unit = self.cost + self.get_levy(region_id, year, time_slice);
107+
108+
self.coeff.abs() * cost_per_unit
109+
}
110+
111+
/// Get the levy/incentive for this process flow with the given parameters, if any
112+
fn get_levy(&self, region_id: &RegionID, year: u32, time_slice: &TimeSliceID) -> f64 {
113+
if self.commodity.levies.is_empty() {
114+
return 0.0;
115+
}
116+
117+
let levy = self
118+
.commodity
119+
.levies
120+
.get(&(region_id.clone(), year, time_slice.clone()))
121+
.unwrap();
122+
let apply_levy = match levy.balance_type {
123+
BalanceType::Net => true,
124+
BalanceType::Consumption => self.coeff < 0.0,
125+
BalanceType::Production => self.coeff > 0.0,
126+
};
127+
128+
if apply_levy {
129+
levy.value
130+
} else {
131+
0.0
132+
}
133+
}
134+
}
135+
101136
/// Type of commodity flow (see [`ProcessFlow`])
102137
#[derive(PartialEq, Default, Debug, Clone, DeserializeLabeledStringEnum)]
103138
pub enum FlowType {

0 commit comments

Comments
 (0)