-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: made it optional to whether convert_ilcd should return string, …
…dict or pydantic
- Loading branch information
Showing
10 changed files
with
169 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ docs/schemas | |
.vscode | ||
.idea | ||
/site/ | ||
/.venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
|
||
from .epdx import * | ||
from .pydantic import * | ||
|
||
__doc__ = epdx.__doc__ | ||
if hasattr(epdx, "__all__"): | ||
__all__ = epdx.__all__ | ||
|
||
|
||
def convert_ilcd(data: str, *, as_type: str = "dict"): | ||
""" | ||
Converts a json formatted ILCD+EPD data into EPDx | ||
The EPDx data can either be returned as a string, a dict or a Pydantic class. | ||
""" | ||
|
||
try: | ||
_epd = epdx._convert_ilcd(data) | ||
except Exception as err: | ||
raise ParsingException(err) | ||
|
||
if as_type == "str": | ||
return _epd | ||
elif as_type == "dict": | ||
return json.loads(_epd) | ||
elif as_type == "pydantic": | ||
return EPD(**json.loads(_epd)) | ||
else: | ||
raise NotImplemented("Currently only 'dict', 'str' and 'pydantic' is implemented as_type.") | ||
|
||
|
||
class ParsingException(Exception): | ||
... |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
def _convert_ilcd(data: str) -> str: | ||
"""Converts a json formatted ILCD+EPD data string into an EPDx formatted json string""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# generated by datamodel-codegen: | ||
# filename: epdx.schema.json | ||
# timestamp: 2024-01-23T14:25:59+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
from enum import Enum | ||
from typing import List, Optional | ||
|
||
from pydantic import BaseModel, conint | ||
|
||
|
||
class ImpactCategory(BaseModel): | ||
a1a3: Optional[float] = None | ||
a4: Optional[float] = None | ||
a5: Optional[float] = None | ||
b1: Optional[float] = None | ||
b2: Optional[float] = None | ||
b3: Optional[float] = None | ||
b4: Optional[float] = None | ||
b5: Optional[float] = None | ||
b6: Optional[float] = None | ||
b7: Optional[float] = None | ||
c1: Optional[float] = None | ||
c2: Optional[float] = None | ||
c3: Optional[float] = None | ||
c4: Optional[float] = None | ||
d: Optional[float] = None | ||
|
||
|
||
class Standard(Enum): | ||
EN15804A1 = 'EN15804A1' | ||
EN15804A2 = 'EN15804A2' | ||
UNKNOWN = 'UNKNOWN' | ||
|
||
|
||
class SubType(Enum): | ||
Generic = 'Generic' | ||
Specific = 'Specific' | ||
Industry = 'Industry' | ||
Representative = 'Representative' | ||
|
||
|
||
class Unit(Enum): | ||
M = 'M' | ||
M2 = 'M2' | ||
M3 = 'M3' | ||
KG = 'KG' | ||
TONES = 'TONES' | ||
PCS = 'PCS' | ||
L = 'L' | ||
M2R1 = 'M2R1' | ||
UNKNOWN = 'UNKNOWN' | ||
|
||
|
||
class Conversion(BaseModel): | ||
to: Unit | ||
value: float | ||
|
||
|
||
class EPD(BaseModel): | ||
adpe: Optional[ImpactCategory] = None | ||
adpf: Optional[ImpactCategory] = None | ||
ap: Optional[ImpactCategory] = None | ||
comment: Optional[str] = None | ||
conversions: Optional[List[Conversion]] = None | ||
cru: Optional[ImpactCategory] = None | ||
declared_unit: Unit | ||
eee: Optional[ImpactCategory] = None | ||
eet: Optional[ImpactCategory] = None | ||
ep: Optional[ImpactCategory] = None | ||
format_version: str | ||
fw: Optional[ImpactCategory] = None | ||
gwp: Optional[ImpactCategory] = None | ||
hwd: Optional[ImpactCategory] = None | ||
id: str | ||
location: str | ||
mer: Optional[ImpactCategory] = None | ||
mrf: Optional[ImpactCategory] = None | ||
name: str | ||
nhwd: Optional[ImpactCategory] = None | ||
nrsf: Optional[ImpactCategory] = None | ||
odp: Optional[ImpactCategory] = None | ||
penre: Optional[ImpactCategory] = None | ||
penrm: Optional[ImpactCategory] = None | ||
penrt: Optional[ImpactCategory] = None | ||
pere: Optional[ImpactCategory] = None | ||
perm: Optional[ImpactCategory] = None | ||
pert: Optional[ImpactCategory] = None | ||
pocp: Optional[ImpactCategory] = None | ||
published_date: datetime | ||
reference_service_life: Optional[conint(ge=0)] = None | ||
rsf: Optional[ImpactCategory] = None | ||
rwd: Optional[ImpactCategory] = None | ||
sm: Optional[ImpactCategory] = None | ||
source: Optional[str] = None | ||
standard: Standard | ||
subtype: SubType | ||
valid_until: datetime | ||
version: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters