Repository navigation
Change component data wrappers to be data classes - #4
Conversation
9589811 to
a22ab4a
Compare
|
I didn't go in detail through the PR yet, but my first impression is we really need to start specifying units. Is SoC in percentage? Is it in Wh, kWh? Etc. I opened a discussion so we don't derail about that in this PR: #6 |
|
Makes sense. Units are described in the protobuf messages, e.g. for Shall I copy these over from the protobuf message docstrings? |
Yes, please! Until we decide how to represent units better I think is a good idea to have it at least in the documentation. |
|
It looks like the commits are not cryptographically signed. Maybe because it was rebased from the UI? I wonder if we can get the DCO check to verify that the commits are signed, and not just that they have the "Signed-Off" line in the commit messages. |
leandro-lucarella-frequenz
left a comment
There was a problem hiding this comment.
I only made a comment on the first occurrence, but when/if fixed it should be fixed on all classes. (like add units to the documentation for all attributes, moving the component_id and timestamp documentation only to ComponentData, etc.)
The DCO bot is provided as is, but merging will be blocked if commits are not cryptographically signed, so having it on a check is not necessary (and it will be redundant in a way) |
|
@jakub-toptal BTW you can see the protobuf comments with less noise in the |
fe9a410 to
4df1d4d
Compare
4df1d4d to
e13f52a
Compare
|
Possible field descriptions: batterysoc_lower_bound: the SoC below which discharge commands will be blocked by the system. inverteractive_power_lower_bound: the maximum discharge power, in Watts, represented in the passive sign convention. This will be a negative number, or zero if no discharging is possible. everywhereactive_power: the 3-phase active power, in Watts, represented in the passive sign convention. |
e13f52a to
5e192cb
Compare
leandro-lucarella-frequenz
left a comment
There was a problem hiding this comment.
Also minor, but I would add a (W) for Watt too (as in in Watt (W)), like with Volt and Ampere, just for consistency.
5e192cb to
6749c09
Compare
6749c09 to
33dea98
Compare
|
Marking this as blocked because until we have a decision on how the pipeline should work, we can't really decide on this one. |
This doesn't really affect the data pipeline. It doesn't change anything, except for making the wrapper classes for If for some reason we decide that the representation needs to change in the context of the data pipeline, we can just change dataclass-based classes instead of property-based classes. |
|
Well, is adding more processing each time you receive a message, because now you need to construct a dataclass for each grpc message. So I agree is nicer to work with in general but if we don't expect users to work with them directly, there is little value in adding the extra processing. And it does change something, how these objects are constructed, so it is even a breaking change (although I'm not sure if anybody else is using it). It is IMHO an unnecessary change if these classes won't be omnipresent in the data pipeline or higher levels, this is why I think we should keep it on hold for now. |
|
The documentation improvements are quite nice though, that might also lean the balance towards merging it anyways :D @ela-kotulska-frequenz @sahas-subramanian-frequenz any opinions on this? Do you know if these classes are constructed somewhere else outside of the SDK (so if the breaking change has any impact)? |
33dea98 to
ff70fb4
Compare
|
@ela-kotulska-frequenz @sahas-subramanian-frequenz please let us know what you think. If this is not a breaking change for our current SDK users, I'd go for it, because it makes it easier to work with, especially in tests. New classes don't need to be provided a protobuf message with raw data. Look at this example: we have to create a quite complex protobuf message to get an instance of |
We can always break things! Please don't take existing code into account. Its not important. |
ff70fb4 to
005f85b
Compare
Performance wise, they are both equal. But it does make writing tests easier. But we're losing the ability to get unexported fields from just If we drop |
005f85b to
2a96604
Compare
| def component_id(self) -> int: | ||
| """Return the component id of the message. | ||
| @staticmethod | ||
| def _set_raw(obj: ComponentData, raw: microgrid_pb.ComponentData) -> None: |
There was a problem hiding this comment.
Why does this have to be a static method?
It is cleaner to make it an instance method that takes self.
| self._raw = raw | ||
| obj.__dict__["_raw"] = raw |
There was a problem hiding this comment.
Why like this?
Why raw can't be passed in constructor?
There was a problem hiding this comment.
Because the idea was to exclude it from the constructor. If you want to instantiate from raw protobuf message, you would you BatteryData.from_proto(raw) instead.
There was a problem hiding this comment.
_raw has to be optional, because we want to use these structs for the output from resampling actor, and it would make tests easier.
We also want to put _raw in the base class (ComponentData). Because these are all data classes with default __init__ methods, If we do that and take it as an optional constructor parameter, it means all derived classes will have broken default constructors i.e params with default arguments appearing before params without default arguments.
The easy workaround for all of these is to have a special method for setting the _raw param.
There was a problem hiding this comment.
This workaround should be very well documented, because is a hack that on the first sight look terribly wrong, is not trivial to realize why this is needed.
There was a problem hiding this comment.
Added more verbose documentation.
There was a problem hiding this comment.
Great, thanks!
7bb8745 to
da74bb7
Compare
leandro-lucarella-frequenz
left a comment
There was a problem hiding this comment.
Just a few minor last comments. Unblocking as the general feeling is this is worth it despite what happens with the individual metrics.
| Keep the dataclass frozen, but bypass it here to store the raw protobuf | ||
| message for in case it was needed later. |
There was a problem hiding this comment.
Here also please be a bit more verbose, mention which alternatives we considered and why we decided for this approach.
There was a problem hiding this comment.
Done. Let me know if that's enough or sth else should be mentioned.
There was a problem hiding this comment.
LGTM, thanks!
| @property | ||
| def timestamp(self) -> datetime: | ||
| """Return the timestamp of the message. | ||
| def _set_raw(self, raw: microgrid_pb.ComponentData) -> None: |
There was a problem hiding this comment.
This should stay protected, as we don't want users calling this themselves. For the users raw is still read-only.
There was a problem hiding this comment.
I know that we don't want users to call this method, but what do you mean by protected? We cannot really make this method inaccessible to the users. The only thing we can do is to make it a private method, which it already is.
There was a problem hiding this comment.
just using a leading _, that's the convention in python. :)
I was just clarifying that even if raw should drop the _, this method shouldn't.
Signed-off-by: Jakub Kozlowicz <jakub.kozlowicz@gmail.com>
Signed-off-by: Jakub Kozlowicz <jakub.kozlowicz@gmail.com>
da74bb7 to
6bd9212
Compare
No description provided.