Skip to content

Commit

Permalink
update generate_api
Browse files Browse the repository at this point in the history
  • Loading branch information
samirdarouich committed Mar 5, 2024
1 parent 27a546f commit d957c60
Show file tree
Hide file tree
Showing 22 changed files with 1,202 additions and 1,673 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Generate sdRDM library
uses: JR-1991/generate-sdrdm-api@main
uses: JR-1991/generate-sdrdm-api@v3.1
with:
library_name: "FAIRFlowChemistry"
schema_path: "./specifications/datamodel.md"
4 changes: 2 additions & 2 deletions FAIRFlowChemistry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__URL__ = "https://github.com/FAIRChemistry/FAIRFlowChemistry"
__COMMIT__ = "8cd2a321d0f28e24e41c7a3ac5d90aa738b1646d"
__URL__ = ""
__COMMIT__ = ""
29 changes: 12 additions & 17 deletions FAIRFlowChemistry/core/calibration.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import sdRDM

import numpy as np
from typing import Dict, List, Optional
from pydantic import PrivateAttr, model_validator
from typing import List, Optional
from pydantic import model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from pydantic_xml import attr, element, wrapped
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict
from lxml.etree import _Element
from .data import Data


Expand Down Expand Up @@ -37,11 +36,14 @@ class Calibration(sdRDM.DataModel):
json_schema_extra=dict(),
)

regression_coefficients: List[float] = element(
description="regression coefficients in order of increasing degree.",
default_factory=ListPlus,
tag="regression_coefficients",
json_schema_extra=dict(multiple=True),
regression_coefficients: List[float] = wrapped(
"regression_coefficients",
element(
description="regression coefficients in order of increasing degree.",
default_factory=ListPlus,
tag="float",
json_schema_extra=dict(multiple=True),
),
)

degree: Optional[int] = element(
Expand All @@ -50,13 +52,6 @@ class Calibration(sdRDM.DataModel):
tag="degree",
json_schema_extra=dict(),
)
_repo: Optional[str] = PrivateAttr(
default="https://github.com/FAIRChemistry/FAIRFlowChemistry"
)
_commit: Optional[str] = PrivateAttr(
default="8cd2a321d0f28e24e41c7a3ac5d90aa738b1646d"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
Expand Down
81 changes: 57 additions & 24 deletions FAIRFlowChemistry/core/component.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import sdRDM

from typing import Dict, List, Optional
from pydantic import PrivateAttr, model_validator
from typing import List, Optional
from pydantic import model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from pydantic_xml import attr, element, wrapped
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict
from lxml.etree import _Element
from .genericattibute import GenericAttibute
from .componenttype import ComponentType

Expand Down Expand Up @@ -61,29 +60,63 @@ class Component(sdRDM.DataModel):
json_schema_extra=dict(),
)

generic_attributes: List[GenericAttibute] = element(
description="a generic attribute as defined by DEXPI.",
default_factory=ListPlus,
tag="generic_attributes",
json_schema_extra=dict(multiple=True),
generic_attributes: List[GenericAttibute] = wrapped(
"generic_attributes",
element(
description="a generic attribute as defined by DEXPI.",
default_factory=ListPlus,
tag="GenericAttibute",
json_schema_extra=dict(multiple=True),
),
)

connections: List[str] = element(
description=(
"component id of other component this component is connected to via pipes,"
" wires or similar."
connections: List[str] = wrapped(
"connections",
element(
description=(
"component id of other component this component is connected to via"
" pipes, wires or similar."
),
default_factory=ListPlus,
tag="string",
json_schema_extra=dict(multiple=True),
),
default_factory=ListPlus,
tag="connections",
json_schema_extra=dict(multiple=True),
)
_repo: Optional[str] = PrivateAttr(
default="https://github.com/FAIRChemistry/FAIRFlowChemistry"
)
_commit: Optional[str] = PrivateAttr(
default="8cd2a321d0f28e24e41c7a3ac5d90aa738b1646d"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

def add_to_generic_attributes(
self,
name: Optional[str] = None,
attribute_uri: Optional[str] = None,
value: Optional[str] = None,
format: Optional[str] = None,
units: Optional[str] = None,
units_uri: Optional[str] = None,
id: Optional[str] = None,
) -> GenericAttibute:
"""
This method adds an object of type 'GenericAttibute' to attribute generic_attributes
Args:
id (str): Unique identifier of the 'GenericAttibute' object. Defaults to 'None'.
name (): bla.. Defaults to None
attribute_uri (): bla.. Defaults to None
value (): bla.. Defaults to None
format (): bla.. Defaults to None
units (): bla.. Defaults to None
units_uri (): bla. Defaults to None
"""
params = {
"name": name,
"attribute_uri": attribute_uri,
"value": value,
"format": format,
"units": units,
"units_uri": units_uri,
}
if id is not None:
params["id"] = id
self.generic_attributes.append(GenericAttibute(**params))
return self.generic_attributes[-1]

@model_validator(mode="after")
def _parse_raw_xml_data(self):
Expand Down
31 changes: 13 additions & 18 deletions FAIRFlowChemistry/core/data.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import sdRDM

from typing import Optional, Union, List, Dict
from pydantic import PrivateAttr, model_validator
from typing import Optional, Union, List
from pydantic import model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from pydantic_xml import attr, element, wrapped
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.base.datatypes import Unit
from sdRDM.tools.utils import elem2dict
from datetime import datetime as Datetime
from sdRDM.base.datatypes import Unit
from lxml.etree import _Element
from .quantity import Quantity


Expand All @@ -31,11 +30,14 @@ class Data(sdRDM.DataModel):
json_schema_extra=dict(),
)

values: List[Union[float, str, Datetime]] = element(
description="values.",
default_factory=ListPlus,
tag="values",
json_schema_extra=dict(multiple=True),
values: List[Union[float, str, Datetime]] = wrapped(
"values",
element(
description="values.",
default_factory=ListPlus,
tag="float",
json_schema_extra=dict(multiple=True),
),
)

unit: Optional[Unit] = element(
Expand All @@ -44,13 +46,6 @@ class Data(sdRDM.DataModel):
tag="unit",
json_schema_extra=dict(),
)
_repo: Optional[str] = PrivateAttr(
default="https://github.com/FAIRChemistry/FAIRFlowChemistry"
)
_commit: Optional[str] = PrivateAttr(
default="8cd2a321d0f28e24e41c7a3ac5d90aa738b1646d"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
Expand Down
69 changes: 59 additions & 10 deletions FAIRFlowChemistry/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from typing import Dict, List, Optional
from pydantic import PrivateAttr, model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from pydantic_xml import attr, element, wrapped
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict
from .measurement import Measurement
from .plantsetup import PlantSetup
from lxml.etree import _Element
from .experiment import Experiment
from .speciesdata import SpeciesData
from .plantsetup import PlantSetup
from .measurement import Measurement


@forge_signature
Expand All @@ -31,13 +30,63 @@ class GeneralInformation(sdRDM.DataModel):
description: Optional[str] = element(
default=None, tag="description", json_schema_extra=dict()
)
_repo: Optional[str] = PrivateAttr(
default="https://github.com/FAIRChemistry/FAIRFlowChemistry"


@forge_signature
class Dataset(sdRDM.DataModel):
""""""

id: Optional[str] = attr(
name="id",
description="Unique identifier of the given object.",
default_factory=lambda: str(uuid4()),
xml="@id",
)
_commit: Optional[str] = PrivateAttr(
default="8cd2a321d0f28e24e41c7a3ac5d90aa738b1646d"

general_information: Optional[GeneralInformation] = element(
description=(
"general data about the datasetm like titel, project name, and description."
),
default_factory=GeneralInformation,
tag="general_information",
json_schema_extra=dict(),
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

experiments: List[Experiment] = wrapped(
"experiments",
element(
description="information about the individual experiment.",
default_factory=ListPlus,
tag="Experiment",
json_schema_extra=dict(multiple=True),
),
)

def add_to_experiments(
self,
plant_setup: Optional[PlantSetup] = None,
measurements: List[Measurement] = ListPlus(),
species_data: List[SpeciesData] = ListPlus(),
id: Optional[str] = None,
) -> Experiment:
"""
This method adds an object of type 'Experiment' to attribute experiments
Args:
id (str): Unique identifier of the 'Experiment' object. Defaults to 'None'.
plant_setup (): the individual plant setup that is used in this one experiment.. Defaults to None
measurements (): different measurements that are made within the scope of one experiment.. Defaults to ListPlus()
species_data (): all provided and calculated data about a specific species.. Defaults to ListPlus()
"""
params = {
"plant_setup": plant_setup,
"measurements": measurements,
"species_data": species_data,
}
if id is not None:
params["id"] = id
self.experiments.append(Experiment(**params))
return self.experiments[-1]

@model_validator(mode="after")
def _parse_raw_xml_data(self):
Expand Down
Loading

0 comments on commit d957c60

Please sign in to comment.