(20260219) Updarted APIs to now show last-in time and loc also.
This commit is contained in:
+18
-5
@@ -569,6 +569,11 @@ def compute_work_done(
|
||||
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
|
||||
work_reports[user_id][punch_date]["last_in"] = punch_ts
|
||||
work_reports[user_id][punch_date]["last_in_loc"] = punch_loc
|
||||
else:
|
||||
work_reports[user_id][punch_date]["last_in"] = punch_ts
|
||||
work_reports[user_id][punch_date]["last_in_loc"] = punch_loc
|
||||
|
||||
# Handle the last out time:
|
||||
if row["I/O Type"] == "Out":
|
||||
@@ -589,19 +594,21 @@ 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_in = punch_info.get("last_in")
|
||||
last_in_loc = punch_info.get("last_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:
|
||||
if first_in is not None and not last_out:
|
||||
if first_in is not None and last_out is None:
|
||||
last_out = first_in + min_work_seconds
|
||||
work_seconds = last_out - first_in
|
||||
work_seconds = min_work_seconds
|
||||
work_ot_seconds = 0.0
|
||||
|
||||
# When the user has neither an in-time, nor an out-time,
|
||||
# we assume that he was absent the whole day:
|
||||
elif not first_in and not last_out:
|
||||
elif first_in is None and last_out is None:
|
||||
work_seconds = 0.0
|
||||
work_ot_seconds = 0.0
|
||||
|
||||
@@ -628,6 +635,8 @@ def compute_work_done(
|
||||
"work_date": punch_date,
|
||||
"first_in": first_in,
|
||||
"first_in_loc": first_in_loc,
|
||||
"last_in": last_in,
|
||||
"last_in_loc": last_in_loc,
|
||||
"last_out": last_out,
|
||||
"last_out_loc": last_out_loc,
|
||||
"work_seconds": work_seconds,
|
||||
@@ -647,6 +656,7 @@ def compute_work_done(
|
||||
async def sync_attendance_to_tcaoff(
|
||||
tcaoff_client: AsyncTheCAOffice,
|
||||
cosec_in_out_summary: dict,
|
||||
chunk_size: int = 10,
|
||||
verbose: bool = False
|
||||
) -> Dict[str, int]:
|
||||
|
||||
@@ -655,6 +665,7 @@ async def sync_attendance_to_tcaoff(
|
||||
:param tcaoff_client: The asynchronous client object that interfaces with TCAOFF.
|
||||
:param cosec_in_out_summary: he table that contains all the work done by all the employees on the date-range that
|
||||
was selected.
|
||||
:param chunk_size: The number of attendance marking requests to fire concurrently.
|
||||
:param verbose: If True, internal debugging print will be more verbose.
|
||||
:return: The dict that gives you the count of the successful and failed attendance marking API calls.
|
||||
"""
|
||||
@@ -707,9 +718,11 @@ async def sync_attendance_to_tcaoff(
|
||||
json_notes = {
|
||||
"cosec": {
|
||||
"workSeconds": wr["work_seconds"],
|
||||
"totHours": wr["work_hours"],
|
||||
"workHours": wr["work_hours"],
|
||||
"firstIn": wr["first_in"],
|
||||
"firstInLoc": wr["first_in_loc"],
|
||||
"lastIn": wr["last_in"],
|
||||
"lastInLoc": wr["last_in_loc"],
|
||||
"lastOut": wr["last_out"],
|
||||
"lastOutLoc": wr["last_out_loc"],
|
||||
}
|
||||
@@ -724,7 +737,7 @@ async def sync_attendance_to_tcaoff(
|
||||
yield lst[i:i + size]
|
||||
|
||||
count = 0
|
||||
for chunk in chunks(tasks[:], size = 25):
|
||||
for chunk in chunks(tasks[:], size = chunk_size):
|
||||
count += 1
|
||||
printer("Task Chunk:", count)
|
||||
_res = await asyncio.gather(*chunk)
|
||||
|
||||
+8
-6
@@ -149,12 +149,13 @@ async def yesterday_cron(
|
||||
await common.sync_attendance_to_tcaoff(
|
||||
tcaoff_client = tcaoff_client,
|
||||
cosec_in_out_summary = json.from_file(common.PREV_DAY_IN_OUT_SUMMARY_CACHE_FILE),
|
||||
chunk_size = 10
|
||||
)
|
||||
|
||||
# If something goes wrong in the COSEC step:
|
||||
except Exception as exception:
|
||||
err_printer(exception)
|
||||
if test_mode: raise
|
||||
# if test_mode: raise
|
||||
|
||||
# Log out of TCAOFF:
|
||||
success = await tcaoff_client.logout()
|
||||
@@ -164,7 +165,7 @@ async def yesterday_cron(
|
||||
except Exception as exception:
|
||||
err_printer(exception)
|
||||
await tcaoff_client.logout()
|
||||
if test_mode: raise
|
||||
# if test_mode: raise
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
@@ -246,18 +247,19 @@ async def today_cron(
|
||||
await common.sync_attendance_to_tcaoff(
|
||||
tcaoff_client = tcaoff_client,
|
||||
cosec_in_out_summary = json.from_file(common.IN_OUT_SUMMARY_CACHE_FILE),
|
||||
chunk_size = 10
|
||||
)
|
||||
|
||||
# If something goes wrong in the COSEC step:
|
||||
except Exception as exception:
|
||||
err_printer(exception)
|
||||
if test_mode: raise
|
||||
# if test_mode: raise
|
||||
|
||||
# If something goes wrong:
|
||||
except Exception as exception:
|
||||
err_printer(exception)
|
||||
await tcaoff_client.logout()
|
||||
if test_mode: raise
|
||||
# if test_mode: raise
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
@@ -284,12 +286,12 @@ async def set_scheduler(
|
||||
await yesterday_cron(
|
||||
cosec_creds = copy.deepcopy(cosec_creds),
|
||||
tcaoff_client = tcaoff_client,
|
||||
# test_mode = test_mode
|
||||
test_mode = test_mode
|
||||
)
|
||||
await today_cron(
|
||||
cosec_creds = copy.deepcopy(cosec_creds),
|
||||
tcaoff_client = tcaoff_client,
|
||||
# test_mode = test_mode
|
||||
test_mode = test_mode
|
||||
)
|
||||
printer("Test Done")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user