Skip to content

Commit

Permalink
feat(time conditions): add ub packages (#441)
Browse files Browse the repository at this point in the history
* WIP

* Fix tests 1

* added tests

* fixed for linter and typecheck

* removed unused import

* reworked sorting of packages dict
  • Loading branch information
DeltaDaniel authored Sep 11, 2024
1 parent c90893b commit 5737de4
Show file tree
Hide file tree
Showing 11 changed files with 10,542 additions and 78 deletions.
2 changes: 1 addition & 1 deletion dev_requirements/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ python-dateutil==2.9.0.post0
# pandas
python-docx==1.1.2
# via kohlrahbi (pyproject.toml)
pytz==2024.1
pytz==2024.2
# via
# efoli
# kohlrahbi (pyproject.toml)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ load-plugins = "pylint_pydantic"

[tool.pytest.ini_options]
pythonpath = ["."]
markers = ["snapshot: mark a test as a snapshot test"]
19 changes: 15 additions & 4 deletions src/kohlrahbi/ahbtable/ahbpackagetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def provide_packages(self, edifact_format: EdifactFormat) -> None:
for _, row in self.table.iterrows():
package = row["Paket"]
# Use re.search to find the first match
match = re.search(r"\[(\d+)P\]", package)
match = re.search(r"\[(\d+P)\]", package)
if not match:
raise ValueError("No valid package key found in the package column.")
# Extract the matched digits
package = match.group(1)
if package != "1":
if package != "1P":
package_conditions = row["Paketvoraussetzung(en)"].strip()
# check whether package was already collected:
existing_text = package_dict[edifact_format].get(package)
Expand Down Expand Up @@ -105,14 +105,25 @@ def dump_as_json(self, output_directory_path: Path) -> None:
The file will be stored in the directory:
'output_directory_path/<edifact_format>/conditions.json'
"""
package_suffix = "P"
package_prefix = "UB"
for edifact_format, format_pkg_dict in self.package_dict.items():
package_json_output_directory_path = output_directory_path / str(edifact_format)
package_json_output_directory_path.mkdir(parents=True, exist_ok=True)
file_path = package_json_output_directory_path / "packages.json"
# resort PackageKeyConditionTextMappings for output
sorted_package_dict = {k: format_pkg_dict[k] for k in sorted(format_pkg_dict, key=int)}
package_dict_p = {k: v for k, v in format_pkg_dict.items() if k.endswith(package_suffix)}
package_dict_ub = {k: v for k, v in format_pkg_dict.items() if k.startswith(package_prefix)}
sorted_package_dict_p = {
k: package_dict_p[k] for k in sorted(package_dict_p, key=lambda x: int(x[: -len(package_suffix)]))
}
sorted_package_dict_ub = {
k: package_dict_ub[k] for k in sorted(package_dict_ub, key=lambda x: int(x[len(package_prefix) :]))
}

sorted_package_dict = {**sorted_package_dict_ub, **sorted_package_dict_p}
array = [
{"package_key": i + "P", "package_expression": sorted_package_dict[i], "edifact_format": edifact_format}
{"package_key": i, "package_expression": sorted_package_dict[i], "edifact_format": edifact_format}
for i in sorted_package_dict
]
with open(file_path, "w", encoding="utf-8") as file:
Expand Down
3 changes: 3 additions & 0 deletions src/kohlrahbi/conditions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from kohlrahbi.ahb import get_pruefi_to_file_mapping
from kohlrahbi.ahbtable.ahbcondtions import AhbConditions
from kohlrahbi.ahbtable.ahbpackagetable import AhbPackageTable
from kohlrahbi.conditions.allgemeine_festlegungen import time_conditions, time_packages
from kohlrahbi.logger import logger
from kohlrahbi.read_functions import get_all_conditions_from_doc

Expand Down Expand Up @@ -55,5 +56,7 @@ def scrape_conditions(
collected_conditions.include_condition_dict(packages.provide_conditions(edifact_format))
collected_packages.include_package_dict(packages.package_dict)
collected_conditions.include_condition_dict(cond_table.conditions_dict)
collected_conditions.include_condition_dict({edifact_format: time_conditions})
collected_packages.include_package_dict({edifact_format: time_packages})
collected_conditions.dump_as_json(output_path)
collected_packages.dump_as_json(output_path)
20 changes: 20 additions & 0 deletions src/kohlrahbi/conditions/allgemeine_festlegungen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# pylint: disable=line-too-long
"""
Contains conditions for times in allgemeine Festlegungen.
"""
time_packages = {
"UB1": "([931] ∧ [932] [490]) ⊻ ([931] ∧ [933] [491])",
"UB2": "([931] ∧ [934] [490]) ⊻ ([931] ∧ [935] [491])",
"UB3": "([931] ∧ [932] [492] ∧ [490]) ⊻ ([931] ∧ [933] [492] ∧ [491]) ⊻ ([931] ∧ [934] [493] ∧ [490]) ⊻ ([931] ∧ [935] [493] ∧ [491])",
}
time_conditions = {
"490": "wenn Wert in diesem DE, an der Stelle CCYYMMDDHHMM ein Zeitpunkt aus dem angegeben Zeitraum der Tabelle Kapitel 3.5 „Übersicht gesetzliche deutsche Sommerzeit (MESZ)“ der Spalten:\n\t„Sommerzeit (MESZ) von“ Darstellung in UTC und\n\t„Sommerzeit (MESZ) bis“ Darstellung in UTC ist.",
"491": "wenn Wert in diesem DE, an der Stelle CCYYMMDDHHMM ein Zeitpunkt aus dem angegeben Zeitraum der Tabelle Kapitel 3.6 „Übersicht gesetzliche deutsche Zeit (MEZ)“ der Spalten: \n\t„Winterzeit (MEZ) von“ Darstellung in UTC und\n\t„Winterzeit (MEZ) bis“ Darstellung in UTC ist.",
"492": "wenn MP-ID in NAD+MR aus Sparte Strom",
"493": "wenn MP-ID in NAD+MR aus Sparte Gas",
"931": "Format: ZZZ = +00",
"932": "Format: HHMM = 2200",
"933": "Format: HHMM = 2300",
"934": "Format: HHMM = 0400",
"935": "Format: HHMM = 0500",
}
3 changes: 3 additions & 0 deletions unittests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from pathlib import Path

from efoli import EdifactFormat

path_to_test_edi_energy_mirror_repo: Path = Path(__file__).parent / "test-edi-energy-mirror-repo"
path_to_test_files_fv2310 = path_to_test_edi_energy_mirror_repo / "edi_energy_de" / Path("FV2310")
# list of pruefis to check against in test_current_state
Expand Down Expand Up @@ -95,3 +97,4 @@
"55213",
"55555",
]
test_formats = [EdifactFormat.ORDCHG, EdifactFormat.ORDRSP, EdifactFormat.IFTSTA, EdifactFormat.IFTSTA]
Loading

0 comments on commit 5737de4

Please sign in to comment.