-
Notifications
You must be signed in to change notification settings - Fork 5
Implement BO Zeitreihe #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2c30503
Implement BO Zeitreihe
hf-kklein a5f9c31
ignore too many instance attributes
hf-kklein 8baff88
ignore import without type
hf-kklein 8c46666
ignore type check in test
hf-kklein ac3f48e
Merge branch 'master' into zeitreihe
hf-kklein ffeda69
remove dead code
hf-kklein a87cf53
Update src/bo4e/bo/zeitreihe.py
hf-kklein bd5af33
Merge branch 'master' into zeitreihe
hf-kklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,78 @@ | ||
| """ | ||
| Contains Zeitreihe class and corresponding marshmallow schema for de-/serialization | ||
| """ | ||
| from typing import List, Optional | ||
|
|
||
| import attr | ||
| from marshmallow import fields | ||
| from marshmallow_enum import EnumField # type:ignore[import] | ||
|
|
||
| from bo4e.bo.geschaeftsobjekt import Geschaeftsobjekt, GeschaeftsobjektSchema | ||
| from bo4e.com.zeitreihenwert import Zeitreihenwert, ZeitreihenwertSchema | ||
| from bo4e.enum.botyp import BoTyp | ||
| from bo4e.enum.medium import Medium | ||
| from bo4e.enum.mengeneinheit import Mengeneinheit | ||
| from bo4e.enum.messart import Messart | ||
| from bo4e.enum.messgroesse import Messgroesse | ||
| from bo4e.enum.wertermittlungsverfahren import Wertermittlungsverfahren | ||
| from bo4e.validators import check_list_length_at_least_one | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods, too-many-instance-attributes | ||
| @attr.s(auto_attribs=True, kw_only=True) | ||
| class Zeitreihe(Geschaeftsobjekt): | ||
| """ | ||
| Abbildung einer allgemeinen Zeitreihe mit einem Wertvektor. | ||
| Die Werte können mit wahlfreier zeitlicher Distanz im Vektor abgelegt sein. | ||
| """ | ||
|
|
||
| # required attributes | ||
| bo_typ: BoTyp = attr.ib(default=BoTyp.ZEITREIHE) | ||
| #: Bezeichnung für die Zeitreihe | ||
| bezeichnung: str = attr.ib(validator=attr.validators.instance_of(str)) | ||
| #: Beschreibt, was gemessen wurde (z.B. Strom, Spannung, Wirkleistung, Scheinleistung) | ||
| messgroesse: Messgroesse = attr.ib(validator=attr.validators.instance_of(Messgroesse)) | ||
| #: Beschreibt die Art der Messung (z.B. aktueller Wert, mittlerer Wert, maximaler Wert) | ||
| messart: Messart = attr.ib(validator=attr.validators.instance_of(Messart)) | ||
| #: Medium, das gemessen wurde (z.B. Wasser, Dampf, Strom, Gas) | ||
| medium: Medium = attr.ib(validator=attr.validators.instance_of(Medium)) | ||
| #: Alle Werte in der Tabelle haben die Einheit, die hier angegeben ist | ||
| einheit: Mengeneinheit = attr.ib(validator=attr.validators.instance_of(Mengeneinheit)) | ||
|
|
||
| #: Hier liegen jeweils die Werte | ||
| werte: List[Zeitreihenwert] = attr.ib( | ||
| validator=attr.validators.deep_iterable( | ||
| member_validator=attr.validators.instance_of(Zeitreihenwert), | ||
| iterable_validator=check_list_length_at_least_one, | ||
| ) | ||
| ) | ||
| # optional attributes | ||
| #: Beschreibt die Verwendung der Zeitreihe | ||
| beschreibung: Optional[str] = attr.ib( | ||
| default=None, validator=attr.validators.optional(attr.validators.instance_of(str)) | ||
| ) | ||
| #: Version der Zeitreihe | ||
| version: Optional[str] = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(str))) | ||
| #: Kennzeichnung, wie die Werte entstanden sind, z.B. durch Messung | ||
| wertherkunft: Optional[Wertermittlungsverfahren] = attr.ib( | ||
| default=None, validator=attr.validators.optional(attr.validators.instance_of(Wertermittlungsverfahren)) | ||
| ) | ||
|
|
||
|
|
||
| class ZeitreiheSchema(GeschaeftsobjektSchema): | ||
| """ | ||
| Schema for de-/serialization of Zeitreihe | ||
| """ | ||
|
|
||
| class_name = Zeitreihe | ||
| bezeichnung = fields.Str() | ||
| messgroesse = EnumField(Messgroesse) | ||
| messart = EnumField(Messart) | ||
| medium = EnumField(Medium) | ||
| einheit = EnumField(Mengeneinheit) | ||
| werte = fields.List(fields.Nested(ZeitreihenwertSchema)) | ||
|
|
||
| # optional attributes | ||
| beschreibung = fields.Str(load_default=None) | ||
| version = fields.Str(load_default=None) | ||
| wertherkunft = EnumField(Wertermittlungsverfahren, load_default=None) | ||
This file contains hidden or 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,39 @@ | ||
| import pytest # type:ignore[import] | ||
|
|
||
| from bo4e.bo.zeitreihe import Zeitreihe, ZeitreiheSchema | ||
| from bo4e.enum.medium import Medium | ||
| from bo4e.enum.mengeneinheit import Mengeneinheit | ||
| from bo4e.enum.messart import Messart | ||
| from bo4e.enum.messgroesse import Messgroesse | ||
| from bo4e.enum.wertermittlungsverfahren import Wertermittlungsverfahren | ||
| from tests.serialization_helper import assert_serialization_roundtrip # type:ignore[import] | ||
| from tests.test_zeitreihenwert import example_zeitreihenwert # type:ignore[import] | ||
|
|
||
|
|
||
| class TestZeitreihe: | ||
| @pytest.mark.parametrize( | ||
| "zeitreihe", | ||
| [ | ||
| pytest.param( | ||
| Zeitreihe( | ||
| bezeichnung="Foo", | ||
| beschreibung="Bar", | ||
| version="0.0.1", | ||
| messgroesse=Messgroesse.BLINDLEISTUNG, | ||
| messart=Messart.MAXIMALWERT, | ||
| medium=Medium.STROM, | ||
| einheit=Mengeneinheit.KVARH, | ||
| wertherkunft=Wertermittlungsverfahren.MESSUNG, | ||
| werte=[example_zeitreihenwert], | ||
| ) | ||
| ), | ||
| ], | ||
| ) | ||
| def test_serialization_roundtrip(self, zeitreihe: Zeitreihe): | ||
| assert_serialization_roundtrip(zeitreihe, ZeitreiheSchema()) | ||
|
|
||
| def test_missing_required_attribute(self): | ||
| with pytest.raises(TypeError) as excinfo: | ||
| _ = Zeitreihe() | ||
|
|
||
| assert "missing 6 required" in str(excinfo.value) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.