(20251122) Reformatted the muster roll data to return only unique combinations to reduce the load on the frontend.
This commit is contained in:
@@ -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"])
|
@muster_roll_report_bp.route("/generate", methods = ["GET"])
|
||||||
@set_api_version(api_version = "1.0.0")
|
@set_api_version(api_version = "1.0.0")
|
||||||
@read_input(sanitize_headers = False, sanitize_data = False)
|
@read_input(sanitize_headers = False, sanitize_data = False)
|
||||||
@@ -142,7 +152,9 @@ def init(blueprint_setup_state):
|
|||||||
header_validator = lambda x: SimpleCosecCredentialsHeaders(**x),
|
header_validator = lambda x: SimpleCosecCredentialsHeaders(**x),
|
||||||
data_validator = lambda x: CosecMusterRollReportRequestData(**x)
|
data_validator = lambda x: CosecMusterRollReportRequestData(**x)
|
||||||
)
|
)
|
||||||
@handle_cancelled_request()
|
@handle_cancelled_request(
|
||||||
|
cleanup_coro = close_browser
|
||||||
|
)
|
||||||
async def muster_roll_report_generate(
|
async def muster_roll_report_generate(
|
||||||
inbound_headers: SimpleCosecCredentialsHeaders | dict = None,
|
inbound_headers: SimpleCosecCredentialsHeaders | dict = None,
|
||||||
inbound_data: CosecMusterRollReportRequestData | dict = None,
|
inbound_data: CosecMusterRollReportRequestData | dict = None,
|
||||||
@@ -174,7 +186,21 @@ async def muster_roll_report_generate(
|
|||||||
|
|
||||||
# If data was loaded:
|
# If data was loaded:
|
||||||
if report_data is not None:
|
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
|
success = True
|
||||||
|
|
||||||
# ┳┓
|
# ┳┓
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ def load_from_cosec(
|
|||||||
masters_dir = os.path.join(base_dir, r"masters")
|
masters_dir = os.path.join(base_dir, r"masters")
|
||||||
|
|
||||||
# Create an instance of the automation object:
|
# Create an instance of the automation object:
|
||||||
cosec = CosecWeb(
|
current_app.cosec = CosecWeb(
|
||||||
cosec_url = cosec_url,
|
cosec_url = cosec_url,
|
||||||
username = username,
|
username = username,
|
||||||
password = password,
|
password = password,
|
||||||
@@ -134,10 +134,10 @@ def load_from_cosec(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Perform the login:
|
# Perform the login:
|
||||||
cosec.login(initial_sleep = 2.5)
|
current_app.cosec.login(initial_sleep = 2.5)
|
||||||
|
|
||||||
# Get the in/out report:
|
# Get the in/out report:
|
||||||
report_path = cosec.get_muster_roll(
|
report_path = current_app.cosec.get_muster_roll(
|
||||||
initial_sleep = 1.0,
|
initial_sleep = 1.0,
|
||||||
on_date = on_date or date_time.get_current_utc_date_time(),
|
on_date = on_date or date_time.get_current_utc_date_time(),
|
||||||
group_ids = group_ids,
|
group_ids = group_ids,
|
||||||
@@ -145,10 +145,10 @@ def load_from_cosec(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Log out to end the cycle:
|
# Log out to end the cycle:
|
||||||
cosec.logout()
|
current_app.cosec.logout()
|
||||||
|
|
||||||
# Close the browser window:
|
# Close the browser window:
|
||||||
cosec.quit()
|
current_app.cosec.quit()
|
||||||
|
|
||||||
# If we didn't get any path, the download failed:
|
# If we didn't get any path, the download failed:
|
||||||
if report_path is None:
|
if report_path is None:
|
||||||
@@ -158,7 +158,7 @@ def load_from_cosec(
|
|||||||
# Else, we parse the data and hold it:
|
# Else, we parse the data and hold it:
|
||||||
else:
|
else:
|
||||||
current_app.printer("Fetched Muster Roll.")
|
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[[
|
report_df = report_df[[
|
||||||
"User ID", "User Name", "Category Name",
|
"User ID", "User Name", "Category Name",
|
||||||
"Grade Name", "Branch Name", "Department Name",
|
"Grade Name", "Branch Name", "Department Name",
|
||||||
|
|||||||
+15
-5
@@ -47,6 +47,7 @@ import datetime
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
# My utils:
|
# My utils:
|
||||||
|
from utils_v2.string import json
|
||||||
from utils_v2.system import files
|
from utils_v2.system import files
|
||||||
from utils_v2.system import pfinfo
|
from utils_v2.system import pfinfo
|
||||||
|
|
||||||
@@ -1247,17 +1248,26 @@ if __name__ == "__main__":
|
|||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
# Convert the Muster Roll to a Pandas DF:
|
# Convert the Muster Roll to a Pandas DF:
|
||||||
muster_roll_path = r"D:\kps\PycharmProjects\cosec\downloads\Monthly_Details.xls"
|
muster_roll_path = r"D:\kps\PycharmProjects\cosec\cosec_web\sample_files\muster_roll.xls"
|
||||||
muster_roll_df = CosecWeb.read_muster_roll_xls(muster_roll_path)
|
muster_roll_df = CosecWeb.read_muster_roll_xls(muster_roll_path)
|
||||||
muster_roll_df = muster_roll_df[[
|
muster_roll_df = muster_roll_df[[
|
||||||
"User ID", "User Name", "Category Name",
|
"User ID", "User Name", "Category Name",
|
||||||
"Grade Name", "Branch Name", "Department Name",
|
"Grade Name", "Branch Name", "Department Name",
|
||||||
"Direct Reporting", "Level-1"
|
"Direct Reporting", "Level-1"
|
||||||
]]
|
]]
|
||||||
muster_roll_df = muster_roll_df[:35]
|
muster_roll_df = muster_roll_df[:20]
|
||||||
print(muster_roll_df.to_string())
|
# print(muster_roll_df.to_string())
|
||||||
print("\n\n---\n\n")
|
# print("\n\n---\n\n")
|
||||||
print(muster_roll_df.info())
|
# print(muster_roll_df.info())
|
||||||
|
unique_branches = muster_roll_df["Branch Name"].unique().tolist()
|
||||||
|
unique_depts = muster_roll_df[["Branch Name", "Department Name"]].drop_duplicates().to_dict(orient = "records")
|
||||||
|
unique_reportees = muster_roll_df[["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
|
||||||
|
}
|
||||||
|
print("UNIQUE COMBOS:", json.to_string(unique_combos))
|
||||||
|
|
||||||
# # Log out to end the cycle:
|
# # Log out to end the cycle:
|
||||||
# cosec.logout()
|
# cosec.logout()
|
||||||
|
|||||||
Reference in New Issue
Block a user