Skip to content

Commit

Permalink
Merge pull request #57 from ocni-dtu/chrk/52_references
Browse files Browse the repository at this point in the history
Chrk/52 references
  • Loading branch information
ocni-dtu committed Jun 5, 2024
2 parents c10811e + e7f450a commit 5d6a24c
Show file tree
Hide file tree
Showing 23 changed files with 394 additions and 198 deletions.
181 changes: 118 additions & 63 deletions lcax.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"assemblies": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Assembly"
"$ref": "#/definitions/AssemblySource"
}
},
"classificationSystem": {
Expand Down Expand Up @@ -155,12 +155,6 @@
"unit"
],
"properties": {
"category": {
"type": [
"string",
"null"
]
},
"classification": {
"type": [
"array",
Expand Down Expand Up @@ -200,7 +194,7 @@
"products": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Product"
"$ref": "#/definitions/ProductSource"
}
},
"quantity": {
Expand Down Expand Up @@ -228,6 +222,34 @@
}
}
},
"AssemblySource": {
"oneOf": [
{
"type": "object",
"required": [
"assembly"
],
"properties": {
"assembly": {
"$ref": "#/definitions/Assembly"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"reference"
],
"properties": {
"reference": {
"$ref": "#/definitions/Reference"
}
},
"additionalProperties": false
}
]
},
"BuildingInfo": {
"type": "object",
"required": [
Expand Down Expand Up @@ -868,27 +890,6 @@
}
}
},
"ExternalImpactData": {
"type": "object",
"required": [
"format",
"url"
],
"properties": {
"format": {
"type": "string"
},
"url": {
"type": "string"
},
"version": {
"type": [
"string",
"null"
]
}
}
},
"GeneralEnergyClass": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -970,40 +971,17 @@
{
"type": "object",
"required": [
"externalImpactData"
"reference"
],
"properties": {
"externalImpactData": {
"$ref": "#/definitions/ExternalImpactData"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"internalImpactData"
],
"properties": {
"internalImpactData": {
"$ref": "#/definitions/InternalImpactData"
"reference": {
"$ref": "#/definitions/Reference"
}
},
"additionalProperties": false
}
]
},
"InternalImpactData": {
"type": "object",
"required": [
"path"
],
"properties": {
"path": {
"type": "string"
}
}
},
"LifeCycleStage": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1108,20 +1086,47 @@
}
},
"transport": {
"anyOf": [
{
"$ref": "#/definitions/Transport"
},
{
"type": "null"
}
]
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Transport"
}
},
"unit": {
"$ref": "#/definitions/Unit"
}
}
},
"ProductSource": {
"oneOf": [
{
"type": "object",
"required": [
"product"
],
"properties": {
"product": {
"$ref": "#/definitions/Product"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"reference"
],
"properties": {
"reference": {
"$ref": "#/definitions/Reference"
}
},
"additionalProperties": false
}
]
},
"ProjectInfo": {
"oneOf": [
{
Expand Down Expand Up @@ -1162,6 +1167,49 @@
"other"
]
},
"Reference": {
"type": "object",
"required": [
"path",
"type"
],
"properties": {
"format": {
"type": [
"string",
"null"
]
},
"overrides": {
"type": [
"object",
"null"
],
"additionalProperties": {
"type": "string"
}
},
"path": {
"type": "string"
},
"type": {
"$ref": "#/definitions/ReferenceType"
},
"version": {
"type": [
"string",
"null"
]
}
}
},
"ReferenceType": {
"type": "string",
"enum": [
"internal",
"external"
]
},
"RoofType": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1310,6 +1358,7 @@
"distance",
"distanceUnit",
"id",
"impactCategories",
"name",
"transportEpd"
],
Expand All @@ -1324,6 +1373,12 @@
"id": {
"type": "string"
},
"impactCategories": {
"type": "array",
"items": {
"$ref": "#/definitions/ImpactCategoryKey"
}
},
"name": {
"type": "string"
},
Expand Down
51 changes: 30 additions & 21 deletions modules/convert/src/lcabyg/parse.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
use crate::lcabyg::edges::EdgeType;
use crate::lcabyg::nodes::{epd_from_lcabyg_stages, Node};
use crate::lcabyg::results::Model::InstanceModel;
use crate::lcabyg::results::{LCAbygResults, YearResult};
use crate::lcabyg::{categories, edges, nodes};
use std::collections::HashMap;

use field_access::FieldAccess;
use serde::{Deserialize, Serialize};
use serde_json::Error;

use lcax_core::country::Country;
use lcax_core::utils::get_version;
use lcax_models::assembly::AssemblySource;
use lcax_models::assembly::{Assembly, Classification};
use lcax_models::life_cycle_base::{ImpactCategoryKey, LifeCycleStage};
use lcax_models::product::{ImpactDataSource, Product as LCAxProduct};
use lcax_models::product::{ImpactDataSource, Product as LCAxProduct, ProductSource};
use lcax_models::project::{
AreaType, BuildingInfo, BuildingType, BuildingTypology, GeneralEnergyClass, Location,
Project as LCAxProject, ProjectInfo, RoofType, SoftwareInfo,
};
use lcax_models::shared::Unit;
use serde::{Deserialize, Serialize};
use serde_json::Error;
use std::collections::HashMap;

use crate::lcabyg::edges::EdgeType;
use crate::lcabyg::nodes::{epd_from_lcabyg_stages, Node};
use crate::lcabyg::results::Model::InstanceModel;
use crate::lcabyg::results::{LCAbygResults, YearResult};
use crate::lcabyg::{categories, edges, nodes};

type Edge = (EdgeType, String, String);

Expand Down Expand Up @@ -114,13 +118,18 @@ fn add_result_from_lcabyg(
&lcax_project.impact_categories,
&lcax_project.life_cycle_stages,
);
for (assembly_id, assembly) in &mut lcax_project.assemblies {
assembly.results = collect_lcabyg_object_results(
&get_result_id(assembly_id, results),
results,
&lcax_project.impact_categories,
&lcax_project.life_cycle_stages,
)
for (assembly_id, _assembly) in &mut lcax_project.assemblies {
match _assembly {
AssemblySource::Assembly(assembly) => {
assembly.results = collect_lcabyg_object_results(
&get_result_id(assembly_id, results),
results,
&lcax_project.impact_categories,
&lcax_project.life_cycle_stages,
)
}
_ => {}
}
}
}

Expand Down Expand Up @@ -262,7 +271,6 @@ fn add_element_data(
comment: node.comment.english.clone(),
quantity: 0.0,
unit: Unit::M,
category: None,
classification: None,
products: Default::default(),
results: None,
Expand Down Expand Up @@ -299,9 +307,10 @@ fn add_element_data(
_ => continue,
}
}
project
.assemblies
.insert(assembly.id.clone(), assembly.clone());
project.assemblies.insert(
assembly.id.clone(),
AssemblySource::Assembly(assembly.clone()),
);
}

fn add_element_to_construction_data(
Expand Down Expand Up @@ -339,7 +348,7 @@ fn add_construction_data(
let product = add_construction_to_product_data(child_id, &construction_edge, nodes);
assembly
.products
.insert(product.id.clone(), product.clone());
.insert(product.id.clone(), ProductSource::Product(product.clone()));
break;
}
_ => continue,
Expand Down
Loading

0 comments on commit 5d6a24c

Please sign in to comment.