Open chicco785 opened 1 month ago
@chicco785 I have a question: What are the advantages of using the CIMdatatype (eg. CurrentFlow) as an annotation (option A) rather than using the class that is currently defined as a true data type (option B)?
CurrentFlow = CIMDatatype(name="CurrentFlow", type=float, symbol=UnitSymbol.A, multiplier=UnitMultiplier.none, profiles=[Profile.EQ,Profile.SC,Profile.SSH,Profile.SV,])
@dataclass
class CurrentLimit(OperationalLimit):
"""
Operational limit on current.
normalValue: The normal value for limit on current flow. The attribute shall be a positive value or zero.
value: Limit on current flow. The attribute shall be a positive value or zero.
"""
normalValue : float = Field(default=0.0, data_type = CurrentFlow, json_schema_extra={"in_profiles":[Profile.EQ, ]})
value : float = Field(default=0.0, data_type = CurrentFlow, json_schema_extra={"in_profiles":[Profile.SSH, ]})
@cached_property
def possible_profiles(self)->set[BaseProfile]:
"""
A resource can be used by multiple profiles. This is the set of profiles
where this element can be found.
"""
return { Profile.EQ, Profile.SSH, }
@dataclass
class CurrentFlow(Base):
"""
Electrical current with sign convention: positive flow is out of the conducting equipment into the connectivity
node. Can be both AC and DC.
multiplier:
unit:
value:
"""
multiplier : Optional[str] = Field(default=None, json_schema_extra={"in_profiles":[Profile.DY, Profile.EQ, Profile.SV, Profile.SSH, ]})
unit : Optional[str] = Field(default=None, json_schema_extra={"in_profiles":[Profile.DY, Profile.EQ, Profile.SV, Profile.SSH, ]})
value : float = Field(default=0.0, json_schema_extra={"in_profiles":[Profile.DY, Profile.EQ, Profile.SV, Profile.SSH, ]})
@dataclass
class CurrentLimit(OperationalLimit):
"""
Operational limit on current.
normalValue: The normal value for limit on current flow. The attribute shall be a positive value or zero.
value: Limit on current flow. The attribute shall be a positive value or zero.
"""
normalValue : CurrentFlow= Field(default=0.0, json_schema_extra={"in_profiles":[Profile.EQ, ]})
value : CurrentFlow= Field(default=0.0, json_schema_extra={"in_profiles":[Profile.SSH, ]})
@cached_property
def possible_profiles(self)->set[BaseProfile]:
"""
A resource can be used by multiple profiles. This is the set of profiles
where this element can be found.
"""
return { Profile.EQ, Profile.SSH, }
To me option B seems to be a more "logical" use of a datatype but I am probably missing something :)
what i was proposing is A, mostly because a datatype is static, i.e. the assigned unit symbol or multiplier do not change. i.e. in the end this is a specialisation of Float, string or something else.
while also in B you could make the unit and the multiplier, "static" i would be highly redundant, and probably make serialisation more complex (you may end up with a lot of chinese boxes)
ps: "data_type" = CurrentFlow
should go in json_schema_extra
otherwise it don't think it will work for Pydantic
Is your feature request related to a problem? Please describe the problem.
The current models get generated as follows, for example:
First, CurrentFlow is dataType, so generating a class that then is never used by actual cim classes is not much of use. This should become an annotation to the field of related classes, making easier validation, serialisation, ect.
Secondly, in the RDF schema is well defined
CurrentFlow
unit isA
, while the generated class allows for every string (not even a string in a range):Thirdly, it does not make sense that we generate a class for
UnitSymbol
:when it is an Enum with well defined values.
Describe the solution you'd like
Generate UnitSymbol and other
<cims:stereotype rdf:resource="http://iec.ch/TC57/NonStandard/UML#enumeration"/>
Create datatypes and annotate them in models.
Additional context
Example of what could look like a generated
CurrentFlow
in the new way: