From 00ce7fc65506ba573abaecc190c2efde16754ef8 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 13 Apr 2026 15:34:28 +0200 Subject: [PATCH] Refactor SQL query for candidate selection: Updated the SQL query to include a new `FROM candidates` clause, ensuring accurate retrieval of the top production candidates based on worth calculations. This change enhances the clarity and functionality of the production selection process. --- src/worker/sql.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/worker/sql.rs b/src/worker/sql.rs index 57c11bc..d82b62a 100644 --- a/src/worker/sql.rs +++ b/src/worker/sql.rs @@ -301,6 +301,7 @@ SELECT ROUND(((sell_cost::float8 * market_percent_val / 100.0 * (0.6 + 0.4 * (LEAST(100.0, GREATEST(0.0, (2.0 * knowledge_char_val + knowledge_dir_val) / 3.0)) / 100.0))) - (GREATEST((sell_cost::float8 * market_percent_val / 100.0 * (0.6 + 0.4 * (LEAST(100.0, GREATEST(0.0, (2.0 * knowledge_char_val + knowledge_dir_val) / 3.0)) / 100.0)) - one_piece_cost_val), 0.0) * (COALESCE($3::float8, 0.0) / 100.0)) - one_piece_cost_val)::numeric, 4)::text AS net_piece, ROUND(COALESCE($3::numeric, 0), 2)::text AS tax_percent, ROUND((((sell_cost::float8 * market_percent_val / 100.0 * (0.6 + 0.4 * (LEAST(100.0, GREATEST(0.0, (2.0 * knowledge_char_val + knowledge_dir_val) / 3.0)) / 100.0))) - (GREATEST((sell_cost::float8 * market_percent_val / 100.0 * (0.6 + 0.4 * (LEAST(100.0, GREATEST(0.0, (2.0 * knowledge_char_val + knowledge_dir_val) / 3.0)) / 100.0)) - one_piece_cost_val), 0.0) * (COALESCE($3::float8, 0.0) / 100.0)) - one_piece_cost_val) / NULLIF(production_time::float8, 0.0))::numeric, 8)::text AS worth +FROM candidates ORDER BY worth DESC LIMIT 5; "#;