{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# Jobs: Loading Large Tables\n", "\n", "Some tables from the database are quite large and the API provides them in a different way:\n", "\n", "1. The standard request is rejected with code 98\n", "2. However, setting the query parameter `job=true` starts a background task.\n", "3. The final table is then available under `data/resultfile` instead of `data/tablefile`.\n", "\n", "_`pystatis` is handling all these details and the whole process for you!. Thus, you will only notice a larger runtime when requesting larger tables (currently about 1 minute of extra timeout)._\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import logging\n", "\n", "from pystatis import Table\n", "\n", "logging.basicConfig(level=logging.INFO)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's assume we want to download the table \"AI001-2-5\".\n", "If the table is not cached yet, a warning message tells us that a background job has been started.\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:pystatis.http_helper:Die Tabelle ist zu groß, um direkt abgerufen zu werden. Es wird eine Verarbeitung im Hintergrund gestartet.\n", "INFO:pystatis.http_helper:Database selected: regio\n", "INFO:pystatis.http_helper:Code 99: Der Bearbeitungsauftrag wurde erstellt. Die Tabelle kann in Kürze als Ergebnis mit folgendem Namen abgerufen werden: AI001-2-5_411043199\n", "WARNING:pystatis.http_helper:Verarbeitung im Hintergrund erfolgreich gestartet. Job-ID: AI001-2-5_411043199.\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n", "INFO:pystatis.http_helper:Verarbeitung im Hintergrund abgeschlossen. Ergebnis kann jetzt abgerufen werden über /data/resultfile und Job-ID: AI001-2-5_411043199.\n", "INFO:pystatis.cache:Data was successfully cached under /Users/miay/.pystatis/data/AI001-2-5/d973b28b323fa878b812/20250412.zip.\n", "INFO:pystatis.http_helper:Database selected: regio\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n" ] } ], "source": [ "t = Table(name=\"AI001-2-5\")\n", "t.get_data()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Requesting the same table again will provide the table instantly from the cache.\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hit\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO:pystatis.http_helper:Database selected: regio\n", "INFO:pystatis.http_helper:Code 0: erfolgreich\n" ] } ], "source": [ "t = Table(name=\"AI001-2-5\")\n", "t.get_data()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "Jahr", "rawType": "object", "type": "string" }, { "name": "Amtlicher Gemeindeschlüssel (AGS)__Code", "rawType": "object", "type": "string" }, { "name": "Amtlicher Gemeindeschlüssel (AGS)", "rawType": "object", "type": "string" }, { "name": "Anteil Siedlungs- und Verkehrsfläche an Gesamtfläche__Prozent", "rawType": "float64", "type": "float" }, { "name": "Anteil Sport-, Freizeit-, Erholungsfläche an Gesamtfläche__Prozent", "rawType": "float64", "type": "float" }, { "name": "Anteil der Fläche für Landwirtschaft an Gesamtfläche__Prozent", "rawType": "float64", "type": "float" }, { "name": "Anteil der Fläche für Siedlung an Gesamtfläche__Prozent", "rawType": "float64", "type": "float" }, { "name": "Anteil der Fläche für Verkehr an Gesamtfläche__Prozent", "rawType": "float64", "type": "float" }, { "name": "Anteil der Fläche für Wald an Gesamtfläche__Prozent", "rawType": "float64", "type": "float" }, { "name": "Freiraumfläche je EW__qm", "rawType": "float64", "type": "float" }, { "name": "Siedlungs- und Verkehrsfläche je EW__qm", "rawType": "float64", "type": "float" } ], "conversionMethod": "pd.DataFrame", "ref": "b51bfc60-b24d-4b0f-84f7-5ccc5067d3de", "rows": [ [ "0", "2022", "01001000", "Flensburg, kreisfreie Stadt", "53.5", "4.4", "22.1", "39.8", "13.8", "6.6", "284.1", "327.9" ], [ "1", "2022", "01002000", "Kiel, kreisfreie Stadt, Landeshauptstadt", "58.8", "10.3", "23.4", "44.9", "13.9", "5.6", "197.4", "281.5" ], [ "2", "2022", "01003000", "Lübeck, kreisfreie Stadt, Hansestadt", "37.9", "6.2", "30.2", "28.9", "9.2", "14.7", "607.5", "371.9" ], [ "3", "2022", "01004000", "Neumünster, kreisfreie Stadt", "51.8", "5.5", "37.7", "41.7", "10.1", "4.3", "434.2", "467.1" ], [ "4", "2022", "01051001", "Albersdorf", "19.7", "1.4", "62.7", "14.0", "5.7", "14.7", "3640.3", "894.6" ] ], "shape": { "columns": 11, "rows": 5 } }, "text/html": [ "
\n", " | Jahr | \n", "Amtlicher Gemeindeschlüssel (AGS)__Code | \n", "Amtlicher Gemeindeschlüssel (AGS) | \n", "Anteil Siedlungs- und Verkehrsfläche an Gesamtfläche__Prozent | \n", "Anteil Sport-, Freizeit-, Erholungsfläche an Gesamtfläche__Prozent | \n", "Anteil der Fläche für Landwirtschaft an Gesamtfläche__Prozent | \n", "Anteil der Fläche für Siedlung an Gesamtfläche__Prozent | \n", "Anteil der Fläche für Verkehr an Gesamtfläche__Prozent | \n", "Anteil der Fläche für Wald an Gesamtfläche__Prozent | \n", "Freiraumfläche je EW__qm | \n", "Siedlungs- und Verkehrsfläche je EW__qm | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "2022 | \n", "01001000 | \n", "Flensburg, kreisfreie Stadt | \n", "53.5 | \n", "4.4 | \n", "22.1 | \n", "39.8 | \n", "13.8 | \n", "6.6 | \n", "284.1 | \n", "327.9 | \n", "
1 | \n", "2022 | \n", "01002000 | \n", "Kiel, kreisfreie Stadt, Landeshauptstadt | \n", "58.8 | \n", "10.3 | \n", "23.4 | \n", "44.9 | \n", "13.9 | \n", "5.6 | \n", "197.4 | \n", "281.5 | \n", "
2 | \n", "2022 | \n", "01003000 | \n", "Lübeck, kreisfreie Stadt, Hansestadt | \n", "37.9 | \n", "6.2 | \n", "30.2 | \n", "28.9 | \n", "9.2 | \n", "14.7 | \n", "607.5 | \n", "371.9 | \n", "
3 | \n", "2022 | \n", "01004000 | \n", "Neumünster, kreisfreie Stadt | \n", "51.8 | \n", "5.5 | \n", "37.7 | \n", "41.7 | \n", "10.1 | \n", "4.3 | \n", "434.2 | \n", "467.1 | \n", "
4 | \n", "2022 | \n", "01051001 | \n", "Albersdorf | \n", "19.7 | \n", "1.4 | \n", "62.7 | \n", "14.0 | \n", "5.7 | \n", "14.7 | \n", "3640.3 | \n", "894.6 | \n", "