Alle logs zu plant mit quantities nebeneinander in Excel exportiert
This commit is contained in:
413
reporting.ipynb
413
reporting.ipynb
@@ -5,6 +5,9 @@
|
|||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "f512fba3-877f-411e-935c-0c878d478b2d",
|
"id": "f512fba3-877f-411e-935c-0c878d478b2d",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
"jupyter": {
|
||||||
|
"source_hidden": true
|
||||||
|
},
|
||||||
"scrolled": true
|
"scrolled": true
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -101,7 +104,11 @@
|
|||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "a993570d-dea2-4bd6-80c0-b36297ce6a3a",
|
"id": "a993570d-dea2-4bd6-80c0-b36297ce6a3a",
|
||||||
"metadata": {},
|
"metadata": {
|
||||||
|
"jupyter": {
|
||||||
|
"source_hidden": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"#Beispiel\n",
|
"#Beispiel\n",
|
||||||
@@ -116,62 +123,14 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": null,
|
||||||
"id": "3a33ffb1-afe7-44b5-863b-9779a95a2a9c",
|
"id": "3a33ffb1-afe7-44b5-863b-9779a95a2a9c",
|
||||||
"metadata": {},
|
"metadata": {
|
||||||
"outputs": [
|
"jupyter": {
|
||||||
{
|
"source_hidden": true
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"PlantName: W-Raps Helmacker Plant 24/25\n",
|
|
||||||
"Maintenance:\n",
|
|
||||||
"name: Scheibeneggen Helmacker Maintenance 24/25\n",
|
|
||||||
"timestamp: 28.07.24 11:34 \n",
|
|
||||||
"equipment: Scheibenegge Catros\n",
|
|
||||||
"quant_type: quantity--price\n",
|
|
||||||
"quant_measure: time\n",
|
|
||||||
"quant_value: 2\n",
|
|
||||||
"quant_inventory_adjustment: None\n",
|
|
||||||
"Seeding:\n",
|
|
||||||
"name: W-Raps Otello KWS Helmacker Seeding 24/25\n",
|
|
||||||
"timestamp: 22.08.24 22:00 \n",
|
|
||||||
"equipment: Sähmaschine Cataya\n",
|
|
||||||
"plant loc: Helmacker\n",
|
|
||||||
"quant_type: quantity--standard\n",
|
|
||||||
"quant_measure: weight\n",
|
|
||||||
"quant_value: 50\n",
|
|
||||||
"quant_inventory_adjustment: decrement\n",
|
|
||||||
"Input:\n",
|
|
||||||
"name: Innovert Raps Input 24/25\n",
|
|
||||||
"timestamp: 12.10.24 13:18 \n",
|
|
||||||
"equipment: Spritze\n",
|
|
||||||
"quant_type: quantity--standard\n",
|
|
||||||
"quant_measure: volume\n",
|
|
||||||
"quant_value: 10\n",
|
|
||||||
"quant_inventory_adjustment: decrement\n",
|
|
||||||
"Input:\n",
|
|
||||||
"name: Innovert Raps Input 24/25\n",
|
|
||||||
"timestamp: 03.11.24 23:00 \n",
|
|
||||||
"equipment: Spritze\n",
|
|
||||||
"quant_type: quantity--standard\n",
|
|
||||||
"quant_measure: volume\n",
|
|
||||||
"quant_value: 10\n",
|
|
||||||
"quant_inventory_adjustment: decrement\n",
|
|
||||||
"Medical:\n",
|
|
||||||
"name: Schneckenkorn Medical 24/25\n",
|
|
||||||
"timestamp: 30.08.24 06:42 \n",
|
|
||||||
"equipment: Schneckenkornstreuer Leinfelder\n",
|
|
||||||
"Harvest:\n",
|
|
||||||
"name: W-Raps Helmacker Harvest 24/25\n",
|
|
||||||
"timestamp: 20.10.24 10:11 \n",
|
|
||||||
"equipment: Mähdrescher Leinfelder\n",
|
|
||||||
"Sale:\n",
|
|
||||||
"name: W-Raps Sale 24/25\n",
|
|
||||||
"timestamp: 28.10.24 07:54 \n"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
},
|
||||||
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# alle logs von einem Plant\n",
|
"# alle logs von einem Plant\n",
|
||||||
"import neofarm.lib as neo\n",
|
"import neofarm.lib as neo\n",
|
||||||
@@ -179,10 +138,13 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"if __name__ == \"__main__\":\n",
|
"if __name__ == \"__main__\":\n",
|
||||||
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
|
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
|
||||||
" \n",
|
"\n",
|
||||||
|
"#Plantname\n",
|
||||||
" PlantName = \"W-Raps Helmacker Plant 24/25\" \n",
|
" PlantName = \"W-Raps Helmacker Plant 24/25\" \n",
|
||||||
" print(f\"PlantName: {PlantName}\")\n",
|
" print(f\"PlantName: {PlantName}\")\n",
|
||||||
|
"\n",
|
||||||
" \n",
|
" \n",
|
||||||
|
"#log Maintenance\n",
|
||||||
" logs = asset.get_logs_of_type(neo.Log.Maintenance)\n",
|
" logs = asset.get_logs_of_type(neo.Log.Maintenance)\n",
|
||||||
" for log in logs:\n",
|
" for log in logs:\n",
|
||||||
" print(\"Maintenance:\")\n",
|
" print(\"Maintenance:\")\n",
|
||||||
@@ -190,16 +152,16 @@
|
|||||||
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
|
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
|
||||||
" print(f\"timestamp: {formatted_date}\") \n",
|
" print(f\"timestamp: {formatted_date}\") \n",
|
||||||
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
||||||
"\n",
|
"#quantity\n",
|
||||||
" input=neo.Log.Maintenance.from_id(log.id)\n",
|
" input=neo.Log.Maintenance.from_id(log.id)\n",
|
||||||
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
||||||
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
||||||
" print(f\"quant_value: {input.quantities[0].value}\")\n",
|
" print(f\"quant_value: {input.quantities[0].value}\")\n",
|
||||||
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
||||||
" #print(f\"quant_value: {input.quantities[0].unit_price.decimal}\")\n",
|
" print(f\"quant_value: {input.quantities[0].unit_price}\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
" \t\n",
|
" \t\n",
|
||||||
" \n",
|
"#log Seeding \n",
|
||||||
" logs = asset.get_logs_of_type(neo.Log.Seeding)\n",
|
" logs = asset.get_logs_of_type(neo.Log.Seeding)\n",
|
||||||
" for log in logs:\n",
|
" for log in logs:\n",
|
||||||
" print(\"Seeding:\")\n",
|
" print(\"Seeding:\")\n",
|
||||||
@@ -208,7 +170,7 @@
|
|||||||
" print(f\"timestamp: {formatted_date}\")\n",
|
" print(f\"timestamp: {formatted_date}\")\n",
|
||||||
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
||||||
" print(f\"plant loc: {log.location[0].name}\")\n",
|
" print(f\"plant loc: {log.location[0].name}\")\n",
|
||||||
"\n",
|
"#quantity\n",
|
||||||
" input=neo.Log.Seeding.from_id(log.id)\n",
|
" input=neo.Log.Seeding.from_id(log.id)\n",
|
||||||
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
||||||
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
||||||
@@ -216,7 +178,7 @@
|
|||||||
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
||||||
" \t\n",
|
" \t\n",
|
||||||
"\n",
|
"\n",
|
||||||
" \n",
|
"#log Input \n",
|
||||||
" logs = asset.get_logs_of_type(neo.Log.Input)\n",
|
" logs = asset.get_logs_of_type(neo.Log.Input)\n",
|
||||||
" for log in logs:\n",
|
" for log in logs:\n",
|
||||||
" print(\"Input:\")\n",
|
" print(\"Input:\")\n",
|
||||||
@@ -226,16 +188,14 @@
|
|||||||
" print(f\"timestamp: {formatted_date}\")\n",
|
" print(f\"timestamp: {formatted_date}\")\n",
|
||||||
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"#quantity\n",
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
" input=neo.Log.Input.from_id(log.id)\n",
|
" input=neo.Log.Input.from_id(log.id)\n",
|
||||||
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
||||||
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
||||||
" print(f\"quant_value: {input.quantities[0].value}\")\n",
|
" print(f\"quant_value: {input.quantities[0].value}\")\n",
|
||||||
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
" \n",
|
"#log Medical\n",
|
||||||
" logs = asset.get_logs_of_type(neo.Log.Medical)\n",
|
" logs = asset.get_logs_of_type(neo.Log.Medical)\n",
|
||||||
" for log in logs:\n",
|
" for log in logs:\n",
|
||||||
" print(\"Medical:\")\n",
|
" print(\"Medical:\")\n",
|
||||||
@@ -244,6 +204,15 @@
|
|||||||
" print(f\"timestamp: {formatted_date}\")\n",
|
" print(f\"timestamp: {formatted_date}\")\n",
|
||||||
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"#quantity\n",
|
||||||
|
" input=neo.Log.Medical.from_id(log.id)\n",
|
||||||
|
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
||||||
|
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
||||||
|
" print(f\"quant_value: {input.quantities[0].value}\")\n",
|
||||||
|
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"#log Harvest \n",
|
||||||
" logs = asset.get_logs_of_type(neo.Log.Harvest)\n",
|
" logs = asset.get_logs_of_type(neo.Log.Harvest)\n",
|
||||||
" for log in logs:\n",
|
" for log in logs:\n",
|
||||||
" print(\"Harvest:\")\n",
|
" print(\"Harvest:\")\n",
|
||||||
@@ -252,19 +221,38 @@
|
|||||||
" print(f\"timestamp: {formatted_date}\")\n",
|
" print(f\"timestamp: {formatted_date}\")\n",
|
||||||
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
" print(f\"equipment: {log.equipment[0].name}\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"#quantity\n",
|
||||||
|
" input=neo.Log.Harvest.from_id(log.id)\n",
|
||||||
|
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
||||||
|
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
||||||
|
" print(f\"quant_value: {input.quantities[0].value}\")\n",
|
||||||
|
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")\n",
|
||||||
|
"\n",
|
||||||
|
"#log Sale \n",
|
||||||
" logs = asset.get_logs_of_type(neo.Log.Sale)\n",
|
" logs = asset.get_logs_of_type(neo.Log.Sale)\n",
|
||||||
" for log in logs:\n",
|
" for log in logs:\n",
|
||||||
" print(\"Sale:\")\n",
|
" print(\"Sale:\")\n",
|
||||||
" print(f\"name: {log.name}\")\n",
|
" print(f\"name: {log.name}\")\n",
|
||||||
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
|
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M \") # Konvertiere in das gewünschte Format\n",
|
||||||
" print(f\"timestamp: {formatted_date}\")"
|
" print(f\"timestamp: {formatted_date}\")\n",
|
||||||
|
"\n",
|
||||||
|
"#quantity\n",
|
||||||
|
" input=neo.Log.Sale.from_id(log.id)\n",
|
||||||
|
" print(f\"quant_type: {input.quantities[0].type}\")\n",
|
||||||
|
" print(f\"quant_measure: {input.quantities[0].measure}\")\n",
|
||||||
|
" print(f\"quant_value: {input.quantities[0].value}\")\n",
|
||||||
|
" print(f\"quant_inventory_adjustment: {input.quantities[0].inventory_adjustment}\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "ce30a9db-735e-4174-ad56-0f0079ab04c6",
|
"id": "ce30a9db-735e-4174-ad56-0f0079ab04c6",
|
||||||
"metadata": {},
|
"metadata": {
|
||||||
|
"jupyter": {
|
||||||
|
"source_hidden": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"#alle logs von einem Plant in Tabelle\n",
|
"#alle logs von einem Plant in Tabelle\n",
|
||||||
@@ -314,6 +302,297 @@
|
|||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "649e4d8e-c3a9-4d5f-9bdf-9427f416fca9",
|
"id": "649e4d8e-c3a9-4d5f-9bdf-9427f416fca9",
|
||||||
|
"metadata": {
|
||||||
|
"jupyter": {
|
||||||
|
"source_hidden": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"#Alle logs zu plant mit quantities untereinander\n",
|
||||||
|
"import neofarm.lib as neo\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"from datetime import datetime\n",
|
||||||
|
"\n",
|
||||||
|
"if __name__ == \"__main__\":\n",
|
||||||
|
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Definiere den Pflanzennamen\n",
|
||||||
|
" PlantName = \"W-Raps Helmacker Plant 24/25\"\n",
|
||||||
|
" print(f\"PlantName: {PlantName}\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Erstelle eine Liste zur Sammlung der Daten\n",
|
||||||
|
" data = []\n",
|
||||||
|
"\n",
|
||||||
|
" # Funktion, um Logs zu verarbeiten und die Daten zur Liste hinzuzufügen\n",
|
||||||
|
" def process_logs(logs, log_type):\n",
|
||||||
|
" for log in logs:\n",
|
||||||
|
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M\")\n",
|
||||||
|
" equipment_name = log.equipment[0].name if log.equipment else \"None\"\n",
|
||||||
|
" location_name = log.location[0].name if hasattr(log, 'location') and log.location else \"None\"\n",
|
||||||
|
"\n",
|
||||||
|
" # Menge und weitere Details (falls vorhanden)\n",
|
||||||
|
" quantities = getattr(log, 'quantities', [])\n",
|
||||||
|
" for quantity in quantities:\n",
|
||||||
|
" data.append({\n",
|
||||||
|
" \"PlantName\": PlantName,\n",
|
||||||
|
" \"LogType\": log_type,\n",
|
||||||
|
" \"Name\": log.name,\n",
|
||||||
|
" \"Timestamp\": formatted_date,\n",
|
||||||
|
" \"Equipment\": equipment_name,\n",
|
||||||
|
" \"Location\": location_name,\n",
|
||||||
|
" \"QuantType\": quantity.type,\n",
|
||||||
|
" \"QuantMeasure\": quantity.measure,\n",
|
||||||
|
" \"QuantValue\": quantity.value,\n",
|
||||||
|
" \"QuantInventoryAdjustment\": quantity.inventory_adjustment\n",
|
||||||
|
" })\n",
|
||||||
|
" # Falls keine Mengeninformationen vorhanden sind\n",
|
||||||
|
" if not quantities:\n",
|
||||||
|
" data.append({\n",
|
||||||
|
" \"PlantName\": PlantName,\n",
|
||||||
|
" \"LogType\": log_type,\n",
|
||||||
|
" \"Name\": log.name,\n",
|
||||||
|
" \"Timestamp\": formatted_date,\n",
|
||||||
|
" \"Equipment\": equipment_name,\n",
|
||||||
|
" \"Location\": location_name,\n",
|
||||||
|
" \"QuantType\": \"None\",\n",
|
||||||
|
" \"QuantMeasure\": \"None\",\n",
|
||||||
|
" \"QuantValue\": \"None\",\n",
|
||||||
|
" \"QuantInventoryAdjustment\": \"None\"\n",
|
||||||
|
" })\n",
|
||||||
|
"\n",
|
||||||
|
" # Verarbeite die verschiedenen Log-Typen\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Maintenance), \"Maintenance\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Seeding), \"Seeding\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Input), \"Input\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Medical), \"Medical\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Harvest), \"Harvest\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Sale), \"Sale\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Erstelle ein DataFrame aus den gesammelten Daten und zeige es an\n",
|
||||||
|
" df = pd.DataFrame(data)\n",
|
||||||
|
" display(df)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "ef3c14f0-b158-4be9-ae7d-fd3b81aeb4ff",
|
||||||
|
"metadata": {
|
||||||
|
"jupyter": {
|
||||||
|
"source_hidden": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"#Alle logs zu plant mit quantities nebeneinander\n",
|
||||||
|
"import neofarm.lib as neo\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"from datetime import datetime\n",
|
||||||
|
"\n",
|
||||||
|
"if __name__ == \"__main__\":\n",
|
||||||
|
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Definiere den Pflanzennamen\n",
|
||||||
|
" PlantName = \"W-Raps Helmacker Plant 24/25\"\n",
|
||||||
|
" print(f\"PlantName: {PlantName}\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Erstelle eine Liste zur Sammlung der Daten\n",
|
||||||
|
" data = []\n",
|
||||||
|
"\n",
|
||||||
|
" # Funktion, um Logs zu verarbeiten und die Daten zur Liste hinzuzufügen\n",
|
||||||
|
" def process_logs(logs, log_type):\n",
|
||||||
|
" for log in logs:\n",
|
||||||
|
" formatted_date = datetime.fromisoformat(log.timestamp).strftime(\"%d.%m.%y %H:%M\")\n",
|
||||||
|
" equipment_name = log.equipment[0].name if log.equipment else \"None\"\n",
|
||||||
|
" location_name = log.location[0].name if hasattr(log, 'location') and log.location else \"\"\n",
|
||||||
|
"\n",
|
||||||
|
" # Menge und weitere Details (bis zu zwei Mengen)\n",
|
||||||
|
" quantities = getattr(log, 'quantities', [])\n",
|
||||||
|
" \n",
|
||||||
|
" # Initialisiere Standardwerte für die zweite Menge\n",
|
||||||
|
" quant_type_2 = quant_measure_2 = quant_value_2 = quant_inventory_adjustment_2 = \"\"\n",
|
||||||
|
"\n",
|
||||||
|
" if len(quantities) > 0:\n",
|
||||||
|
" # Erste Menge vorhanden\n",
|
||||||
|
" quant_type_1 = quantities[0].type\n",
|
||||||
|
" quant_measure_1 = quantities[0].measure\n",
|
||||||
|
" quant_value_1 = quantities[0].value\n",
|
||||||
|
" quant_inventory_adjustment_1 = quantities[0].inventory_adjustment\n",
|
||||||
|
" else:\n",
|
||||||
|
" # Keine Mengenangaben vorhanden\n",
|
||||||
|
" quant_type_1 = quant_measure_1 = quant_value_1 = quant_inventory_adjustment_1 = \"\"\n",
|
||||||
|
" \n",
|
||||||
|
" if len(quantities) > 1:\n",
|
||||||
|
" # Zweite Menge vorhanden\n",
|
||||||
|
" quant_type_2 = quantities[1].type\n",
|
||||||
|
" quant_measure_2 = quantities[1].measure\n",
|
||||||
|
" quant_value_2 = quantities[1].value\n",
|
||||||
|
" quant_inventory_adjustment_2 = quantities[1].inventory_adjustment\n",
|
||||||
|
"\n",
|
||||||
|
" # Daten zur Tabelle hinzufügen\n",
|
||||||
|
" data.append({\n",
|
||||||
|
" \"PlantName\": PlantName,\n",
|
||||||
|
" \"LogType\": log_type,\n",
|
||||||
|
" \"Name\": log.name,\n",
|
||||||
|
" \"Timestamp\": formatted_date,\n",
|
||||||
|
" \"Equipment\": equipment_name,\n",
|
||||||
|
" \"Location\": location_name,\n",
|
||||||
|
" \"QuantType_1\": quant_type_1,\n",
|
||||||
|
" \"QuantMeasure_1\": quant_measure_1,\n",
|
||||||
|
" \"QuantValue_1\": quant_value_1,\n",
|
||||||
|
" \"QuantInventoryAdjustment_1\": quant_inventory_adjustment_1,\n",
|
||||||
|
" \"QuantType_2\": quant_type_2,\n",
|
||||||
|
" \"QuantMeasure_2\": quant_measure_2,\n",
|
||||||
|
" \"QuantValue_2\": quant_value_2,\n",
|
||||||
|
" \"QuantInventoryAdjustment_2\": quant_inventory_adjustment_2\n",
|
||||||
|
" })\n",
|
||||||
|
"\n",
|
||||||
|
" # Verarbeite die verschiedenen Log-Typen\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Maintenance), \"Maintenance\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Seeding), \"Seeding\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Input), \"Input\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Medical), \"Medical\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Harvest), \"Harvest\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Sale), \"Sale\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Erstelle ein DataFrame aus den gesammelten Daten und zeige es an\n",
|
||||||
|
" df = pd.DataFrame(data)\n",
|
||||||
|
" display(df)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "c1b73098-08f3-43fd-9bf0-d3d628b15e0d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"#Alle logs zu plant mit quantities nebeneinander in Excel exportiert\n",
|
||||||
|
"import neofarm.lib as neo\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"from datetime import datetime\n",
|
||||||
|
"import os\n",
|
||||||
|
"from openpyxl import load_workbook\n",
|
||||||
|
"from openpyxl.utils import get_column_letter\n",
|
||||||
|
"from openpyxl.styles import Alignment\n",
|
||||||
|
"\n",
|
||||||
|
"# Spezifizierter Pfad zum Downloads-Ordner (Windows-Standardpfad)\n",
|
||||||
|
"downloads_folder = os.path.join(os.path.expanduser(\"~\"), \"Downloads\")\n",
|
||||||
|
"file_path = os.path.join(downloads_folder, \"PlantLogs.xlsx\")\n",
|
||||||
|
"\n",
|
||||||
|
"if __name__ == \"__main__\":\n",
|
||||||
|
" asset = neo.Asset.Plant.from_id(\"76f89f82-1238-43bb-b34f-796a92d491a2\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Definiere den Pflanzennamen\n",
|
||||||
|
" PlantName = \"W-Raps Helmacker Plant 24/25\"\n",
|
||||||
|
" print(f\"PlantName: {PlantName}\")\n",
|
||||||
|
"\n",
|
||||||
|
" data = []\n",
|
||||||
|
"\n",
|
||||||
|
" # Funktion, um Logs zu verarbeiten und die Daten zur Liste hinzuzufügen\n",
|
||||||
|
" def process_logs(logs, log_type):\n",
|
||||||
|
" for log in logs:\n",
|
||||||
|
" # Entferne die Zeitzone vom Timestamp\n",
|
||||||
|
" timestamp = datetime.fromisoformat(log.timestamp).replace(tzinfo=None) # Sicherstellen, dass es timezone-unaware ist\n",
|
||||||
|
" equipment_name = log.equipment[0].name if log.equipment else \"\"\n",
|
||||||
|
" location_name = log.location[0].name if hasattr(log, 'location') and log.location else \"\"\n",
|
||||||
|
"\n",
|
||||||
|
" quantities = getattr(log, 'quantities', [])\n",
|
||||||
|
" quant_type_2 = quant_measure_2 = quant_value_2 = quant_inventory_adjustment_2 = \"\"\n",
|
||||||
|
"\n",
|
||||||
|
" if len(quantities) > 0:\n",
|
||||||
|
" quant_type_1 = quantities[0].type\n",
|
||||||
|
" quant_measure_1 = quantities[0].measure\n",
|
||||||
|
" quant_value_1 = quantities[0].value\n",
|
||||||
|
" quant_inventory_adjustment_1 = quantities[0].inventory_adjustment\n",
|
||||||
|
" else:\n",
|
||||||
|
" quant_type_1 = quant_measure_1 = quant_value_1 = quant_inventory_adjustment_1 = \"\"\n",
|
||||||
|
" \n",
|
||||||
|
" if len(quantities) > 1:\n",
|
||||||
|
" quant_type_2 = quantities[1].type\n",
|
||||||
|
" quant_measure_2 = quantities[1].measure\n",
|
||||||
|
" quant_value_2 = quantities[1].value\n",
|
||||||
|
" quant_inventory_adjustment_2 = quantities[1].inventory_adjustment\n",
|
||||||
|
"\n",
|
||||||
|
" data.append({\n",
|
||||||
|
" \"PlantName\": PlantName,\n",
|
||||||
|
" \"LogType\": log_type,\n",
|
||||||
|
" \"Name\": log.name,\n",
|
||||||
|
" \"Timestamp\": timestamp, # Direkte Speicherung des datetime-Objekts\n",
|
||||||
|
" \"Equipment\": equipment_name,\n",
|
||||||
|
" \"Location\": location_name,\n",
|
||||||
|
" \"QuantType_1\": quant_type_1,\n",
|
||||||
|
" \"QuantMeasure_1\": quant_measure_1,\n",
|
||||||
|
" \"QuantValue_1\": quant_value_1,\n",
|
||||||
|
" \"QuantInventoryAdjustment_1\": quant_inventory_adjustment_1,\n",
|
||||||
|
" \"QuantType_2\": quant_type_2,\n",
|
||||||
|
" \"QuantMeasure_2\": quant_measure_2,\n",
|
||||||
|
" \"QuantValue_2\": quant_value_2,\n",
|
||||||
|
" \"QuantInventoryAdjustment_2\": quant_inventory_adjustment_2\n",
|
||||||
|
" })\n",
|
||||||
|
"\n",
|
||||||
|
" # Verarbeite die verschiedenen Log-Typen\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Maintenance), \"Maintenance\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Seeding), \"Seeding\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Input), \"Input\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Medical), \"Medical\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Harvest), \"Harvest\")\n",
|
||||||
|
" process_logs(asset.get_logs_of_type(neo.Log.Sale), \"Sale\")\n",
|
||||||
|
"\n",
|
||||||
|
" # Erstelle ein DataFrame\n",
|
||||||
|
" df = pd.DataFrame(data)\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",
|
||||||
|
" print(\"Der Export wurde abgebrochen.\")\n",
|
||||||
|
" else:\n",
|
||||||
|
" df.to_excel(file_path, index=False)\n",
|
||||||
|
" else:\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",
|
||||||
|
"\n",
|
||||||
|
" # Füge Autofilter hinzu\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",
|
||||||
|
" # Setze den Zeilenumbruch\n",
|
||||||
|
" cell.alignment = Alignment(wrap_text=True) # Zeilenumbruch aktivieren\n",
|
||||||
|
" \n",
|
||||||
|
" # Formatieren der Timestamp-Spalte als Datum\n",
|
||||||
|
" if col_letter == 'D': # Angenommen, die Timestamp-Spalte ist Spalte D\n",
|
||||||
|
" cell.number_format = 'DD.MM.YYYY' # Setze das Datumsformat\n",
|
||||||
|
" \n",
|
||||||
|
" max_length = max(max_length, len(str(cell.value)) if cell.value else 0)\n",
|
||||||
|
" adjusted_width = (max_length + 2) * 1.2 # Extra Puffer hinzufügen\n",
|
||||||
|
" worksheet.column_dimensions[col_letter].width = adjusted_width\n",
|
||||||
|
"\n",
|
||||||
|
" # Speichern Sie die Datei\n",
|
||||||
|
" workbook.save(file_path)\n",
|
||||||
|
" print(f\"Die Datei wurde erfolgreich nach '{file_path}' exportiert, mit Autofilter, Zeilenumbruch und angepasster Spaltenbreite.\")\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "ebcc62d0-4334-4c61-aaa2-14cd96e8a6f0",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "de57b155-d635-4367-9a56-90d033c3a922",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
|
|||||||
Reference in New Issue
Block a user