|
|
|
|
@ -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,
|
|
|
|
|
|