-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.