-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move generator to formatter
Move the generator functionality to formatter as an index formatter.
- Loading branch information
Showing
10 changed files
with
113 additions
and
132 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
28 changes: 28 additions & 0 deletions
28
src/libecalc/presentation/exporter/configs/formatter_config.py
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,28 @@ | ||
import abc | ||
from typing import List | ||
|
||
from libecalc.presentation.exporter.formatters.formatter import IndexFormatter | ||
from libecalc.presentation.exporter.formatters.index_formatter import TimeIndexFormatter | ||
|
||
|
||
class FormatterConfig(abc.ABC): | ||
@staticmethod | ||
@abc.abstractmethod | ||
def get_row_index_formatters() -> List[IndexFormatter]: ... | ||
|
||
|
||
class TimeFormatterConfig(FormatterConfig): | ||
@staticmethod | ||
def get_row_index_formatters() -> List[IndexFormatter]: | ||
return [ | ||
TimeIndexFormatter( | ||
name="forecastYear", | ||
title="Years", | ||
time_format="%Y", | ||
), | ||
TimeIndexFormatter( | ||
name="forecastMonth", | ||
title="Months", | ||
time_format="%m", | ||
), | ||
] |
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
18 changes: 18 additions & 0 deletions
18
src/libecalc/presentation/exporter/formatters/formattable.py
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,18 @@ | ||
import abc | ||
from datetime import datetime | ||
from typing import Iterator, Protocol, Tuple, Union | ||
|
||
from libecalc.domain.tabular.tabular import HasColumns, Tabular | ||
|
||
|
||
class Formattable(Tabular, HasColumns, Protocol): ... | ||
|
||
|
||
class FormattableGroup(Protocol): | ||
@property | ||
@abc.abstractmethod | ||
def groups(self) -> Iterator[Tuple[str, Formattable]]: ... | ||
|
||
|
||
RowIndex = Union[str, int, float, datetime] | ||
ColumnIndex = Union[str] |
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
40 changes: 40 additions & 0 deletions
40
src/libecalc/presentation/exporter/formatters/index_formatter.py
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,40 @@ | ||
import abc | ||
from datetime import datetime | ||
|
||
from libecalc.presentation.exporter.formatters.formattable import RowIndex | ||
|
||
|
||
class IndexFormatter(abc.ABC): | ||
""" | ||
Index formatter can be used to format the index in a Formatter | ||
""" | ||
|
||
@abc.abstractmethod | ||
def format(self, index: RowIndex) -> str: ... | ||
|
||
@abc.abstractmethod | ||
def get_title(self) -> str: ... | ||
|
||
@abc.abstractmethod | ||
def get_id(self) -> str: ... | ||
|
||
|
||
class TimeIndexFormatter(IndexFormatter): | ||
def __init__( | ||
self, | ||
name: str, | ||
title: str, | ||
time_format: str, | ||
): | ||
self.name = name | ||
self.title = title | ||
self.time_format = time_format | ||
|
||
def get_id(self) -> str: | ||
return self.name | ||
|
||
def get_title(self) -> str: | ||
return self.title | ||
|
||
def format(self, index: datetime) -> str: | ||
return datetime.strftime(index, self.time_format) |
This file was deleted.
Oops, something went wrong.
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