refactor: Streamline actual data queries by removing labor details, add optional asset filtering, and update EAC disposal cost calculation.

main
MrWaradana 3 weeks ago
parent d1aa0ced70
commit d2861e1a35

@ -186,7 +186,8 @@ class Eac:
# final_value adalah PV pada titik proyeksi periods
pmt_mnt_cost = -float(npf.pmt(disc_rate, periods, final_value))
eac_disposal_cost_proyeksi = 0.07 * pmt_mnt_cost
eac_disposal_cost_proyeksi = -npf.pmt(disc_rate, row["seq"], 0, 0.05 * rc_total_cost_0) if row["seq"] > 0 else 0.0
# menghitung PMT biaya akuisisi
# Rumus PMT: PMT = PV * [r(1 + r)^n] / [(1 + r)^n 1]
# dimana PV = rc_total_cost_0, r = disc_rate, n = row["seq"]

@ -108,22 +108,13 @@ def get_recursive_query(cursor, assetnum, worktype="CM"):
query = f"""
select
DATE_PART('year', a.reportdate) as tahun,
COUNT(DISTINCT a.wonum) as raw_{worktype.lower()}_interval,
sum(a.actmatcost) as raw_{worktype.lower()}_material_cost,
(
ROUND(SUM(EXTRACT(EPOCH FROM (a.actfinish - a.actstart)) / 3600), 2)
) AS raw_{worktype.lower()}_labor_time,
CASE
WHEN COUNT(DISTINCT b.laborcode) = 0 THEN 3
ELSE COUNT(DISTINCT b.laborcode)
END AS raw_{worktype.lower()}_labor_human
from public.wo_maximo as a
LEFT JOIN public.wo_maximo_labtrans AS b
ON b.wonum = a.wonum
{where_query}
group by DATE_PART('year', a.reportdate);
"""
DATE_PART('year', a.reportdate) as tahun,
COUNT(DISTINCT a.wonum) as raw_{worktype.lower()}_interval,
sum(a.actmatcost) as raw_{worktype.lower()}_material_cost
from public.wo_maximo as a
{where_query}
group by DATE_PART('year', a.reportdate);
"""
# Eksekusi query dan fetch hasil
cursor.execute(query)
return cursor.fetchall()
@ -457,7 +448,7 @@ async def insert_ms_equipment_data():
try:
connection, connection_wo_db = get_connection()
cursor_db_app = connection.cursor(cursor_factory=DictCursor)
query_main = "SELECT DISTINCT(assetnum) FROM ms_equipment_master"
query_main = f"SELECT DISTINCT(assetnum) FROM ms_equipment_master WHERE assetnum = 'A27860'"
cursor_db_app.execute(query_main)
results = cursor_db_app.fetchall()
@ -568,7 +559,7 @@ async def insert_lcca_maximo_corrective_data():
data_corrective_maintenance = get_recursive_query(
cursor_production, assetnum, worktype="CM"
)
print(data_corrective_maintenance)
# print(data_corrective_maintenance)
start_year = 2015
end_year = 2056
seq = 0
@ -868,7 +859,7 @@ async def insert_acquisition_cost_data():
except Exception:
pass
async def query_data():
async def query_data(target_assetnum: str = None):
connection = None
connection_wo_db = None
connection_production_wo = None
@ -948,7 +939,11 @@ async def query_data():
# Query untuk mendapatkan semua data dari tabel `lcc_ms_equipment_data`
# query_main = "SELECT * FROM lcc_ms_equipment_data"
query_main = "SELECT DISTINCT(assetnum) FROM ms_equipment_master"
cursor.execute(query_main)
if target_assetnum:
query_main += " WHERE assetnum = %s"
cursor.execute(query_main, (target_assetnum,))
else:
cursor.execute(query_main)
# Fetch semua hasil query
results = cursor.fetchall()
@ -1044,7 +1039,6 @@ async def query_data():
year=year,
labour_cost_lookup=labour_cost_lookup,
)
if not data_exists:
cursor.execute(
insert_query,

@ -10,11 +10,11 @@ from src.modules.equipment.Eac import Eac, main as eac_run
async def main():
start_time = time.time()
# try:
# await query_data()
# except Exception as e:
# print(f"Error in query_data: {str(e)}")
# return
try:
await query_data()
except Exception as e:
print(f"Error in query_data: {str(e)}")
return
try:
prediction_result = await predict_run()

Loading…
Cancel
Save