From fca3def8924ead555b41e6f3300e416fdfac663a Mon Sep 17 00:00:00 2001 From: Wir Date: Wed, 20 Nov 2024 15:13:46 +0100 Subject: [PATCH] Reporting in Excel --- reporting.ipynb | 1997 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 1878 insertions(+), 119 deletions(-) diff --git a/reporting.ipynb b/reporting.ipynb index 8c73327..18ae297 100644 --- a/reporting.ipynb +++ b/reporting.ipynb @@ -385,6 +385,9 @@ "execution_count": null, "id": "d6d12b59-4895-426e-9a30-c9cee801671e", "metadata": { + "jupyter": { + "source_hidden": true + }, "scrolled": true }, "outputs": [], @@ -1121,13 +1124,16 @@ "cell_type": "code", "execution_count": null, "id": "a7c72234-8838-461c-a4d7-b1c0170f789f", - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + }, + "scrolled": true + }, "outputs": [], "source": [ "#Mein Master Report\n", "\n", - "\n", - "# alle logs von einem Plant \n", "import neofarm.lib as neo\n", "from datetime import datetime\n", "\n", @@ -1145,7 +1151,7 @@ " 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\"location: {location[0].name}\")\n", + " print(f\"plant_location: {location[0].name}\")\n", " \n", " \t\n", " \n", @@ -1154,6 +1160,7 @@ " 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", @@ -1161,16 +1168,27 @@ " print(f\"timestamp: {formatted_date}\") \n", " print(f\"equipment: {log.equipment[0].name}\")\n", " print(f\"plant_name: {plant.name}\")\n", - "\n", - "#quantity\n", - " input=neo.Log.Maintenance.from_id(log.id)\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_unit_name: {input.quantities[0].units.name}\")\n", - " print(f\"quant0_unit_price_1: = {input.quantities[0].unit_price}\")\n", - " print(f\"quant0_total_price_1: = {input.quantities[0].total_price}\")\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", @@ -1182,11 +1200,12 @@ " \n", " #quantity\n", " input=neo.Log.Purchase.from_id(log.id)\n", - " \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_unit: {input.quantities[0].units.name}\")\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", @@ -1195,31 +1214,48 @@ " \n", " \n", " if len(input.quantities) > 1:\n", - " print(f\"quant1_type: {input.quantities[1].type}\") \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\"quant1materialtype: {input.quantities[1].material_types[0].name}\")\n", - " \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", - "\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", - "\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", - "\n", - "\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", - "\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", @@ -1232,6 +1268,8 @@ " 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", @@ -1239,33 +1277,52 @@ " 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", - " #quantity\n", - " input=neo.Log.Seeding.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_unit: {input.quantities[0].units.name}\")\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", + " #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}\")\n", - " print(f\"unit1_name: {input.quantities[1].units.name}\")\n", - " \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_unit: {input.quantities[2].units.name}\")\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", @@ -1278,27 +1335,99 @@ " 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", - " \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}\")\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_asset: = {input.quantities[0].inventory_asset.name}\")\n", - " #print(f\"quant_inventory_name: {input.quantities[0].inventory_asset.get_logs_of_type(Log.Purchase)}\")\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_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", - " print (f\"quant1_unit_price: = {input.quantities[1].unit_price}\")\n", - " print (f\"quant1_total_price: = {input.quantities[1].total_price}\")\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", @@ -1311,27 +1440,47 @@ " 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", - "#quantity\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_unit: {input.quantities[0].units.name}\")\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_unit: {input.quantities[1].units.name}\")\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", - " medical_cost = 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", @@ -1344,25 +1493,33 @@ " 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", + " 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}\")\n", - " print(f\"quant0_unit: {input.quantities[0].units.name}\")\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_unit: {input.quantities[1].units.name}\")\n", - " harvest_cost = 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", @@ -1376,25 +1533,30 @@ " 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\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_unit: {input.quantities[0].units.name}\")\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", - "final_cost = harvest_cost + 2\n", - "print(f\"final_cost: {final_cost}\")\n", "\n", "\n", "\n", @@ -1405,7 +1567,11 @@ "cell_type": "code", "execution_count": null, "id": "5d34dcc9-a4b9-423f-91d4-da1958ecc20e", - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "#Kosten\n", @@ -1449,55 +1615,16 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "ac163dc6-3593-4bdb-976b-a4e4bd651b5e", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Input:\n", - "name: Innovert Raps Input 24/25\n", - "timestamp: 03.11.24\n", - "plant_name: W-Raps Helmacker Plant 24/25\n", - "plant_crop: Raps\n", - "plant_season: 24/25\n", - "equipment: Spritze\n", - "quant0_type: quantity--standard\n", - "quant0_measure: volume\n", - "quant0_value: 10.0\n", - "quant0_unit: l\n", - "quant0_inventory_adjustment: decrement\n", - "quant0_inventory_asset: = Innovert Raps Material 08/24\n", - "quant0_purchase: = Innovert Raps Purchase 24/25\n", - "quant0_purchase: = quantity--material\n", - "quant0_purchase: = ratio\n", - "area: = 3.02 ha\n", - "\n", - "Input:\n", - "name: Innovert Raps Input 24/25\n", - "timestamp: 12.10.24\n", - "plant_name: W-Raps Helmacker Plant 24/25\n", - "plant_crop: Raps\n", - "plant_season: 24/25\n", - "equipment: Spritze\n", - "quant0_type: quantity--standard\n", - "quant0_measure: volume\n", - "quant0_value: 10.0\n", - "quant0_unit: l\n", - "quant0_inventory_adjustment: decrement\n", - "quant0_inventory_asset: = Innovert Raps Material 08/24\n", - "quant0_purchase: = Innovert Raps Purchase 24/25\n", - "quant0_purchase: = quantity--material\n", - "quant0_purchase: = ratio\n", - "area: = 3.02 ha\n" - ] + "metadata": { + "jupyter": { + "source_hidden": true } - ], + }, + "outputs": [], "source": [ - "#log Purchase und Input\n", + "#Mein Input log\n", "import neofarm.lib as neo\n", "from datetime import datetime\n", "\n", @@ -1514,37 +1641,1669 @@ " 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", - "\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}\")\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_asset: = {input.quantities[0].inventory_asset.name}\")\n", - " print(f\"quant0_purchase: = {purchase.name}\")\n", - " print(f\"quant0_purchase: = {purchase.quantities[1].type}\")\n", - " print(f\"quant0_purchase: = {purchase.quantities[1].measure}\")\n", - " print(f\"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", + " 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", - " \"\"\"\n", - " print(f\"quant1_type: {input.quantities[1].type}\") \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", - " print (f\"quant1_unit_price: = {input.quantities[1].unit_price}\")\n", - " print (f\"quant1_total_price: = {input.quantities[1].total_price}\")\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": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
log_typenametimestampplant_nameplant_areaplant_area_unitplant_cropplant_seasonplant_locationequipment...purch_q4_valuepurch_q4_unitpurch_q5_typepurch_q5_measurepurch_q5_valuepurch_q5_unitpurch_q6_typepurch_q6_measurepurch_q6_valuepurch_q6_unit
0log--activityMove 24/25 Nachtweide Raps Plant to Nachtweide14.10.2024W-Raps Nachtweide Plant 24/254.5haRaps24/25Nachtweide...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1log--activityMove W-Raps Helmacker Plant 24/25 to Helmacker14.10.2024W-Raps Helmacker Plant 24/253.02haRaps24/25Helmacker...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2log--activityMove W-Raps Helmacker Plant 24/25 to Helmacker22.10.2024W-Raps Helmacker Plant 24/253.02haRaps24/25Helmacker...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3log--maintenanceScheibeneggen Helmacker Maintenance 24/2528.07.2024W-Raps Helmacker Plant 24/253.02haRaps24/25HelmackerScheibenegge Catros...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4log--purchaseSchneckenkorn Purchase 24/2511.08.2024...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
5log--purchaseInnovert Raps Purchase 24/2510.08.2024...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
6log--purchaseW-Raps Saatgut Otello KWS Saatgut Purchase 24/2501.08.2024...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
7log--seedingW-Raps Otello KWS Nachtweide Seeding 24/2528.08.2024W-Raps Nachtweide Plant 24/254.5haRaps24/25NachtweideSähmaschine Cataya...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
8log--seedingW-Raps Otello KWS Helmacker Seeding 24/2522.08.2024W-Raps Helmacker Plant 24/253.02haRaps24/25HelmackerSähmaschine Cataya...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
9log--inputInnovert Raps Input 24/2503.11.2024W-Raps Helmacker Plant 24/253.02haRaps24/25HelmackerSpritze...60.0g/lquantity--materialratio70.0g/lquantity--materialratio4.0g/l
10log--inputInnovert Raps Input 24/2512.10.2024W-Raps Helmacker Plant 24/253.02haRaps24/25HelmackerSpritze...60.0g/lquantity--materialratio70.0g/lquantity--materialratio4.0g/l
11log--medicalSchneckenkorn Medical 24/2530.08.2024W-Raps Helmacker Plant 24/253.02haRaps24/25HelmackerSchneckenkornstreuer Leinfelder...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
12log--harvestW-Raps Nachtweide Harvest 24/2528.10.2024W-Raps Nachtweide Plant 24/254.5haRaps24/25NachtweideMähdrescher Leinfelder...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
13log--harvestW-Raps Helmacker Harvest 24/2520.10.2024W-Raps Helmacker Plant 24/253.02haRaps24/25HelmackerMähdrescher Leinfelder...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
14log--saleW-Raps Sale 24/2528.10.2024W-Raps Helmacker Plant 24/253.02haRaps24/25Helmacker...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", + "

15 rows × 105 columns

\n", + "
" + ], + "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": []