fix script equipment

main
MrWaradana 4 weeks ago
parent a1ea7e8b8c
commit 87d334ed73

@ -292,8 +292,8 @@ class Prediksi:
# append record using the difference for raw_cm_interval # append record using the difference for raw_cm_interval
records_to_insert.append( records_to_insert.append(
( (
str(uuid4()), str(uuid4()), # id
int(max_seq), int(max_seq), # seq
float(row["pm_interval"]) if not pd.isna(row.get("pm_interval", None)) else 0.0, float(row["pm_interval"]) if not pd.isna(row.get("pm_interval", None)) else 0.0,
float(row["year"]) if not pd.isna(row.get("year", None)) else 0.0, float(row["year"]) if not pd.isna(row.get("year", None)) else 0.0,
equipment_id, equipment_id,
@ -312,8 +312,6 @@ class Prediksi:
float(row["predictive_material_cost"]) if not pd.isna(row.get("predictive_material_cost", None)) else 0.0, float(row["predictive_material_cost"]) if not pd.isna(row.get("predictive_material_cost", None)) else 0.0,
float(row["predictive_labor_time"]) if not pd.isna(row.get("predictive_labor_time", None)) else 0.0, float(row["predictive_labor_time"]) if not pd.isna(row.get("predictive_labor_time", None)) else 0.0,
float(row["predictive_labor_human"]) if not pd.isna(row.get("predictive_labor_human", None)) else 0.0, float(row["predictive_labor_human"]) if not pd.isna(row.get("predictive_labor_human", None)) else 0.0,
float(row["loss_output_mw"]) if not pd.isna(row.get("loss_output_mw", None)) else 0.0,
float(row["loss_price"]) if not pd.isna(row.get("loss_price", None)) else 0.0,
) )
) )
@ -651,7 +649,7 @@ class Prediksi:
# Authentication: sign-in and refresh helpers # Authentication: sign-in and refresh helpers
async def sign_in(self, username: str = "Admin", password: str = "password") -> dict: async def sign_in(self, username: str = "lcca_admin", password: str = "password") -> dict:
"""Sign in to AUTH_APP_URL/sign-in using provided username/password. """Sign in to AUTH_APP_URL/sign-in using provided username/password.
Stores access_token and refresh_token on the instance when successful and returns the parsed response dict. Stores access_token and refresh_token on the instance when successful and returns the parsed response dict.
@ -673,6 +671,21 @@ class Prediksi:
return data return data
except httpx.HTTPError as e: except httpx.HTTPError as e:
print(f"Sign-in failed: {e}") print(f"Sign-in failed: {e}")
# Try to sign out if sign-in failed
try:
signout_url = f"{self.AUTH_APP_URL}/sign-out"
async with httpx.AsyncClient() as client:
await client.get(signout_url, timeout=10.0)
print("Signed out due to sign-in failure.")
except Exception as signout_exc:
print(f"Sign-out failed: {signout_exc}")
# Try to sign in again
try:
signin_res = await self.sign_in()
if getattr(self, "access_token", None):
return signin_res
except Exception as signin_exc:
print(f"Sign-in failed after sign-out: {signin_exc}")
return None return None
async def refresh_access_token(self) -> str: async def refresh_access_token(self) -> str:

@ -17,31 +17,32 @@ except ImportError:
async def main(): async def main():
start_time = time.time() start_time = time.time()
# try:
# await query_data()
# except Exception as e:
# print(f"Error in query_data: {str(e)}")
# return
try: try:
await query_data() prediction_result = await predict_run()
except Exception as e: if prediction_result is False:
print(f"Error in query_data: {str(e)}") print("Prediction step failed or was skipped. Skipping EAC run.")
return return
try:
await predict_run()
except Exception as e: except Exception as e:
print(f"Error in predict_equipment_data: {str(e)}") print(f"Error in predict_run: {str(e)}")
return return
try: try:
# eac = Eac()
# eac.hitung_eac_equipment(assetnum)
result = eac_run() result = eac_run()
result = result if not asyncio.iscoroutine(result) else await result if asyncio.iscoroutine(result):
result = await result
# if the function returned a list of objects, optionally log or handle it
if isinstance(result, (list, tuple)): if isinstance(result, (list, tuple)):
print(f"EAC run returned {len(result)} items.") print(f"EAC run returned {len(result)} items.")
else: else:
print("EAC run completed.") print("EAC run completed.")
except Exception as e: except Exception as e:
print(f"Error in hitung_eac_equipment: {str(e)}") print(f"Error in eac_run: {str(e)}")
return return
end_time = time.time() end_time = time.time()

Loading…
Cancel
Save