Skip to content
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

feat: add SQLModels for FlatAnwendungshandbuch; Add PoC for SQLite #557

Merged
merged 9 commits into from
Jan 29, 2025

Conversation

hf-kklein
Copy link
Contributor

No description provided.

from efoli import EdifactFormat, EdifactFormatVersion

# the models here do NOT inherit from the original models, because I didn't manage to fix the issue that arise:
# https://github.com/Hochfrequenz/kohlrahbi/issues/556
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +28 to +56
def _load_flat_ahb_to_db(
session: Session, json_path: Path, edifact_format: EdifactFormat, edifact_format_version: EdifactFormatVersion
) -> str:
"""returns the pruefi"""
# you may use this kind of function to eventually load _all_ AHBs into a DB
# if you e.g. check out our machine-readable AHB repository,
# for json_path in _mr_ahb_submodule_path.rglob("FV*/**/*.json"):
# with open(json_path, "r", encoding="utf-8") as json_file:
# edifact_format = EdifactFormat(json_path.parent.parent.name)
# edifact_format_version = EdifactFormatVersion(json_path.parent.parent.parent.name)
# _load_flat_ahb_to_db(...)
with open(json_path, "r", encoding="utf-8") as json_file:
file_body = json.loads(json_file.read())
flat_ahb = FlatAnwendungshandbuch.model_validate(file_body)
edifact_format = EdifactFormat.UTILMD
edifact_format_version = EdifactFormatVersion.FV2504
file_body["meta"]["edifact_format"] = str(edifact_format)
file_body["meta"]["edifact_format_version"] = str(edifact_format_version)
meta = AhbMetaInformation.model_validate(file_body["meta"])
session.add(meta)
flat_ahb.meta = meta
for line_index, raw_line in enumerate(file_body["lines"]):
raw_line["position_inside_ahb"] = line_index
line = AhbLine.model_validate(raw_line)
flat_ahb.lines.append(line)
session.add(line)
session.add(flat_ahb)
session.commit()
session.flush()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hamidhajiparvaneh weil du im daily danach gefragt hattest, wie die daten in die datenbank kommen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hf-kklein hf-kklein marked this pull request as ready for review January 29, 2025 11:59
@hf-kklein hf-kklein merged commit 4e34b8a into main Jan 29, 2025
8 checks passed
@hf-kklein hf-kklein deleted the sqlmodel branch January 29, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants