Skip to content

Commit

Permalink
fix: fixed ilcd parse issue and added more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ocni-dtu committed Apr 1, 2024
1 parent 1d6708f commit ae8b9c5
Show file tree
Hide file tree
Showing 5 changed files with 5,848 additions and 44 deletions.
83 changes: 41 additions & 42 deletions src/epd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ use schemars::JsonSchema;
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::HashMap;

use crate::ilcd::{Exchange, LCIAResult, ModuleAnie, ILCD};
use crate::ilcd::{Exchange, LCIAResult, ModuleAnie, ILCD, DataSetName};

#[cfg(feature = "jsbindings")]
use tsify::Tsify;

#[derive(Serialize, JsonSchema, Clone)]
#[cfg_attr(
feature = "jsbindings",
derive(Tsify),
tsify(into_wasm_abi, from_wasm_abi)
feature = "jsbindings",
derive(Tsify),
tsify(into_wasm_abi, from_wasm_abi)
)]
pub struct EPD {
pub id: String,
Expand Down Expand Up @@ -325,8 +325,8 @@ pub struct Conversion {

impl<'de> Deserialize<'de> for EPD {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
where
D: Deserializer<'de>,
{
let helper = ILCD::deserialize(deserializer)?;
let subtype = helper
Expand Down Expand Up @@ -373,15 +373,7 @@ impl<'de> Deserialize<'de> for EPD {

Ok(EPD {
id: helper.process_information.data_set_information.uuid,
name: helper
.process_information
.data_set_information
.name
.base_name
.first()
.unwrap()
.value
.to_string(),
name: get_name(helper.process_information.data_set_information.name),
version: helper.version,
format_version,
declared_unit,
Expand Down Expand Up @@ -453,7 +445,7 @@ fn get_ilcd_standard(helper: &ILCD) -> Standard {
.compliance
{
for description in &compliance.reference_to_compliance_system.short_description {
match Standard::from(&description.value) {
match Standard::from(&description.value.clone().unwrap()) {
Standard::UNKNOWN => continue,
standard => return standard,
}
Expand Down Expand Up @@ -500,7 +492,7 @@ fn get_ilcd_declared_unit(exchange: &Exchange) -> Unit {
&flow_property.reference_unit,
) {
(Some(reference_flow), Some(reference_unit)) if reference_flow == true => {
return Unit::from(reference_unit)
return Unit::from(reference_unit);
}
_ => continue,
}
Expand Down Expand Up @@ -535,15 +527,15 @@ fn collect_from_lcia_result(
{
let impact_value = Some(ImpactCategory::from(&lcia_result.other.anies));
match &description.value {
value if value.contains("(GWP)") || value.contains("(GWP-total)") => {
Some(value) if value.contains("(GWP)") || value.contains("(GWP-total)") => {
gwp = impact_value
}
value if value.contains("(ODP)") => odp = impact_value,
value if value.contains("(AP)") => ap = impact_value,
value if value.contains("(EP)") => ep = impact_value,
value if value.contains("(POCP)") => pocp = impact_value,
value if value.contains("(ADPE)") => adpe = impact_value,
value if value.contains("(ADPF)") => adpf = impact_value,
Some(value) if value.contains("(ODP)") => odp = impact_value,
Some(value) if value.contains("(AP)") => ap = impact_value,
Some(value) if value.contains("(EP)") => ep = impact_value,
Some(value) if value.contains("(POCP)") => pocp = impact_value,
Some(value) if value.contains("(ADPE)") => adpe = impact_value,
Some(value) if value.contains("(ADPF)") => adpf = impact_value,
_ => continue,
}
}
Expand Down Expand Up @@ -610,24 +602,24 @@ fn collect_from_exchanges(
_ => continue,
};
match &description.value {
_description if _description == "Use of renewable primary energy (PERE)" => pere = impact_value,
_description if _description == "Use of renewable primary energy resources used as raw materials (PERM)" => perm = impact_value,
_description if _description == "Total use of renewable primary energy resources (PERT)" => pert = impact_value,
_description if _description == "Use of non renewable primary energy (PENRE)" => penre = impact_value,
_description if _description == "Use of non renewable primary energy resources used as raw materials (PENRM)" => penrm = impact_value,
_description if _description == "Total use of non renewable primary energy resource (PENRT)" => penrt = impact_value,
_description if _description == "Use of secondary material (SM)" => sm = impact_value,
_description if _description == "Use of renewable secondary fuels (RSF)" => rsf = impact_value,
_description if _description == "Use of non renewable secondary fuels (NRSF)" => nrsf = impact_value,
_description if _description == "Use of net fresh water (FW)" => fw = impact_value,
_description if _description == "Hazardous waste disposed (HWD)" => hwd = impact_value,
_description if _description == "Non hazardous waste dispose (NHWD)" => nhwd = impact_value,
_description if _description == "Radioactive waste disposed (RWD)" => rwd = impact_value,
_description if _description == "Components for re-use (CRU)" => cru = impact_value,
_description if _description == "Materials for recycling (MFR)" => mfr = impact_value,
_description if _description == "Materials for energy recovery (MER)" => mer = impact_value,
_description if _description == "Exported electrical energy (EEE)" => eee = impact_value,
_description if _description == "Exported thermal energy (EET)" => eet = impact_value,
Some(_description) if _description == "Use of renewable primary energy (PERE)" => pere = impact_value,
Some(_description) if _description == "Use of renewable primary energy resources used as raw materials (PERM)" => perm = impact_value,
Some(_description) if _description == "Total use of renewable primary energy resources (PERT)" => pert = impact_value,
Some(_description) if _description == "Use of non renewable primary energy (PENRE)" => penre = impact_value,
Some(_description) if _description == "Use of non renewable primary energy resources used as raw materials (PENRM)" => penrm = impact_value,
Some(_description) if _description == "Total use of non renewable primary energy resource (PENRT)" => penrt = impact_value,
Some(_description) if _description == "Use of secondary material (SM)" => sm = impact_value,
Some(_description) if _description == "Use of renewable secondary fuels (RSF)" => rsf = impact_value,
Some(_description) if _description == "Use of non renewable secondary fuels (NRSF)" => nrsf = impact_value,
Some(_description) if _description == "Use of net fresh water (FW)" => fw = impact_value,
Some(_description) if _description == "Hazardous waste disposed (HWD)" => hwd = impact_value,
Some(_description) if _description == "Non hazardous waste dispose (NHWD)" => nhwd = impact_value,
Some(_description) if _description == "Radioactive waste disposed (RWD)" => rwd = impact_value,
Some(_description) if _description == "Components for re-use (CRU)" => cru = impact_value,
Some(_description) if _description == "Materials for recycling (MFR)" => mfr = impact_value,
Some(_description) if _description == "Materials for energy recovery (MER)" => mer = impact_value,
Some(_description) if _description == "Exported electrical energy (EEE)" => eee = impact_value,
Some(_description) if _description == "Exported thermal energy (EET)" => eet = impact_value,
_ => continue
}
}
Expand Down Expand Up @@ -658,3 +650,10 @@ fn collect_from_exchanges(
eet,
)
}

fn get_name(base_name: DataSetName) -> String {
match base_name.base_name.first() {
Some(name) if name.value.is_some() => name.value.clone().unwrap(),
_ => "".to_string()
}
}
3 changes: 1 addition & 2 deletions src/ilcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl From<&AnieValue> for f64 {
pub struct ValueObject {
_type: String,
ref_object_id: String,
uri: String,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -225,6 +224,6 @@ pub struct DataSetName {

#[derive(Deserialize, Debug)]
pub struct ValueLang {
pub value: String,
pub value: Option<String>,
pub lang: String,
}

0 comments on commit ae8b9c5

Please sign in to comment.