From d74a0b2b3d942aed59dcefb242dbc24317e378bd Mon Sep 17 00:00:00 2001 From: MrWaradana Date: Mon, 15 Dec 2025 16:53:00 +0700 Subject: [PATCH] update plant simulation script --- src/modules/plant/run_plant_simulation.py | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/modules/plant/run_plant_simulation.py b/src/modules/plant/run_plant_simulation.py index c824468..936a11a 100644 --- a/src/modules/plant/run_plant_simulation.py +++ b/src/modules/plant/run_plant_simulation.py @@ -330,6 +330,22 @@ def main(): cost_a_pm = 0 cost_a_pinjaman = 0 cost_a_depreciation = 0 + net_capacity_factor_v = 0 + eaf_v = 0 + + # Prefetch CF/EAF master data once to avoid repeated queries per row + cur.execute( + """ + SELECT year as tahun, cf, eaf + FROM lcc_ms_year_data + """ + ) + year_rows = cur.fetchall() + year_data_map = { + int(t): (validate_number(cf), validate_number(eaf)) + for (t, cf, eaf) in year_rows + if t is not None + } for row in rows: # row adalah tuple sesuai urutan select_sql @@ -337,6 +353,18 @@ def main(): seq = data["seq"] # primary key / unique key untuk WHERE + # Ambil net_capacity_factor dan eaf dari year-data cache berdasarkan tahun + cf_eaf = ( + year_data_map.get(int(data["tahun"])) + if data.get("tahun") is not None + else None + ) + if cf_eaf: + net_capacity_factor_v, eaf_v = cf_eaf + else: + net_capacity_factor_v = 0 + eaf_v = 0 + if data["is_actual"] == 1: net_capacity_factor = validate_number(data["net_capacity_factor"]) eaf = validate_number(data["eaf"]) @@ -368,6 +396,9 @@ def main(): cost_bd_pm_nonmi = cost_bd_pm_nonmi # last value cost_bd_bd = cost_bd_bd # last value + net_capacity_factor = net_capacity_factor_v + eaf = eaf_v + # ++++++ REVENUE +++++++ revenue_total = revenue_a + revenue_b + revenue_c + revenue_d if seq > 0: