(20260216) Attendance mark is now truly async.
This commit is contained in:
+15
-3
@@ -164,6 +164,7 @@ def get_muster_roll(
|
||||
|
||||
# Start by assuming failure:
|
||||
success = False
|
||||
report_path = None
|
||||
|
||||
# If test mode:
|
||||
if test_mode:
|
||||
@@ -232,7 +233,7 @@ def get_muster_roll(
|
||||
# Sort by hierarchy (BFS):
|
||||
pass
|
||||
|
||||
print(f"MUSTER ROLL ({len(report_data)}):", json.to_string(report_data))
|
||||
# print(f"MUSTER ROLL ({len(report_data)}):", json.to_string(report_data))
|
||||
|
||||
# Save the data to a JSON file:
|
||||
json.to_file(
|
||||
@@ -428,6 +429,7 @@ def get_in_out_summary(
|
||||
|
||||
# Start by assuming failure:
|
||||
success = False
|
||||
report_path = None
|
||||
|
||||
# If test mode:
|
||||
if test_mode:
|
||||
@@ -523,7 +525,7 @@ def compute_work_done(
|
||||
To calculate the full work done by all the employees on all the provided dates.
|
||||
:param in_out_df: The table that contains all the work done by all the employees on the date-range that was
|
||||
selected.
|
||||
:return: A list of dicts that containthe information of all the work done.
|
||||
:return: A list of dicts that contain the information of all the work done.
|
||||
"""
|
||||
|
||||
# Create the structure that will be given as the output:
|
||||
@@ -546,16 +548,19 @@ def compute_work_done(
|
||||
punch_dt = date_time.parse_date_time(row["Punch Time"], timezone = date_time.TIMEZONE_IST)
|
||||
punch_date = punch_dt.strftime("%Y-%m-%d")
|
||||
punch_ts = punch_dt.timestamp()
|
||||
punch_loc = row[" Device/Source Detail"]
|
||||
|
||||
# Handle the first in time:
|
||||
if row["I/O Type"] == "In":
|
||||
if work_reports[user_id][punch_date].get("first_in") is None:
|
||||
work_reports[user_id][punch_date]["first_in"] = punch_ts
|
||||
work_reports[user_id][punch_date]["first_in_loc"] = punch_loc
|
||||
|
||||
# Handle the last out time:
|
||||
if row["I/O Type"] == "Out":
|
||||
if work_reports[user_id][punch_date].get("first_in") is not None:
|
||||
work_reports[user_id][punch_date]["last_out"] = punch_ts
|
||||
work_reports[user_id][punch_date]["last_out_loc"] = punch_loc
|
||||
|
||||
# Now use the first_in and last out times of each record to figure out the amount of work done:
|
||||
for user_id, user_reports in work_reports.items():
|
||||
@@ -569,7 +574,9 @@ def compute_work_done(
|
||||
|
||||
# Extract, clean and compute punch timing:
|
||||
first_in = punch_info.get("first_in")
|
||||
first_in_loc = punch_info.get("first_in_loc")
|
||||
last_out = punch_info.get("last_out")
|
||||
last_out_loc = punch_info.get("last_out_loc")
|
||||
|
||||
# When the user has a valid in-time, but no known out time,
|
||||
# we assume that he worked a full day:
|
||||
@@ -606,7 +613,9 @@ def compute_work_done(
|
||||
"user_id": user_id,
|
||||
"work_date": punch_date,
|
||||
"first_in": first_in,
|
||||
"first_in_loc": first_in_loc,
|
||||
"last_out": last_out,
|
||||
"last_out_loc": last_out_loc,
|
||||
"work_seconds": work_seconds,
|
||||
"work_hours": work_hours,
|
||||
"work_ot_seconds": work_ot_seconds,
|
||||
@@ -695,7 +704,8 @@ async def sync_attendance_to_tcaoff(
|
||||
yield lst[i:i + size]
|
||||
|
||||
count = 0
|
||||
for chunk in chunks(tasks[:]):
|
||||
for chunk in chunks(tasks[:30]):
|
||||
start_time = time.time()
|
||||
count += 1
|
||||
printer("Task Chunk:", count)
|
||||
_res = await asyncio.gather(*chunk)
|
||||
@@ -704,6 +714,8 @@ async def sync_attendance_to_tcaoff(
|
||||
results["success"] += success
|
||||
results["failure"] += failure
|
||||
results["total"] += len(_res)
|
||||
print("BATCH TIME TAKEN:", time.time() - start_time)
|
||||
print("\n\n---\n\n")
|
||||
|
||||
# Done here:
|
||||
printer(results)
|
||||
|
||||
Reference in New Issue
Block a user