(20251122) Reformatted the muster roll data to return only unique combinations to reduce the load on the frontend.

This commit is contained in:
2025-11-22 11:35:03 +05:30
parent 6cbcac4545
commit 8f6736cd84
3 changed files with 49 additions and 13 deletions
+28 -2
View File
@@ -123,6 +123,16 @@ def init(blueprint_setup_state):
# ---------------------------------------------------------------------------------------------------------------------
async def close_browser() -> None:
current_app.printer("Closing failed browser session.")
current_app.cosec.quit()
current_app.printer("Cleanup attempt completed.")
# ---------------------------------------------------------------------------------------------------------------------
@muster_roll_report_bp.route("/generate", methods = ["GET"])
@set_api_version(api_version = "1.0.0")
@read_input(sanitize_headers = False, sanitize_data = False)
@@ -142,7 +152,9 @@ def init(blueprint_setup_state):
header_validator = lambda x: SimpleCosecCredentialsHeaders(**x),
data_validator = lambda x: CosecMusterRollReportRequestData(**x)
)
@handle_cancelled_request()
@handle_cancelled_request(
cleanup_coro = close_browser
)
async def muster_roll_report_generate(
inbound_headers: SimpleCosecCredentialsHeaders | dict = None,
inbound_data: CosecMusterRollReportRequestData | dict = None,
@@ -174,7 +186,21 @@ async def muster_roll_report_generate(
# If data was loaded:
if report_data is not None:
report_data = report_data.to_dict(orient = "records")
report_data = report_data.copy()
report_data = report_data[[
"User ID", "User Name", "Category Name",
"Grade Name", "Branch Name", "Department Name",
"Direct Reporting", "Level-1"
]]
unique_branches = report_data["Branch Name"].unique().tolist()
unique_depts = report_data[["Branch Name", "Department Name"]].drop_duplicates().to_dict(orient = "records")
unique_reportees = report_data[["Branch Name", "Department Name", "Direct Reporting"]].drop_duplicates().to_dict(orient = "records")
unique_combos = {
"Branch Name": unique_branches,
"Department Name": unique_depts,
"Direct Reporting": unique_reportees
}
report_data = unique_combos
success = True
# ┳┓
+6 -6
View File
@@ -124,7 +124,7 @@ def load_from_cosec(
masters_dir = os.path.join(base_dir, r"masters")
# Create an instance of the automation object:
cosec = CosecWeb(
current_app.cosec = CosecWeb(
cosec_url = cosec_url,
username = username,
password = password,
@@ -134,10 +134,10 @@ def load_from_cosec(
)
# Perform the login:
cosec.login(initial_sleep = 2.5)
current_app.cosec.login(initial_sleep = 2.5)
# Get the in/out report:
report_path = cosec.get_muster_roll(
report_path = current_app.cosec.get_muster_roll(
initial_sleep = 1.0,
on_date = on_date or date_time.get_current_utc_date_time(),
group_ids = group_ids,
@@ -145,10 +145,10 @@ def load_from_cosec(
)
# Log out to end the cycle:
cosec.logout()
current_app.cosec.logout()
# Close the browser window:
cosec.quit()
current_app.cosec.quit()
# If we didn't get any path, the download failed:
if report_path is None:
@@ -158,7 +158,7 @@ def load_from_cosec(
# Else, we parse the data and hold it:
else:
current_app.printer("Fetched Muster Roll.")
report_df = cosec.read_muster_roll_xls(report_path)
report_df = current_app.cosec.read_muster_roll_xls(report_path)
report_df = report_df[[
"User ID", "User Name", "Category Name",
"Grade Name", "Branch Name", "Department Name",