You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
import asyncio
|
|
import time
|
|
|
|
# prefer package-relative imports, but allow running this file directly as a script
|
|
try:
|
|
from src.modules.equipment.insert_actual_data import query_data, insert_lcca_maximo_corrective_data, insert_ms_equipment_data, insert_acquisition_cost_data
|
|
from src.modules.equipment.Prediksi import Prediksi, main as predict_run
|
|
from src.modules.equipment.Eac import Eac, main as eac_run
|
|
except ImportError:
|
|
# fallback when there's no parent package (e.g., python run.py)
|
|
from insert_actual_data import query_data, insert_lcca_maximo_corrective_data, insert_ms_equipment_data, insert_acquisition_cost_data
|
|
from Prediksi import Prediksi, main as predict_run
|
|
from Eac import Eac, main as eac_run
|
|
|
|
|
|
# Panggil fungsi
|
|
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:
|
|
prediction_result = await predict_run()
|
|
if prediction_result is False:
|
|
print("Prediction step failed or was skipped. Skipping EAC run.")
|
|
return
|
|
except Exception as e:
|
|
print(f"Error in predict_run: {str(e)}")
|
|
return
|
|
|
|
try:
|
|
result = eac_run()
|
|
if asyncio.iscoroutine(result):
|
|
result = await result
|
|
|
|
if isinstance(result, (list, tuple)):
|
|
print(f"EAC run returned {len(result)} items.")
|
|
else:
|
|
print("EAC run completed.")
|
|
except Exception as e:
|
|
print(f"Error in eac_run: {str(e)}")
|
|
return
|
|
|
|
end_time = time.time()
|
|
execution_time = end_time - start_time
|
|
# format execution time into h/m/s as needed
|
|
if execution_time >= 3600:
|
|
hours = int(execution_time // 3600)
|
|
minutes = int((execution_time % 3600) // 60)
|
|
seconds = execution_time % 60
|
|
message = f"Script calculation finished in {hours}h {minutes}m {seconds:.2f}s."
|
|
elif execution_time >= 60:
|
|
minutes = int(execution_time // 60)
|
|
seconds = execution_time % 60
|
|
message = f"Script calculation finished in {minutes}m {seconds:.2f}s."
|
|
else:
|
|
message = f"Script calculation finished in {execution_time:.2f} seconds."
|
|
|
|
print(message)
|
|
return message
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(
|
|
main()
|
|
)
|