Files
farmos.py-wagner/reporting.ipynb
2024-11-20 15:13:46 +01:00

3334 lines
180 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "f512fba3-877f-411e-935c-0c878d478b2d",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#alle Seeding logs\n",
"import neofarm.lib as neo\n",
"\n",
"#plant = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
"#print(plant.name)\n",
"\n",
"\n",
"seedings = neo.Log.Seeding.get_list()\n",
"for seeding in seedings:\n",
" plant = seeding.plant\n",
" equipment = seeding.equipment[0]\n",
" quantity1 = seeding.quantities[0]\n",
" quantity2 = seeding.quantities[1]\n",
" print(f\"name: {seeding.name}\")\n",
" print(f\"timestamp: {seeding.timestamp}\")\n",
" print(f\"plant name: {plant.name}\")\n",
" print(f\"plant crop: {plant.crop[0].name}\")\n",
" print(f\"plant loc: {plant.location[0].name}\")\n",
" print(f\"equipment: {equipment.name}\")\n",
" print(f\"isMovement: {seeding.isMovement}\")\n",
" print(f\"Q1 type: {quantity1.type}\")\n",
" print(f\"Q1 measure: {quantity1.measure}\")\n",
" print(f\"Q1 value: {quantity1.value}\")\n",
" print(f\"Q1 units: {quantity1.units.name}\")\n",
" print(f\"Q1 inv adj: {quantity1.inventory_adjustment}\")\n",
" print(f\"Q1 inv ass: {quantity1.inventory_asset.name}\")\n",
" print(f\"Q2 type: {quantity2.type}\")\n",
" print(f\"Q2 measure: {quantity2.measure}\")\n",
" print(f\"Q2 value: {quantity2.value}\")\n",
" print(f\"Q2 units: {quantity2.units.name}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c1bf2175-65f7-4704-8d39-15a08849c9ae",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"import neofarm.lib as neo\n",
"\n",
"#plant = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
"#print(plant.name)\n",
"\n",
"\n",
"seedings = neo.Log.Purchase.get_list()\n",
"for seeding in seedings:\n",
" plant = seeding.plant\n",
" #equipment = seeding.equipment[0]\n",
" quantity1 = seeding.quantities[0]\n",
" # quantity2 = seeding.quantities[1]\n",
" print(f\"name: {seeding.name}\")\n",
" print(f\"timestamp: {seeding.timestamp}\")\n",
" #print(f\"plant name: {plant.name}\")\n",
" #print(f\"plant crop: {plant.crop[0].name}\")\n",
" #print(f\"plant loc: {plant.location[0].name}\")\n",
" #print(f\"equipment: {equipment.name}\")\n",
" print(f\"isMovement: {seeding.isMovement}\")\n",
" print(f\"Q1 type: {quantity1.type}\")\n",
" print(f\"Q1 measure: {quantity1.measure}\")\n",
" print(f\"Q1 value: {quantity1.value}\")\n",
" print(f\"Q1 units: {quantity1.units.name}\")\n",
" print(f\"Q1 inv adj: {quantity1.inventory_adjustment}\")\n",
" print(f\"Q1 inv ass: {quantity1.inventory_asset.name}\")\n",
" print(f\"Q2 type: {quantity2.type}\")\n",
" print(f\"Q2 measure: {quantity2.measure}\")\n",
" print(f\"Q2 value: {quantity2.value}\")\n",
" print(f\"Q2 units: {quantity2.units.name}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fdf49f3b-3949-4895-97fb-f5bd2484fce3",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"import neofarm.lib as neo\n",
"\n",
"inputs = neo.Input.get_list()\n",
"for element in inputs:\n",
" #equipment = element.equipment[0]\n",
" print(f\"name: {element.name}\")\n",
" print(f\"timestamp: {element.timestamp}\")\n",
" print(f\"plant name: {element.plant.name}\")\n",
" print(f\"plant crop: {element.plant.crop[0].name}\")\n",
" print(f\"plant loc: {element.plant.location[0].name}\")\n",
" print(f\"equipment: {element.equipment[0].name}\")\n",
" print(f\"isMovement: {element.isMovement}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28598d92-24f2-47cb-bb19-9943800eefe1",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"import neofarm.lib as neo\n",
"\n",
"data = neo.Log.Harvest.get_list()\n",
"for element in data:\n",
" #equipment = element.equipment[0]\n",
" print(f\"name: {element.name}\")\n",
" print(f\"timestamp: {element.timestamp}\")\n",
" print(f\"plant name: {element.plant.name}\")\n",
" print(f\"plant crop: {element.plant.crop[0].name}\")\n",
" print(f\"plant loc: {element.plant.location[0].name}\")\n",
" print(f\"equipment: {element.equipment[0].name}\")\n",
" print(f\"isMovement: {element.isMovement}\")\n",
" print(f\"Name vom Inventory asset von der Quantity: {element.quantities[0].inventory_asset.name}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a993570d-dea2-4bd6-80c0-b36297ce6a3a",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#Beispiel\n",
"import neofarm.lib as neo\n",
"\n",
"if __name__ == \"__main__\":\n",
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
" logs = asset.get_logs_of_type(neo.Log.Activity)\n",
" for log in logs:\n",
" print(log.name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3a33ffb1-afe7-44b5-863b-9779a95a2a9c",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"# alle logs von einem Plant \n",
"import neofarm.lib as neo\n",
"from datetime import datetime\n",
"\n",
"if __name__ == \"__main__\":\n",
" \n",
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
"\n",
"#Plantname\n",
" PlantName = \"W-Raps Helmacker Plant 24/25\" \n",
" print(f\"PlantName: {PlantName}\")\n",
"\n",
" \n",
"#log Maintenance\n",
" logs = asset.get_logs_of_type(neo.Log.Maintenance)\n",
" for log in logs:\n",
" print(\"Maintenance:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\") \n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
"#quantity\n",
" input=neo.Log.Maintenance.from_id(log.id)\n",
" print(f\"quant_type: {input.quantities[0].type}\")\n",
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant_value: {input.quantities[0].value}\")\n",
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant_value: {input.quantities[0].value}\")\n",
" print(f\"unit_name: {input.quantities[0].units.name}\")\n",
" print (f\"unit_price_1: = {input.quantities[0].unit_price}\")\n",
" print (f\"unit_price_1: = {input.quantities[0].total_price}\")\n",
" \t\n",
"#log Seeding \n",
" logs = asset.get_logs_of_type(neo.Log.Seeding)\n",
" for log in logs:\n",
" print(\"Seeding:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
" print(f\"plant loc: {log.location[0].name}\")\n",
"#quantity\n",
" input=neo.Log.Seeding.from_id(log.id)\n",
" print(f\"quant_type: {input.quantities[0].type}\")\n",
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant_value: {input.quantities[0].value}\")\n",
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant_inventory_name: {input.quantities[0].inventory_asset.name}\")\n",
"\n",
"#log Input \n",
" logs = asset.get_logs_of_type(neo.Log.Input)\n",
" for log in logs:\n",
" print(\"Input:\")\n",
" print(f\"name: {log.name}\")\n",
" #print(f\"name: {log.id}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
"\n",
"#quantity\n",
" input=neo.Log.Input.from_id(log.id)\n",
" print(f\"quant_type: {input.quantities[0].type}\")\n",
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant_value: {input.quantities[0].value}\")\n",
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
"\n",
"#log Medical\n",
" logs = asset.get_logs_of_type(neo.Log.Medical)\n",
" for log in logs:\n",
" print(\"Medical:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
"\n",
"#quantity\n",
" input=neo.Log.Medical.from_id(log.id)\n",
" print(f\"quant_type: {input.quantities[0].type}\")\n",
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant_value: {input.quantities[0].value}\")\n",
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
"\n",
"\n",
"#log Harvest \n",
" logs = asset.get_logs_of_type(neo.Log.Harvest)\n",
" for log in logs:\n",
" print(\"Harvest:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
"\n",
"#quantity\n",
" input=neo.Log.Harvest.from_id(log.id)\n",
" print(f\"quant_type: {input.quantities[0].type}\")\n",
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant_value: {input.quantities[0].value}\")\n",
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
"\n",
"#log Sale \n",
" logs = asset.get_logs_of_type(neo.Log.Sale)\n",
" for log in logs:\n",
" print(\"Sale:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
"\n",
"#quantity\n",
" input=neo.Log.Sale.from_id(log.id)\n",
" print(f\"quant_type: {input.quantities[0].type}\")\n",
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant_value: {input.quantities[0].value}\")\n",
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de57b155-d635-4367-9a56-90d033c3a922",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#Alle logs zu plant mit quantities untereinander tabelle\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"if __name__ == \"__main__\":\n",
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
"\n",
" # Definiere den Pflanzennamen\n",
" PlantName = \"W-Raps Helmacker Plant 24/25\"\n",
" print(f\"PlantName: {PlantName}\")\n",
"\n",
" # Erstelle eine Liste zur Sammlung der Daten\n",
" data = []\n",
"\n",
" # Funktion, um Logs zu verarbeiten und die Daten zur Liste hinzuzufügen\n",
" def process_logs(logs, log_type):\n",
" for log in logs:\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" equipment_name = log.equipment[0].name if log.equipment else \"None\"\n",
" location_name = log.location[0].name if hasattr(log, 'location') and log.location else \"None\"\n",
"\n",
" # Menge und weitere Details (falls vorhanden)\n",
" quantities = getattr(log, 'quantities', [])\n",
" for quantity in quantities:\n",
" data.append({\n",
" \"PlantName\": PlantName,\n",
" \"LogType\": log_type,\n",
" \"Name\": log.name,\n",
" \"Timestamp\": formatted_date,\n",
" \"Equipment\": equipment_name,\n",
" \"Location\": location_name,\n",
" \"QuantType\": quantity.type,\n",
" \"QuantMeasure\": quantity.measure,\n",
" \"QuantValue\": quantity.value,\n",
" \"UnitName\": quantities[0].units.name,\n",
" \"QuantInventoryAdjustment\": quantity.inventory_adjustment\n",
" \n",
" })\n",
" # Falls keine Mengeninformationen vorhanden sind\n",
" if not quantities:\n",
" data.append({\n",
" \"PlantName\": PlantName,\n",
" \"LogType\": log_type,\n",
" \"Name\": log.name,\n",
" \"Timestamp\": formatted_date,\n",
" \"Equipment\": equipment_name,\n",
" \"Location\": location_name,\n",
" \"QuantType\": \"\",\n",
" \"QuantMeasure\": \"\",\n",
" \"QuantValue\": \"\",\n",
" \"UnitName\": quantities[0].units.name,\n",
" \"QuantInventoryAdjustment\": \"\"\n",
" \n",
" })\n",
"\n",
" # Verarbeite die verschiedenen Log-Typen\n",
" process_logs(asset.get_logs_of_type(neo.Log.Maintenance), \"Maintenance\")\n",
" process_logs(asset.get_logs_of_type(neo.Log.Seeding), \"Seeding\")\n",
" process_logs(asset.get_logs_of_type(neo.Log.Input), \"Input\")\n",
" process_logs(asset.get_logs_of_type(neo.Log.Medical), \"Medical\")\n",
" process_logs(asset.get_logs_of_type(neo.Log.Harvest), \"Harvest\")\n",
" process_logs(asset.get_logs_of_type(neo.Log.Sale), \"Sale\")\n",
"\n",
" # Erstelle ein DataFrame aus den gesammelten Daten und zeige es an\n",
" df = pd.DataFrame(data)\n",
" display(df)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e3fe365-b32b-4210-847c-bea0b36bd34c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "946b0281-c77a-4a1e-8e91-5f06ba74afa5",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6d12b59-4895-426e-9a30-c9cee801671e",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#Master Report je Plant\n",
"# Importieren der benötigten Bibliotheken\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"def process_logs(asset_id, plant_name):\n",
" \"\"\"\n",
" Diese Funktion ruft alle Log-Daten für eine bestimmte Pflanzen-ID ab,\n",
" formatiert sie und organisiert sie in einer Liste von Dictionarys.\n",
" Schließlich gibt sie einen DataFrame zurück, der die aggregierten Log-Daten enthält.\n",
" \n",
" Parameter:\n",
" asset_id (str): Die ID der Pflanze, für die die Logs abgerufen werden sollen.\n",
" plant_name (str): Der Name der Pflanze.\n",
"\n",
" Rückgabe:\n",
" pd.DataFrame: Ein DataFrame mit allen gesammelten Log-Daten zur angegebenen Pflanze.\n",
" \"\"\"\n",
" # Lade die Pflanze basierend auf ihrer ID\n",
" asset = neo.Asset.Plant.from_id(asset_id)\n",
" data = [] # Liste zum Sammeln der Log-Daten\n",
" \n",
" # Definieren der Log-Typen, die abgefragt werden sollen\n",
" log_types = [\n",
" (\"Maintenance\", neo.Log.Maintenance),\n",
" (\"Seeding\", neo.Log.Seeding),\n",
" (\"Input\", neo.Log.Input),\n",
" (\"Medical\", neo.Log.Medical),\n",
" (\"Harvest\", neo.Log.Harvest),\n",
" (\"Sale\", neo.Log.Sale),\n",
" ]\n",
" \n",
" # Durchlaufen jeder Log-Typ-Kombination und Abrufen der zugehörigen Log-Daten\n",
" for log_name, log_type in log_types:\n",
" logs = asset.get_logs_of_type(log_type)\n",
" \n",
" # Verarbeitung der einzelnen Logs für den aktuellen Log-Typ\n",
" for log in logs:\n",
" # Formatieren des Timestamps im deutschen Datumsformat\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" \n",
" # Abrufen des ersten Equipment-Namens oder Standardwert, falls nicht vorhanden\n",
" equipment_name = log.equipment[0].name if log.equipment else \"None\"\n",
"\n",
" \n",
" # Abrufen des ersten Location-Namens oder leer, falls nicht vorhanden\n",
" location_name = log.location[0].name if hasattr(log, 'location') and log.location else \"\"\n",
"\n",
" # Abrufen des ersten inventory_asset-Namens oder leer, falls nicht vorhanden\n",
" inventory_asset_name = log.inventory_asset.name if hasattr(log, 'inventory_asset') and log.inventory_asset else \"\"\n",
"\n",
" \n",
" # Abrufen aller Mengen (quantities) im Log\n",
" quantities = getattr(log, 'quantities', [])\n",
" \n",
" # Initialisieren von Platzhaltern für den Fall, dass weniger als zwei Mengen vorhanden sind\n",
" quant_type_2 = quant_measure_2 = quant_value_2 = quant_inventory_adjustment_2 = quant_unit_price_1 = quant_total_price_1 =quant_inventory_name_1 = \"\"\n",
" quant_unit_name_1 = quant_unit_name_2 = \"\"\n",
"\n",
"\n",
"\n",
"\n",
" \n",
" # Verarbeitung der ersten Menge, falls vorhanden\n",
" if len(quantities) > 0:\n",
" quant_type_1 = quantities[0].type\n",
" quant_measure_1 = quantities[0].measure\n",
" quant_value_1 = quantities[0].value\n",
" quant_unit_price_1 = quantities[0].unit_price if hasattr(quantities[0], 'unit_price') and quantities[0].unit_price else \"\"\n",
" quant_total_price_1 = quantities[0].total_price if hasattr(quantities[0], 'total_price') and quantities[0].total_price else \"\"\n",
" quant_inventory_adjustment_1 = quantities[0].inventory_adjustment\n",
" quant_inventory_name_1 = quantities[0].inventory_asset.name if hasattr(quantities[0], 'inventory_asset.name') and quantities[0].inventory_asset.name else \"\"\n",
" quant_unit_name_1 = quantities[0].units.name if quantities[0].units else \"\"\n",
" quant_inventory_name_1 = quantities[0].inventory_asset.name if quantities[0].inventory_asset else \"\"\n",
" \n",
" \n",
" else:\n",
" # Leere Werte, falls keine Menge vorhanden ist\n",
" quant_type_1 = quant_measure_1 = quant_value_1 = quant_inventory_adjustment_1 = quant_unit_price_1 = quant_total_price_1 = quant_inventory_name_1 = \"\"\n",
"\n",
" # Verarbeitung der zweiten Menge, falls vorhanden\n",
" if len(quantities) > 1:\n",
" quant_type_2 = quantities[1].type\n",
" quant_measure_2 = quantities[1].measure\n",
" quant_value_2 = quantities[1].value\n",
" quant_inventory_adjustment_2 = quantities[1].inventory_adjustment\n",
" quant_unit_name_2 = quantities[1].units.name if quantities[1].units else \"\"\n",
"\n",
" # Hinzufügen der gesammelten Daten für diesen Log als Dictionary in die Liste\n",
" data.append({\n",
" \"PlantName\": plant_name,\n",
" \"LogType\": log_name,\n",
" \"Name\": log.name,\n",
" \"Timestamp\": formatted_date,\n",
" \"Equipment\": equipment_name,\n",
" \"Location\": location_name,\n",
" \"QuantType_1\": quant_type_1,\n",
" \"QuantMeasure_1\": quant_measure_1,\n",
" \"QuantValue_1\": quant_value_1,\n",
" \"QuantUnitName1\": quant_unit_name_1,\n",
" \"QuantUnitPrice_1\" : quant_unit_price_1,\n",
" \"QuantTotalPrice_1\" : quant_total_price_1,\n",
" \"QuantInventoryAdjustment_1\": quant_inventory_adjustment_1,\n",
" \"QuantInventoryName_1\": quant_inventory_name_1,\n",
" \"QuantType_2\": quant_type_2,\n",
" \"QuantMeasure_2\": quant_measure_2,\n",
" \"QuantValue_2\": quant_value_2,\n",
" \"QuantUnitName2\": quant_unit_name_2,\n",
" \"QuantInventoryAdjustment_2\": quant_inventory_adjustment_2\n",
" })\n",
" \n",
" # Rückgabe des DataFrames mit allen gesammelten Log-Daten\n",
" return pd.DataFrame(data)\n",
"\n",
"# Beispielaufruf zur Demonstration\n",
"if __name__ == \"__main__\":\n",
" # ID und Name der Pflanze definieren\n",
" asset_id = \"76f89f82-1238-43bb-b34f-796a92d491a2\"\n",
" plant_name = \"W-Raps Helmacker Plant 24/25\"\n",
" \n",
" # Abrufen und Formatieren der Logs in einem DataFrame\n",
" df = process_logs(asset_id, plant_name)\n",
" \n",
" # Konvertieren des 'Timestamp' in ein Datum für die korrekte Anzeige und Berechnung\n",
" df['Timestamp'] = pd.to_datetime(df['Timestamp'], format=\"%d.%m.%Y\")\n",
" \n",
" # Anzeigen des DataFrames zur Veranschaulichung\n",
" display(df)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19779605-63f3-46b0-b382-ec0e979b2eae",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#Master Report Baustelle\n",
"# Importieren der benötigten Bibliotheken\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"def process_logs(asset_id, plant_name):\n",
" \"\"\"\n",
" Diese Funktion ruft alle Log-Daten für eine bestimmte Pflanzen-ID ab,\n",
" formatiert sie und organisiert sie in einer Liste von Dictionarys.\n",
" Schließlich gibt sie einen DataFrame zurück, der die aggregierten Log-Daten enthält.\n",
" \n",
" Parameter:\n",
" asset_id (str): Die ID der Pflanze, für die die Logs abgerufen werden sollen.\n",
" plant_name (str): Der Name der Pflanze.\n",
"\n",
" Rückgabe:\n",
" pd.DataFrame: Ein DataFrame mit allen gesammelten Log-Daten zur angegebenen Pflanze.\n",
" \"\"\"\n",
" # Lade die Pflanze basierend auf ihrer ID\n",
" asset = neo.Asset.Plant.from_id(asset_id)\n",
" data = [] # Liste zum Sammeln der Log-Daten\n",
" \n",
" # Definieren der Log-Typen, die abgefragt werden sollen\n",
" log_types = [\n",
" (\"Maintenance\", neo.Log.Maintenance),\n",
" (\"Seeding\", neo.Log.Seeding),\n",
" (\"Input\", neo.Log.Input),\n",
" (\"Medical\", neo.Log.Medical),\n",
" (\"Harvest\", neo.Log.Harvest),\n",
" (\"Sale\", neo.Log.Sale),\n",
" ]\n",
" \n",
" # Durchlaufen jeder Log-Typ-Kombination und Abrufen der zugehörigen Log-Daten\n",
" for log_name, log_type in log_types:\n",
" logs = asset.get_logs_of_type(log_type)\n",
" \n",
" # Verarbeitung der einzelnen Logs für den aktuellen Log-Typ\n",
" for log in logs:\n",
" # Formatieren des Timestamps im deutschen Datumsformat\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" \n",
" # Abrufen des ersten Equipment-Namens oder Standardwert, falls nicht vorhanden\n",
" equipment_name = log.equipment[0].name if log.equipment else \"None\"\n",
"\n",
" \n",
" # Abrufen des ersten Location-Namens oder leer, falls nicht vorhanden\n",
" location_name = log.location[0].name if hasattr(log, 'location') and log.location else \"\"\n",
"\n",
" # Abrufen des ersten inventory_asset-Namens oder leer, falls nicht vorhanden\n",
" #inventory_asset_name = log.inventory_asset.name if hasattr(log, 'inventory_asset') and log.inventory_asset else \"\"\n",
"\n",
" \n",
" # Abrufen aller Mengen (quantities) im Log\n",
" quantities = getattr(log, 'quantities', [])\n",
" \n",
" # Initialisieren von Platzhaltern für den Fall, dass weniger als zwei Mengen vorhanden sind\n",
" quant_type_2 = quant_measure_2 = quant_value_2 = quant_inventory_adjustment_2 = quant_unit_price_1 = quant_total_price_1 =quant_inventory_name_1 = \"\"\n",
" quant_unit_name_1 = quant_unit_name_2 = \"\"\n",
"\n",
"\n",
"\n",
"\n",
" \n",
" # Verarbeitung der ersten Menge, falls vorhanden\n",
" if len(quantities) > 0:\n",
" quant_type_1 = quantities[0].type\n",
" quant_measure_1 = quantities[0].measure\n",
" quant_value_1 = quantities[0].value\n",
" quant_unit_price_1 = quantities[0].unit_price if hasattr(quantities[0], 'unit_price') and quantities[0].unit_price else \"\"\n",
" quant_total_price_1 = quantities[0].total_price if hasattr(quantities[0], 'total_price') and quantities[0].total_price else \"\"\n",
" quant_inventory_adjustment_1 = quantities[0].inventory_adjustment\n",
" quant_inventory_name_1 = quantities[0].inventory_asset.name if hasattr(quantities[0], 'inventory_asset.name') and quantities[0].inventory_asset.name else \"\"\n",
" quant_unit_name_1 = quantities[0].units.name if quantities[0].units else \"\"\n",
" quant_inventory_name_1 = quantities[0].inventory_asset.name if quantities[0].inventory_asset else \"\"\n",
" \n",
" \n",
" else:\n",
" # Leere Werte, falls keine Menge vorhanden ist\n",
" quant_type_1 = quant_measure_1 = quant_value_1 = quant_inventory_adjustment_1 = quant_unit_price_1 = quant_total_price_1 = quant_inventory_name_1 = \"\"\n",
"\n",
" # Verarbeitung der zweiten Menge, falls vorhanden\n",
" if len(quantities) > 1:\n",
" quant_type_2 = quantities[1].type\n",
" quant_measure_2 = quantities[1].measure\n",
" quant_value_2 = quantities[1].value\n",
" quant_inventory_adjustment_2 = quantities[1].inventory_adjustment\n",
" quant_unit_name_2 = quantities[1].units.name if quantities[1].units else \"\"\n",
"\n",
" # Hinzufügen der gesammelten Daten für diesen Log als Dictionary in die Liste\n",
" data.append({\n",
" \"PlantName\": plant_name,\n",
" \"LogType\": log_name,\n",
" \"Name\": log.name,\n",
" \"Timestamp\": formatted_date,\n",
" \"Equipment\": equipment_name,\n",
" \"Location\": location_name,\n",
" \"QuantType_1\": quant_type_1,\n",
" \"QuantMeasure_1\": quant_measure_1,\n",
" \"QuantValue_1\": quant_value_1,\n",
" \"QuantUnitName1\": quant_unit_name_1,\n",
" \"QuantUnitPrice_1\" : quant_unit_price_1,\n",
" \"QuantTotalPrice_1\" : quant_total_price_1,\n",
" \"QuantInventoryAdjustment_1\": quant_inventory_adjustment_1,\n",
" \"QuantInventoryName_1\": quant_inventory_name_1,\n",
" \"QuantType_2\": quant_type_2,\n",
" \"QuantMeasure_2\": quant_measure_2,\n",
" \"QuantValue_2\": quant_value_2,\n",
" \"QuantUnitName2\": quant_unit_name_2,\n",
" \"QuantInventoryAdjustment_2\": quant_inventory_adjustment_2\n",
" })\n",
" \n",
" # Rückgabe des DataFrames mit allen gesammelten Log-Daten\n",
" return pd.DataFrame(data)\n",
"\n",
"# Beispielaufruf zur Demonstration\n",
"if __name__ == \"__main__\":\n",
" # ID und Name der Pflanze definieren\n",
" asset_id = \"76f89f82-1238-43bb-b34f-796a92d491a2\"\n",
" plant_name = \"W-Raps Helmacker Plant 24/25\"\n",
" \n",
" # Abrufen und Formatieren der Logs in einem DataFrame\n",
" df = process_logs(asset_id, plant_name)\n",
" \n",
" # Konvertieren des 'Timestamp' in ein Datum für die korrekte Anzeige und Berechnung\n",
" df['Timestamp'] = pd.to_datetime(df['Timestamp'], format=\"%d.%m.%Y\")\n",
" \n",
" # Anzeigen des DataFrames zur Veranschaulichung\n",
" display(df)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "172b3075-7435-40e1-bbb5-138e1ca48800",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#ExcelExport\n",
"import pandas as pd\n",
"import os\n",
"from openpyxl import load_workbook\n",
"from openpyxl.utils import get_column_letter\n",
"from openpyxl.styles import Alignment\n",
"\n",
"def export_to_excel(df, file_path, date_column=\"D\"):\n",
" # Exportiere den DataFrame zu Excel\n",
" df.to_excel(file_path, index=False)\n",
" \n",
" # Lade die Arbeitsmappe, um Formatierungen hinzuzufügen\n",
" workbook = load_workbook(file_path)\n",
" worksheet = workbook.active\n",
" worksheet.auto_filter.ref = worksheet.dimensions\n",
"\n",
" # Passen Sie die Spaltenbreite an und aktivieren Sie den Zeilenumbruch\n",
" for col in worksheet.columns:\n",
" max_length = 0\n",
" col_letter = get_column_letter(col[0].column)\n",
" for cell in col:\n",
" cell.alignment = Alignment(wrap_text=True)\n",
" \n",
" # Setze das Datumsformat für die angegebene Spalte\n",
" if col_letter == date_column:\n",
" cell.number_format = 'DD.MM.YYYY'\n",
" \n",
" max_length = max(max_length, len(str(cell.value)) if cell.value else 0)\n",
" \n",
" adjusted_width = (max_length + 2) * 1.0\n",
" worksheet.column_dimensions[col_letter].width = adjusted_width\n",
"\n",
" workbook.save(file_path)\n",
" print(f\"Die Datei wurde erfolgreich nach '{file_path}' exportiert, mit Autofilter, Zeilenumbruch und angepasster Spaltenbreite.\")\n",
"\n",
"# Beispielaufruf\n",
"if __name__ == \"__main__\":\n",
" downloads_folder = os.path.join(os.path.expanduser(\"~\"), \"Downloads\")\n",
" file_path = os.path.join(downloads_folder, \"PlantLogs.xlsx\")\n",
" \n",
" \n",
" # Prüfe, ob die Datei bereits existiert\n",
" if os.path.exists(file_path):\n",
" overwrite = input(f\"Die Datei '{file_path}' existiert bereits. Möchten Sie sie überschreiben? (ja/nein): \")\n",
" if overwrite.lower() == 'ja':\n",
" export_to_excel(df, file_path)\n",
" else:\n",
" print(\"Der Export wurde abgebrochen.\")\n",
" else:\n",
" export_to_excel(df, file_path)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc1f2524-ca06-426f-a402-9e61ec9ddfbe",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "849c4af5-f0f9-47f4-b841-fa8dc3e27c15",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#Alle Seeding Logs\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"# Liste für die Sammlung der Seeding-Log-Daten\n",
"data = []\n",
"\n",
"# Alle Seeding-Logs abrufen\n",
"seedings = neo.Log.Seeding.get_list()\n",
"for seeding in seedings:\n",
" plant = seeding.plant\n",
" equipment = seeding.equipment[0]\n",
" quantity1 = seeding.quantities[0]\n",
" quantity2 = seeding.quantities[1]\n",
" \n",
" # Seeding-Daten als Dictionary hinzufügen\n",
" data.append({\n",
" \"name\": seeding.name,\n",
" \"timestamp\": datetime.fromisoformat(seeding.timestamp).strftime(\"%d.%m.%Y\"), # Konvertiere in das gewünschte Format\n",
" \"plant_name\": plant.name,\n",
" \"plant_crop\": plant.crop[0].name,\n",
" \"plant_location\": plant.location[0].name,\n",
" \"equipment\": equipment.name,\n",
" \"isMovement\": seeding.isMovement,\n",
" \"Q1_type\": quantity1.type,\n",
" \"Q1_measure\": quantity1.measure,\n",
" \"Q1_value\": quantity1.value,\n",
" \"Q1_units\": quantity1.units.name,\n",
" \"Q1_inventory_adjustment\": quantity1.inventory_adjustment,\n",
" \"Q1_inventory_asset\": quantity1.inventory_asset.name,\n",
" \"Q2_type\": quantity2.type,\n",
" \"Q2_measure\": quantity2.measure,\n",
" \"Q2_value\": quantity2.value,\n",
" \"Q2_units\": quantity2.units.name\n",
" })\n",
"\n",
"# DataFrame erstellen und anzeigen\n",
"df = pd.DataFrame(data)\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27e54d8e-cda2-465c-88eb-963a0fff3c5d",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#Alle Maintenance Logs\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"# Liste für die Sammlung der Mainenance-Log-Daten\n",
"data = []\n",
"\n",
"# Alle Maintenance-Logs abrufen\n",
"maintenances = neo.Log.Maintenance.get_list()\n",
"for maintenance in maintenances:\n",
" plant = maintenance.plant\n",
" equipment = maintenance.equipment[0]\n",
" quantity1 = maintenance.quantities[0]\n",
" \n",
" \n",
" # Maintenance-Daten als Dictionary hinzufügen\n",
" data.append({\n",
" \"name\": maintenance.name,\n",
" \"timestamp\": datetime.fromisoformat(maintenance.timestamp).strftime(\"%d.%m.%Y\"), # Konvertiere in das gewünschte Format\n",
" \"plant_name\": plant.name,\n",
" \"equipment\": equipment.name,\n",
" \"Q1_type\": quantity1.type,\n",
" \"Q1_measure\": quantity1.measure,\n",
" \"Q1_value\": quantity1.value,\n",
" \"Q1_units\": quantity1.units.name,\n",
" \"Q1_inventory_adjustment\": quantity1.inventory_adjustment,\n",
"\n",
"\n",
" })\n",
"\n",
"# DataFrame erstellen und anzeigen\n",
"df = pd.DataFrame(data)\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8e0222a-25c8-4f3f-a1e8-5e7753432c4b",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#Alle Input Logs\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"# Liste für die Sammlung der Input-Log-Daten\n",
"data = []\n",
"\n",
"# Alle Input-Logs abrufen\n",
"inputs = neo.Log.Input.get_list()\n",
"for input in inputs:\n",
" plant = input.plant\n",
" equipment = input.equipment[0]\n",
" quantity1 = input.quantities[0]\n",
"\n",
" \n",
" # Input-Daten als Dictionary hinzufügen\n",
" data.append({\n",
" \"name\": input.name,\n",
" \"timestamp\": datetime.fromisoformat(input.timestamp).strftime(\"%d.%m.%Y\"), # Konvertiere in das gewünschte Format\n",
" \"plant_name\": plant.name,\n",
" \"plant_crop\": plant.crop[0].name,\n",
" \"plant_location\": plant.location[0].name,\n",
" \"equipment\": equipment.name,\n",
" \"isMovement\": input.isMovement,\n",
" \"Q1_type\": quantity1.type,\n",
" \"Q1_measure\": quantity1.measure,\n",
" \"Q1_value\": quantity1.value,\n",
" \"Q1_units\": quantity1.units.name,\n",
" \"Q1_inventory_adjustment\": quantity1.inventory_adjustment,\n",
" \"Q1_inventory_asset\": quantity1.inventory_asset.name,\n",
"\n",
" })\n",
"\n",
"# DataFrame erstellen und anzeigen\n",
"df = pd.DataFrame(data)\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "318b15bd-4ea4-4eb6-b434-00900f1528dc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6356e491-8615-40eb-ad75-a21cb517afc2",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#Alle Medical Logs\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"# Liste für die Sammlung der Medical-Log-Daten\n",
"data = []\n",
"\n",
"# Alle Medical-Logs abrufen\n",
"medicals = neo.Log.Medical.get_list()\n",
"for medical in medicals:\n",
" plant = medical.plant\n",
" equipment = medical.equipment[0]\n",
" quantity1 = medical.quantities[0]\n",
"\n",
" \n",
" # Medical-Daten als Dictionary hinzufügen\n",
" data.append({\n",
" \"name\": medical.name,\n",
" \"timestamp\": datetime.fromisoformat(medical.timestamp).strftime(\"%d.%m.%Y\"), # Konvertiere in das gewünschte Format\n",
" \"plant_name\": plant.name,\n",
" \"plant_crop\": plant.crop[0].name,\n",
" \"plant_location\": plant.location[0].name,\n",
" \"equipment\": equipment.name,\n",
" \"isMovement\": medical.isMovement,\n",
" \"Q1_type\": quantity1.type,\n",
" \"Q1_measure\": quantity1.measure,\n",
" \"Q1_value\": quantity1.value,\n",
" \"Q1_units\": quantity1.units.name,\n",
" \"Q1_inventory_adjustment\": quantity1.inventory_adjustment,\n",
" \"Q1_inventory_asset\": quantity1.inventory_asset.name,\n",
"\n",
" })\n",
"\n",
"# DataFrame erstellen und anzeigen\n",
"df = pd.DataFrame(data)\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee597e4c-7275-4cda-8cc6-2daf82dbd4d8",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#Alle Harvest Logs\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"# Liste für die Sammlung der Harvest-Log-Daten\n",
"data = []\n",
"\n",
"# Alle Harvest-Logs abrufen\n",
"harvests = neo.Log.Harvest.get_list()\n",
"for harvest in harvests:\n",
" plant = harvest.plant\n",
" equipment = harvest.equipment[0]\n",
" quantity1 = harvest.quantities[0]\n",
"\n",
" \n",
" # Harvest-Daten als Dictionary hinzufügen\n",
" data.append({\n",
" \"name\": harvest.name,\n",
" \"timestamp\": datetime.fromisoformat(harvest.timestamp).strftime(\"%d.%m.%Y\"), # Konvertiere in das gewünschte Format\n",
" \"plant_name\": plant.name,\n",
" \"plant_crop\": plant.crop[0].name,\n",
" \"plant_location\": plant.location[0].name,\n",
" \"equipment\": equipment.name,\n",
" \"isMovement\": harvest.isMovement,\n",
" \"Q1_type\": quantity1.type,\n",
" \"Q1_measure\": quantity1.measure,\n",
" \"Q1_value\": quantity1.value,\n",
" \"Q1_units\": quantity1.units.name,\n",
" \"Q1_inventory_adjustment\": quantity1.inventory_adjustment,\n",
" \"Q1_inventory_asset\": quantity1.inventory_asset.name,\n",
"\n",
" })\n",
"\n",
"# DataFrame erstellen und anzeigen\n",
"df = pd.DataFrame(data)\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3279d05b-5bae-497e-891d-3337844904f7",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#Alle Sale Logs\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"# Liste für die Sammlung der Sale-Log-Daten\n",
"data = []\n",
"\n",
"# Alle Sale-Logs abrufen\n",
"sales = neo.Log.Sale.get_list()\n",
"for sale in sales:\n",
" plant = sale.plant\n",
" \n",
" quantity1 = sale.quantities[0]\n",
"\n",
" \n",
" # Sale-Daten als Dictionary hinzufügen\n",
" data.append({\n",
" \"name\": sale.name,\n",
" \"timestamp\": datetime.fromisoformat(sale.timestamp).strftime(\"%d.%m.%Y\"), # Konvertiere in das gewünschte Format\n",
" \"plant_name\": plant.name,\n",
" \"plant_crop\": plant.crop[0].name,\n",
" \"plant_location\": plant.location[0].name,\n",
" \"equipment\": equipment.name,\n",
" \"isMovement\": sale.isMovement,\n",
" \"Q1_type\": quantity1.type,\n",
" \"Q1_measure\": quantity1.measure,\n",
" \"Q1_value\": quantity1.value,\n",
" \"Q1_units\": quantity1.units.name,\n",
" \"Q1_inventory_adjustment\": quantity1.inventory_adjustment,\n",
" \"Q1_inventory_asset\": quantity1.inventory_asset.name,\n",
"\n",
" })\n",
"\n",
"# DataFrame erstellen und anzeigen\n",
"df = pd.DataFrame(data)\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8471814f-e362-424c-af3e-aa7865048782",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#alle Purchase Logs Baustelle\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"# Liste für die Sammlung der Purchase-Log-Daten\n",
"data = []\n",
"\n",
"# Alle Purchase-Logs abrufen\n",
"purchases = neo.Log.Purchase.get_list()\n",
"for purchase in purchases:\n",
" quantities = purchase.quantities\n",
" \n",
" # Hilfsfunktion, um sicher Werte abzurufen oder Standardwerte zurückzugeben\n",
" def get_quantity_info(quantities, index):\n",
" if len(quantities) > index:\n",
" quantity = quantities[index]\n",
" return {\n",
" f\"Q{index}_type\": quantity.type,\n",
" #f\"Q{index}_typex\": taxonomy.material_type if taxonomy.material_type else \"\",\n",
"\n",
" \n",
" f\"Q{index}_measure\": quantity.measure,\n",
" f\"Q{index}_value\": quantity.value,\n",
" f\"Q{index}_units\": quantity.units.name if quantity.units else \"\",\n",
" f\"Q{index}_quant_unit_price\" : quantities[0].unit_price if hasattr(quantities[0], 'unit_price') and quantities[0].unit_price else \"\",\n",
" f\"Q{index}_quant_total_price\" : quantities[0].total_price if hasattr(quantities[0], 'total_price') and quantities[0].total_price else \"\",\n",
" f\"Q{index}_inventory_adjustment\": quantity.inventory_adjustment,\n",
" f\"Q{index}_inventory_asset\": quantity.inventory_asset.name if quantity.inventory_asset else \"\"\n",
" }\n",
" else:\n",
" # Rückgabe von Standardwerten, wenn die Menge nicht vorhanden ist\n",
" return {\n",
" f\"Q{index}_type\": \"\",\n",
" f\"Q{index}_measure\": \"\",\n",
" f\"Q{index}_value\": \"\",\n",
" f\"Q{index}_units\": \"\",\n",
" f\"Q{index}_quant_unit_price\": \"\",\n",
" f\"Q{index}_quant_total_price\" : \"\",\n",
" f\"Q{index}_inventory_adjustment\": \"\",\n",
" f\"Q{index}_inventory_asset\": \"\"\n",
" }\n",
"\n",
" # Alle Mengeninformationen abrufen und gruppieren\n",
" quantity_info = {}\n",
" for i in range(8): # Von 0 bis 7\n",
" quantity_info.update(get_quantity_info(quantities, i))\n",
"\n",
" # Purchase-Daten als Dictionary hinzufügen\n",
" data.append({\n",
" \"name\": purchase.name,\n",
" \"timestamp\": datetime.fromisoformat(purchase.timestamp).strftime(\"%d.%m.%Y\"), # Konvertiere in das gewünschte Format\n",
" **quantity_info\n",
" })\n",
"\n",
"# DataFrame erstellen und anzeigen\n",
"df = pd.DataFrame(data)\n",
"df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7c72234-8838-461c-a4d7-b1c0170f789f",
"metadata": {
"jupyter": {
"source_hidden": true
},
"scrolled": true
},
"outputs": [],
"source": [
"#Mein Master Report\n",
"\n",
"import neofarm.lib as neo\n",
"from datetime import datetime\n",
"\n",
"if __name__ == \"__main__\":\n",
" \n",
"#log Activity\n",
" \n",
" logs = neo.Log.Activity.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" location = log.location\n",
" print(\"\")\n",
" print(\"Activity:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_location: {location[0].name}\")\n",
" \n",
" \t\n",
" \n",
"#log Maintenance\n",
" \n",
" logs = neo.Log.Maintenance.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" input=neo.Log.Maintenance.from_id(log.id)\n",
" print(\"\")\n",
" print(\"Maintenance:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\") \n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_area: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value}\")\n",
" print(f\"plant_area_unit: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].units.name}\")\n",
" print(f\"plant_location: {location[0].name}\")\n",
" \n",
" #Quantity0\n",
" print(\"\")\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}\")\n",
" print(f\"quant0_value_unit: {input.quantities[0].units.name}\")\n",
" print(f\"quant0_unit_price: = {input.quantities[0].unit_price}\")\n",
" print(f\"quant0_total_price: = {input.quantities[0].total_price}\")\n",
" #total cost\n",
" print(\"\")\n",
" total_cost = input.quantities[0].total_price \n",
" print(f\"total_cost: {total_cost:.2f}\")\n",
" \n",
" \n",
"\n",
"\n",
" \n",
"#Log Purchase\n",
" logs = neo.Log.Purchase.get_list()\n",
" for log in logs:\n",
" print(\"\")\n",
" print(\"Purchase:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\") \n",
" \n",
" #quantity\n",
" input=neo.Log.Purchase.from_id(log.id)\n",
" #Quantity1\n",
" print(\"\") \n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}\")\n",
" print(f\"quant0_value_unit: {input.quantities[0].units.name}\")\n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_unit_price: = {input.quantities[0].unit_price}\")\n",
" print(f\"quant0_total_price: = {input.quantities[0].total_price}\")\n",
" print(f\"quant0_inventory_asset: = {input.quantities[0].inventory_asset.name}\")\n",
" \n",
" \n",
" \n",
" if len(input.quantities) > 1:\n",
" #Quantity2\n",
" print(\"\")\n",
" print(f\"quant1_type: {input.quantities[1].type}\")\n",
" print(f\"quant1_materialtype: {input.quantities[1].material_types[0].name}\")\n",
" print(f\"quant1_measure: {input.quantities[1].measure}\")\n",
" print(f\"quant1_value: {input.quantities[1].value}\")\n",
" print(f\"quant1_value_unit: {input.quantities[1].units.name}\")\n",
" #Quantity3\n",
" print(\"\")\n",
" print(f\"quant2_type: {input.quantities[2].type}\") \n",
" print(f\"quant2_materialtype: {input.quantities[2].material_types[0].name}\")\n",
" print(f\"quant2_measure: {input.quantities[2].measure}\")\n",
" print(f\"quant2_value: {input.quantities[2].value}\") \n",
" print(f\"quant2_value_unit: {input.quantities[2].units.name}\")\n",
" #Quantity4\n",
" print(\"\")\n",
" print(f\"quant3_type: {input.quantities[3].type}\") \n",
" print(f\"quant3_materialtype: {input.quantities[3].material_types[0].name}\")\n",
" print(f\"quant3_measure: {input.quantities[3].measure}\")\n",
" print(f\"quant3_value: {input.quantities[3].value}\") \n",
" print(f\"quant3_value_unit: {input.quantities[3].units.name}\")\n",
" #Quantity5\n",
" print(\"\")\n",
" print(f\"quant4_type: {input.quantities[4].type}\") \n",
" print(f\"quant4_materialtype: {input.quantities[4].material_types[0].name}\")\n",
" print(f\"quant4_measure: {input.quantities[4].measure}\")\n",
" print(f\"quant4_value: {input.quantities[4].value}\") \n",
" print(f\"quant4_value_unit: {input.quantities[4].units.name}\")\n",
" #Quantity\n",
" print(\"\")\n",
" print(f\"quant5_type: {input.quantities[5].type}\") \n",
" print(f\"quant5_materialtype: {input.quantities[5].material_types[0].name}\")\n",
" print(f\"quant5_measure: {input.quantities[5].measure}\")\n",
" print(f\"quant5_value: {input.quantities[5].value}\") \n",
" print(f\"quant5_value_unit: {input.quantities[5].units.name}\")\n",
" #Quantity7\n",
" print(\"\")\n",
" print(f\"quant6_type: {input.quantities[6].type}\") \n",
" print(f\"quant6_materialtype: {input.quantities[6].material_types[0].name}\")\n",
" print(f\"quant6_measure: {input.quantities[6].measure}\")\n",
" print(f\"quant6_value: {input.quantities[6].value}\") \n",
" print(f\"quant6_value_unit: {input.quantities[6].units.name}\")\n",
" \n",
" \n",
"\n",
" \n",
"\n",
"\n",
"\n",
"#log Seeding \n",
" logs = neo.Log.Seeding.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" location = log.location\n",
" input=neo.Log.Seeding.from_id(log.id)\n",
" seed_purchase = input.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0]\n",
" print(\"\")\n",
" print(\"Seeding:\")\n",
" print(f\"name: {log.name}\")\n",
" print(f\"notes: {log.notes}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_area: = {input.quantities[1].value}\")\n",
" print(f\"plant_area_unit: = {input.quantities[1].units.name}\")\n",
" print(f\"plant loc: {log.location[0].name}\")\n",
" print(f\"plant_crop: {plant.crops[0].name}\")\n",
" print(f\"plant_season: {plant.seasons[0].name}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
" #quantity1\n",
" print(\"\")\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}\")\n",
" print(f\"quant0_value_unit: {input.quantities[0].units.name}\")\n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_inventory_name: {input.quantities[0].inventory_asset.name}\")\n",
" #quantity2\n",
" print(\"\")\n",
" if len(input.quantities) > 1:\n",
" print(f\"quant1_type: {input.quantities[1].type}\") \n",
" print(f\"quant1_measure: {input.quantities[1].measure}\")\n",
" print(f\"quant1_value: {input.quantities[1].value}{input.quantities[1].units.name}\")\n",
" #quantity3\n",
" print(\"\")\n",
" print(f\"quant2_type: {input.quantities[2].type}\") \n",
" print(f\"quant2_measure: {input.quantities[2].measure}\")\n",
" print(f\"quant2_value: {input.quantities[2].value}\") \n",
" print(f\"quant2_value_unit: {input.quantities[2].units.name}\") \n",
" print (f\"quant2_unit_price: = {input.quantities[2].unit_price}\")\n",
" print (f\"quant2_total_price: = {input.quantities[2].total_price}\")\n",
"\n",
"\n",
" #purchase\n",
" print(\"\")\n",
" print(f\"purch_name: {seed_purchase.name}\")\n",
" print(f\"purch_inv_asset: {seed_purchase.quantities[0].inventory_asset.name}\")\n",
" print(f\"purch_q0_type: {seed_purchase.quantities[0].type}\")\n",
" print(f\"purch_q0_measure: {seed_purchase.quantities[0].measure}\")\n",
" print(f\"purch_q0_unit_price: {seed_purchase.quantities[0].unit_price}\")\n",
" print(f\"purch_q0_unit_price_unit: {seed_purchase.quantities[0].units.name}\")\n",
" \n",
" \n",
" \n",
" #total cost\n",
" print(\"\")\n",
" total_cost = input.quantities[2].total_price + seed_purchase.quantities[0].unit_price * input.quantities[0].value\n",
" print(f\"total_cost: {total_cost:.2f}\")\n",
"\n",
" \n",
" \n",
"#log Input \n",
" logs = neo.Log.Input.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" print(\"\")\n",
" print(\"Input:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_area: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value}\")\n",
" print(f\"plant_area_unit: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].units.name}\")\n",
" print(f\"plant_crop: {plant.crops[0].name}\")\n",
" print(f\"plant_season: {plant.seasons[0].name}\")\n",
" print(f\"plant_location: {plant.location[0].name}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
" print(\"\")\n",
" #quantity\n",
" input=neo.Log.Input.from_id(log.id)\n",
" purchase = input.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0]\n",
" #quantitiy 0\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}{input.quantities[0].units.name}\")\n",
" \n",
" application_rate = input.quantities[0].value / input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value\n",
" print(f\"application_rate l/ha: {application_rate:.2f}\")\n",
" \n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_inventory_asset: {input.quantities[0].inventory_asset.name}\")\n",
" \n",
" #quantitity 1\n",
" \n",
" print(\"\")\n",
" if len(input.quantities) > 1:\n",
" print(f\"quant1_type: {input.quantities[1].type}\")\n",
" print(f\"quant1_measure: {input.quantities[1].measure}\")\n",
" print(f\"quant1_value: {input.quantities[1].value}\")\n",
" print(f\"quant1_value: {input.quantities[1].units.name}\")\n",
" print(f\"quant1_unit_price: {input.quantities[1].unit_price}\")\n",
" print(f\"quant1_total_price: {input.quantities[1].total_price}\")\n",
" \n",
" \n",
"\n",
"\n",
" \n",
" #purchase\n",
" print(\"\")\n",
" print(f\"purch_name: {purchase.name}\")\n",
" print(f\"purch_inv_asset: {purchase.quantities[0].inventory_asset.name}\")\n",
" print(f\"purch_q0_type: {purchase.quantities[0].type}\")\n",
" print(f\"purch_q0_measure: {purchase.quantities[0].measure}\")\n",
" print(f\"purch_q0_unit_price: {purchase.quantities[0].unit_price}\")\n",
" print(f\"purch_q0_unit_price_unit: {purchase.quantities[0].units.name}\")\n",
" if len(purchase.quantities) > 1:\n",
" \n",
" #Purchase q1\n",
" print(\"\")\n",
" print(f\"purch_q1_type: {purchase.quantities[1].type}\")\n",
" print(f\"purch_q1_material_type: {purchase.quantities[1].material_types[0].name}\")\n",
" print(f\"purch_q1_measure: {purchase.quantities[1].measure}\")\n",
" print(f\"purch_q1_value: {purchase.quantities[1].value}\")\n",
" print(f\"purch_q1_value_unit: {purchase.quantities[1].units.name}\")\n",
" #Purchase q2\n",
" print(\"\")\n",
" print(f\"purch_q2_type: {purchase.quantities[2].type}\")\n",
" print(f\"purch_q2_material_type: {purchase.quantities[2].material_types[0].name}\")\n",
" print(f\"purch_q2_measure: {purchase.quantities[2].measure}\")\n",
" print(f\"purch_q1_value: {purchase.quantities[2].value}\")\n",
" print(f\"purch_q1_value_unit: {purchase.quantities[2].units.name}\")\n",
" #Purchase q3\n",
" print(\"\")\n",
" print(f\"purch_q3_type: {purchase.quantities[3].type}\")\n",
" print(f\"purch_q3_material_type: {purchase.quantities[3].material_types[0].name}\")\n",
" print(f\"purch_q3_measure: {purchase.quantities[3].measure}\")\n",
" print(f\"purch_q1_value: {purchase.quantities[3].value}\")\n",
" print(f\"purch_q1_value_unit: {purchase.quantities[3].units.name}\")\n",
" #Purchase q4\n",
" print(\"\")\n",
" print(f\"purch_q4_type: {purchase.quantities[4].type}\")\n",
" print(f\"purch_q4_material_type: {purchase.quantities[4].material_types[0].name}\")\n",
" print(f\"purch_q4_measure: {purchase.quantities[4].measure}\")\n",
" print(f\"purch_q1_value: {purchase.quantities[4].value}\")\n",
" print(f\"purch_q1_value_unit: {purchase.quantities[4].units.name}\")\n",
" #Purchase q5\n",
" print(\"\")\n",
" print(f\"purch_q5_type: {purchase.quantities[5].type}\")\n",
" print(f\"purch_q5_material_type: {purchase.quantities[5].material_types[0].name}\")\n",
" print(f\"purch_q5_measure: {purchase.quantities[5].measure}\")\n",
" print(f\"purch_q1_value: {purchase.quantities[5].value}\")\n",
" print(f\"purch_q1_value_unit: {purchase.quantities[5].units.name}\")\n",
" #Purchase q6\n",
" print(\"\")\n",
" print(f\"purch_q6_type: {purchase.quantities[6].type}\")\n",
" print(f\"purch_q6_material_type: {purchase.quantities[6].material_types[0].name}\")\n",
" print(f\"purch_q6_measure: {purchase.quantities[6].measure}\")\n",
" print(f\"purch_q1_value: {purchase.quantities[6].value}\")\n",
" print(f\"purch_q1_value_unit: {purchase.quantities[6].units.name}\")\n",
" #total cost\n",
" print(\"\")\n",
" total_cost = input.quantities[1].total_price + input.quantities[0].value * purchase.quantities[0].unit_price\n",
" print(f\"total_cost: {total_cost:.2f}\") \n",
"\n",
"\n",
"#log Medical\n",
" logs = neo.Log.Medical.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
"\n",
" print(\"\")\n",
" print(\"Medical:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_area: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value}\")\n",
" print(f\"plant_area_unit: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].units.name}\")\n",
" print(f\"plant_crop: {plant.crops[0].name}\")\n",
" print(f\"plant_season: {plant.seasons[0].name}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
" \n",
" #Quantity0\n",
" print(\"\") \n",
" input=neo.Log.Medical.from_id(log.id)\n",
" med_purchase = input.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0]\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}\")\n",
" print(f\"quant0_value_unit: {input.quantities[0].units.name}\")\n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_inventory_name: {input.quantities[0].inventory_asset.name}\")\n",
" \n",
" #Quantity 1\n",
" print(\"\") \n",
" if len(input.quantities) > 1:\n",
" print(f\"quant1_type: {input.quantities[1].type}\") \n",
" print(f\"quant1_measure: {input.quantities[1].measure}\")\n",
" print(f\"quant1_value: {input.quantities[1].value}\") \n",
" print(f\"quant1_value_unit: {input.quantities[1].units.name}\") \n",
" print (f\"quant1_unit_price: = {input.quantities[1].unit_price}\")\n",
" print (f\"quant1_total_price: = {input.quantities[1].total_price}\")\n",
"\n",
"\n",
" #purchase\n",
" print(\"\")\n",
" print(f\"purch_name: {med_purchase.name}\")\n",
" print(f\"purch_inv_asset: {med_purchase.quantities[0].inventory_asset.name}\")\n",
" print(f\"purch_q0_type: {med_purchase.quantities[0].type}\")\n",
" print(f\"purch_q0_measure: {med_purchase.quantities[0].measure}\")\n",
" print(f\"purch_q0_unit_price: {med_purchase.quantities[0].unit_price}\")\n",
" print(f\"purch_q0_unit_price_unit: {med_purchase.quantities[0].units.name}\")\n",
"\n",
" #total cost\n",
" print(\"\")\n",
" total_cost = input.quantities[1].total_price + input.quantities[0].value * med_purchase.quantities[0].unit_price\n",
" print(f\"total_cost: {total_cost:.2f}\") \n",
"\n",
"#log Harvest \n",
" logs = neo.Log.Harvest.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
"\n",
" print(\"\")\n",
" print(\"Harvest:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_area: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value}\")\n",
" print(f\"plant_area_unit: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].units.name}\")\n",
" print(f\"plant_crop: {plant.crops[0].name}\")\n",
" print(f\"plant_season: {plant.seasons[0].name}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
" plant_area = input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value\n",
"#quantity\n",
" input=neo.Log.Harvest.from_id(log.id)\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}{input.quantities[0].units.name}\")\n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_inventory_name: {input.quantities[0].inventory_asset.name}\")\n",
"\n",
" #Quantity 1\n",
" print(\"\") \n",
" if len(input.quantities) > 1:\n",
" print(f\"quant1_type: {input.quantities[1].type}\") \n",
" print(f\"quant1_measure: {input.quantities[1].measure}\")\n",
" print(f\"quant1_value: {input.quantities[1].value}\") \n",
" print(f\"quant1_value_unit: {input.quantities[1].units.name}\") \n",
" \n",
"\n",
" #total cost\n",
" print(\"\")\n",
" total_cost = input.quantities[1].value * plant_area\n",
" print(f\"total_cost: {total_cost:.2f}\") \n",
"\n",
"\n",
" \n",
"#log Sale \n",
" logs = neo.Log.Sale.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" print(\"\")\n",
" print(\"Sale:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_area: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value}\")\n",
" print(f\"plant_area_unit: {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].units.name}\")\n",
" print(f\"plant_crop: {plant.crops[0].name}\")\n",
" print(f\"plant_season: {plant.seasons[0].name}\")\n",
"\n",
" #Quantity 1\n",
" print(\"\")\n",
" input=neo.Log.Sale.from_id(log.id)\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}\")\n",
" print(f\"quant0_value_unit: {input.quantities[0].units.name}\")\n",
" print (f\"quant0_unit_price: = {input.quantities[0].unit_price}\")\n",
" print (f\"quant0_total_price: = {input.quantities[0].total_price}\")\n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_inventory_name: {input.quantities[0].inventory_asset.name}\")\n",
"\n",
"#total \n",
" print(\"\")\n",
" total_sale = input.quantities[0].total_price\n",
" print(f\"total_Sale: {total_sale:.2f}\") \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5d34dcc9-a4b9-423f-91d4-da1958ecc20e",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#Kosten\n",
"import neofarm.lib as neo\n",
"from datetime import datetime\n",
"#log Harvest \n",
"logs = neo.Log.Harvest.get_list()\n",
"for log in logs:\n",
" plant = log.plant\n",
"\n",
" print(\"\")\n",
" print(\"Harvest:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_crop: {plant.crops[0].name}\")\n",
" print(f\"plant_season: {plant.seasons[0].name}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
"\n",
"#quantity\n",
" input=neo.Log.Harvest.from_id(log.id)\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}\")\n",
" print(f\"quant0_unit: {input.quantities[0].units.name}\")\n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_inventory_name: {input.quantities[0].inventory_asset.name}\")\n",
"\n",
" if len(input.quantities) > 1:\n",
" print(f\"quant1_type: {input.quantities[1].type}\") \n",
" print(f\"quant1_measure: {input.quantities[1].measure}\")\n",
" print(f\"quant1_value: {input.quantities[1].value}\") \n",
" print(f\"quant1_unit: {input.quantities[1].units.name}\")\n",
"\n",
"harvest_cost = input.quantities[1].value\n",
"final_cost = harvest_cost + 2\n",
"print (final_cost)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac163dc6-3593-4bdb-976b-a4e4bd651b5e",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#Mein Input log\n",
"import neofarm.lib as neo\n",
"from datetime import datetime\n",
"\n",
"\n",
"#log Input \n",
"logs = neo.Log.Input.get_list()\n",
"for log in logs:\n",
" plant = log.plant\n",
" print(\"\")\n",
" print(\"Input:\")\n",
" print(f\"name: {log.name}\")\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\") # Konvertiere in das gewünschte Format\n",
" print(f\"timestamp: {formatted_date}\")\n",
" print(f\"plant_name: {plant.name}\")\n",
" print(f\"plant_crop: {plant.crops[0].name}\")\n",
" print(f\"plant_season: {plant.seasons[0].name}\")\n",
" print(f\"plant loc: {plant.location[0].name}\")\n",
" print(f\"equipment: {log.equipment[0].name}\")\n",
" print(\"\")\n",
"#quantity\n",
" input=neo.Log.Input.from_id(log.id)\n",
" purchase = input.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0]\n",
" #quantitiy 0\n",
" print(f\"quant0_type: {input.quantities[0].type}\")\n",
" print(f\"quant0_measure: {input.quantities[0].measure}\")\n",
" print(f\"quant0_value: {input.quantities[0].value}{input.quantities[0].units.name}\")\n",
" \n",
" application_rate = input.quantities[0].value / input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value\n",
" print(f\"application_rate: {application_rate:.2f} l/ha\")\n",
"\n",
" print(f\"quant0_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
" print(f\"quant0_inventory_asset: {input.quantities[0].inventory_asset.name}\")\n",
" \n",
" #quantitity 1\n",
" \n",
" print(\"\")\n",
" if len(input.quantities) > 1:\n",
" print(f\"quant1_type: {input.quantities[1].type}\")\n",
" print(f\"quant1_measure: {input.quantities[1].measure}\")\n",
" print(f\"quant1_value: {input.quantities[1].value}{input.quantities[1].units.name}\")\n",
" print(f\"quant1_unit_price: {input.quantities[1].unit_price}€\")\n",
" print(f\"quant1_total_price: {input.quantities[1].total_price}€\")\n",
"\n",
" \n",
" #total cost\n",
" print(\"\")\n",
" total_price = input.quantities[1].total_price + input.quantities[0].value * purchase.quantities[0].unit_price\n",
" print(f\"total_cost: {total_price:.2f} €\")\n",
" \n",
" #seeding\n",
" print(\"\")\n",
" print(f\"seeding_area: = {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].value} {input.plant.get_logs_of_type(neo.Log.Seeding)[0].quantities[1].units.name}\")\n",
" \n",
" #purchase\n",
" print(\"\")\n",
" print(f\"purch_name: {purchase.name}\")\n",
" print(f\"purch_inv_asset: {purchase.quantities[0].inventory_asset.name}\")\n",
" print(f\"purch_q0_type: {purchase.quantities[0].type}\")\n",
" print(f\"purch_q0_measure: {purchase.quantities[0].measure}\")\n",
" print(f\"purch_q0_unit_price: {purchase.quantities[0].unit_price} € / {input.quantities[0].units.name}\")\n",
" if len(purchase.quantities) > 1:\n",
" \n",
" #Purchase q1\n",
" print(\"\")\n",
" print(f\"purch_q1_type: {purchase.quantities[1].type}\")\n",
" print(f\"purch_q1_material_type: {purchase.quantities[1].material_types[0].name}\")\n",
" print(f\"purch_q1_measure: {purchase.quantities[1].measure}\")\n",
" print(f\"purch_q1_value: {purchase.quantities[1].value} {purchase.quantities[1].units.name}\")\n",
" #Purchase q2\n",
" print(\"\")\n",
" print(f\"purch_q2_type: {purchase.quantities[2].type}\")\n",
" print(f\"purch_q2_material_type: {purchase.quantities[2].material_types[0].name}\")\n",
" print(f\"purch_q2_measure: {purchase.quantities[2].measure}\")\n",
" print(f\"purch_q2_value: {purchase.quantities[2].value} {purchase.quantities[2].units.name}\")\n",
" #Purchase q3\n",
" print(\"\")\n",
" print(f\"purch_q3_type: {purchase.quantities[3].type}\")\n",
" print(f\"purch_q3_material_type: {purchase.quantities[3].material_types[0].name}\")\n",
" print(f\"purch_q3_measure: {purchase.quantities[3].measure}\")\n",
" print(f\"purch_q3_value: {purchase.quantities[3].value} {purchase.quantities[3].units.name}\")\n",
" #Purchase q4\n",
" print(\"\")\n",
" print(f\"purch_q4_type: {purchase.quantities[4].type}\")\n",
" print(f\"purch_q4_material_type: {purchase.quantities[4].material_types[0].name}\")\n",
" print(f\"purch_q4_measure: {purchase.quantities[4].measure}\")\n",
" print(f\"purch_q4_value: {purchase.quantities[4].value} {purchase.quantities[4].units.name}\")\n",
" #Purchase q5\n",
" print(\"\")\n",
" print(f\"purch_q5_type: {purchase.quantities[5].type}\")\n",
" print(f\"purch_q5_material_type: {purchase.quantities[5].material_types[0].name}\")\n",
" print(f\"purch_q5_measure: {purchase.quantities[5].measure}\")\n",
" print(f\"purch_q5_value: {purchase.quantities[5].value} {purchase.quantities[5].units.name}\")\n",
" #Purchase q6\n",
" print(\"\")\n",
" print(f\"purch_q6_type: {purchase.quantities[6].type}\")\n",
" print(f\"purch_q6_material_type: {purchase.quantities[6].material_types[0].name}\")\n",
" print(f\"purch_q6_measure: {purchase.quantities[6].measure}\")\n",
" print(f\"purch_q6_value: {purchase.quantities[6].value} {purchase.quantities[6].units.name}\")\n",
" \n",
"\n",
"\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88fbb7dc-3f05-4eea-b16c-698acb344c69",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"#chatgpt Input log\n",
"import neofarm.lib as neo\n",
"import pandas as pd\n",
"import os\n",
"from openpyxl import load_workbook\n",
"from openpyxl.utils import get_column_letter\n",
"from openpyxl.styles import Alignment\n",
"from datetime import datetime\n",
"\n",
"def format_log_details(log):\n",
" \"\"\"Formats and returns details for a given input log.\"\"\"\n",
" plant = log.plant\n",
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y\")\n",
" details = {\n",
" \"name\": log.name,\n",
" \"timestamp\": formatted_date,\n",
" \"plant_name\": plant.name,\n",
" \"plant_crop\": plant.crops[0].name,\n",
" \"plant_season\": plant.seasons[0].name,\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"None\"\n",
" }\n",
" return details\n",
"\n",
"def get_quantity_details(input_log):\n",
" \"\"\"Returns details about quantities for the given input log.\"\"\"\n",
" purchase = input_log.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0]\n",
" seeding_log = input_log.plant.get_logs_of_type(neo.Log.Seeding)[0]\n",
" seeding_value = seeding_log.quantities[1].value\n",
" aufwandmenge = input_log.quantities[0].value / seeding_value\n",
" \n",
" quantity_details = {\n",
" \"quant0_type\": input_log.quantities[0].type,\n",
" \"quant0_measure\": input_log.quantities[0].measure,\n",
" \"quant0_value\": f\"{input_log.quantities[0].value}{input_log.quantities[0].units.name}\",\n",
" \"Aufwandmenge\": f\"{aufwandmenge:.2f} l/ha\",\n",
" \"quant0_inventory_adjustment\": input_log.quantities[0].inventory_adjustment\n",
" }\n",
" \n",
" if len(input_log.quantities) > 1:\n",
" quantity_details.update({\n",
" \"quant1_type\": input_log.quantities[1].type,\n",
" \"quant1_measure\": input_log.quantities[1].measure,\n",
" \"quant1_value\": f\"{input_log.quantities[1].value}{input_log.quantities[1].units.name}\",\n",
" \"quant1_unit_price\": input_log.quantities[1].unit_price,\n",
" \"quant1_total_price\": input_log.quantities[1].total_price\n",
" })\n",
" \n",
" total_price = input_log.quantities[1].total_price + input_log.quantities[0].value * purchase.quantities[0].unit_price\n",
" quantity_details[\"total_cost\"] = f\"{total_price:.2f} €\"\n",
" \n",
" return quantity_details\n",
"\n",
"def get_purchase_details(purchase):\n",
" \"\"\"Returns details about purchase quantities.\"\"\"\n",
" purchase_details = {\n",
" \"purch_name\": purchase.name,\n",
" \"purch_inv_asset\": purchase.quantities[0].inventory_asset.name,\n",
" \"purch_q0_type\": purchase.quantities[0].type,\n",
" \"purch_q0_measure\": purchase.quantities[0].measure,\n",
" \"purch_q0_unit_price\": purchase.quantities[0].unit_price\n",
" }\n",
" \n",
" for i, quantity in enumerate(purchase.quantities[1:], start=1):\n",
" purchase_details.update({\n",
" f\"purch_q{i}_type\": quantity.type,\n",
" f\"purch_q{i}_material_type\": quantity.material_types[0].name if quantity.material_types else \"None\",\n",
" f\"purch_q{i}_measure\": quantity.measure,\n",
" f\"purch_q{i}_value\": f\"{quantity.value} {quantity.units.name}\"\n",
" })\n",
" \n",
" return purchase_details\n",
"\n",
"def export_to_excel(df, file_path, date_column=\"D\"):\n",
" # Exportiere den DataFrame zu Excel\n",
" df.to_excel(file_path, index=False)\n",
" \n",
" # Lade die Arbeitsmappe, um Formatierungen hinzuzufügen\n",
" workbook = load_workbook(file_path)\n",
" worksheet = workbook.active\n",
" worksheet.auto_filter.ref = worksheet.dimensions\n",
"\n",
" # Passen Sie die Spaltenbreite an und aktivieren Sie den Zeilenumbruch\n",
" for col in worksheet.columns:\n",
" max_length = 0\n",
" col_letter = get_column_letter(col[0].column)\n",
" for cell in col:\n",
" cell.alignment = Alignment(wrap_text=True)\n",
" \n",
" # Setze das Datumsformat für die angegebene Spalte\n",
" if col_letter == date_column:\n",
" cell.number_format = 'DD.MM.YYYY'\n",
" \n",
" max_length = max(max_length, len(str(cell.value)) if cell.value else 0)\n",
" \n",
" adjusted_width = (max_length + 2) * 1.0\n",
" worksheet.column_dimensions[col_letter].width = adjusted_width\n",
"\n",
" workbook.save(file_path)\n",
" print(f\"Die Datei wurde erfolgreich nach '{file_path}' exportiert, mit Autofilter, Zeilenumbruch und angepasster Spaltenbreite.\")\n",
"\n",
"def main():\n",
" logs = neo.Log.Input.get_list()\n",
" log_data = []\n",
"\n",
" for log in logs:\n",
" log_details = format_log_details(log)\n",
" input_log = neo.Log.Input.from_id(log.id)\n",
" quantity_details = get_quantity_details(input_log)\n",
" purchase = input_log.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0]\n",
" purchase_details = get_purchase_details(purchase)\n",
" seeding_log = input_log.plant.get_logs_of_type(neo.Log.Seeding)[0]\n",
" log_details[\"seeding_area\"] = f\"{seeding_log.quantities[1].value} {seeding_log.quantities[1].units.name}\"\n",
"\n",
" combined_details = {**log_details, **quantity_details, **purchase_details}\n",
" log_data.append(combined_details)\n",
" \n",
" df = pd.DataFrame(log_data)\n",
" print(df)\n",
"\n",
" # Exportiere den DataFrame nach Excel\n",
" downloads_folder = os.path.join(os.path.expanduser(\"~\"), \"Downloads\")\n",
" file_path = os.path.join(downloads_folder, \"PlantLogs.xlsx\")\n",
"\n",
" # Prüfe, ob die Datei bereits existiert\n",
" if os.path.exists(file_path):\n",
" overwrite = input(f\"Die Datei '{file_path}' existiert bereits. Möchten Sie sie überschreiben? (ja/nein): \")\n",
" if overwrite.lower() == 'ja':\n",
" export_to_excel(df, file_path)\n",
" else:\n",
" print(\"Der Export wurde abgebrochen.\")\n",
" else:\n",
" export_to_excel(df, file_path)\n",
"\n",
"if __name__ == \"__main__\":\n",
" main()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b98c0f4-2c9a-4033-bfb6-526627b8649a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"id": "69002e37-7e9a-42d9-b2f6-b9d1c58b879b",
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true,
"source_hidden": true
},
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>log_type</th>\n",
" <th>name</th>\n",
" <th>timestamp</th>\n",
" <th>plant_name</th>\n",
" <th>plant_area</th>\n",
" <th>plant_area_unit</th>\n",
" <th>plant_crop</th>\n",
" <th>plant_season</th>\n",
" <th>plant_location</th>\n",
" <th>equipment</th>\n",
" <th>...</th>\n",
" <th>purch_q4_value</th>\n",
" <th>purch_q4_unit</th>\n",
" <th>purch_q5_type</th>\n",
" <th>purch_q5_measure</th>\n",
" <th>purch_q5_value</th>\n",
" <th>purch_q5_unit</th>\n",
" <th>purch_q6_type</th>\n",
" <th>purch_q6_measure</th>\n",
" <th>purch_q6_value</th>\n",
" <th>purch_q6_unit</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>log--activity</td>\n",
" <td>Move 24/25 Nachtweide Raps Plant to Nachtweide</td>\n",
" <td>14.10.2024</td>\n",
" <td>W-Raps Nachtweide Plant 24/25</td>\n",
" <td>4.5</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Nachtweide</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>log--activity</td>\n",
" <td>Move W-Raps Helmacker Plant 24/25 to Helmacker</td>\n",
" <td>14.10.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>log--activity</td>\n",
" <td>Move W-Raps Helmacker Plant 24/25 to Helmacker</td>\n",
" <td>22.10.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>log--maintenance</td>\n",
" <td>Scheibeneggen Helmacker Maintenance 24/25</td>\n",
" <td>28.07.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td>Scheibenegge Catros</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>log--purchase</td>\n",
" <td>Schneckenkorn Purchase 24/25</td>\n",
" <td>11.08.2024</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>log--purchase</td>\n",
" <td>Innovert Raps Purchase 24/25</td>\n",
" <td>10.08.2024</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>log--purchase</td>\n",
" <td>W-Raps Saatgut Otello KWS Saatgut Purchase 24/25</td>\n",
" <td>01.08.2024</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>log--seeding</td>\n",
" <td>W-Raps Otello KWS Nachtweide Seeding 24/25</td>\n",
" <td>28.08.2024</td>\n",
" <td>W-Raps Nachtweide Plant 24/25</td>\n",
" <td>4.5</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Nachtweide</td>\n",
" <td>Sähmaschine Cataya</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>log--seeding</td>\n",
" <td>W-Raps Otello KWS Helmacker Seeding 24/25</td>\n",
" <td>22.08.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td>Sähmaschine Cataya</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>log--input</td>\n",
" <td>Innovert Raps Input 24/25</td>\n",
" <td>03.11.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td>Spritze</td>\n",
" <td>...</td>\n",
" <td>60.0</td>\n",
" <td>g/l</td>\n",
" <td>quantity--material</td>\n",
" <td>ratio</td>\n",
" <td>70.0</td>\n",
" <td>g/l</td>\n",
" <td>quantity--material</td>\n",
" <td>ratio</td>\n",
" <td>4.0</td>\n",
" <td>g/l</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>log--input</td>\n",
" <td>Innovert Raps Input 24/25</td>\n",
" <td>12.10.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td>Spritze</td>\n",
" <td>...</td>\n",
" <td>60.0</td>\n",
" <td>g/l</td>\n",
" <td>quantity--material</td>\n",
" <td>ratio</td>\n",
" <td>70.0</td>\n",
" <td>g/l</td>\n",
" <td>quantity--material</td>\n",
" <td>ratio</td>\n",
" <td>4.0</td>\n",
" <td>g/l</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>log--medical</td>\n",
" <td>Schneckenkorn Medical 24/25</td>\n",
" <td>30.08.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td>Schneckenkornstreuer Leinfelder</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>log--harvest</td>\n",
" <td>W-Raps Nachtweide Harvest 24/25</td>\n",
" <td>28.10.2024</td>\n",
" <td>W-Raps Nachtweide Plant 24/25</td>\n",
" <td>4.5</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Nachtweide</td>\n",
" <td>Mähdrescher Leinfelder</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>log--harvest</td>\n",
" <td>W-Raps Helmacker Harvest 24/25</td>\n",
" <td>20.10.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td>Mähdrescher Leinfelder</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>log--sale</td>\n",
" <td>W-Raps Sale 24/25</td>\n",
" <td>28.10.2024</td>\n",
" <td>W-Raps Helmacker Plant 24/25</td>\n",
" <td>3.02</td>\n",
" <td>ha</td>\n",
" <td>Raps</td>\n",
" <td>24/25</td>\n",
" <td>Helmacker</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>15 rows × 105 columns</p>\n",
"</div>"
],
"text/plain": [
" log_type name \\\n",
"0 log--activity Move 24/25 Nachtweide Raps Plant to Nachtweide \n",
"1 log--activity Move W-Raps Helmacker Plant 24/25 to Helmacker \n",
"2 log--activity Move W-Raps Helmacker Plant 24/25 to Helmacker \n",
"3 log--maintenance Scheibeneggen Helmacker Maintenance 24/25 \n",
"4 log--purchase Schneckenkorn Purchase 24/25 \n",
"5 log--purchase Innovert Raps Purchase 24/25 \n",
"6 log--purchase W-Raps Saatgut Otello KWS Saatgut Purchase 24/25 \n",
"7 log--seeding W-Raps Otello KWS Nachtweide Seeding 24/25 \n",
"8 log--seeding W-Raps Otello KWS Helmacker Seeding 24/25 \n",
"9 log--input Innovert Raps Input 24/25 \n",
"10 log--input Innovert Raps Input 24/25 \n",
"11 log--medical Schneckenkorn Medical 24/25 \n",
"12 log--harvest W-Raps Nachtweide Harvest 24/25 \n",
"13 log--harvest W-Raps Helmacker Harvest 24/25 \n",
"14 log--sale W-Raps Sale 24/25 \n",
"\n",
" timestamp plant_name plant_area plant_area_unit \\\n",
"0 14.10.2024 W-Raps Nachtweide Plant 24/25 4.5 ha \n",
"1 14.10.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"2 22.10.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"3 28.07.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"4 11.08.2024 \n",
"5 10.08.2024 \n",
"6 01.08.2024 \n",
"7 28.08.2024 W-Raps Nachtweide Plant 24/25 4.5 ha \n",
"8 22.08.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"9 03.11.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"10 12.10.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"11 30.08.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"12 28.10.2024 W-Raps Nachtweide Plant 24/25 4.5 ha \n",
"13 20.10.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"14 28.10.2024 W-Raps Helmacker Plant 24/25 3.02 ha \n",
"\n",
" plant_crop plant_season plant_location equipment \\\n",
"0 Raps 24/25 Nachtweide \n",
"1 Raps 24/25 Helmacker \n",
"2 Raps 24/25 Helmacker \n",
"3 Raps 24/25 Helmacker Scheibenegge Catros \n",
"4 \n",
"5 \n",
"6 \n",
"7 Raps 24/25 Nachtweide Sähmaschine Cataya \n",
"8 Raps 24/25 Helmacker Sähmaschine Cataya \n",
"9 Raps 24/25 Helmacker Spritze \n",
"10 Raps 24/25 Helmacker Spritze \n",
"11 Raps 24/25 Helmacker Schneckenkornstreuer Leinfelder \n",
"12 Raps 24/25 Nachtweide Mähdrescher Leinfelder \n",
"13 Raps 24/25 Helmacker Mähdrescher Leinfelder \n",
"14 Raps 24/25 Helmacker \n",
"\n",
" ... purch_q4_value purch_q4_unit purch_q5_type purch_q5_measure \\\n",
"0 ... NaN NaN NaN NaN \n",
"1 ... NaN NaN NaN NaN \n",
"2 ... NaN NaN NaN NaN \n",
"3 ... NaN NaN NaN NaN \n",
"4 ... NaN NaN NaN NaN \n",
"5 ... NaN NaN NaN NaN \n",
"6 ... NaN NaN NaN NaN \n",
"7 ... NaN NaN NaN NaN \n",
"8 ... NaN NaN NaN NaN \n",
"9 ... 60.0 g/l quantity--material ratio \n",
"10 ... 60.0 g/l quantity--material ratio \n",
"11 ... NaN NaN NaN NaN \n",
"12 ... NaN NaN NaN NaN \n",
"13 ... NaN NaN NaN NaN \n",
"14 ... NaN NaN NaN NaN \n",
"\n",
" purch_q5_value purch_q5_unit purch_q6_type purch_q6_measure \\\n",
"0 NaN NaN NaN NaN \n",
"1 NaN NaN NaN NaN \n",
"2 NaN NaN NaN NaN \n",
"3 NaN NaN NaN NaN \n",
"4 NaN NaN NaN NaN \n",
"5 NaN NaN NaN NaN \n",
"6 NaN NaN NaN NaN \n",
"7 NaN NaN NaN NaN \n",
"8 NaN NaN NaN NaN \n",
"9 70.0 g/l quantity--material ratio \n",
"10 70.0 g/l quantity--material ratio \n",
"11 NaN NaN NaN NaN \n",
"12 NaN NaN NaN NaN \n",
"13 NaN NaN NaN NaN \n",
"14 NaN NaN NaN NaN \n",
"\n",
" purch_q6_value purch_q6_unit \n",
"0 NaN NaN \n",
"1 NaN NaN \n",
"2 NaN NaN \n",
"3 NaN NaN \n",
"4 NaN NaN \n",
"5 NaN NaN \n",
"6 NaN NaN \n",
"7 NaN NaN \n",
"8 NaN NaN \n",
"9 4.0 g/l \n",
"10 4.0 g/l \n",
"11 NaN NaN \n",
"12 NaN NaN \n",
"13 NaN NaN \n",
"14 NaN NaN \n",
"\n",
"[15 rows x 105 columns]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#Mein Master Report mit DF 2.0\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"import neofarm.lib as neo\n",
"\n",
"def process_logs():\n",
" # Liste zum Sammeln aller Log-Daten\n",
" all_logs = []\n",
"\n",
" # Activity Logs\n",
" logs = neo.Log.Activity.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" \n",
" \n",
" \n",
" }\n",
"\n",
" all_logs.append(base_data)\n",
"\n",
"\n",
"\n",
"\n",
" # Maintenance Logs\n",
" logs = neo.Log.Maintenance.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" #\"notes\": log.notes,\n",
" \n",
" #Daten für q0\n",
" \"q0_type\": log.quantities[0].type,\n",
" #\"q0_material_type\": log.quantities[0].material_types[0].name if log.quantities[0].material_types else None,\n",
" \"q0_material_type\": \"\",\n",
" \"q0_measure\": log.quantities[0].measure if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'measure') else \"\",\n",
" \"q0_value\": log.quantities[0].value if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'value') else \"\",\n",
" \"q0_unit\": log.quantities[0].units.name if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'units') and hasattr(log.quantities[0].units, 'name') else \"\",\n",
" \"q0_unit_price\": log.quantities[0].unit_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'unit_price') else \"\",\n",
" \"q0_total_price\": log.quantities[0].total_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'total_price') else \"\",\n",
" \"q0_inventory_adjustment\": log.quantities[0].inventory_adjustment if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'inventory_adjustment') else \"\",\n",
" \"q0_inventory_asset\": log.quantities[0].q0_inventory_asset if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'q0_inventory_asset') else \"\",\n",
" }\n",
" \n",
" #Abfrage für q1 bis q7 \n",
" if len(log.quantities) > 1:\n",
" base_data.update({\n",
" \n",
" \"q1_type\": log.quantities[1].type,\n",
" #\"q1_material_type\": log.quantities[1].material_types[1].name if log.quantities[1].material_types else None,\n",
" \"q1_material_type\": \"\",\n",
" \"q1_measure\": log.quantities[1].measure if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'measure') else \"\",\n",
" \"q1_value\": log.quantities[1].value if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'value') else \"\",\n",
" \"q1_unit\": log.quantities[1].units.name if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'units') and hasattr(log.quantities[1].units, 'name') else \"\",\n",
" \"q1_unit_price\": log.quantities[1].unit_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'unit_price') else \"\",\n",
" \"q1_total_price\": log.quantities[1].total_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'total_price') else \"\",\n",
" \"q1_inventory_adjustment\": log.quantities[1].inventory_adjustment if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'inventory_adjustment') else \"\",\n",
" \"q1_inventory_asset\": log.quantities[1].q1_inventory_asset if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'q1_inventory_asset') else \"\",\n",
" \n",
" })\n",
"\n",
" if len(log.quantities) > 2:\n",
" base_data.update({\n",
" \"q2_type\": log.quantities[2].type,\n",
" #\"q2_material_type\": log.quantities[2].material_types[2].name if log.quantities[2].material_types else None,\n",
" \"q2_material_type\": \"\",\n",
" \"q2_measure\": log.quantities[2].measure if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'measure') else \"\",\n",
" \"q2_value\": log.quantities[2].value if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'value') else \"\",\n",
" \"q2_unit\": log.quantities[2].units.name if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'units') and hasattr(log.quantities[2].units, 'name') else \"\",\n",
" \"q2_unit_price\": log.quantities[2].unit_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'unit_price') else \"\",\n",
" \"q2_total_price\": log.quantities[2].total_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'total_price') else \"\",\n",
" \"q2_inventory_adjustment\": log.quantities[2].inventory_adjustment if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'inventory_adjustment') else \"\",\n",
" \"q2_inventory_asset\": log.quantities[2].q2_inventory_asset if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'q2_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 3:\n",
" base_data.update({\n",
" \"q3_type\": log.quantities[3].type,\n",
" #\"q3_material_type\": log.quantities[3].material_types[3].name if log.quantities[3].material_types else None,\n",
" \"q3_material_type\": \"\",\n",
" \"q3_measure\": log.quantities[3].measure if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'measure') else \"\",\n",
" \"q3_value\": log.quantities[3].value if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'value') else \"\",\n",
" \"q3_unit\": log.quantities[3].units.name if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'units') and hasattr(log.quantities[3].units, 'name') else \"\",\n",
" \"q3_unit_price\": log.quantities[3].unit_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'unit_price') else \"\",\n",
" \"q3_total_price\": log.quantities[3].total_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'total_price') else \"\",\n",
" \"q3_inventory_adjustment\": log.quantities[3].inventory_adjustment if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'inventory_adjustment') else \"\",\n",
" \"q3_inventory_asset\": log.quantities[3].q3_inventory_asset if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'q3_inventory_asset') else \"\",\n",
" })\n",
"\n",
"\n",
"\n",
" all_logs.append(base_data)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" \n",
" \n",
"\n",
" # Purchase Logs\n",
" logs = neo.Log.Purchase.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" \n",
" #Daten für q0\n",
" \"q0_type\": log.quantities[0].type,\n",
" #\"q0_material_type\": log.quantities[0].material_types[0].name if log.quantities[0].material_types else None,\n",
" \"q0_material_type\": \"\",\n",
" \"q0_measure\": log.quantities[0].measure if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'measure') else \"\",\n",
" \"q0_value\": log.quantities[0].value if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'value') else \"\",\n",
" \"q0_unit\": log.quantities[0].units.name if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'units') and hasattr(log.quantities[0].units, 'name') else \"\",\n",
" \"q0_unit_price\": log.quantities[0].unit_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'unit_price') else \"\",\n",
" \"q0_total_price\": log.quantities[0].total_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'total_price') else \"\",\n",
" \"q0_inventory_adjustment\": log.quantities[0].inventory_adjustment if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'inventory_adjustment') else \"\",\n",
" \"q0_inventory_asset\": log.quantities[0].q0_inventory_asset if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'q0_inventory_asset') else \"\",\n",
" }\n",
" \n",
" #Abfrage für q1 bis q7 \n",
" if len(log.quantities) > 1:\n",
" base_data.update({\n",
" \n",
" \"q1_type\": log.quantities[1].type,\n",
" \"q1_material_type\": log.quantities[1].material_types[0].name if log.quantities[1].material_types else None,\n",
" #\"q1_material_type\": \"\",\n",
" \"q1_measure\": log.quantities[1].measure if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'measure') else \"\",\n",
" \"q1_value\": log.quantities[1].value if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'value') else \"\",\n",
" \"q1_unit\": log.quantities[1].units.name if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'units') and hasattr(log.quantities[1].units, 'name') else \"\",\n",
" \"q1_unit_price\": log.quantities[1].unit_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'unit_price') else \"\",\n",
" \"q1_total_price\": log.quantities[1].total_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'total_price') else \"\",\n",
" \"q1_inventory_adjustment\": log.quantities[1].inventory_adjustment if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'inventory_adjustment') else \"\",\n",
" \"q1_inventory_asset\": log.quantities[1].q1_inventory_asset if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'q1_inventory_asset') else \"\",\n",
" \n",
" })\n",
"\n",
" if len(log.quantities) > 2:\n",
" base_data.update({\n",
" \"q2_type\": log.quantities[2].type,\n",
" \"q2_material_type\": log.quantities[2].material_types[0].name if log.quantities[2].material_types else None,\n",
" \"q2_measure\": log.quantities[2].measure if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'measure') else \"\",\n",
" \"q2_value\": log.quantities[2].value if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'value') else \"\",\n",
" \"q2_unit\": log.quantities[2].units.name if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'units') and hasattr(log.quantities[2].units, 'name') else \"\",\n",
" \"q2_unit_price\": log.quantities[2].unit_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'unit_price') else \"\",\n",
" \"q2_total_price\": log.quantities[2].total_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'total_price') else \"\",\n",
" \"q2_inventory_adjustment\": log.quantities[2].inventory_adjustment if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'inventory_adjustment') else \"\",\n",
" \"q2_inventory_asset\": log.quantities[2].q2_inventory_asset if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'q2_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 3:\n",
" base_data.update({\n",
" \"q3_type\": log.quantities[3].type,\n",
" \"q3_material_type\": log.quantities[3].material_types[0].name if log.quantities[3].material_types else None,\n",
" \"q3_measure\": log.quantities[3].measure if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'measure') else \"\",\n",
" \"q3_value\": log.quantities[3].value if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'value') else \"\",\n",
" \"q3_unit\": log.quantities[3].units.name if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'units') and hasattr(log.quantities[3].units, 'name') else \"\",\n",
" \"q3_unit_price\": log.quantities[3].unit_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'unit_price') else \"\",\n",
" \"q3_total_price\": log.quantities[3].total_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'total_price') else \"\",\n",
" \"q3_inventory_adjustment\": log.quantities[3].inventory_adjustment if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'inventory_adjustment') else \"\",\n",
" \"q3_inventory_asset\": log.quantities[3].q3_inventory_asset if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'q3_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 4:\n",
" base_data.update({\n",
" \"q4_type\": log.quantities[4].type,\n",
" \"q4_material_type\": log.quantities[4].material_types[0].name if log.quantities[4].material_types else None,\n",
" \"q4_measure\": log.quantities[4].measure if log and log.quantities and len(log.quantities) > 4 and hasattr(log.quantities[4], 'measure') else \"\",\n",
" \"q4_value\": log.quantities[4].value if log and log.quantities and len(log.quantities) > 4 and hasattr(log.quantities[4], 'value') else \"\",\n",
" \"q4_unit\": log.quantities[4].units.name if log and log.quantities and len(log.quantities) > 4 and hasattr(log.quantities[4], 'units') and hasattr(log.quantities[4].units, 'name') else \"\",\n",
" \"q4_unit_price\": log.quantities[4].unit_price if log and log.quantities and len(log.quantities) > 4 and hasattr(log.quantities[4], 'unit_price') else \"\",\n",
" \"q4_total_price\": log.quantities[4].total_price if log and log.quantities and len(log.quantities) > 4 and hasattr(log.quantities[4], 'total_price') else \"\",\n",
" \"q4_inventory_adjustment\": log.quantities[4].inventory_adjustment if log and log.quantities and len(log.quantities) > 4 and hasattr(log.quantities[4], 'inventory_adjustment') else \"\",\n",
" \"q4_inventory_asset\": log.quantities[4].q4_inventory_asset if log and log.quantities and len(log.quantities) > 4 and hasattr(log.quantities[4], 'q4_inventory_asset') else \"\",\n",
" })\n",
" all_logs.append(base_data)\n",
" \n",
" if len(log.quantities) > 5:\n",
" base_data.update({\n",
" \"q5_type\": log.quantities[5].type,\n",
" \"q5_material_type\": log.quantities[5].material_types[0].name if log.quantities[5].material_types else None,\n",
" \"q5_measure\": log.quantities[5].measure if log and log.quantities and len(log.quantities) > 5 and hasattr(log.quantities[5], 'measure') else \"\",\n",
" \"q5_value\": log.quantities[5].value if log and log.quantities and len(log.quantities) > 5 and hasattr(log.quantities[5], 'value') else \"\",\n",
" \"q5_unit\": log.quantities[5].units.name if log and log.quantities and len(log.quantities) > 5 and hasattr(log.quantities[5], 'units') and hasattr(log.quantities[5].units, 'name') else \"\",\n",
" \"q5_unit_price\": log.quantities[5].unit_price if log and log.quantities and len(log.quantities) > 5 and hasattr(log.quantities[5], 'unit_price') else \"\",\n",
" \"q5_total_price\": log.quantities[5].total_price if log and log.quantities and len(log.quantities) > 5 and hasattr(log.quantities[5], 'total_price') else \"\",\n",
" \"q5_inventory_adjustment\": log.quantities[5].inventory_adjustment if log and log.quantities and len(log.quantities) > 5 and hasattr(log.quantities[5], 'inventory_adjustment') else \"\",\n",
" \"q5_inventory_asset\": log.quantities[5].q5_inventory_asset if log and log.quantities and len(log.quantities) > 5 and hasattr(log.quantities[5], 'q5_inventory_asset') else \"\",\n",
" })\n",
" if len(log.quantities) > 6:\n",
" base_data.update({\n",
" \"q6_type\": log.quantities[6].type,\n",
" \"q6_material_type\": log.quantities[6].material_types[0].name if log.quantities[6].material_types else None,\n",
" \"q6_measure\": log.quantities[6].measure if log and log.quantities and len(log.quantities) > 6 and hasattr(log.quantities[6], 'measure') else \"\",\n",
" \"q6_value\": log.quantities[6].value if log and log.quantities and len(log.quantities) > 6 and hasattr(log.quantities[6], 'value') else \"\",\n",
" \"q6_unit\": log.quantities[6].units.name if log and log.quantities and len(log.quantities) > 6 and hasattr(log.quantities[6], 'units') and hasattr(log.quantities[6].units, 'name') else \"\",\n",
" \"q6_unit_price\": log.quantities[6].unit_price if log and log.quantities and len(log.quantities) > 6 and hasattr(log.quantities[6], 'unit_price') else \"\",\n",
" \"q6_total_price\": log.quantities[6].total_price if log and log.quantities and len(log.quantities) > 6 and hasattr(log.quantities[6], 'total_price') else \"\",\n",
" \"q6_inventory_adjustment\": log.quantities[6].inventory_adjustment if log and log.quantities and len(log.quantities) > 6 and hasattr(log.quantities[6], 'inventory_adjustment') else \"\",\n",
" \"q6_inventory_asset\": log.quantities[6].q6_inventory_asset if log and log.quantities and len(log.quantities) > 6 and hasattr(log.quantities[6], 'q6_inventory_asset') else \"\",\n",
" })\n",
" \n",
"\n",
"\n",
"\n",
"\n",
" # Seeding Logs\n",
" logs = neo.Log.Seeding.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" #\"notes\": log.notes,\n",
" \n",
" #Daten für q0\n",
" \"q0_type\": log.quantities[0].type,\n",
" #\"q0_material_type\": log.quantities[0].material_types[0].name if log.quantities[0].material_types else None,\n",
" \"q0_material_type\": \"\",\n",
" \"q0_measure\": log.quantities[0].measure if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'measure') else \"\",\n",
" \"q0_value\": log.quantities[0].value if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'value') else \"\",\n",
" \"q0_unit\": log.quantities[0].units.name if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'units') and hasattr(log.quantities[0].units, 'name') else \"\",\n",
" \"q0_unit_price\": log.quantities[0].unit_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'unit_price') else \"\",\n",
" \"q0_total_price\": log.quantities[0].total_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'total_price') else \"\",\n",
" \"q0_inventory_adjustment\": log.quantities[0].inventory_adjustment if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'inventory_adjustment') else \"\",\n",
" \"q0_inventory_asset\": log.quantities[0].q0_inventory_asset if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'q0_inventory_asset') else \"\",\n",
" }\n",
" \n",
" #Abfrage für q1 bis q7 \n",
" if len(log.quantities) > 1:\n",
" base_data.update({\n",
" \n",
" \"q1_type\": log.quantities[1].type,\n",
" #\"q1_material_type\": log.quantities[1].material_types[1].name if log.quantities[1].material_types else None,\n",
" \"q1_material_type\": \"\",\n",
" \"q1_measure\": log.quantities[1].measure if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'measure') else \"\",\n",
" \"q1_value\": log.quantities[1].value if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'value') else \"\",\n",
" \"q1_unit\": log.quantities[1].units.name if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'units') and hasattr(log.quantities[1].units, 'name') else \"\",\n",
" \"q1_unit_price\": log.quantities[1].unit_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'unit_price') else \"\",\n",
" \"q1_total_price\": log.quantities[1].total_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'total_price') else \"\",\n",
" \"q1_inventory_adjustment\": log.quantities[1].inventory_adjustment if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'inventory_adjustment') else \"\",\n",
" \"q1_inventory_asset\": log.quantities[1].q1_inventory_asset if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'q1_inventory_asset') else \"\",\n",
" \n",
" })\n",
"\n",
" if len(log.quantities) > 2:\n",
" base_data.update({\n",
" \"q2_type\": log.quantities[2].type,\n",
" #\"q2_material_type\": log.quantities[2].material_types[2].name if log.quantities[2].material_types else None,\n",
" \"q2_material_type\": \"\",\n",
" \"q2_measure\": log.quantities[2].measure if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'measure') else \"\",\n",
" \"q2_value\": log.quantities[2].value if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'value') else \"\",\n",
" \"q2_unit\": log.quantities[2].units.name if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'units') and hasattr(log.quantities[2].units, 'name') else \"\",\n",
" \"q2_unit_price\": log.quantities[2].unit_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'unit_price') else \"\",\n",
" \"q2_total_price\": log.quantities[2].total_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'total_price') else \"\",\n",
" \"q2_inventory_adjustment\": log.quantities[2].inventory_adjustment if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'inventory_adjustment') else \"\",\n",
" \"q2_inventory_asset\": log.quantities[2].q2_inventory_asset if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'q2_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 3:\n",
" base_data.update({\n",
" \"q3_type\": log.quantities[3].type,\n",
" #\"q3_material_type\": log.quantities[3].material_types[3].name if log.quantities[3].material_types else None,\n",
" \"q3_material_type\": \"\",\n",
" \"q3_measure\": log.quantities[3].measure if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'measure') else \"\",\n",
" \"q3_value\": log.quantities[3].value if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'value') else \"\",\n",
" \"q3_unit\": log.quantities[3].units.name if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'units') and hasattr(log.quantities[3].units, 'name') else \"\",\n",
" \"q3_unit_price\": log.quantities[3].unit_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'unit_price') else \"\",\n",
" \"q3_total_price\": log.quantities[3].total_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'total_price') else \"\",\n",
" \"q3_inventory_adjustment\": log.quantities[3].inventory_adjustment if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'inventory_adjustment') else \"\",\n",
" \"q3_inventory_asset\": log.quantities[3].q3_inventory_asset if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'q3_inventory_asset') else \"\",\n",
" })\n",
"\n",
"\n",
"\n",
" all_logs.append(base_data)\n",
" \n",
"\n",
" # Input Logs\n",
" logs = neo.Log.Input.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" purchase = log.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0]\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" #\"notes\": log.notes,\n",
" \n",
" #Daten für q0\n",
" \"q0_type\": log.quantities[0].type,\n",
" #\"q0_material_type\": log.quantities[0].material_types[0].name if log.quantities[0].material_types else None,\n",
" \"q0_material_type\": \"\",\n",
" \"q0_measure\": log.quantities[0].measure if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'measure') else \"\",\n",
" \"q0_value\": log.quantities[0].value if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'value') else \"\",\n",
" \"q0_unit\": log.quantities[0].units.name if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'units') and hasattr(log.quantities[0].units, 'name') else \"\",\n",
" \"q0_unit_price\": log.quantities[0].unit_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'unit_price') else \"\",\n",
" \"q0_total_price\": log.quantities[0].total_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'total_price') else \"\",\n",
" \"q0_inventory_adjustment\": log.quantities[0].inventory_adjustment if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'inventory_adjustment') else \"\",\n",
" \"q0_inventory_asset\": log.quantities[0].q0_inventory_asset if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'q0_inventory_asset') else \"\",\n",
" }\n",
" \n",
" #Abfrage für q1 bis q7 \n",
" if len(log.quantities) > 1:\n",
" base_data.update({\n",
" \n",
" \"q1_type\": log.quantities[1].type,\n",
" #\"q1_material_type\": log.quantities[1].material_types[0].name if log.quantities[1].material_types else None,\n",
" \"q1_material_type\": \"\",\n",
" \"q1_measure\": log.quantities[1].measure if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'measure') else \"\",\n",
" \"q1_value\": log.quantities[1].value if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'value') else \"\",\n",
" \"q1_unit\": log.quantities[1].units.name if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'units') and hasattr(log.quantities[1].units, 'name') else \"\",\n",
" \"q1_unit_price\": log.quantities[1].unit_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'unit_price') else \"\",\n",
" \"q1_total_price\": log.quantities[1].total_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'total_price') else \"\",\n",
" \"q1_inventory_adjustment\": log.quantities[1].inventory_adjustment if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'inventory_adjustment') else \"\",\n",
" \"q1_inventory_asset\": log.quantities[1].q1_inventory_asset if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'q1_inventory_asset') else \"\",\n",
" \n",
" })\n",
"\n",
" if len(log.quantities) > 2:\n",
" base_data.update({\n",
" \"q2_type\": log.quantities[2].type,\n",
" #\"q2_material_type\": log.quantities[2].material_types[0].name if log.quantities[2].material_types else None,\n",
" \"q2_material_type\": \"\",\n",
" \"q2_measure\": log.quantities[2].measure if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'measure') else \"\",\n",
" \"q2_value\": log.quantities[2].value if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'value') else \"\",\n",
" \"q2_unit\": log.quantities[2].units.name if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'units') and hasattr(log.quantities[2].units, 'name') else \"\",\n",
" \"q2_unit_price\": log.quantities[2].unit_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'unit_price') else \"\",\n",
" \"q2_total_price\": log.quantities[2].total_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'total_price') else \"\",\n",
" \"q2_inventory_adjustment\": log.quantities[2].inventory_adjustment if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'inventory_adjustment') else \"\",\n",
" \"q2_inventory_asset\": log.quantities[2].q2_inventory_asset if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'q2_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 3:\n",
" base_data.update({\n",
" \"q3_type\": log.quantities[3].type,\n",
" #\"q3_material_type\": log.quantities[3].material_types[0].name if log.quantities[3].material_types else None,\n",
" \"q3_material_type\": \"\",\n",
" \"q3_measure\": log.quantities[3].measure if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'measure') else \"\",\n",
" \"q3_value\": log.quantities[3].value if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'value') else \"\",\n",
" \"q3_unit\": log.quantities[3].units.name if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'units') and hasattr(log.quantities[3].units, 'name') else \"\",\n",
" \"q3_unit_price\": log.quantities[3].unit_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'unit_price') else \"\",\n",
" \"q3_total_price\": log.quantities[3].total_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'total_price') else \"\",\n",
" \"q3_inventory_adjustment\": log.quantities[3].inventory_adjustment if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'inventory_adjustment') else \"\",\n",
" \"q3_inventory_asset\": log.quantities[3].q3_inventory_asset if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'q3_inventory_asset') else \"\",\n",
" })\n",
" #Purchase logs q0\n",
" base_data.update({\n",
" \"purch_name\": purchase.name,\n",
" \"purch_inv_asset\": purchase.quantities[0].inventory_asset.name,\n",
" \"purch_q0_type\": purchase.quantities[0].type,\n",
" \"purch_q0_measure\": purchase.quantities[0].measure,\n",
" \"purch_q0_unit_price\": purchase.quantities[0].unit_price,\n",
" \"purch_q0_unit\": purchase.quantities[0].units.name,\n",
" })\n",
" #Purchase logs q1\n",
" base_data.update({\n",
" \"purch_q1_type\": purchase.quantities[1].type,\n",
" \"purch_material_type\": purchase.quantities[1].material_types[0].name,\n",
" \"purch_q1_measure\": purchase.quantities[1].measure,\n",
" \"purch_q1_value\": purchase.quantities[1].value,\n",
" \"purch_q1_unit\": purchase.quantities[1].units.name,\n",
"\n",
" })\n",
"\n",
" #Purchase logs q2\n",
" base_data.update({\n",
" \"purch_q2_type\": purchase.quantities[2].type,\n",
" \"purch_material_type\": purchase.quantities[2].material_types[0].name,\n",
" \"purch_q2_measure\": purchase.quantities[2].measure,\n",
" \"purch_q2_value\": purchase.quantities[2].value,\n",
" \"purch_q2_unit\": purchase.quantities[2].units.name,\n",
"\n",
" })\n",
" #Purchase logs q3\n",
" base_data.update({\n",
" \"purch_q3_type\": purchase.quantities[3].type,\n",
" \"purch_material_type\": purchase.quantities[3].material_types[0].name,\n",
" \"purch_q3_measure\": purchase.quantities[3].measure,\n",
" \"purch_q3_value\": purchase.quantities[3].value,\n",
" \"purch_q3_unit\": purchase.quantities[3].units.name,\n",
"\n",
" })\n",
" #Purchase logs q4\n",
" base_data.update({\n",
" \"purch_q4_type\": purchase.quantities[4].type,\n",
" \"purch_material_type\": purchase.quantities[4].material_types[0].name,\n",
" \"purch_q4_measure\": purchase.quantities[4].measure,\n",
" \"purch_q4_value\": purchase.quantities[4].value,\n",
" \"purch_q4_unit\": purchase.quantities[4].units.name,\n",
"\n",
" })\n",
" #Purchase logs q5\n",
" base_data.update({\n",
" \"purch_q5_type\": purchase.quantities[5].type,\n",
" \"purch_material_type\": purchase.quantities[5].material_types[0].name,\n",
" \"purch_q5_measure\": purchase.quantities[5].measure,\n",
" \"purch_q5_value\": purchase.quantities[5].value,\n",
" \"purch_q5_unit\": purchase.quantities[5].units.name,\n",
"\n",
" })\n",
" #Purchase logs q6\n",
" base_data.update({\n",
" \"purch_q6_type\": purchase.quantities[6].type,\n",
" \"purch_material_type\": purchase.quantities[6].material_types[0].name,\n",
" \"purch_q6_measure\": purchase.quantities[6].measure,\n",
" \"purch_q6_value\": purchase.quantities[6].value,\n",
" \"purch_q6_unit\": purchase.quantities[6].units.name,\n",
"\n",
" })\n",
"\n",
" \n",
" all_logs.append(base_data)\n",
"\n",
"\n",
" # Medical Logs\n",
" logs = neo.Log.Medical.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" #\"notes\": log.notes,\n",
" \n",
" #Daten für q0\n",
" \"q0_type\": log.quantities[0].type,\n",
" #\"q0_material_type\": log.quantities[0].material_types[0].name if log.quantities[0].material_types else None,\n",
" \"q0_material_type\": \"\",\n",
" \"q0_measure\": log.quantities[0].measure if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'measure') else \"\",\n",
" \"q0_value\": log.quantities[0].value if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'value') else \"\",\n",
" \"q0_unit\": log.quantities[0].units.name if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'units') and hasattr(log.quantities[0].units, 'name') else \"\",\n",
" \"q0_unit_price\": log.quantities[0].unit_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'unit_price') else \"\",\n",
" \"q0_total_price\": log.quantities[0].total_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'total_price') else \"\",\n",
" \"q0_inventory_adjustment\": log.quantities[0].inventory_adjustment if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'inventory_adjustment') else \"\",\n",
" \"q0_inventory_asset\": log.quantities[0].q0_inventory_asset if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'q0_inventory_asset') else \"\",\n",
" }\n",
" \n",
" #Abfrage für q1 bis q7 \n",
" if len(log.quantities) > 1:\n",
" base_data.update({\n",
" \n",
" \"q1_type\": log.quantities[1].type,\n",
" #\"q1_material_type\": log.quantities[1].material_types[1].name if log.quantities[1].material_types else None,\n",
" \"q1_material_type\": \"\",\n",
" \"q1_measure\": log.quantities[1].measure if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'measure') else \"\",\n",
" \"q1_value\": log.quantities[1].value if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'value') else \"\",\n",
" \"q1_unit\": log.quantities[1].units.name if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'units') and hasattr(log.quantities[1].units, 'name') else \"\",\n",
" \"q1_unit_price\": log.quantities[1].unit_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'unit_price') else \"\",\n",
" \"q1_total_price\": log.quantities[1].total_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'total_price') else \"\",\n",
" \"q1_inventory_adjustment\": log.quantities[1].inventory_adjustment if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'inventory_adjustment') else \"\",\n",
" \"q1_inventory_asset\": log.quantities[1].q1_inventory_asset if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'q1_inventory_asset') else \"\",\n",
" \n",
" })\n",
"\n",
" if len(log.quantities) > 2:\n",
" base_data.update({\n",
" \"q2_type\": log.quantities[2].type,\n",
" #\"q2_material_type\": log.quantities[2].material_types[2].name if log.quantities[2].material_types else None,\n",
" \"q2_material_type\": \"\",\n",
" \"q2_measure\": log.quantities[2].measure if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'measure') else \"\",\n",
" \"q2_value\": log.quantities[2].value if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'value') else \"\",\n",
" \"q2_unit\": log.quantities[2].units.name if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'units') and hasattr(log.quantities[2].units, 'name') else \"\",\n",
" \"q2_unit_price\": log.quantities[2].unit_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'unit_price') else \"\",\n",
" \"q2_total_price\": log.quantities[2].total_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'total_price') else \"\",\n",
" \"q2_inventory_adjustment\": log.quantities[2].inventory_adjustment if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'inventory_adjustment') else \"\",\n",
" \"q2_inventory_asset\": log.quantities[2].q2_inventory_asset if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'q2_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 3:\n",
" base_data.update({\n",
" \"q3_type\": log.quantities[3].type,\n",
" #\"q3_material_type\": log.quantities[3].material_types[3].name if log.quantities[3].material_types else None,\n",
" \"q3_material_type\": \"\",\n",
" \"q3_measure\": log.quantities[3].measure if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'measure') else \"\",\n",
" \"q3_value\": log.quantities[3].value if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'value') else \"\",\n",
" \"q3_unit\": log.quantities[3].units.name if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'units') and hasattr(log.quantities[3].units, 'name') else \"\",\n",
" \"q3_unit_price\": log.quantities[3].unit_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'unit_price') else \"\",\n",
" \"q3_total_price\": log.quantities[3].total_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'total_price') else \"\",\n",
" \"q3_inventory_adjustment\": log.quantities[3].inventory_adjustment if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'inventory_adjustment') else \"\",\n",
" \"q3_inventory_asset\": log.quantities[3].q3_inventory_asset if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'q3_inventory_asset') else \"\",\n",
" })\n",
"\n",
"\n",
"\n",
" all_logs.append(base_data)\n",
" \n",
"\n",
" \n",
" # Harvest Logs\n",
" logs = neo.Log.Harvest.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" #\"notes\": log.notes,\n",
" \n",
" #Daten für q0\n",
" \"q0_type\": log.quantities[0].type,\n",
" #\"q0_material_type\": log.quantities[0].material_types[0].name if log.quantities[0].material_types else None,\n",
" \"q0_material_type\": \"\",\n",
" \"q0_measure\": log.quantities[0].measure if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'measure') else \"\",\n",
" \"q0_value\": log.quantities[0].value if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'value') else \"\",\n",
" \"q0_unit\": log.quantities[0].units.name if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'units') and hasattr(log.quantities[0].units, 'name') else \"\",\n",
" \"q0_unit_price\": log.quantities[0].unit_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'unit_price') else \"\",\n",
" \"q0_total_price\": log.quantities[0].total_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'total_price') else \"\",\n",
" \"q0_inventory_adjustment\": log.quantities[0].inventory_adjustment if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'inventory_adjustment') else \"\",\n",
" \"q0_inventory_asset\": log.quantities[0].q0_inventory_asset if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'q0_inventory_asset') else \"\",\n",
" }\n",
" \n",
" #Abfrage für q1 bis q7 \n",
" if len(log.quantities) > 1:\n",
" base_data.update({\n",
" \n",
" \"q1_type\": log.quantities[1].type,\n",
" #\"q1_material_type\": log.quantities[1].material_types[1].name if log.quantities[1].material_types else None,\n",
" \"q1_material_type\": \"\",\n",
" \"q1_measure\": log.quantities[1].measure if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'measure') else \"\",\n",
" \"q1_value\": log.quantities[1].value if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'value') else \"\",\n",
" \"q1_unit\": log.quantities[1].units.name if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'units') and hasattr(log.quantities[1].units, 'name') else \"\",\n",
" #\"q1_unit_price\": log.quantities[1].unit_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'unit_price') else \"\",\n",
" #\"q1_total_price\": log.quantities[1].total_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'total_price') else \"\",\n",
" \"q1_inventory_adjustment\": log.quantities[1].inventory_adjustment if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'inventory_adjustment') else \"\",\n",
" \"q1_inventory_asset\": log.quantities[1].q1_inventory_asset if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'q1_inventory_asset') else \"\",\n",
" \n",
" })\n",
"\n",
" if len(log.quantities) > 2:\n",
" base_data.update({\n",
" \"q2_type\": log.quantities[2].type,\n",
" #\"q2_material_type\": log.quantities[2].material_types[2].name if log.quantities[2].material_types else None,\n",
" \"q2_material_type\": \"\",\n",
" \"q2_measure\": log.quantities[2].measure if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'measure') else \"\",\n",
" \"q2_value\": log.quantities[2].value if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'value') else \"\",\n",
" \"q2_unit\": log.quantities[2].units.name if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'units') and hasattr(log.quantities[2].units, 'name') else \"\",\n",
" \"q2_unit_price\": log.quantities[2].unit_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'unit_price') else \"\",\n",
" \"q2_total_price\": log.quantities[2].total_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'total_price') else \"\",\n",
" \"q2_inventory_adjustment\": log.quantities[2].inventory_adjustment if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'inventory_adjustment') else \"\",\n",
" \"q2_inventory_asset\": log.quantities[2].q2_inventory_asset if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'q2_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 3:\n",
" base_data.update({\n",
" \"q3_type\": log.quantities[3].type,\n",
" #\"q3_material_type\": log.quantities[3].material_types[3].name if log.quantities[3].material_types else None,\n",
" \"q3_material_type\": \"\",\n",
" \"q3_measure\": log.quantities[3].measure if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'measure') else \"\",\n",
" \"q3_value\": log.quantities[3].value if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'value') else \"\",\n",
" \"q3_unit\": log.quantities[3].units.name if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'units') and hasattr(log.quantities[3].units, 'name') else \"\",\n",
" \"q3_unit_price\": log.quantities[3].unit_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'unit_price') else \"\",\n",
" \"q3_total_price\": log.quantities[3].total_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'total_price') else \"\",\n",
" \"q3_inventory_adjustment\": log.quantities[3].inventory_adjustment if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'inventory_adjustment') else \"\",\n",
" \"q3_inventory_asset\": log.quantities[3].q3_inventory_asset if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'q3_inventory_asset') else \"\",\n",
" })\n",
"\n",
"\n",
"\n",
" all_logs.append(base_data)\n",
"\n",
" \n",
" # Sale Logs\n",
" logs = neo.Log.Sale.get_list()\n",
" for log in logs:\n",
" plant = log.plant\n",
" seeding_logs = plant.get_logs_of_type(neo.Log.Seeding) if plant and hasattr(plant, 'get_logs_of_type') else []\n",
" first_seeding_log = seeding_logs[0] if seeding_logs else None\n",
" \n",
" try:\n",
" timestamp = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%Y\")\n",
" except ValueError:\n",
" timestamp = \"Invalid Date\"\n",
" \n",
" base_data = { \n",
" \"log_type\": log.type,\n",
" \"name\": log.name,\n",
" \"timestamp\": timestamp,\n",
" \"plant_name\": plant.name if plant else \"\",\n",
" \"plant_area\": first_seeding_log.quantities[1].value if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_area_unit\": first_seeding_log.quantities[1].units.name if first_seeding_log and len(first_seeding_log.quantities) > 1 else \"\",\n",
" \"plant_crop\": plant.crops[0].name if plant and plant.crops else \"\",\n",
" \"plant_season\": plant.seasons[0].name if plant and plant.seasons else \"\",\n",
" \"plant_location\": plant.location[0].name if plant and plant.location else \"\",\n",
" \"equipment\": log.equipment[0].name if log.equipment else \"\",\n",
" \"notes\": \"\",\n",
" #\"notes\": log.notes,\n",
" \n",
" #Daten für q0\n",
" \"q0_type\": log.quantities[0].type,\n",
" #\"q0_material_type\": log.quantities[0].material_types[0].name if log.quantities[0].material_types else None,\n",
" \"q0_material_type\": \"\",\n",
" \"q0_measure\": log.quantities[0].measure if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'measure') else \"\",\n",
" \"q0_value\": log.quantities[0].value if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'value') else \"\",\n",
" \"q0_unit\": log.quantities[0].units.name if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'units') and hasattr(log.quantities[0].units, 'name') else \"\",\n",
" \"q0_unit_price\": log.quantities[0].unit_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'unit_price') else \"\",\n",
" \"q0_total_price\": log.quantities[0].total_price if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'total_price') else \"\",\n",
" \"q0_inventory_adjustment\": log.quantities[0].inventory_adjustment if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'inventory_adjustment') else \"\",\n",
" \"q0_inventory_asset\": log.quantities[0].q0_inventory_asset if log and log.quantities and len(log.quantities) > 0 and hasattr(log.quantities[0], 'q0_inventory_asset') else \"\",\n",
" }\n",
" \n",
" #Abfrage für q1 bis q7 \n",
" if len(log.quantities) > 1:\n",
" base_data.update({\n",
" \n",
" \"q1_type\": log.quantities[1].type,\n",
" #\"q1_material_type\": log.quantities[1].material_types[1].name if log.quantities[1].material_types else None,\n",
" \"q1_material_type\": \"\",\n",
" \"q1_measure\": log.quantities[1].measure if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'measure') else \"\",\n",
" \"q1_value\": log.quantities[1].value if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'value') else \"\",\n",
" \"q1_unit\": log.quantities[1].units.name if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'units') and hasattr(log.quantities[1].units, 'name') else \"\",\n",
" \"q1_unit_price\": log.quantities[1].unit_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'unit_price') else \"\",\n",
" \"q1_total_price\": log.quantities[1].total_price if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'total_price') else \"\",\n",
" \"q1_inventory_adjustment\": log.quantities[1].inventory_adjustment if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'inventory_adjustment') else \"\",\n",
" \"q1_inventory_asset\": log.quantities[1].q1_inventory_asset if log and log.quantities and len(log.quantities) > 1 and hasattr(log.quantities[1], 'q1_inventory_asset') else \"\",\n",
" \n",
" })\n",
"\n",
" if len(log.quantities) > 2:\n",
" base_data.update({\n",
" \"q2_type\": log.quantities[2].type,\n",
" #\"q2_material_type\": log.quantities[2].material_types[2].name if log.quantities[2].material_types else None,\n",
" \"q2_material_type\": \"\",\n",
" \"q2_measure\": log.quantities[2].measure if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'measure') else \"\",\n",
" \"q2_value\": log.quantities[2].value if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'value') else \"\",\n",
" \"q2_unit\": log.quantities[2].units.name if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'units') and hasattr(log.quantities[2].units, 'name') else \"\",\n",
" \"q2_unit_price\": log.quantities[2].unit_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'unit_price') else \"\",\n",
" \"q2_total_price\": log.quantities[2].total_price if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'total_price') else \"\",\n",
" \"q2_inventory_adjustment\": log.quantities[2].inventory_adjustment if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'inventory_adjustment') else \"\",\n",
" \"q2_inventory_asset\": log.quantities[2].q2_inventory_asset if log and log.quantities and len(log.quantities) > 2 and hasattr(log.quantities[2], 'q2_inventory_asset') else \"\",\n",
" })\n",
"\n",
" if len(log.quantities) > 3:\n",
" base_data.update({\n",
" \"q3_type\": log.quantities[3].type,\n",
" #\"q3_material_type\": log.quantities[3].material_types[3].name if log.quantities[3].material_types else None,\n",
" \"q3_material_type\": \"\",\n",
" \"q3_measure\": log.quantities[3].measure if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'measure') else \"\",\n",
" \"q3_value\": log.quantities[3].value if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'value') else \"\",\n",
" \"q3_unit\": log.quantities[3].units.name if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'units') and hasattr(log.quantities[3].units, 'name') else \"\",\n",
" \"q3_unit_price\": log.quantities[3].unit_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'unit_price') else \"\",\n",
" \"q3_total_price\": log.quantities[3].total_price if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'total_price') else \"\",\n",
" \"q3_inventory_adjustment\": log.quantities[3].inventory_adjustment if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'inventory_adjustment') else \"\",\n",
" \"q3_inventory_asset\": log.quantities[3].q3_inventory_asset if log and log.quantities and len(log.quantities) > 3 and hasattr(log.quantities[3], 'q3_inventory_asset') else \"\",\n",
" })\n",
"\n",
"\n",
"\n",
" all_logs.append(base_data) \n",
"\n",
"\n",
"\n",
" \n",
"\n",
" # DataFrame erstellen\n",
" df = pd.DataFrame(all_logs)\n",
" return df\n",
"\n",
"if __name__ == \"__main__\":\n",
" df = process_logs()\n",
" #print(df.head()) # Vorschau der ersten Zeilen\n",
" display(df)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fac482ff-e5c1-4fa2-9175-441f874043f9",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Die Datei 'C:\\Users\\Wir\\Downloads\\PlantLogs.xlsx' existiert bereits. Möchten Sie sie überschreiben? (ja/nein): ja\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Die Datei wurde erfolgreich nach 'C:\\Users\\Wir\\Downloads\\PlantLogs.xlsx' exportiert, mit Autofilter, Zeilenumbruch und angepasster Spaltenbreite.\n"
]
}
],
"source": [
"#Mein Excel Export\n",
"import pandas as pd\n",
"import os\n",
"from openpyxl import load_workbook\n",
"from openpyxl.utils import get_column_letter\n",
"from openpyxl.styles import Alignment\n",
"from datetime import datetime\n",
"\n",
"def export_to_excel(df, file_path, date_column=2): # Spaltenindex für C\n",
" # Stelle sicher, dass die Spalte als datetime formatiert ist\n",
" #df.iloc[:, date_column] = pd.to_datetime(df.iloc[:, date_column], errors='coerce')\n",
" df.iloc[:, date_column] = pd.to_datetime(df.iloc[:, date_column], errors='coerce', dayfirst=True)\n",
"\n",
"\n",
" # Exportiere den DataFrame zu Excel\n",
" df.to_excel(file_path, index=False)\n",
"\n",
" # Lade die Arbeitsmappe, um Formatierungen hinzuzufügen\n",
" workbook = load_workbook(file_path)\n",
" worksheet = workbook.active\n",
" worksheet.auto_filter.ref = worksheet.dimensions\n",
"\n",
" # Passen Sie die Spaltenbreite an und aktivieren Sie den Zeilenumbruch\n",
" for col in worksheet.columns:\n",
" max_length = 0\n",
" col_letter = get_column_letter(col[0].column)\n",
" for cell in col:\n",
" cell.alignment = Alignment(wrap_text=True)\n",
" \n",
" # Setze das Datumsformat für die angegebene Spalte\n",
" if col[0].column == date_column + 1 and isinstance(cell.value, datetime): # Index + 1 für Excel\n",
" cell.number_format = 'DD.MM.YYYY'\n",
" \n",
" max_length = max(max_length, len(str(cell.value)) if cell.value else 0)\n",
"\n",
" adjusted_width = (max_length + 2) * 1.0\n",
" worksheet.column_dimensions[col_letter].width = adjusted_width\n",
"\n",
" workbook.save(file_path)\n",
" print(f\"Die Datei wurde erfolgreich nach '{file_path}' exportiert, mit Autofilter, Zeilenumbruch und angepasster Spaltenbreite.\")\n",
"\n",
"# Beispielaufruf\n",
"if __name__ == \"__main__\":\n",
" downloads_folder = os.path.join(os.path.expanduser(\"~\"), \"Downloads\")\n",
" file_path = os.path.join(downloads_folder, \"PlantLogs.xlsx\")\n",
"\n",
" # Prüfe, ob die Datei bereits existiert\n",
" if os.path.exists(file_path):\n",
" overwrite = input(f\"Die Datei '{file_path}' existiert bereits. Möchten Sie sie überschreiben? (ja/nein): \")\n",
" if overwrite.lower() == 'ja':\n",
" export_to_excel(df, file_path)\n",
" else:\n",
" print(\"Der Export wurde abgebrochen.\")\n",
" else:\n",
" export_to_excel(df, file_path)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a80fed7-beee-4a54-ba45-e3e65be80cad",
"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
}