-
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.
Merge pull request #204 from hf-kklein/re-structure
chore: restructure model classes and functions into separate modules
- Loading branch information
Showing
10 changed files
with
193 additions
and
137 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""enums used inside the package""" | ||
|
||
from enum import Enum | ||
|
||
|
||
class Division(Enum): | ||
""" | ||
Allows to distinguish divisions used by German utilities, German "Sparte". | ||
""" | ||
|
||
STROM = 1 #: electricity | ||
GAS = 2 #: gas | ||
|
||
|
||
class DayType(str, Enum): | ||
""" | ||
An enum to differentiate between calendar days and working days. | ||
""" | ||
|
||
WORKING_DAY = "WT" #: working day, German "Werktag" | ||
CALENDAR_DAY = "KT" #: calendar day, German "Kalendertag" | ||
|
||
|
||
class EndDateType(Enum): | ||
""" | ||
An enum to distinguish inclusive and exclusive end dates. | ||
""" | ||
|
||
INCLUSIVE = 1 | ||
""" | ||
If a contract ends with the year 2022 and the end date is denoted as "2022-12-31", | ||
then the end date is inclusive. Most dates in human (spoken) communication are meant | ||
inclusively. | ||
""" | ||
|
||
EXCLUSIVE = 2 | ||
""" | ||
If a contract ends with the year 2022 and the end date is denoted as "2023-01-01", | ||
then the end date is exclusive. Most end dates handled by technical systems are meant | ||
exclusively. | ||
""" | ||
|
||
|
||
class MonthType(Enum): | ||
""" | ||
When calculating periods defined as 'nth working day of a month' the | ||
BNetzA regulations distinguish between two types of month which are | ||
modelled in this enum. | ||
Some periods refer to the "Liefermonat", others to the "Fristenmonat". | ||
""" | ||
|
||
LIEFERMONAT = 1 | ||
""" | ||
The "Liefermonat" is the month in which the supply starts. | ||
""" | ||
FRISTENMONAT = 2 | ||
""" | ||
The grid operators prefer a key date based handling of supply contracts. | ||
The key date in these cases is usually expressed as a specific working day | ||
in the so called "Fristenmonat". | ||
The "Fristenmonat" starts at the first day of the month | ||
_before_ the "Liefermonat". | ||
Quote: 'Nach der Festlegung BK6-06-009 (GPKE) der Monat vor dem Liefermonat.' | ||
""" | ||
# pylint:disable=line-too-long | ||
# source: https://www.bundesnetzagentur.de/DE/Beschlusskammern/1_GZ/BK6-GZ/_bis_2010/2006/BK6-06-009/BK6-06-009_Beschluss_download.pdf?__blob=publicationFile&v=5 | ||
|
||
|
||
__all__ = ["Division", "EndDateType", "MonthType", "DayType"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""static timezone object for Berlin/Germany""" | ||
|
||
from pytz import timezone | ||
|
||
GERMAN_TIME_ZONE = timezone("Europe/Berlin") | ||
__all__ = ["GERMAN_TIME_ZONE"] |
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,57 @@ | ||
"""model classes used in this package""" | ||
|
||
from dataclasses import dataclass | ||
from typing import Literal, Union | ||
|
||
from bdew_datetimes.enums import DayType, EndDateType | ||
|
||
_DayTyp = Union[DayType, Literal["WT", "KT"]] | ||
|
||
|
||
@dataclass | ||
class Period: | ||
""" | ||
A period is a German "Frist": A tuple that consists of a number of days and a day type. | ||
""" | ||
|
||
number_of_days: int | ||
""" | ||
number of days (might be any value <0, >0 or ==0) | ||
""" | ||
day_type: DayType | ||
""" | ||
the kind of days to add/subtract | ||
""" | ||
|
||
def __init__( | ||
self, | ||
number_of_days: int, | ||
day_type: _DayTyp, | ||
end_date_type: EndDateType = EndDateType.EXCLUSIVE, | ||
): | ||
""" | ||
Initialize the Period by providing a number of days and a day_type which define the period. | ||
""" | ||
self.number_of_days = number_of_days | ||
# If the Period is about something ending (e.g. a contract), then the user may | ||
# provide an end_date_type. | ||
# Internally we handle all end dates as exclusive, because: | ||
# https://hf-kklein.github.io/exclusive_end_dates.github.io/ | ||
if end_date_type == EndDateType.INCLUSIVE: | ||
if self.number_of_days > 0: | ||
self.number_of_days = self.number_of_days - 1 | ||
elif self.number_of_days < 0: | ||
self.number_of_days = self.number_of_days + 1 | ||
if isinstance(day_type, DayType): | ||
pass | ||
elif isinstance(day_type, str): | ||
day_type = DayType(day_type) | ||
else: | ||
raise ValueError( | ||
f"'{day_type}' is not an allowed value; Check the typing" | ||
) | ||
self.day_type: DayType = day_type | ||
|
||
|
||
__all__ = ["Period"] |
Oops, something went wrong.