refactor: Standardize module imports to absolute paths and re-enable data querying in run script.

main
MrWaradana 3 weeks ago
parent 56ec7a1bad
commit fa4ea74d9b

@ -5,8 +5,7 @@ import json
import sys import sys
import os import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) from src.modules.config import get_connection
from config import get_connection
import argparse import argparse

@ -15,10 +15,8 @@ from dotenv import load_dotenv
import sys import sys
import os import os
from equipment.formula import rc_labor_cost, rc_lost_cost, rc_total_cost from .formula import rc_labor_cost, rc_lost_cost, rc_total_cost
from src.modules.config import get_connection, get_production_connection
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from config import get_connection, get_production_connection
import json import json
load_dotenv() load_dotenv()

@ -8,10 +8,8 @@ from datetime import datetime
import sys import sys
import os import os
import httpx import httpx
from where_query_sql import get_where_query_sql from src.modules.config import get_connection, get_production_connection
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) from .where_query_sql import get_where_query_sql
from config import get_connection, get_production_connection
async def fetch_api_data( async def fetch_api_data(
assetnum: str, year: int, RELIABILITY_APP_URL: str, token: str assetnum: str, year: int, RELIABILITY_APP_URL: str, token: str

@ -1,27 +1,20 @@
import asyncio import asyncio
import time import time
# prefer package-relative imports, but allow running this file directly as a script # clean absolute imports
try: from src.modules.equipment.insert_actual_data import query_data
from .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 .Prediksi import Prediksi, main as predict_run from src.modules.equipment.Eac import Eac, main as eac_run
from .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
from Prediksi import main as predict_run
from Eac import main as eac_run
# Panggil fungsi # Panggil fungsi
async def main(): async def main():
start_time = time.time() start_time = time.time()
# try: try:
# await query_data() await query_data()
# except Exception as e: except Exception as e:
# print(f"Error in query_data: {str(e)}") print(f"Error in query_data: {str(e)}")
# return return
try: try:
prediction_result = await predict_run(assetnum="A22277") prediction_result = await predict_run(assetnum="A22277")

Loading…
Cancel
Save