Enhance production management by adding region_id to ProductionPlan and updating SQL queries: Introduced region_id to the ProductionPlan struct and modified the insert production query to include weather_type_id based on region. Updated finished productions query to account for weather effects on quality ratings, ensuring accurate production assessments. Improved comments for clarity on the impact of weather on production quality.
This commit is contained in:
@@ -30,7 +30,7 @@ struct StockInfo {
|
||||
|
||||
// SQL-Queries analog zur C++-Implementierung
|
||||
// Wichtig: Pro `production.id` darf hier **genau eine Zeile** zurückkommen.
|
||||
// Durch die Joins auf Director/Knowledge kann es sonst zu Mehrfachzeilen mit
|
||||
// Durch die Joins auf Director/Knowledge/Wetter kann es sonst zu Mehrfachzeilen mit
|
||||
// unterschiedlicher berechneter Qualität kommen. Deshalb wird die Qualität
|
||||
// über MAX() aggregiert und nach `production_id` gruppiert.
|
||||
const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
@@ -41,13 +41,24 @@ const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
p.quantity,
|
||||
p.start_timestamp,
|
||||
pr.production_time,
|
||||
-- Aggregierte Qualitätsbewertung pro Produktion
|
||||
-- Aggregierte Qualitätsbewertung pro Produktion inkl. Wettereinfluss
|
||||
MAX(
|
||||
CASE
|
||||
WHEN k2.id IS NOT NULL
|
||||
THEN (k.knowledge * 2 + k2.knowledge) / 3
|
||||
ELSE k.knowledge
|
||||
END
|
||||
GREATEST(
|
||||
0,
|
||||
LEAST(
|
||||
100,
|
||||
ROUND(
|
||||
(
|
||||
CASE
|
||||
WHEN k2.id IS NOT NULL
|
||||
THEN (k.knowledge * 2 + k2.knowledge) / 3
|
||||
ELSE k.knowledge
|
||||
END
|
||||
)::numeric
|
||||
+ COALESCE(pwe.quality_effect, 0) * 2.5
|
||||
)
|
||||
)
|
||||
)::int
|
||||
) AS quality,
|
||||
br.region_id,
|
||||
br.falukant_user_id AS user_id
|
||||
@@ -63,6 +74,10 @@ const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
AND k.character_id = c.id
|
||||
JOIN falukant_data.stock s
|
||||
ON s.branch_id = br.id
|
||||
-- Optionaler Wettereinfluss: pro (Produkt, Wetter) genau ein Datensatz
|
||||
LEFT JOIN falukant_type.product_weather_effect pwe
|
||||
ON pwe.product_id = p.product_id
|
||||
AND pwe.weather_type_id = p.weather_type_id
|
||||
LEFT JOIN falukant_data.director d
|
||||
ON d.employer_user_id = c.user_id
|
||||
LEFT JOIN falukant_data.knowledge k2
|
||||
|
||||
Reference in New Issue
Block a user