(20251225) Added multi-day In/Out Summary compatibility.
This commit is contained in:
+40
-15
@@ -33,6 +33,9 @@
|
||||
|
||||
# To make sibling directories accessible for imports:
|
||||
import sys
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.append(".")
|
||||
sys.path.append("..")
|
||||
|
||||
@@ -41,6 +44,7 @@ import os
|
||||
|
||||
# To work with date and time:
|
||||
import time
|
||||
import datetime
|
||||
|
||||
# Cosec-related:
|
||||
from cosec_web.cosec_web import CosecWeb
|
||||
@@ -189,12 +193,20 @@ def get_in_out_summary(cosec_creds: dict):
|
||||
|
||||
# Get the in/out report:
|
||||
now_utc = date_time.get_current_utc_date_time()
|
||||
from_dt = now_utc - datetime.timedelta(
|
||||
days = cosec_creds["generalConfig"]["timedelta"]["days"],
|
||||
hours = cosec_creds["generalConfig"]["timedelta"]["hours"],
|
||||
minutes = cosec_creds["generalConfig"]["timedelta"]["minutes"],
|
||||
seconds = cosec_creds["generalConfig"]["timedelta"]["seconds"],
|
||||
)
|
||||
to_dt = now_utc
|
||||
report_path = cosec.get_in_out_summary(
|
||||
initial_sleep = 1.0,
|
||||
from_date = now_utc,
|
||||
to_date = now_utc,
|
||||
from_date = from_dt,
|
||||
to_date = to_dt,
|
||||
group_ids = cosec_creds["inOutConfig"]["groupIds"],
|
||||
download_timeout = 60.0
|
||||
download_timeout = 60.0,
|
||||
timezone = cosec_creds["generalConfig"]["timezone"],
|
||||
)
|
||||
|
||||
# Log out to end the cycle:
|
||||
@@ -212,15 +224,16 @@ def get_in_out_summary(cosec_creds: dict):
|
||||
|
||||
# Assume that the punch time in the data is IST data,
|
||||
# then normalize it to UTC:
|
||||
report_data["Punch Time"] = report_data["Punch Time"].apply(
|
||||
lambda x: date_time.to_timezone(
|
||||
def parse_dt(x):
|
||||
if pd.isnull(x): return None
|
||||
else: return date_time.to_timezone(
|
||||
datetime_object = date_time.as_if_timezone(
|
||||
datetime_object = x,
|
||||
timezone = date_time.TIMEZONE_IST
|
||||
datetime_object = date_time.parse_date_time(x),
|
||||
timezone = cosec_creds["generalConfig"]["timezone"]
|
||||
),
|
||||
timezone = date_time.TIMEZONE_UTC
|
||||
).timestamp()
|
||||
)
|
||||
report_data["Punch Time"] = report_data["Punch Time"].apply(lambda x: parse_dt(x))
|
||||
|
||||
# Do the remaining cleanup and formatting:
|
||||
report_data = report_data.where(report_data.notna(), None)
|
||||
@@ -245,11 +258,11 @@ def get_reports(cosec_creds: dict) -> None:
|
||||
|
||||
# Get the Muster Roll and then wait
|
||||
# for the driver's resources to get freed:
|
||||
try:
|
||||
get_muster_roll(cosec_creds = cosec_creds)
|
||||
time.sleep(2.5)
|
||||
except Exception as e:
|
||||
print("MUSTER ROLL FETCH FAILED!")
|
||||
# try:
|
||||
# get_muster_roll(cosec_creds = cosec_creds)
|
||||
# time.sleep(2.5)
|
||||
# except Exception as e:
|
||||
# print("MUSTER ROLL FETCH FAILED!")
|
||||
|
||||
# Get the In-Out Summary and then wait
|
||||
# for the driver's resources to get freed:
|
||||
@@ -258,6 +271,7 @@ def get_reports(cosec_creds: dict) -> None:
|
||||
time.sleep(2.5)
|
||||
except Exception as e:
|
||||
print("IN-OUT SUMMARY FETCH FAILED!")
|
||||
raise e
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
@@ -298,6 +312,16 @@ if __name__ == "__main__":
|
||||
"username": "<usr>",
|
||||
"password": "<pwd>"
|
||||
},
|
||||
"generalConfig": {
|
||||
"pollInterval": 3600,
|
||||
"timezone": "Asia/Kolkata",
|
||||
"timedelta": {
|
||||
"days": 0,
|
||||
"hours": 24,
|
||||
"minutes": 0,
|
||||
"seconds": 0
|
||||
}
|
||||
},
|
||||
"musterRollConfig": {
|
||||
"groupIds": ["2", "3", "4"]
|
||||
},
|
||||
@@ -307,7 +331,8 @@ if __name__ == "__main__":
|
||||
}
|
||||
"""
|
||||
|
||||
cosec_creds = json.from_file(cosec_creds_file)
|
||||
loop(
|
||||
cosec_creds = json.from_file(cosec_creds_file),
|
||||
interval_seconds = 900 # ... Run every 15 mins.
|
||||
cosec_creds = cosec_creds,
|
||||
interval_seconds = cosec_creds["generalConfig"]["pollInterval"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user