Skip to content

Commit

Permalink
feat: corrected serialization of models
Browse files Browse the repository at this point in the history
  • Loading branch information
ocni-dtu committed May 9, 2024
1 parent ecde85b commit d77a0a4
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 85 deletions.
54 changes: 27 additions & 27 deletions lcax.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,16 +766,16 @@
"EPD": {
"type": "object",
"required": [
"declared_unit",
"format_version",
"declaredUnit",
"formatVersion",
"id",
"impacts",
"location",
"name",
"published_date",
"publishedDate",
"standard",
"subtype",
"valid_until",
"validUntil",
"version"
],
"properties": {
Expand All @@ -794,10 +794,10 @@
"$ref": "#/definitions/Conversion"
}
},
"declared_unit": {
"declaredUnit": {
"$ref": "#/definitions/Unit"
},
"format_version": {
"formatVersion": {
"type": "string"
},
"id": {
Expand All @@ -819,7 +819,7 @@
"location": {
"$ref": "#/definitions/Country"
},
"meta_data": {
"metaData": {
"type": [
"object",
"null"
Expand All @@ -831,11 +831,11 @@
"name": {
"type": "string"
},
"published_date": {
"publishedDate": {
"type": "string",
"format": "date"
},
"reference_service_life": {
"referenceServiceLife": {
"type": [
"integer",
"null"
Expand All @@ -859,7 +859,7 @@
"subtype": {
"$ref": "#/definitions/SubType"
},
"valid_until": {
"validUntil": {
"type": "string",
"format": "date"
},
Expand Down Expand Up @@ -946,10 +946,10 @@
{
"type": "object",
"required": [
"epd"
"ePD"
],
"properties": {
"epd": {
"ePD": {
"$ref": "#/definitions/EPD"
}
},
Expand All @@ -958,10 +958,10 @@
{
"type": "object",
"required": [
"techflow"
"techFlow"
],
"properties": {
"techflow": {
"techFlow": {
"$ref": "#/definitions/TechFlow"
}
},
Expand All @@ -970,10 +970,10 @@
{
"type": "object",
"required": [
"externalimpactdata"
"externalImpactData"
],
"properties": {
"externalimpactdata": {
"externalImpactData": {
"$ref": "#/definitions/ExternalImpactData"
}
},
Expand All @@ -982,10 +982,10 @@
{
"type": "object",
"required": [
"internalimpactdata"
"internalImpactData"
],
"properties": {
"internalimpactdata": {
"internalImpactData": {
"$ref": "#/definitions/InternalImpactData"
}
},
Expand Down Expand Up @@ -1127,10 +1127,10 @@
{
"type": "object",
"required": [
"buildinginfo"
"buildingInfo"
],
"properties": {
"buildinginfo": {
"buildingInfo": {
"$ref": "#/definitions/BuildingInfo"
}
},
Expand All @@ -1139,10 +1139,10 @@
{
"type": "object",
"required": [
"infrastructureinfo"
"infrastructureInfo"
],
"properties": {
"infrastructureinfo": {
"infrastructureInfo": {
"type": "object",
"additionalProperties": {
"type": "string"
Expand Down Expand Up @@ -1232,8 +1232,8 @@
"TechFlow": {
"type": "object",
"required": [
"declared_unit",
"format_version",
"declaredUnit",
"formatVersion",
"id",
"impacts",
"location",
Expand All @@ -1255,10 +1255,10 @@
"$ref": "#/definitions/Conversion"
}
},
"declared_unit": {
"declaredUnit": {
"$ref": "#/definitions/Unit"
},
"format_version": {
"formatVersion": {
"type": "string"
},
"id": {
Expand All @@ -1280,7 +1280,7 @@
"location": {
"$ref": "#/definitions/Country"
},
"meta_data": {
"metaData": {
"type": [
"object",
"null"
Expand Down
30 changes: 1 addition & 29 deletions modules/models/src/epd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::life_cycle_base::{ImpactCategory, ImpactCategoryKey};
use crate::shared::{Conversion, Source, Unit};

#[derive(Serialize, Deserialize, JsonSchema, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(
feature = "jsbindings",
derive(Tsify),
Expand Down Expand Up @@ -109,32 +110,3 @@ impl From<&Option<String>> for SubType {
}
}
}

// mod my_date_format {
// use chrono::{NaiveDate};
// use serde::{self, Serializer, Deserializer, Deserialize};
//
// const FORMAT: &'static str = "%Y-%m-%d";
//
// pub fn serialize<S>(
// date: &NaiveDate,
// serializer: S,
// ) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// let s = format!("{}", date.format(FORMAT));
// serializer.serialize_str(&s)
// }
//
// pub fn deserialize<'de, D>(
// deserializer: D,
// ) -> Result<NaiveDate, D::Error>
// where
// D: Deserializer<'de>,
// {
// let s = String::deserialize(deserializer)?;
// let dt = NaiveDate::parse_from_str(&s, FORMAT).map_err(serde::de::Error::custom)?;
// Ok(dt)
// }
// }
2 changes: 1 addition & 1 deletion modules/models/src/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Transport {
}

#[derive(Deserialize, Serialize, JsonSchema, Clone)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
pub enum ImpactDataSource {
EPD(EPD),
Expand Down
4 changes: 2 additions & 2 deletions modules/models/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ pub enum ProjectPhase {
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
pub struct Location {
pub country: lcax_core::country::Country,
pub country: Country,
pub city: Option<String>,
pub address: Option<String>,
}

#[derive(Deserialize, Serialize, JsonSchema, Clone)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
pub enum ProjectInfo {
BuildingInfo(BuildingInfo),
Expand Down
1 change: 1 addition & 0 deletions modules/models/src/techflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::life_cycle_base::{ImpactCategory, ImpactCategoryKey};
use crate::shared::{Conversion, Source, Unit};

#[derive(Deserialize, Serialize, JsonSchema, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(
feature = "jsbindings",
derive(Tsify),
Expand Down
22 changes: 11 additions & 11 deletions packages/javascript/src/lcax.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface BuildingInfo {
buildingModelScope: BuildingModelScope | null;
}

export type ProjectInfo = { buildinginfo: BuildingInfo } | { infrastructureinfo: Record<string, string> };
export type ProjectInfo = { buildingInfo: BuildingInfo } | { infrastructureInfo: Record<string, string> };

export interface Location {
country: Country;
Expand Down Expand Up @@ -119,20 +119,20 @@ export type Standard = "EN15804A1" | "EN15804A2" | "UNKNOWN";
export interface EPD {
id: string;
name: string;
declared_unit: Unit;
declaredUnit: Unit;
version: string;
published_date: NaiveDate;
valid_until: NaiveDate;
format_version: string;
publishedDate: NaiveDate;
validUntil: NaiveDate;
formatVersion: string;
source: Source | null;
reference_service_life: number | null;
referenceServiceLife: number | null;
standard: Standard;
comment: string | null;
location: Country;
subtype: SubType;
conversions: Conversion[] | null;
impacts: Record<ImpactCategoryKey, ImpactCategory>;
meta_data: Record<string, string> | null;
metaData: Record<string, string> | null;
}

export interface InternalImpactData {
Expand All @@ -145,7 +145,7 @@ export interface ExternalImpactData {
version: string | null;
}

export type ImpactDataSource = { epd: EPD } | { techflow: TechFlow } | { externalimpactdata: ExternalImpactData } | { internalimpactdata: InternalImpactData };
export type ImpactDataSource = { ePD: EPD } | { techFlow: TechFlow } | { externalImpactData: ExternalImpactData } | { internalImpactData: InternalImpactData };

export interface Transport {
id: string;
Expand Down Expand Up @@ -188,14 +188,14 @@ export type Unit = "M" | "M2" | "M3" | "KG" | "TONES" | "PCS" | "L" | "M2R1" | "
export interface TechFlow {
id: string;
name: string;
declared_unit: Unit;
format_version: string;
declaredUnit: Unit;
formatVersion: string;
source: Source | null;
comment: string | null;
location: Country;
conversions: Conversion[] | null;
impacts: Record<ImpactCategoryKey, ImpactCategory>;
meta_data: Record<string, string> | null;
metaData: Record<string, string> | null;
}

export interface Classification {
Expand Down
Binary file modified packages/javascript/src/lcax_bg.wasm
Binary file not shown.
Binary file modified packages/python/src/lcax/lcax.abi3.so
Binary file not shown.
Loading

0 comments on commit d77a0a4

Please sign in to comment.