(20251119) Added caching to the muster roll data.

This commit is contained in:
2025-11-19 19:42:44 +05:30
parent a2f6390755
commit 6cbcac4545
5 changed files with 240 additions and 50 deletions
+9 -48
View File
@@ -68,6 +68,9 @@ from utils_v2.api.async_quart import (
from backend.models.api.common import SimpleCosecCredentialsHeaders
from backend.models.api.reports.muster_roll import CosecMusterRollReportRequestData
# Helpers:
from backend.api.helpers import muster_roll
# Cosec-related:
from cosec_web.cosec_web import CosecWeb
@@ -160,61 +163,19 @@ async def muster_roll_report_generate(
success = False
report_data = None
# Figure out the paths:
base_dir = files.get_parent_directory(
files.get_file_directory(include_filename = False),
depth = 4
)
# Put together the directory for the drivers, the downloads, etc.:
chrome_driver_dir = os.path.join(base_dir, r"drivers/chrome")
user_data_dir = os.path.join(base_dir, r"browser/user_data")
downloads_dir = os.path.join(base_dir, r"downloads")
# Show all the paths for debugging:
current_app.printer("PATHS:", chrome_driver_dir, user_data_dir, downloads_dir)
# Create an instance of the automation object:
cosec = CosecWeb(
# Get the muster roll data:
report_data = muster_roll.load(
cosec_url = inbound_headers.cosecUrl,
username = inbound_headers.cosecUsername,
password = inbound_headers.cosecPassword,
driver_dir = chrome_driver_dir,
user_data_dir = user_data_dir,
downloads_dir = downloads_dir,
)
# Perform the login:
cosec.login(initial_sleep = 2.5)
# Get the in/out report:
report_path = cosec.get_muster_roll(
initial_sleep = 1.0,
on_date = inbound_data.onDate,
group_ids = inbound_data.groupIds,
download_timeout = 60.0
on_date = inbound_data.onDate,
)
# Log out to end the cycle:
cosec.logout()
# Close the browser window:
cosec.quit()
# If we didn't get any path, the download failed:
if report_path is None:
success = False
# Convert the In/Out Summary to a Pandas DF:
else:
# If data was loaded:
if report_data is not None:
report_data = report_data.to_dict(orient = "records")
success = True
report_df = cosec.read_muster_roll_xls(report_path)
report_df = report_df[[
"User ID", "User Name", "Category Name",
"Grade Name", "Branch Name", "Department Name",
"Direct Reporting", "Level-1"
]]
report_data = report_df.to_dict(orient = "records")
# ┳┓
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓