1867 lines
80 KiB
Plaintext
1867 lines
80 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "73e934a8-9027-4ad1-ad15-e68fba847768",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Anmelden und token holen\n",
|
|
"from farmOS import farmOS\n",
|
|
"\n",
|
|
"hostname = \"farmos.wagframe.duckdns.org\"\n",
|
|
"username = \"matze\"\n",
|
|
"password = \"m6ChEHx5gMqgctr8dpb3fhATZbQS8hv4\"\n",
|
|
"\n",
|
|
"# Create the client.\n",
|
|
"farm_client = farmOS(\n",
|
|
" hostname=hostname,\n",
|
|
" client_id = \"jupyter\", # Optional. The default oauth client_id \"farm\" is enabled on all farmOS servers.\n",
|
|
")\n",
|
|
"import json\n",
|
|
"# Authorize the client, save the token.\n",
|
|
"# A scope can be specified, but will default to the default scope set when initializing the client.\n",
|
|
"token = farm_client.authorize(username, password)\n",
|
|
"#farm_client.info()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "dcf25e45-f887-4fd5-aed8-44090ed75680",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Excel Export\n",
|
|
"import os\n",
|
|
"# Definiere den Basispfad und den Dateinamen\n",
|
|
"base_file_path = '/Users/Wir/Downloads/assets'\n",
|
|
"file_extension = '.xlsx'\n",
|
|
"file_index = 1\n",
|
|
"file_path = f\"{base_file_path}_{file_index}{file_extension}\"\n",
|
|
"\n",
|
|
"# Überprüfe, ob die Datei bereits existiert und erhöhe den Index\n",
|
|
"while os.path.exists(file_path):\n",
|
|
" file_index += 1\n",
|
|
" file_path = f\"{base_file_path}_{file_index}{file_extension}\"\n",
|
|
"\n",
|
|
"# Exportiere den DataFrame in eine Excel-Datei\n",
|
|
"df.to_excel(file_path, index=False)\n",
|
|
"print(f\"Die Datei wurde erfolgreich unter '{file_path}' gespeichert.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d6022671-c929-4dbb-b60c-8d0ce17a1663",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#API Info\n",
|
|
"\n",
|
|
"info = farm_client.info()\n",
|
|
"info"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ca74d822-4f5c-46d7-8129-31bbf28a1e00",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"Land\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"from shapely.geometry import Polygon\n",
|
|
"from shapely import wkt # for converting WKT string to shapely Polygon\n",
|
|
"from pyproj import CRS, Transformer # for coordinate transformation (if necessary)\n",
|
|
"\n",
|
|
"# Assuming this is your response\n",
|
|
"response = farm_client.asset.get('land')\n",
|
|
"all_land_assets = response['data']\n",
|
|
"\n",
|
|
"# Function to calculate area in hectares\n",
|
|
"def calculate_area(geometry_wkt):\n",
|
|
" # Convert WKT (Well-Known Text) to Polygon\n",
|
|
" polygon = wkt.loads(geometry_wkt)\n",
|
|
"\n",
|
|
" # Define the CRS (Coordinate Reference System) for the land's coordinates\n",
|
|
" crs_wgs84 = CRS(\"EPSG:4326\") # WGS 84, latitude-longitude\n",
|
|
" crs_projected = CRS(\"EPSG:25832\") # A projected CRS for accurate area calculation\n",
|
|
"\n",
|
|
" # Transform coordinates to a projected CRS for area calculation\n",
|
|
" transformer = Transformer.from_crs(crs_wgs84, crs_projected, always_xy=True)\n",
|
|
" projected_polygon = Polygon([transformer.transform(*coord) for coord in polygon.exterior.coords])\n",
|
|
"\n",
|
|
" # Calculate the area in square meters and convert to hectares\n",
|
|
" area_sq_meters = projected_polygon.area\n",
|
|
" area_hectares = area_sq_meters / 10_000 # 1 hectare = 10,000 square meters\n",
|
|
"\n",
|
|
" # Round to 4 decimal places\n",
|
|
" return round(area_hectares, 4)\n",
|
|
"\n",
|
|
"\n",
|
|
"land_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Created\": pd.to_datetime(asset[\"attributes\"][\"created\"]).strftime('%d.%m.%Y'),\n",
|
|
" \"Area (ha)\": calculate_area(asset[\"attributes\"][\"intrinsic_geometry\"][\"value\"]),\n",
|
|
" \"Asset type\": asset[\"type\"],\n",
|
|
" \"Is fixed\": asset[\"attributes\"][\"is_fixed\"],\n",
|
|
" \"land_type\": asset[\"attributes\"][\"land_type\"],\n",
|
|
" \"Is location\": asset[\"attributes\"][\"is_location\"]\n",
|
|
" }\n",
|
|
" for asset in all_land_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(land_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "33c1b024-fb74-472c-b229-36d8041b1336",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"Plant\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"\n",
|
|
"# Assuming this is your response\n",
|
|
"response = farm_client.asset.get('plant')\n",
|
|
"all_plant_assets = response['data']\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"plant_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Created\": pd.to_datetime(asset[\"attributes\"][\"created\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_plant_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(plant_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d64e0dc4-a685-4a42-810c-cafd8f43b988",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"equipment\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"\n",
|
|
"# Assuming this is your response\n",
|
|
"response = farm_client.asset.get('equipment')\n",
|
|
"all_equipment_assets = response['data']\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"equipment_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Created\": pd.to_datetime(asset[\"attributes\"][\"created\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_equipment_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(equipment_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "718ed35b-39f5-4732-8967-8f204e41f653",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"material\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"\n",
|
|
"# Assuming this is your response\n",
|
|
"response = farm_client.asset.get('material')\n",
|
|
"all_material_assets = response['data']\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"material_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Created\": pd.to_datetime(asset[\"attributes\"][\"created\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_material_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(material_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7e3ac788-1146-4aa3-a155-4f5d0c16ef02",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"product\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"\n",
|
|
"# Assuming this is your response\n",
|
|
"response = farm_client.asset.get('product')\n",
|
|
"all_product_assets = response['data']\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"product_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Created\": pd.to_datetime(asset[\"attributes\"][\"created\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_product_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(product_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "96784d50-f9bf-43a2-ae95-1e53f9c8ffb4",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
},
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"seed\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"\n",
|
|
"# Assuming this is your response\n",
|
|
"response = farm_client.asset.get('seed')\n",
|
|
"all_seed_assets = response['data']\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"seed_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Created\": pd.to_datetime(asset[\"attributes\"][\"created\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_seed_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(seed_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "22b12932-9e79-4cfe-ab03-9a76d93a7a3f",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"harvest\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"response = farm_client.log.get('harvest')\n",
|
|
"all_harvest_assets = response['data']\n",
|
|
"\n",
|
|
"harvest_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Timestamp\": pd.to_datetime(asset[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_harvest_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(harvest_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0d6a676c-94cb-4d9e-8c3b-24a40be73dea",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"activity\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"response = farm_client.log.get('activity')\n",
|
|
"all_activity_assets = response['data']\n",
|
|
"\n",
|
|
"activity_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Timestamp\": pd.to_datetime(asset[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_activity_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(activity_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "3dab14bd-e7e6-4a5f-b838-c6498fb20f23",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"input\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"response = farm_client.log.get('input')\n",
|
|
"all_input_assets = response['data']\n",
|
|
"\n",
|
|
"input_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Timestamp\": pd.to_datetime(asset[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_input_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(input_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "625d3e17-635c-4775-94e7-a0179cf690de",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"maintenance\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"response = farm_client.log.get('maintenance')\n",
|
|
"all_maintenance_assets = response['data']\n",
|
|
"\n",
|
|
"maintenance_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Timestamp\": pd.to_datetime(asset[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_maintenance_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(maintenance_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bad0e10e-a112-45b0-a454-672348389dea",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"medical\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"response = farm_client.log.get('medical')\n",
|
|
"all_medical_assets = response['data']\n",
|
|
"\n",
|
|
"medical_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Timestamp\": pd.to_datetime(asset[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_medical_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(medical_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a08ff50e-499c-497d-879c-85c0c9b107c2",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Zeige alle \"seeding\" Daten\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"response = farm_client.log.get('seeding')\n",
|
|
"all_seeding_assets = response['data']\n",
|
|
"\n",
|
|
"seeding_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Timestamp\": pd.to_datetime(asset[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" \n",
|
|
" }\n",
|
|
" for asset in all_seeding_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Create a pandas DataFrame from the extracted data\n",
|
|
"df = pd.DataFrame(seeding_asset_data)\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die Tabelle an\n",
|
|
"df\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "64a933c4-75b3-4dd5-902c-5da2850d585f",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#filter auf einen harvest log\n",
|
|
"response = farm_client.log.get('harvest')\n",
|
|
"all_harvest_assets = response['data']\n",
|
|
"\n",
|
|
"harvest_asset_data = [\n",
|
|
" {\n",
|
|
" \"Name\": asset[\"attributes\"][\"name\"],\n",
|
|
" \"Status\": asset[\"attributes\"][\"status\"],\n",
|
|
" \"Timestamp\": pd.to_datetime(asset[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" }\n",
|
|
" for asset in all_harvest_assets\n",
|
|
"]\n",
|
|
"\n",
|
|
"# Erstelle ein Pandas DataFrame aus den extrahierten Daten\n",
|
|
"df = pd.DataFrame(harvest_asset_data)\n",
|
|
"\n",
|
|
"# Filtere den DataFrame, um nur den gewünschten Harvest anzuzeigen (enthält den Teilstring)\n",
|
|
"df_filtered = df[df['Name'].str.contains(\"Helmacker\", na=False)]\n",
|
|
"\n",
|
|
"# Setze Pandas-Optionen für eine bessere Anzeige\n",
|
|
"pd.set_option('display.max_columns', None) # Alle Spalten anzeigen\n",
|
|
"pd.set_option('display.max_colwidth', 50) # Maximale Spaltenbreite setzen\n",
|
|
"pd.set_option('display.width', 1000) # Maximale Breite der Tabelle\n",
|
|
"\n",
|
|
"# Zeige die gefilterte Tabelle an\n",
|
|
"df_filtered\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d23c84ac-9a04-4019-9b0c-0c549620af35",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Versuch\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"def get_related_logs_of_type(asset, type): \n",
|
|
" response = farm_client.resource.get('log', type)\n",
|
|
" ret = []\n",
|
|
" for log in response['data']:\n",
|
|
" log_assets = log['relationships']['asset']['data']\n",
|
|
" for log_asset in log_assets:\n",
|
|
" if log_asset['id'] == asset['id']:\n",
|
|
" ret.append(log)\n",
|
|
" return ret\n",
|
|
"\n",
|
|
"def get_related_quantities_of_measure(log, measure):\n",
|
|
" quantities = log['relationships']['quantity']['data']\n",
|
|
" ret = []\n",
|
|
" for quant_ref in quantities:\n",
|
|
" quant_id = quant_ref['id']\n",
|
|
" quant = farm_client.resource.get_id('quantity', 'standard', quant_id)\n",
|
|
" if quant['data']['attributes']['measure'] == measure:\n",
|
|
" ret.append(quant)\n",
|
|
" return ret\n",
|
|
"\n",
|
|
"# Beispiel für eine API-Abfrage mit farm_client\n",
|
|
"response = farm_client.resource.get('log', 'harvest')\n",
|
|
"\n",
|
|
"logs = []\n",
|
|
"for item in response['data']:\n",
|
|
" # plant name und fläche holen\n",
|
|
" assets = item['relationships']['asset']['data']\n",
|
|
" plant_name = ''\n",
|
|
" plant_area = 0.0\n",
|
|
" for asset in assets:\n",
|
|
" if asset['type'] == 'asset--plant': \n",
|
|
" plant_id = asset['id']\n",
|
|
" seedings = get_related_logs_of_type(asset, 'seeding')\n",
|
|
" for seeding in seedings:\n",
|
|
" area_quants = get_related_quantities_of_measure(seeding, 'area')\n",
|
|
" for area_quant in area_quants:\n",
|
|
" plant_area += float(area_quant['data']['attributes']['value']['decimal'])\n",
|
|
" plant = farm_client.asset.get_id('plant', plant_id)\n",
|
|
" plant_name = plant['data']['attributes']['name']\n",
|
|
" \n",
|
|
" \n",
|
|
" # log aufbauen\n",
|
|
" log = {\n",
|
|
" \n",
|
|
" \n",
|
|
" 'Plant': plant_name,\n",
|
|
" 'Area': plant_area,\n",
|
|
" \n",
|
|
" 'Timestamp': pd.to_datetime(item[\"attributes\"][\"timestamp\"]).strftime('%d.%m.%Y'),\n",
|
|
" 'Log Name': item['attributes']['name'],\n",
|
|
" 'Status': item['attributes']['status'],\n",
|
|
" 'Revision Created': pd.to_datetime(item[\"attributes\"][\"revision_created\"]).strftime('%d.%m.%Y'),\n",
|
|
" 'Link': item['links']['self']['href']\n",
|
|
" }\n",
|
|
" logs.append(log)\n",
|
|
"\n",
|
|
"# Erstelle ein DataFrame aus den Harvest Logs\n",
|
|
"df = pd.DataFrame(logs)\n",
|
|
"df"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "7c9f3572-702d-4760-a3ec-3f883908ad0f",
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"editable": true,
|
|
"jupyter": {
|
|
"outputs_hidden": true,
|
|
"source_hidden": true
|
|
},
|
|
"slideshow": {
|
|
"slide_type": ""
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{\n",
|
|
" \"jsonapi\": {\n",
|
|
" \"version\": \"1.0\",\n",
|
|
" \"meta\": {\n",
|
|
" \"links\": {\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"http://jsonapi.org/format/1.0/\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"log--harvest\",\n",
|
|
" \"id\": \"750511d3-5f7b-4e70-b541-d2f70696734f\",\n",
|
|
" \"links\": {\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"attributes\": {\n",
|
|
" \"drupal_internal__id\": 94,\n",
|
|
" \"drupal_internal__revision_id\": 450,\n",
|
|
" \"langcode\": \"en\",\n",
|
|
" \"revision_created\": \"2024-10-29T09:24:07+00:00\",\n",
|
|
" \"revision_log_message\": null,\n",
|
|
" \"name\": \"W-Raps Helmacker Harvest 24/25\",\n",
|
|
" \"timestamp\": \"2024-10-20T10:11:15+00:00\",\n",
|
|
" \"status\": \"done\",\n",
|
|
" \"created\": \"2024-10-15T10:12:32+00:00\",\n",
|
|
" \"changed\": \"2024-10-29T09:24:07+00:00\",\n",
|
|
" \"default_langcode\": true,\n",
|
|
" \"revision_translation_affected\": true,\n",
|
|
" \"comment\": {\n",
|
|
" \"status\": 2,\n",
|
|
" \"cid\": 0,\n",
|
|
" \"last_comment_timestamp\": 1728987169,\n",
|
|
" \"last_comment_name\": null,\n",
|
|
" \"last_comment_uid\": 1,\n",
|
|
" \"comment_count\": 0\n",
|
|
" },\n",
|
|
" \"data\": null,\n",
|
|
" \"notes\": null,\n",
|
|
" \"flag\": [],\n",
|
|
" \"is_group_assignment\": false,\n",
|
|
" \"geometry\": null,\n",
|
|
" \"is_movement\": false,\n",
|
|
" \"quick\": [],\n",
|
|
" \"lot_number\": null\n",
|
|
" },\n",
|
|
" \"relationships\": {\n",
|
|
" \"log_type\": {\n",
|
|
" \"data\": {\n",
|
|
" \"type\": \"log_type--log_type\",\n",
|
|
" \"id\": \"bb376a51-4586-46c8-b1cd-cdeea278599a\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": \"harvest\"\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/log_type?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/log_type?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"revision_user\": {\n",
|
|
" \"data\": {\n",
|
|
" \"type\": \"user--user\",\n",
|
|
" \"id\": \"a93c675c-72b1-40ea-90ae-41df789b7607\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 1\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/revision_user?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/revision_user?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"uid\": {\n",
|
|
" \"data\": {\n",
|
|
" \"type\": \"user--user\",\n",
|
|
" \"id\": \"a93c675c-72b1-40ea-90ae-41df789b7607\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 1\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/uid?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/uid?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"file\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/file?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/file?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"image\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/image?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/image?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"group\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/group?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/group?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"location\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/location?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/location?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"asset\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"asset--plant\",\n",
|
|
" \"id\": \"76f89f82-1238-43bb-b34f-796a92d491a2\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 100\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/asset?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/asset?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"category\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/category?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/category?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"quantity\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"quantity--standard\",\n",
|
|
" \"id\": \"c74fca04-27cc-44b1-8139-40f3fe3d3a4e\",\n",
|
|
" \"meta\": {\n",
|
|
" \"target_revision_id\": 208,\n",
|
|
" \"drupal_internal__target_id\": 129\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/quantity?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/quantity?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"owner\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"user--user\",\n",
|
|
" \"id\": \"a93c675c-72b1-40ea-90ae-41df789b7607\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 1\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/owner?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/owner?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"equipment\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"asset--equipment\",\n",
|
|
" \"id\": \"5faba68c-aa10-45b4-b1e0-d687ef1a8562\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 79\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/equipment?resourceVersion=id%3A450\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/750511d3-5f7b-4e70-b541-d2f70696734f/relationships/equipment?resourceVersion=id%3A450\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" {\n",
|
|
" \"type\": \"log--harvest\",\n",
|
|
" \"id\": \"71c022be-53c6-481f-b787-da0d16cfbf6f\",\n",
|
|
" \"links\": {\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"attributes\": {\n",
|
|
" \"drupal_internal__id\": 111,\n",
|
|
" \"drupal_internal__revision_id\": 454,\n",
|
|
" \"langcode\": \"en\",\n",
|
|
" \"revision_created\": \"2024-10-29T12:32:20+00:00\",\n",
|
|
" \"revision_log_message\": null,\n",
|
|
" \"name\": \"W-Raps Nachtweide Harvest 24/25\",\n",
|
|
" \"timestamp\": \"2024-10-28T23:00:00+00:00\",\n",
|
|
" \"status\": \"done\",\n",
|
|
" \"created\": \"2024-10-15T10:12:32+00:00\",\n",
|
|
" \"changed\": \"2024-10-29T12:32:20+00:00\",\n",
|
|
" \"default_langcode\": true,\n",
|
|
" \"revision_translation_affected\": true,\n",
|
|
" \"comment\": {\n",
|
|
" \"status\": 2,\n",
|
|
" \"cid\": 0,\n",
|
|
" \"last_comment_timestamp\": 1730193847,\n",
|
|
" \"last_comment_name\": null,\n",
|
|
" \"last_comment_uid\": 1,\n",
|
|
" \"comment_count\": 0\n",
|
|
" },\n",
|
|
" \"data\": null,\n",
|
|
" \"notes\": null,\n",
|
|
" \"flag\": [],\n",
|
|
" \"is_group_assignment\": false,\n",
|
|
" \"geometry\": null,\n",
|
|
" \"is_movement\": false,\n",
|
|
" \"quick\": [],\n",
|
|
" \"lot_number\": null\n",
|
|
" },\n",
|
|
" \"relationships\": {\n",
|
|
" \"log_type\": {\n",
|
|
" \"data\": {\n",
|
|
" \"type\": \"log_type--log_type\",\n",
|
|
" \"id\": \"bb376a51-4586-46c8-b1cd-cdeea278599a\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": \"harvest\"\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/log_type?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/log_type?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"revision_user\": {\n",
|
|
" \"data\": {\n",
|
|
" \"type\": \"user--user\",\n",
|
|
" \"id\": \"a93c675c-72b1-40ea-90ae-41df789b7607\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 1\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/revision_user?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/revision_user?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"uid\": {\n",
|
|
" \"data\": {\n",
|
|
" \"type\": \"user--user\",\n",
|
|
" \"id\": \"a93c675c-72b1-40ea-90ae-41df789b7607\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 1\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/uid?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/uid?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"file\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/file?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/file?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"image\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/image?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/image?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"group\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/group?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/group?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"location\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/location?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/location?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"asset\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"asset--plant\",\n",
|
|
" \"id\": \"c0371d6c-0b48-4256-96bc-2c75004e5636\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 106\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/asset?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/asset?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"category\": {\n",
|
|
" \"data\": [],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/category?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/category?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"quantity\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"quantity--standard\",\n",
|
|
" \"id\": \"75ddbac7-e03e-41ab-814c-4aab1246ce3e\",\n",
|
|
" \"meta\": {\n",
|
|
" \"target_revision_id\": 216,\n",
|
|
" \"drupal_internal__target_id\": 134\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/quantity?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/quantity?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"owner\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"user--user\",\n",
|
|
" \"id\": \"a93c675c-72b1-40ea-90ae-41df789b7607\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 1\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/owner?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/owner?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"equipment\": {\n",
|
|
" \"data\": [\n",
|
|
" {\n",
|
|
" \"type\": \"asset--equipment\",\n",
|
|
" \"id\": \"5faba68c-aa10-45b4-b1e0-d687ef1a8562\",\n",
|
|
" \"meta\": {\n",
|
|
" \"drupal_internal__target_id\": 79\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"related\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/equipment?resourceVersion=id%3A454\"\n",
|
|
" },\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest/71c022be-53c6-481f-b787-da0d16cfbf6f/relationships/equipment?resourceVersion=id%3A454\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"links\": {\n",
|
|
" \"self\": {\n",
|
|
" \"href\": \"https://farmos.wagframe.duckdns.org/api/log/harvest\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
"}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Beispiel Json print\n",
|
|
"import json\n",
|
|
"\n",
|
|
"response = farm_client.resource.get('log', 'harvest')\n",
|
|
"print(json.dumps(response, indent=4))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "a2300251-b38a-4aa8-abe0-1290572e2d3a",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"W-Raps Helmacker Plant 24/25\n",
|
|
"active\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Erhalte Pflanzdaten und speichere den Namen\n",
|
|
"plant_id = \"76f89f82-1238-43bb-b34f-796a92d491a2\"\n",
|
|
"plant = farm_client.asset.get_id('plant', plant_id)\n",
|
|
"plant_name = plant.get('data', {}).get('attributes', {}).get('name', '')\n",
|
|
"plant_status= plant.get('data', {}).get('attributes', {}).get('status', '')\n",
|
|
"print (plant_name)\n",
|
|
"print (plant_status)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a48c8376-158d-4877-b86e-fded7aab1b74",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"source_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Verschachtelte Abfrage test2\n",
|
|
"from farmOS import farmOS \n",
|
|
"import pandas as pd\n",
|
|
"import json\n",
|
|
"\n",
|
|
"def get_related_logs_of_type(asset, log_type): \n",
|
|
" response = farm_client.resource.get('log', log_type)\n",
|
|
" ret = []\n",
|
|
" for log in response['data']:\n",
|
|
" log_assets = log['relationships']['asset']['data']\n",
|
|
" for log_asset in log_assets:\n",
|
|
" if log_asset['id'] == asset['id']:\n",
|
|
" ret.append(log)\n",
|
|
" return ret\n",
|
|
"\n",
|
|
"def get_related_quantities_of_measure(log, measure):\n",
|
|
" quantities = log['relationships']['quantity']['data']\n",
|
|
" ret = []\n",
|
|
" for quant_ref in quantities:\n",
|
|
" quant_id = quant_ref['id']\n",
|
|
" quant = farm_client.resource.get_id('quantity', 'standard', quant_id)\n",
|
|
" if quant['data']['attributes']['measure'] == measure:\n",
|
|
" ret.append(quant)\n",
|
|
" return ret\n",
|
|
"\n",
|
|
"def get_related_quantities_of_weight(log, weight):\n",
|
|
" quantities = log['relationships']['quantity']['data']\n",
|
|
" ret = []\n",
|
|
" for quant_ref in quantities:\n",
|
|
" quant_id = quant_ref['id']\n",
|
|
" quant = farm_client.resource.get_id('quantity', 'standard', quant_id)\n",
|
|
" if quant['data']['attributes']['measure'] == weight: # Korrektur: Verwendung von weight\n",
|
|
" ret.append(quant)\n",
|
|
" return ret\n",
|
|
"\n",
|
|
"# API-Anfrage, um alle Harvest-Logs zu erhalten\n",
|
|
"response = farm_client.resource.get('log', 'harvest')\n",
|
|
"\n",
|
|
"logs = []\n",
|
|
"for item in response.get('data', []):\n",
|
|
" # plant name und fläche holen\n",
|
|
" assets = item.get('relationships', {}).get('asset', {}).get('data', [])\n",
|
|
" plant_name = ''\n",
|
|
" plant_area = 0.0\n",
|
|
" plant_status = ''\n",
|
|
" measure = ''\n",
|
|
" weight_measure = ''\n",
|
|
"\n",
|
|
" for asset in assets:\n",
|
|
" if asset['type'] == 'asset--plant': \n",
|
|
" plant_id = asset['id']\n",
|
|
" \n",
|
|
" # Alle Seeding-Logs für das Pflanzasset abrufen\n",
|
|
" seedings = get_related_logs_of_type(asset, 'seeding')\n",
|
|
" for seeding in seedings:\n",
|
|
" area_quants = get_related_quantities_of_measure(seeding, 'area')\n",
|
|
" \n",
|
|
" for area_quant in area_quants:\n",
|
|
" plant_area += float(area_quant.get('data', {}).get('attributes', {}).get('value', {}).get('decimal', 0))\n",
|
|
" measure = area_quant.get('data', {}).get('attributes', {}).get('measure', '')\n",
|
|
"\n",
|
|
" \n",
|
|
" \n",
|
|
" for seeding in seedings:\n",
|
|
" weight_quants = get_related_quantities_of_weight(seeding, 'weight')\n",
|
|
" \n",
|
|
" for weight_quant in weight_quants:\n",
|
|
" weight_measure = weight_quant.get('data', {}).get('attributes', {}).get('measure', '')\n",
|
|
" \n",
|
|
"\n",
|
|
" \n",
|
|
" # Pflanzendaten abrufen und Namen sowie Status speichern\n",
|
|
" plant = farm_client.asset.get_id('plant', plant_id)\n",
|
|
" plant_name = plant.get('data', {}).get('attributes', {}).get('name', '')\n",
|
|
" plant_status = plant.get('data', {}).get('attributes', {}).get('status', '')\n",
|
|
"\n",
|
|
" # Log erstellen und relevante Felder extrahieren\n",
|
|
" log = {\n",
|
|
" 'Plant': plant_name,\n",
|
|
" 'Area': plant_area,\n",
|
|
" 'Plant Status': plant_status,\n",
|
|
" 'Quantity measure': measure,\n",
|
|
" 'Weight measure': weight_measure, # Hinzufügen von weight_measure zur Log-Ausgabe\n",
|
|
" 'Timestamp': pd.to_datetime(item['attributes']['timestamp']).strftime('%d.%m.%Y') if 'timestamp' in item['attributes'] else None,\n",
|
|
" 'Log Name': item['attributes'].get('name', ''),\n",
|
|
" 'Log Status': item['attributes'].get('status', ''),\n",
|
|
" 'Revision Created': pd.to_datetime(item['attributes'].get('revision_created')).strftime('%d.%m.%Y') if 'revision_created' in item['attributes'] else None,\n",
|
|
" 'Link': item.get('links', {}).get('self', {}).get('href', ''),\n",
|
|
" 'Is Movement': item['attributes'].get('is_movement', ''),\n",
|
|
" }\n",
|
|
" logs.append(log)\n",
|
|
"\n",
|
|
"# DataFrame aus den Harvest Logs erstellen\n",
|
|
"df = pd.DataFrame(logs)\n",
|
|
"df\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "b753f464-3a65-4824-a231-6614e156b9e3",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<h3 style='font-weight:bold;'>W-Raps Helmacker Plant 24/25</h3>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<style type=\"text/css\">\n",
|
|
"#T_c6924 th {\n",
|
|
" font-weight: bold;\n",
|
|
" text-align: center;\n",
|
|
" white-space: break-spaces;\n",
|
|
" max-width: 100px;\n",
|
|
"}\n",
|
|
"#T_c6924 td {\n",
|
|
" text-align: center;\n",
|
|
"}\n",
|
|
"</style>\n",
|
|
"<table id=\"T_c6924\">\n",
|
|
" <thead>\n",
|
|
" <tr>\n",
|
|
" <th class=\"blank level0\" > </th>\n",
|
|
" <th id=\"T_c6924_level0_col0\" class=\"col_heading level0 col0\" >PlantStatus</th>\n",
|
|
" <th id=\"T_c6924_level0_col1\" class=\"col_heading level0 col1\" >SeedingLog AreaMeasure Quant1</th>\n",
|
|
" <th id=\"T_c6924_level0_col2\" class=\"col_heading level0 col2\" >SeedingLog Area Quant1</th>\n",
|
|
" <th id=\"T_c6924_level0_col3\" class=\"col_heading level0 col3\" >SeedingLog AreaMeasure Quant0</th>\n",
|
|
" <th id=\"T_c6924_level0_col4\" class=\"col_heading level0 col4\" >SeedingLog AreaDecimal Quant0</th>\n",
|
|
" <th id=\"T_c6924_level0_col5\" class=\"col_heading level0 col5\" >Timestamp HarvestLog</th>\n",
|
|
" <th id=\"T_c6924_level0_col6\" class=\"col_heading level0 col6\" >LogName HarvestLog</th>\n",
|
|
" <th id=\"T_c6924_level0_col7\" class=\"col_heading level0 col7\" >LogStatus HarvestLog</th>\n",
|
|
" <th id=\"T_c6924_level0_col8\" class=\"col_heading level0 col8\" >IsMovement HarvestLog</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th id=\"T_c6924_level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
|
|
" <td id=\"T_c6924_row0_col0\" class=\"data row0 col0\" >active</td>\n",
|
|
" <td id=\"T_c6924_row0_col1\" class=\"data row0 col1\" >area</td>\n",
|
|
" <td id=\"T_c6924_row0_col2\" class=\"data row0 col2\" >3.020000</td>\n",
|
|
" <td id=\"T_c6924_row0_col3\" class=\"data row0 col3\" >weight</td>\n",
|
|
" <td id=\"T_c6924_row0_col4\" class=\"data row0 col4\" >50.000000</td>\n",
|
|
" <td id=\"T_c6924_row0_col5\" class=\"data row0 col5\" >20.10.2024</td>\n",
|
|
" <td id=\"T_c6924_row0_col6\" class=\"data row0 col6\" >W-Raps Helmacker Harvest 24/25</td>\n",
|
|
" <td id=\"T_c6924_row0_col7\" class=\"data row0 col7\" >done</td>\n",
|
|
" <td id=\"T_c6924_row0_col8\" class=\"data row0 col8\" >False</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n"
|
|
],
|
|
"text/plain": [
|
|
"<pandas.io.formats.style.Styler at 0x12cac636cf0>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<h3 style='font-weight:bold;'>W-Raps Nachtweide Plant 24/25 </h3>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<style type=\"text/css\">\n",
|
|
"#T_4f0b9 th {\n",
|
|
" font-weight: bold;\n",
|
|
" text-align: center;\n",
|
|
" white-space: break-spaces;\n",
|
|
" max-width: 100px;\n",
|
|
"}\n",
|
|
"#T_4f0b9 td {\n",
|
|
" text-align: center;\n",
|
|
"}\n",
|
|
"</style>\n",
|
|
"<table id=\"T_4f0b9\">\n",
|
|
" <thead>\n",
|
|
" <tr>\n",
|
|
" <th class=\"blank level0\" > </th>\n",
|
|
" <th id=\"T_4f0b9_level0_col0\" class=\"col_heading level0 col0\" >PlantStatus</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col1\" class=\"col_heading level0 col1\" >SeedingLog AreaMeasure Quant1</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col2\" class=\"col_heading level0 col2\" >SeedingLog Area Quant1</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col3\" class=\"col_heading level0 col3\" >SeedingLog AreaMeasure Quant0</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col4\" class=\"col_heading level0 col4\" >SeedingLog AreaDecimal Quant0</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col5\" class=\"col_heading level0 col5\" >Timestamp HarvestLog</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col6\" class=\"col_heading level0 col6\" >LogName HarvestLog</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col7\" class=\"col_heading level0 col7\" >LogStatus HarvestLog</th>\n",
|
|
" <th id=\"T_4f0b9_level0_col8\" class=\"col_heading level0 col8\" >IsMovement HarvestLog</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th id=\"T_4f0b9_level0_row0\" class=\"row_heading level0 row0\" >1</th>\n",
|
|
" <td id=\"T_4f0b9_row0_col0\" class=\"data row0 col0\" >active</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col1\" class=\"data row0 col1\" >area</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col2\" class=\"data row0 col2\" >4.500000</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col3\" class=\"data row0 col3\" >weight</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col4\" class=\"data row0 col4\" >66.000000</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col5\" class=\"data row0 col5\" >28.10.2024</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col6\" class=\"data row0 col6\" >W-Raps Nachtweide Harvest 24/25</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col7\" class=\"data row0 col7\" >done</td>\n",
|
|
" <td id=\"T_4f0b9_row0_col8\" class=\"data row0 col8\" >False</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n"
|
|
],
|
|
"text/plain": [
|
|
"<pandas.io.formats.style.Styler at 0x12caf68afc0>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"#Verschachtelte Abfrage test3\n",
|
|
"from farmOS import farmOS \n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"def get_related_logs_of_type(asset, log_type): \n",
|
|
" response = farm_client.resource.get('log', log_type)\n",
|
|
" return [log for log in response['data'] if any(log_asset['id'] == asset['id'] for log_asset in log['relationships']['asset']['data'])]\n",
|
|
"\n",
|
|
"def get_related_quantities(log, measure_type):\n",
|
|
" quantities = log['relationships']['quantity']['data']\n",
|
|
" return [farm_client.resource.get_id('quantity', 'standard', quant_ref['id']) for quant_ref in quantities if farm_client.resource.get_id('quantity', 'standard', quant_ref['id'])['data']['attributes']['measure'] == measure_type]\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"def get_related_quantities_of_measure(log, measure):\n",
|
|
" quantities = log['relationships']['quantity']['data']\n",
|
|
" ret = []\n",
|
|
" for quant_ref in quantities:\n",
|
|
" quant_id = quant_ref['id']\n",
|
|
" quant = farm_client.resource.get_id('quantity', 'standard', quant_id)\n",
|
|
" if quant['data']['attributes']['measure'] == measure:\n",
|
|
" ret.append(quant)\n",
|
|
" return ret\n",
|
|
"\n",
|
|
"# API-Anfrage, um alle Harvest-Logs zu erhalten\n",
|
|
"response = farm_client.resource.get('log', 'harvest')\n",
|
|
"\n",
|
|
"logs = []\n",
|
|
"for item in response.get('data', []):\n",
|
|
" assets = item.get('relationships', {}).get('asset', {}).get('data', [])\n",
|
|
" plant_name = ''\n",
|
|
" plant_area = 0.0\n",
|
|
" plant_status = ''\n",
|
|
" quantity_measure = ''\n",
|
|
" weight_measure = ''\n",
|
|
" weight_decimal = 0.0\n",
|
|
"\n",
|
|
" for asset in assets:\n",
|
|
" if asset['type'] == 'asset--plant': \n",
|
|
" plant_id = asset['id']\n",
|
|
" \n",
|
|
" # Alle Seeding-Logs für das Pflanzasset abrufen\n",
|
|
" seedings = get_related_logs_of_type(asset, 'seeding')\n",
|
|
" \n",
|
|
" # Fläche und Menge abrufen\n",
|
|
" for seeding in seedings:\n",
|
|
" area_quants = get_related_quantities(seeding, 'area')\n",
|
|
" for area_quant in area_quants:\n",
|
|
" plant_area += float(area_quant.get('data', {}).get('attributes', {}).get('value', {}).get('decimal', 0))\n",
|
|
" quantity_measure = area_quant.get('data', {}).get('attributes', {}).get('measure', '')\n",
|
|
"\n",
|
|
" weight_quants = get_related_quantities(seeding, 'weight')\n",
|
|
" for weight_quant in weight_quants:\n",
|
|
" weight_measure = weight_quant.get('data', {}).get('attributes', {}).get('measure', '')\n",
|
|
" weight_decimal += float(weight_quant.get('data', {}).get('attributes', {}).get('value', {}).get('decimal', 0))\n",
|
|
" \n",
|
|
" # Pflanzendaten abrufen\n",
|
|
" plant = farm_client.asset.get_id('plant', plant_id)\n",
|
|
" plant_name = plant.get('data', {}).get('attributes', {}).get('name', '')\n",
|
|
" plant_status = plant.get('data', {}).get('attributes', {}).get('status', '')\n",
|
|
"\n",
|
|
" # Log erstellen und relevante Felder extrahieren\n",
|
|
" log = {\n",
|
|
" 'PlantName': plant_name,\n",
|
|
" 'PlantStatus': plant_status,\n",
|
|
" 'SeedingLog AreaMeasure Quant1': quantity_measure,\n",
|
|
" 'SeedingLog Area Quant1': plant_area,\n",
|
|
" 'SeedingLog AreaMeasure Quant0': weight_measure,\n",
|
|
" 'SeedingLog AreaDecimal Quant0' : weight_decimal,\n",
|
|
" 'Timestamp HarvestLog': pd.to_datetime(item['attributes'].get('timestamp')).strftime('%d.%m.%Y') if 'timestamp' in item['attributes'] else None,\n",
|
|
" 'LogName HarvestLog': item['attributes'].get('name', ''),\n",
|
|
" 'LogStatus HarvestLog': item['attributes'].get('status', ''),\n",
|
|
" 'IsMovement HarvestLog': item['attributes'].get('is_movement', ''),\n",
|
|
" }\n",
|
|
" logs.append(log)\n",
|
|
"\n",
|
|
"# DataFrame aus den Harvest Logs erstellen\n",
|
|
"df = pd.DataFrame(logs)\n",
|
|
"from IPython.display import display, HTML # Für Jupyter Notebook geeignet\n",
|
|
"\n",
|
|
"# Gruppierung und Anzeige als HTML-Format\n",
|
|
"grouped = df.groupby('PlantName')\n",
|
|
"for plant, data in grouped:\n",
|
|
" display(HTML(f\"<h3 style='font-weight:bold;'>{plant}</h3>\")) # Pflanzname als fettgedruckte Überschrift\n",
|
|
" \n",
|
|
" # Style der Tabelle anpassen\n",
|
|
" styled_table = data.drop(columns=['PlantName']).style.set_table_styles(\n",
|
|
" [\n",
|
|
" {'selector': 'th', 'props': [('font-weight', 'bold'), ('text-align', 'center'), ('white-space', 'break-spaces'), ('max-width', '100px')]},\n",
|
|
" {'selector': 'td', 'props': [('text-align', 'center')]}\n",
|
|
" ]\n",
|
|
" )\n",
|
|
"\n",
|
|
" display(styled_table)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"id": "3df54bf3-d8aa-4ec6-bb12-23b05f0aeb99",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<h3 style='font-weight:bold;'>W-Raps Helmacker Plant 24/25</h3>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<style type=\"text/css\">\n",
|
|
"#T_3b1ce th {\n",
|
|
" font-weight: bold;\n",
|
|
" text-align: center;\n",
|
|
" white-space: break-spaces;\n",
|
|
" max-width: 100px;\n",
|
|
"}\n",
|
|
"#T_3b1ce td {\n",
|
|
" text-align: center;\n",
|
|
"}\n",
|
|
"</style>\n",
|
|
"<table id=\"T_3b1ce\">\n",
|
|
" <thead>\n",
|
|
" <tr>\n",
|
|
" <th class=\"blank level0\" > </th>\n",
|
|
" <th id=\"T_3b1ce_level0_col0\" class=\"col_heading level0 col0\" >PlantStatus</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col1\" class=\"col_heading level0 col1\" >SeedingLog AreaMeasure Quant1</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col2\" class=\"col_heading level0 col2\" >SeedingLog Area Quant1</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col3\" class=\"col_heading level0 col3\" >SeedingLog WeightMeasure Quant0</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col4\" class=\"col_heading level0 col4\" >SeedingLog WeightDecimal Quant0</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col5\" class=\"col_heading level0 col5\" >Timestamp HarvestLog</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col6\" class=\"col_heading level0 col6\" >LogName HarvestLog</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col7\" class=\"col_heading level0 col7\" >LogStatus HarvestLog</th>\n",
|
|
" <th id=\"T_3b1ce_level0_col8\" class=\"col_heading level0 col8\" >IsMovement HarvestLog</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th id=\"T_3b1ce_level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
|
|
" <td id=\"T_3b1ce_row0_col0\" class=\"data row0 col0\" >active</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col1\" class=\"data row0 col1\" >area</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col2\" class=\"data row0 col2\" >3.020000</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col3\" class=\"data row0 col3\" >weight</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col4\" class=\"data row0 col4\" >50.000000</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col5\" class=\"data row0 col5\" >20.10.2024</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col6\" class=\"data row0 col6\" >W-Raps Helmacker Harvest 24/25</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col7\" class=\"data row0 col7\" >done</td>\n",
|
|
" <td id=\"T_3b1ce_row0_col8\" class=\"data row0 col8\" >False</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n"
|
|
],
|
|
"text/plain": [
|
|
"<pandas.io.formats.style.Styler at 0x12caf68bad0>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<h3 style='font-weight:bold;'>W-Raps Nachtweide Plant 24/25 </h3>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<style type=\"text/css\">\n",
|
|
"#T_bb745 th {\n",
|
|
" font-weight: bold;\n",
|
|
" text-align: center;\n",
|
|
" white-space: break-spaces;\n",
|
|
" max-width: 100px;\n",
|
|
"}\n",
|
|
"#T_bb745 td {\n",
|
|
" text-align: center;\n",
|
|
"}\n",
|
|
"</style>\n",
|
|
"<table id=\"T_bb745\">\n",
|
|
" <thead>\n",
|
|
" <tr>\n",
|
|
" <th class=\"blank level0\" > </th>\n",
|
|
" <th id=\"T_bb745_level0_col0\" class=\"col_heading level0 col0\" >PlantStatus</th>\n",
|
|
" <th id=\"T_bb745_level0_col1\" class=\"col_heading level0 col1\" >SeedingLog AreaMeasure Quant1</th>\n",
|
|
" <th id=\"T_bb745_level0_col2\" class=\"col_heading level0 col2\" >SeedingLog Area Quant1</th>\n",
|
|
" <th id=\"T_bb745_level0_col3\" class=\"col_heading level0 col3\" >SeedingLog WeightMeasure Quant0</th>\n",
|
|
" <th id=\"T_bb745_level0_col4\" class=\"col_heading level0 col4\" >SeedingLog WeightDecimal Quant0</th>\n",
|
|
" <th id=\"T_bb745_level0_col5\" class=\"col_heading level0 col5\" >Timestamp HarvestLog</th>\n",
|
|
" <th id=\"T_bb745_level0_col6\" class=\"col_heading level0 col6\" >LogName HarvestLog</th>\n",
|
|
" <th id=\"T_bb745_level0_col7\" class=\"col_heading level0 col7\" >LogStatus HarvestLog</th>\n",
|
|
" <th id=\"T_bb745_level0_col8\" class=\"col_heading level0 col8\" >IsMovement HarvestLog</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th id=\"T_bb745_level0_row0\" class=\"row_heading level0 row0\" >1</th>\n",
|
|
" <td id=\"T_bb745_row0_col0\" class=\"data row0 col0\" >active</td>\n",
|
|
" <td id=\"T_bb745_row0_col1\" class=\"data row0 col1\" >area</td>\n",
|
|
" <td id=\"T_bb745_row0_col2\" class=\"data row0 col2\" >4.500000</td>\n",
|
|
" <td id=\"T_bb745_row0_col3\" class=\"data row0 col3\" >weight</td>\n",
|
|
" <td id=\"T_bb745_row0_col4\" class=\"data row0 col4\" >66.000000</td>\n",
|
|
" <td id=\"T_bb745_row0_col5\" class=\"data row0 col5\" >28.10.2024</td>\n",
|
|
" <td id=\"T_bb745_row0_col6\" class=\"data row0 col6\" >W-Raps Nachtweide Harvest 24/25</td>\n",
|
|
" <td id=\"T_bb745_row0_col7\" class=\"data row0 col7\" >done</td>\n",
|
|
" <td id=\"T_bb745_row0_col8\" class=\"data row0 col8\" >False</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n"
|
|
],
|
|
"text/plain": [
|
|
"<pandas.io.formats.style.Styler at 0x12caf68a450>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"testtttt\n",
|
|
"from farmOS import farmOS \n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"def get_related_logs_of_type(asset, log_type): \n",
|
|
" response = farm_client.resource.get('log', log_type)\n",
|
|
" return [log for log in response['data'] if any(log_asset['id'] == asset['id'] for log_asset in log['relationships']['asset']['data'])]\n",
|
|
"\n",
|
|
"def get_related_quantities(log, measure_type):\n",
|
|
" quantities = log['relationships']['quantity']['data']\n",
|
|
" return [farm_client.resource.get_id('quantity', 'standard', quant_ref['id']) \n",
|
|
" for quant_ref in quantities \n",
|
|
" if farm_client.resource.get_id('quantity', 'standard', quant_ref['id'])['data']['attributes']['measure'] == measure_type]\n",
|
|
"\n",
|
|
"def get_related_taxonomy_units(taxonomy_term, measure):\n",
|
|
" taxonomy = taxonomy_term['relationships']['units']['data']\n",
|
|
" ret = []\n",
|
|
" for tax_ref in taxonomy:\n",
|
|
" tax_id = tax_ref['id']\n",
|
|
" quant = farm_client.resource.get_id('quantity', 'standard', tax_id)\n",
|
|
" if quant['data']['attributes']['measure'] == measure:\n",
|
|
" ret.append(quant)\n",
|
|
" return ret\n",
|
|
"\n",
|
|
"# API-Anfrage, um alle Harvest-Logs zu erhalten\n",
|
|
"response = farm_client.resource.get('log', 'harvest')\n",
|
|
"\n",
|
|
"logs = []\n",
|
|
"for item in response.get('data', []):\n",
|
|
" assets = item.get('relationships', {}).get('asset', {}).get('data', [])\n",
|
|
" plant_name = ''\n",
|
|
" plant_area = 0.0\n",
|
|
" plant_status = ''\n",
|
|
" quantity_measure = ''\n",
|
|
" weight_measure = ''\n",
|
|
" weight_decimal = 0.0\n",
|
|
"\n",
|
|
" for asset in assets:\n",
|
|
" if asset['type'] == 'asset--plant': \n",
|
|
" plant_id = asset['id']\n",
|
|
" \n",
|
|
" # Alle Seeding-Logs für das Pflanzasset abrufen\n",
|
|
" seedings = get_related_logs_of_type(asset, 'seeding')\n",
|
|
" \n",
|
|
" # Fläche und Menge abrufen\n",
|
|
" for seeding in seedings:\n",
|
|
" area_quants = get_related_quantities(seeding, 'area')\n",
|
|
" for area_quant in area_quants:\n",
|
|
" plant_area += float(area_quant.get('data', {}).get('attributes', {}).get('value', {}).get('decimal', 0))\n",
|
|
" quantity_measure = area_quant.get('data', {}).get('attributes', {}).get('measure', '')\n",
|
|
"\n",
|
|
" weight_quants = get_related_quantities(seeding, 'weight')\n",
|
|
" for weight_quant in weight_quants:\n",
|
|
" weight_measure = weight_quant.get('data', {}).get('attributes', {}).get('measure', '')\n",
|
|
" weight_decimal += float(weight_quant.get('data', {}).get('attributes', {}).get('value', {}).get('decimal', 0))\n",
|
|
" \n",
|
|
" # Pflanzendaten abrufen\n",
|
|
" plant = farm_client.asset.get_id('plant', plant_id)\n",
|
|
" plant_name = plant.get('data', {}).get('attributes', {}).get('name', '')\n",
|
|
" plant_status = plant.get('data', {}).get('attributes', {}).get('status', '')\n",
|
|
"\n",
|
|
" # Log erstellen und relevante Felder extrahieren\n",
|
|
" log = {\n",
|
|
" 'PlantName': plant_name,\n",
|
|
" 'PlantStatus': plant_status,\n",
|
|
" 'SeedingLog AreaMeasure Quant1': quantity_measure,\n",
|
|
" 'SeedingLog Area Quant1': plant_area,\n",
|
|
" 'SeedingLog WeightMeasure Quant0': weight_measure,\n",
|
|
" 'SeedingLog WeightDecimal Quant0' : weight_decimal,\n",
|
|
" 'Timestamp HarvestLog': pd.to_datetime(item['attributes'].get('timestamp')).strftime('%d.%m.%Y') if 'timestamp' in item['attributes'] else None,\n",
|
|
" 'LogName HarvestLog': item['attributes'].get('name', ''),\n",
|
|
" 'LogStatus HarvestLog': item['attributes'].get('status', ''),\n",
|
|
" 'IsMovement HarvestLog': item['attributes'].get('is_movement', ''),\n",
|
|
" }\n",
|
|
" logs.append(log)\n",
|
|
"\n",
|
|
"# DataFrame aus den Harvest Logs erstellen\n",
|
|
"df = pd.DataFrame(logs)\n",
|
|
"from IPython.display import display, HTML # Für Jupyter Notebook geeignet\n",
|
|
"\n",
|
|
"# Gruppierung und Anzeige als HTML-Format\n",
|
|
"grouped = df.groupby('PlantName')\n",
|
|
"for plant, data in grouped:\n",
|
|
" display(HTML(f\"<h3 style='font-weight:bold;'>{plant}</h3>\")) # Pflanzname als fettgedruckte Überschrift\n",
|
|
" \n",
|
|
" # Style der Tabelle anpassen\n",
|
|
" styled_table = data.drop(columns=['PlantName']).style.set_table_styles(\n",
|
|
" [\n",
|
|
" {'selector': 'th', 'props': [('font-weight', 'bold'), ('text-align', 'center'), ('white-space', 'break-spaces'), ('max-width', '100px')]},\n",
|
|
" {'selector': 'td', 'props': [('text-align', 'center')]}\n",
|
|
" ]\n",
|
|
" )\n",
|
|
"\n",
|
|
" display(styled_table)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "da71b53e-0621-47af-84ca-11e266ec8c2e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|