lcax_models 3.4.3

LCAx is an open, machine and human-readable data format for exchanging LCA results.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
use crate::assembly::AssemblyReference;
use crate::life_cycle_base::{ImpactCategoryKey, Impacts, LifeCycleModule};
use crate::shared::{MetaData, Unit};
use lcax_core::country::Country;
use lcax_core::utils::get_version;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[cfg(feature = "jsbindings")]
use wasm_bindgen::prelude::*;

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

#[cfg(feature = "pybindings")]
use pyo3::exceptions::PyTypeError;

#[cfg(feature = "pybindings")]
use pyo3::prelude::*;

#[cfg(feature = "pybindings")]
use pyo3::types::PyType;

#[cfg(feature = "jsbindings")]
use strum::IntoEnumIterator;

#[cfg(feature = "jsbindings")]
use strum_macros::EnumIter;

#[derive(Deserialize, Serialize, JsonSchema, Default, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(
    feature = "jsbindings",
    derive(Tsify),
    tsify(into_wasm_abi, from_wasm_abi)
)]
#[cfg_attr(feature = "pybindings", pyclass(get_all, set_all))]
pub struct Project {
    pub id: String,
    pub name: String,
    pub description: Option<String>,
    pub comment: Option<String>,
    pub location: Location,
    pub owner: Option<String>,
    pub format_version: String,
    pub lcia_method: Option<String>,
    pub classification_systems: Option<Vec<String>>,
    pub reference_study_period: Option<u8>,
    pub life_cycle_modules: Vec<LifeCycleModule>,
    pub impact_categories: Vec<ImpactCategoryKey>,
    pub assemblies: Vec<AssemblyReference>,
    pub results: Option<Impacts>,
    pub project_info: Option<BuildingInfo>,
    pub project_phase: ProjectPhase,
    pub software_info: SoftwareInfo,
    pub meta_data: Option<MetaData>,
}

#[cfg_attr(feature = "pybindings", pymethods)]
impl Project {
    #[cfg(feature = "pybindings")]
    #[new]
    #[pyo3(signature=(name, location, project_phase, software_info, life_cycle_modules, impact_categories, assemblies, id=None, description=None, comment=None, owner=None, format_version=None, lcia_method=None, classification_systems=None, reference_study_period=None, results=None, project_info=None, meta_data=None ))]
    pub fn new_py(
        name: &str,
        location: Location,
        project_phase: ProjectPhase,
        software_info: SoftwareInfo,
        life_cycle_modules: Vec<LifeCycleModule>,
        impact_categories: Vec<ImpactCategoryKey>,
        assemblies: Vec<AssemblyReference>,
        id: Option<String>,
        description: Option<String>,
        comment: Option<String>,
        owner: Option<String>,
        format_version: Option<String>,
        lcia_method: Option<String>,
        classification_systems: Option<Vec<String>>,
        reference_study_period: Option<u8>,
        results: Option<Impacts>,
        project_info: Option<BuildingInfo>,
        meta_data: Option<MetaData>,
    ) -> Project {
        Project::new(
            id,
            name,
            description,
            comment,
            location,
            owner,
            format_version,
            lcia_method,
            classification_systems,
            reference_study_period,
            life_cycle_modules,
            impact_categories,
            assemblies,
            results,
            project_info,
            project_phase,
            software_info,
            meta_data,
        )
    }

    #[cfg(feature = "pybindings")]
    #[classmethod]
    #[pyo3(name = "loads")]
    pub fn loads_py(_cls: &Bound<'_, PyType>, value: &str) -> PyResult<Self> {
        match Project::loads(value) {
            Ok(project) => Ok(project),
            Err(error) => Err(PyTypeError::new_err(error.to_string())),
        }
    }

    #[cfg(feature = "pybindings")]
    #[pyo3(name = "dumps")]
    pub fn dumps_py(&self) -> PyResult<String> {
        match Project::dumps(self) {
            Ok(project) => Ok(project),
            Err(error) => Err(PyTypeError::new_err(error.to_string())),
        }
    }
    #[cfg(feature = "pybindings")]
    fn __repr__(&self) -> String {
        format!("Project: {}", self.id)
    }

    #[cfg(feature = "pybindings")]
    fn __str__(&self) -> String {
        self.__repr__()
    }
}

impl Project {
    pub fn new(
        id: Option<String>,
        name: &str,
        description: Option<String>,
        comment: Option<String>,
        location: Location,
        owner: Option<String>,
        format_version: Option<String>,
        lcia_method: Option<String>,
        classification_systems: Option<Vec<String>>,
        reference_study_period: Option<u8>,
        life_cycle_modules: Vec<LifeCycleModule>,
        impact_categories: Vec<ImpactCategoryKey>,
        assemblies: Vec<AssemblyReference>,
        results: Option<Impacts>,
        project_info: Option<BuildingInfo>,
        project_phase: ProjectPhase,
        software_info: SoftwareInfo,
        meta_data: Option<MetaData>,
    ) -> Self {
        let _id = id.unwrap_or_else(|| uuid::Uuid::new_v4().to_string());
        let _format_version = format_version.unwrap_or_else(|| get_version().to_string());
        Project {
            id: _id,
            name: name.to_string(),
            description,
            comment,
            location,
            owner,
            format_version: _format_version,
            lcia_method,
            classification_systems,
            reference_study_period,
            life_cycle_modules,
            impact_categories,
            assemblies,
            results,
            project_info,
            project_phase,
            software_info,
            meta_data,
        }
    }

    pub fn loads(value: &str) -> Result<Project, serde_json::Error> {
        serde_json::from_str(value)
    }

    pub fn dumps(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string(self)
    }

    pub fn resolve_impact_categories(&mut self) {
        self.impact_categories = match self.results {
            Some(ref results) => {
                let mut keys = Vec::new();
                for (key, _) in results.iter() {
                    keys.push(key.clone());
                }
                keys
            }
            None => vec![],
        }
    }
    pub fn resolve_life_cycle_stages(&mut self) {
        self.life_cycle_modules = match self.results {
            Some(ref results) => {
                let mut keys = Vec::new();
                for (_, value) in results.iter() {
                    for (key, _) in value.iter() {
                        if keys.contains(key) {
                            continue;
                        }
                        keys.push(key.clone());
                    }
                }
                keys
            }
            None => vec![],
        }
    }
}

#[derive(Deserialize, Serialize, JsonSchema, Default, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
#[cfg_attr(feature = "pybindings", pyclass(get_all, set_all))]
pub struct SoftwareInfo {
    pub lca_software: String,
    pub lca_software_version: Option<String>,
    pub goal_and_scope_definition: Option<String>,
    pub calculation_type: Option<String>,
}

#[cfg_attr(feature = "pybindings", pymethods)]
impl SoftwareInfo {
    #[cfg(feature = "pybindings")]
    #[new]
    #[pyo3(signature=(lca_software, lca_software_version=None, goal_and_scope_definition=None, calculation_type=None))]
    pub fn new_py(
        lca_software: String,
        lca_software_version: Option<String>,
        goal_and_scope_definition: Option<String>,
        calculation_type: Option<String>,
    ) -> SoftwareInfo {
        SoftwareInfo::new(
            lca_software,
            lca_software_version,
            goal_and_scope_definition,
            calculation_type,
        )
    }
}

impl SoftwareInfo {
    pub fn new(
        lca_software: String,
        lca_software_version: Option<String>,
        goal_and_scope_definition: Option<String>,
        calculation_type: Option<String>,
    ) -> Self {
        SoftwareInfo {
            lca_software,
            lca_software_version,
            goal_and_scope_definition,
            calculation_type,
        }
    }
}

#[derive(Deserialize, Serialize, JsonSchema, Default, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(
    feature = "jsbindings",
    derive(Tsify, EnumIter),
    tsify(into_wasm_abi, from_wasm_abi)
)]
#[cfg_attr(feature = "pybindings", pyclass(eq, eq_int))]
pub enum ProjectPhase {
    #[allow(non_camel_case_types)]
    STRATEGIC_DESIGN,
    #[allow(non_camel_case_types)]
    CONCEPT_DESIGN,
    #[allow(non_camel_case_types)]
    TECHNICAL_DESIGN,
    CONSTRUCTION,
    #[allow(non_camel_case_types)]
    POST_COMPLETION,
    #[allow(non_camel_case_types)]
    IN_USE,
    #[default]
    OTHER,
}

#[cfg(feature = "jsbindings")]
#[allow(non_snake_case)]
#[wasm_bindgen]
pub fn projectPhases() -> Vec<ProjectPhase> {
    ProjectPhase::iter().collect()
}

#[derive(Deserialize, Serialize, JsonSchema, Default, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
#[cfg_attr(feature = "pybindings", pyclass(get_all, set_all))]
pub struct Location {
    pub country: Country,
    pub city: Option<String>,
    pub address: Option<String>,
}

#[cfg_attr(feature = "pybindings", pymethods)]
impl Location {
    #[cfg(feature = "pybindings")]
    #[new]
    #[pyo3(signature=(country, city=None, address=None))]
    pub fn new_py(country: Country, city: Option<String>, address: Option<String>) -> Location {
        Location::new(country, city, address)
    }
}

impl Location {
    pub fn new(country: Country, city: Option<String>, address: Option<String>) -> Self {
        Location {
            country,
            city,
            address,
        }
    }
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
#[cfg_attr(feature = "pybindings", pyclass(get_all, set_all))]
pub struct BuildingInfo {
    pub building_type: BuildingType,
    pub building_typology: Vec<BuildingTypology>,
    pub certifications: Option<Vec<String>>,
    pub building_mass: Option<ValueUnit>,
    pub building_height: Option<ValueUnit>,
    pub gross_floor_area: Option<AreaType>,
    pub heated_floor_area: Option<AreaType>,
    pub building_footprint: Option<ValueUnit>,
    pub floors_above_ground: u16,
    pub floors_below_ground: Option<u16>,
    pub roof_type: Option<RoofType>,
    pub frame_type: Option<String>,
    pub building_completion_year: Option<u16>,
    pub building_permit_year: Option<u16>,
    pub energy_demand_heating: Option<f64>,
    pub energy_supply_heating: Option<f64>,
    pub energy_demand_electricity: Option<f64>,
    pub energy_supply_electricity: Option<f64>,
    pub exported_electricity: Option<f64>,
    pub general_energy_class: GeneralEnergyClass,
    pub local_energy_class: Option<String>,
    pub building_users: Option<u32>,
    pub building_model_scope: Option<Vec<BuildingModelScope>>,
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
#[cfg_attr(feature = "pybindings", pyclass(get_all, set_all))]
pub struct AreaType {
    pub value: f64,
    pub unit: Unit,
    pub definition: String,
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "jsbindings", derive(Tsify))]
#[cfg_attr(feature = "pybindings", pyclass(get_all, set_all))]
pub struct ValueUnit {
    pub value: f64,
    pub unit: Unit,
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(
    feature = "jsbindings",
    derive(Tsify, EnumIter),
    tsify(into_wasm_abi, from_wasm_abi)
)]
#[cfg_attr(feature = "pybindings", pyclass(eq, eq_int))]
pub enum RoofType {
    FLAT,
    PITCHED,
    SADDLE,
    PYRAMID,
    UNKNOWN,
    OTHER,
}

#[cfg(feature = "jsbindings")]
#[allow(non_snake_case)]
#[wasm_bindgen]
pub fn roofTypes() -> Vec<RoofType> {
    RoofType::iter().collect()
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(
    feature = "jsbindings",
    derive(Tsify, EnumIter),
    tsify(into_wasm_abi, from_wasm_abi)
)]
#[cfg_attr(feature = "pybindings", pyclass(eq, eq_int))]
pub enum GeneralEnergyClass {
    EXISTING,
    STANDARD,
    ADVANCED,
    UNKNOWN,
}

#[cfg(feature = "jsbindings")]
#[allow(non_snake_case)]
#[wasm_bindgen]
pub fn generalEnergyClasses() -> Vec<GeneralEnergyClass> {
    GeneralEnergyClass::iter().collect()
}

impl From<&String> for GeneralEnergyClass {
    fn from(class: &String) -> Self {
        match class.to_ascii_lowercase().as_str() {
            "lowenergy" => GeneralEnergyClass::ADVANCED,
            _ => GeneralEnergyClass::UNKNOWN,
        }
    }
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(
    feature = "jsbindings",
    derive(Tsify, EnumIter),
    tsify(into_wasm_abi, from_wasm_abi)
)]
#[cfg_attr(feature = "pybindings", pyclass(eq, eq_int))]
pub enum BuildingModelScope {
    #[allow(non_camel_case_types)]
    FACILITATING_WORKS,
    SUBSTRUCTURE,
    #[allow(non_camel_case_types)]
    SUPERSTRUCTURE_FRAME,
    #[allow(non_camel_case_types)]
    SUPERSTRUCTURE_ENVELOPE,
    #[allow(non_camel_case_types)]
    SUPERSTRUCTURE_INTERNAL_ELEMENTS,
    FINISHES,
    #[allow(non_camel_case_types)]
    BUILDING_SERVICES,
    #[allow(non_camel_case_types)]
    EXTERNAL_WORKS,
    #[allow(non_camel_case_types)]
    FF_E,
}

#[cfg(feature = "jsbindings")]
#[allow(non_snake_case)]
#[wasm_bindgen]
pub fn buildingModelScopes() -> Vec<BuildingModelScope> {
    BuildingModelScope::iter().collect()
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(
    feature = "jsbindings",
    derive(Tsify, EnumIter),
    tsify(into_wasm_abi, from_wasm_abi)
)]
#[cfg_attr(feature = "pybindings", pyclass(eq, eq_int))]
pub enum BuildingType {
    #[allow(non_camel_case_types)]
    NEW_CONSTRUCTION_WORKS,
    DEMOLITION,
    #[allow(non_camel_case_types)]
    DECONSTRUCTION_AND_NEW_CONSTRUCTION_WORKS,
    #[allow(non_camel_case_types)]
    RETROFIT_WORKS,
    #[allow(non_camel_case_types)]
    EXTENSION_WORKS,
    #[allow(non_camel_case_types)]
    RETROFIT_AND_EXTENSION_WORKS,
    #[allow(non_camel_case_types)]
    FIT_OUT_WORKS,
    OPERATIONS,
    UNKNOWN,
    OTHER,
}

#[cfg(feature = "jsbindings")]
#[allow(non_snake_case)]
#[wasm_bindgen]
pub fn buildingTypes() -> Vec<BuildingType> {
    BuildingType::iter().collect()
}

#[derive(Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(
    feature = "jsbindings",
    derive(Tsify, EnumIter),
    tsify(into_wasm_abi, from_wasm_abi)
)]
#[cfg_attr(feature = "pybindings", pyclass(eq, eq_int))]
pub enum BuildingTypology {
    OFFICE,
    RESIDENTIAL,
    PUBLIC,
    COMMERCIAL,
    INDUSTRIAL,
    INFRASTRUCTURE,
    AGRICULTURAL,
    EDUCATIONAL,
    HEALTH,
    UNKNOWN,
    OTHER,
}

#[cfg(feature = "jsbindings")]
#[allow(non_snake_case)]
#[wasm_bindgen]
pub fn buildingTypologies() -> Vec<BuildingTypology> {
    BuildingTypology::iter().collect()
}

impl From<&String> for BuildingTypology {
    fn from(unit: &String) -> Self {
        match unit.to_ascii_lowercase().as_str() {
            "office" => BuildingTypology::OFFICE,
            "residential" => BuildingTypology::RESIDENTIAL,
            "public" => BuildingTypology::PUBLIC,
            "commercial" => BuildingTypology::COMMERCIAL,
            "industrial" => BuildingTypology::INDUSTRIAL,
            "infrastructure" => BuildingTypology::INFRASTRUCTURE,
            "agricultural" => BuildingTypology::AGRICULTURAL,
            "educational" => BuildingTypology::EDUCATIONAL,
            "health" => BuildingTypology::HEALTH,
            _ => BuildingTypology::OTHER,
        }
    }
}