rebdhuhn


Namerebdhuhn JSON
Version 0.2.3 PyPI version JSON
download
home_pageNone
SummaryConverts (already scraped) Entscheidungsbaumdiagramm tables to real graphs
upload_time2024-05-03 08:52:07
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseGPL
keywords ahb automation bdew edi@energy
VCS
bugtrack_url
requirements attrs cattrs certifi charset-normalizer idna lxml networkx requests svgutils urllib3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # rebdhuhn

![Unittests status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Unittests/badge.svg)
![Coverage status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Coverage/badge.svg)
![Linting status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Linting/badge.svg)
![Black status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Black/badge.svg)
![PyPi Status Badge](https://img.shields.io/pypi/v/rebdhuhn)

🇩🇪 Dieses Repository enthält ein Python-Paket namens [`rebdhuhn`](https://pypi.org/project/rebdhuhn) (früher: `ebdtable2graph`), das genutzt werden kann, um aus .docx-Dateien extrahierte maschinenlesbare Tabellen, die einen Entscheidungsbaum (EBD) modellieren, in echte Graphen zu konvertieren. Diese Entscheidungsbäume sind Teil eines regulatorischen Regelwerks für die deutsche Energiewirtschaft und kommen in der Eingangsprüfung der Marktkommunikation zum Einsatz.

🇬🇧 This repository contains the source code of the Python package [`rebdhuhn`](https://pypi.org/project/rebdhuhn) (formerly known as `ebdtable2graph`).

## Rationale

Assume, that you scraped the Entscheidungsbaumdiagramm tables by EDI@Energy from their somewhat "digitized" PDF/DOCX files.
(To do so, you can use the package [`ebdamame`](https://github.com/Hochfrequenz/ebdamame) (was: 'ebddocx2table`).)
Also assume, that the result of your scraping is a [`rebdhuhn.models.EbdTable`](src/rebdhuhn/models/ebd_table.py).

The package `rebdhuhn` contains logic to convert your scraped data into a graph.
This graph can then be exported e.g. as SVG and/or UML.

## How to use `rebdhuhn`?

Install the package from pypi:

```bash
pip install rebdhuhn
```

### Create an Instance of `EbdTable`

`EbdTable` contains the raw data by BDEW in a machine-readable format.
Creating instances of `EbdTable` is out of scope for this package.
Ask Hochfrequenz for support on this topic.
In the following example we hard code the information.

```python
from rebdhuhn.graph_conversion import convert_table_to_graph
from rebdhuhn.models import EbdCheckResult, EbdTable, EbdTableMetaData, EbdTableRow, EbdTableSubRow, EbdGraph

ebd_table: EbdTable  # this is the result of scraping the docx file
ebd_table = EbdTable(  # this data shouldn't be handwritten
    metadata=EbdTableMetaData(
        ebd_code="E_0003",
        chapter="7.39 AD: Bestellung der Aggregationsebene der Bilanzkreissummenzeitreihe auf Ebene der Regelzone",
        sub_chapter="7.39.1 E_0003_Bestellung der Aggregationsebene RZ prüfen",
        role="ÜNB",
    ),
    rows=[
        EbdTableRow(
            step_number="1",
            description="Erfolgt der Eingang der Bestellung fristgerecht?",
            sub_rows=[
                EbdTableSubRow(
                    check_result=EbdCheckResult(result=False, subsequent_step_number=None),
                    result_code="A01",
                    note="Fristüberschreitung",
                ),
                EbdTableSubRow(
                    check_result=EbdCheckResult(result=True, subsequent_step_number="2"),
                    result_code=None,
                    note=None,
                ),
            ],
        ),
        EbdTableRow(
            step_number="2",
            description="Erfolgt die Bestellung zum Monatsersten 00:00 Uhr?",
            sub_rows=[
                EbdTableSubRow(
                    check_result=EbdCheckResult(result=False, subsequent_step_number=None),
                    result_code="A02",
                    note="Gewählter Zeitpunkt nicht zulässig",
                ),
                EbdTableSubRow(
                    check_result=EbdCheckResult(result=True, subsequent_step_number="Ende"),
                    result_code=None,
                    note=None,
                ),
            ],
        ),
    ],
)
assert isinstance(ebd_table, EbdTable)

ebd_graph = convert_table_to_graph(ebd_table)
assert isinstance(ebd_graph, EbdGraph)
```

#### Export as PlantUML

```python
from rebdhuhn import convert_graph_to_plantuml

plantuml_code = convert_graph_to_plantuml(ebd_graph)
with open("e_0003.puml", "w+", encoding="utf-8") as uml_file:
    uml_file.write(plantuml_code)
```

The file `e_0003.puml` now looks like this:

```puml
@startuml
...
if (<b>1: </b> Erfolgt der Eingang der Bestellung fristgerecht?) then (ja)
else (nein)
    :A01;
    note left
        Fristüberschreitung
    endnote
    kill;
endif
if (<b>2: </b> Erfolgt die Bestellung zum Monatsersten 00:00 Uhr?) then (ja)
    end
else (nein)
    :A02;
    note left
        Gewählter Zeitpunkt nicht zulässig
    endnote
    kill;
endif
@enduml
```

#### Export the graph as SVG

First, make sure to have a local instance of [kroki](https://kroki.io) up and running via docker (localhost:8125):

Add the required `.env` file to the repository root by opening a new terminal session, changing the directory to
```bash
cd path\to\rebdhuhn\repository\root
```
and executing the `create_env_file.py` script via
```bash
python create_env_file.py
```
Run the `docker-desktop` app on your local maschine and host the local kroki instance on PORT `8125` via
```bash
docker-compose up -d
```

To export the graph as SVG, use
```python
from rebdhuhn import convert_plantuml_to_svg_kroki

svg_code = convert_plantuml_to_svg_kroki(plantuml_code)
with open("e_0003.svg", "w+", encoding="utf-8") as svg_file:
    svg_file.write(svg_code)
```

![](mwe_e0003.svg)

## How to use this Repository on Your Machine (for development)

Please follow the instructions in
our [Python Template Repository](https://github.com/Hochfrequenz/python_template_repository#how-to-use-this-repository-on-your-machine)
. And for further information, see the [Tox Repository](https://github.com/tox-dev/tox).

## Contribute

You are very welcome to contribute to this template repository by opening a pull request against the main branch.

## Related Tools and Context

This repository is part of the [Hochfrequenz Libraries and Tools for a truly digitized market communication](https://github.com/Hochfrequenz/digital_market_communication/).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "rebdhuhn",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "ahb, automation, bdew, edi@energy",
    "author": null,
    "author_email": "Hochfrequenz Unternehmensberatung GmbH <info@hochfrequenz.de>",
    "download_url": "https://files.pythonhosted.org/packages/f4/33/8ae5f1bcbfbe8df284f535c8a524aa655ed56cb2a20cf332c1d237397251/rebdhuhn-0.2.3.tar.gz",
    "platform": null,
    "description": "# rebdhuhn\n\n![Unittests status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Unittests/badge.svg)\n![Coverage status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Coverage/badge.svg)\n![Linting status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Linting/badge.svg)\n![Black status badge](https://github.com/Hochfrequenz/rebdhuhn/workflows/Black/badge.svg)\n![PyPi Status Badge](https://img.shields.io/pypi/v/rebdhuhn)\n\n\ud83c\udde9\ud83c\uddea Dieses Repository enth\u00e4lt ein Python-Paket namens [`rebdhuhn`](https://pypi.org/project/rebdhuhn) (fr\u00fcher: `ebdtable2graph`), das genutzt werden kann, um aus .docx-Dateien extrahierte maschinenlesbare Tabellen, die einen Entscheidungsbaum (EBD) modellieren, in echte Graphen zu konvertieren. Diese Entscheidungsb\u00e4ume sind Teil eines regulatorischen Regelwerks f\u00fcr die deutsche Energiewirtschaft und kommen in der Eingangspr\u00fcfung der Marktkommunikation zum Einsatz.\n\n\ud83c\uddec\ud83c\udde7 This repository contains the source code of the Python package [`rebdhuhn`](https://pypi.org/project/rebdhuhn) (formerly known as `ebdtable2graph`).\n\n## Rationale\n\nAssume, that you scraped the Entscheidungsbaumdiagramm tables by EDI@Energy from their somewhat \"digitized\" PDF/DOCX files.\n(To do so, you can use the package [`ebdamame`](https://github.com/Hochfrequenz/ebdamame) (was: 'ebddocx2table`).)\nAlso assume, that the result of your scraping is a [`rebdhuhn.models.EbdTable`](src/rebdhuhn/models/ebd_table.py).\n\nThe package `rebdhuhn` contains logic to convert your scraped data into a graph.\nThis graph can then be exported e.g. as SVG and/or UML.\n\n## How to use `rebdhuhn`?\n\nInstall the package from pypi:\n\n```bash\npip install rebdhuhn\n```\n\n### Create an Instance of `EbdTable`\n\n`EbdTable` contains the raw data by BDEW in a machine-readable format.\nCreating instances of `EbdTable` is out of scope for this package.\nAsk Hochfrequenz for support on this topic.\nIn the following example we hard code the information.\n\n```python\nfrom rebdhuhn.graph_conversion import convert_table_to_graph\nfrom rebdhuhn.models import EbdCheckResult, EbdTable, EbdTableMetaData, EbdTableRow, EbdTableSubRow, EbdGraph\n\nebd_table: EbdTable  # this is the result of scraping the docx file\nebd_table = EbdTable(  # this data shouldn't be handwritten\n    metadata=EbdTableMetaData(\n        ebd_code=\"E_0003\",\n        chapter=\"7.39 AD: Bestellung der Aggregationsebene der Bilanzkreissummenzeitreihe auf Ebene der Regelzone\",\n        sub_chapter=\"7.39.1 E_0003_Bestellung der Aggregationsebene RZ pr\u00fcfen\",\n        role=\"\u00dcNB\",\n    ),\n    rows=[\n        EbdTableRow(\n            step_number=\"1\",\n            description=\"Erfolgt der Eingang der Bestellung fristgerecht?\",\n            sub_rows=[\n                EbdTableSubRow(\n                    check_result=EbdCheckResult(result=False, subsequent_step_number=None),\n                    result_code=\"A01\",\n                    note=\"Frist\u00fcberschreitung\",\n                ),\n                EbdTableSubRow(\n                    check_result=EbdCheckResult(result=True, subsequent_step_number=\"2\"),\n                    result_code=None,\n                    note=None,\n                ),\n            ],\n        ),\n        EbdTableRow(\n            step_number=\"2\",\n            description=\"Erfolgt die Bestellung zum Monatsersten 00:00 Uhr?\",\n            sub_rows=[\n                EbdTableSubRow(\n                    check_result=EbdCheckResult(result=False, subsequent_step_number=None),\n                    result_code=\"A02\",\n                    note=\"Gew\u00e4hlter Zeitpunkt nicht zul\u00e4ssig\",\n                ),\n                EbdTableSubRow(\n                    check_result=EbdCheckResult(result=True, subsequent_step_number=\"Ende\"),\n                    result_code=None,\n                    note=None,\n                ),\n            ],\n        ),\n    ],\n)\nassert isinstance(ebd_table, EbdTable)\n\nebd_graph = convert_table_to_graph(ebd_table)\nassert isinstance(ebd_graph, EbdGraph)\n```\n\n#### Export as PlantUML\n\n```python\nfrom rebdhuhn import convert_graph_to_plantuml\n\nplantuml_code = convert_graph_to_plantuml(ebd_graph)\nwith open(\"e_0003.puml\", \"w+\", encoding=\"utf-8\") as uml_file:\n    uml_file.write(plantuml_code)\n```\n\nThe file `e_0003.puml` now looks like this:\n\n```puml\n@startuml\n...\nif (<b>1: </b> Erfolgt der Eingang der Bestellung fristgerecht?) then (ja)\nelse (nein)\n    :A01;\n    note left\n        Frist\u00fcberschreitung\n    endnote\n    kill;\nendif\nif (<b>2: </b> Erfolgt die Bestellung zum Monatsersten 00:00 Uhr?) then (ja)\n    end\nelse (nein)\n    :A02;\n    note left\n        Gew\u00e4hlter Zeitpunkt nicht zul\u00e4ssig\n    endnote\n    kill;\nendif\n@enduml\n```\n\n#### Export the graph as SVG\n\nFirst, make sure to have a local instance of [kroki](https://kroki.io) up and running via docker (localhost:8125):\n\nAdd the required `.env` file to the repository root by opening a new terminal session, changing the directory to\n```bash\ncd path\\to\\rebdhuhn\\repository\\root\n```\nand executing the `create_env_file.py` script via\n```bash\npython create_env_file.py\n```\nRun the `docker-desktop` app on your local maschine and host the local kroki instance on PORT `8125` via\n```bash\ndocker-compose up -d\n```\n\nTo export the graph as SVG, use\n```python\nfrom rebdhuhn import convert_plantuml_to_svg_kroki\n\nsvg_code = convert_plantuml_to_svg_kroki(plantuml_code)\nwith open(\"e_0003.svg\", \"w+\", encoding=\"utf-8\") as svg_file:\n    svg_file.write(svg_code)\n```\n\n![](mwe_e0003.svg)\n\n## How to use this Repository on Your Machine (for development)\n\nPlease follow the instructions in\nour [Python Template Repository](https://github.com/Hochfrequenz/python_template_repository#how-to-use-this-repository-on-your-machine)\n. And for further information, see the [Tox Repository](https://github.com/tox-dev/tox).\n\n## Contribute\n\nYou are very welcome to contribute to this template repository by opening a pull request against the main branch.\n\n## Related Tools and Context\n\nThis repository is part of the [Hochfrequenz Libraries and Tools for a truly digitized market communication](https://github.com/Hochfrequenz/digital_market_communication/).\n",
    "bugtrack_url": null,
    "license": "GPL",
    "summary": "Converts (already scraped) Entscheidungsbaumdiagramm tables to real graphs",
    "version": "0.2.3",
    "project_urls": {
        "Changelog": "https://github.com/Hochfrequenz/rebdhuhn/releases",
        "Homepage": "https://github.com/Hochfrequenz/rebdhuhn",
        "Issue Tracker": "https://github.com/Hochfrequenz/rebdhuhn/issues",
        "Repository": "https://github.com/Hochfrequenz/rebdhuhn"
    },
    "split_keywords": [
        "ahb",
        " automation",
        " bdew",
        " edi@energy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8b0db50f70323ba5d53bf2d96f30860a18ca852fac01571cc146329d34f5cd6",
                "md5": "d5c96343024235b4d10cbd711eab009b",
                "sha256": "a0898842cbb94962178b5d98b884abe6b4ca768f0396ea4d34007f0eda7c0e11"
            },
            "downloads": -1,
            "filename": "rebdhuhn-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d5c96343024235b4d10cbd711eab009b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 46178,
            "upload_time": "2024-05-03T08:52:05",
            "upload_time_iso_8601": "2024-05-03T08:52:05.716608Z",
            "url": "https://files.pythonhosted.org/packages/d8/b0/db50f70323ba5d53bf2d96f30860a18ca852fac01571cc146329d34f5cd6/rebdhuhn-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f4338ae5f1bcbfbe8df284f535c8a524aa655ed56cb2a20cf332c1d237397251",
                "md5": "2a5878ba866b011140d083c0c86a2803",
                "sha256": "f18b060f123c0a0ca8b626de619380cedaad95bf81bd1cc944a276327ff817c8"
            },
            "downloads": -1,
            "filename": "rebdhuhn-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2a5878ba866b011140d083c0c86a2803",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 49941,
            "upload_time": "2024-05-03T08:52:07",
            "upload_time_iso_8601": "2024-05-03T08:52:07.385686Z",
            "url": "https://files.pythonhosted.org/packages/f4/33/8ae5f1bcbfbe8df284f535c8a524aa655ed56cb2a20cf332c1d237397251/rebdhuhn-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-03 08:52:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Hochfrequenz",
    "github_project": "rebdhuhn",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "attrs",
            "specs": [
                [
                    "==",
                    "23.2.0"
                ]
            ]
        },
        {
            "name": "cattrs",
            "specs": [
                [
                    "==",
                    "23.2.3"
                ]
            ]
        },
        {
            "name": "certifi",
            "specs": [
                [
                    "==",
                    "2024.2.2"
                ]
            ]
        },
        {
            "name": "charset-normalizer",
            "specs": [
                [
                    "==",
                    "3.3.2"
                ]
            ]
        },
        {
            "name": "idna",
            "specs": [
                [
                    "==",
                    "3.7"
                ]
            ]
        },
        {
            "name": "lxml",
            "specs": [
                [
                    "==",
                    "5.2.1"
                ]
            ]
        },
        {
            "name": "networkx",
            "specs": [
                [
                    "==",
                    "3.3"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "svgutils",
            "specs": [
                [
                    "==",
                    "0.3.4"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.2.1"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "rebdhuhn"
}
        
Elapsed time: 0.26314s