From fbca231de54a6d873975974a09ee44c1a74d3289 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 1 Dec 2025 10:04:09 +0100 Subject: [PATCH] Add running_productions_quantity to ProductionPlan: Introduced a new field to track the quantity of ongoing productions. Updated the DirectorWorker to parse this new field from the database and adjusted the free capacity calculation accordingly. Enhanced logging to provide detailed information when production cannot be started due to capacity constraints. --- src/worker/director.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/worker/director.rs b/src/worker/director.rs index bbf5d16..ad672ea 100644 --- a/src/worker/director.rs +++ b/src/worker/director.rs @@ -26,6 +26,7 @@ struct ProductionPlan { stock_size: i32, used_in_stock: i32, running_productions: i32, + running_productions_quantity: i32, } #[derive(Debug, Clone)] @@ -378,6 +379,10 @@ impl DirectorWorker { stock_size: row.get("stock_size")?.parse().ok()?, used_in_stock: row.get("used_in_stock")?.parse().ok()?, running_productions: row.get("running_productions")?.parse().ok()?, + running_productions_quantity: row + .get("running_productions_quantity")? + .parse() + .ok()?, }) } @@ -391,7 +396,10 @@ impl DirectorWorker { return Ok(()); } - let free_capacity = plan.stock_size - plan.used_in_stock - plan.running_productions; + // Freie Lagerkapazität: Gesamtbestand minus bereits belegter Bestand + // (Inventar) minus bereits eingeplante Produktionsmengen. + let free_capacity = + plan.stock_size - plan.used_in_stock - plan.running_productions_quantity; // Stückkosten monetär berechnen. Da money ein f64 ist, arbeiten wir hier ebenfalls // mit Gleitkomma und runden erst am Ende auf eine ganze Stückzahl ab. @@ -406,6 +414,13 @@ impl DirectorWorker { let to_produce = free_capacity.min(max_money_production).min(300).max(0); if to_produce < 1 { + eprintln!( + "[DirectorWorker] Keine Produktion gestartet: free_capacity={}, max_money_production={}, running_productions={}, running_qty={}", + free_capacity, + max_money_production, + plan.running_productions, + plan.running_productions_quantity + ); return Ok(()); }