diff --git a/scripts/common.py b/scripts/common.py index 72a18de..42f1b61 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -540,7 +540,8 @@ def get_in_out_summary( def compute_work_done( in_out_df: pd.DataFrame, - working_hours_lookup: dict + working_hours_lookup: dict, + today: datetime.datetime = None ) -> List[Dict[str, Union[str, int, float, None]]]: """ @@ -548,10 +549,17 @@ def compute_work_done( :param in_out_df: The table that contains all the work done by all the employees on the date-range that was selected. :param working_hours_lookup: The lookup table that tells you how many hours a day is the employee expected to work. + :param today: Today's date to use as reference when calculating work done. Useful when the team member has not + logged out, and we need to assume calculations. :return: A list of dicts that contain the information of all the work done. """ # Input cleaning: + now = date_time.get_current_ist_date_time() + now_ts = now.timestamp() + if today is None: today = date_time.get_current_ist_date_time() + today = today.replace(hour = 0, minute = 0, second = 0, microsecond = 0) + today_ts = today.timestamp() if not isinstance(working_hours_lookup, dict): working_hours_lookup = {} @@ -617,10 +625,17 @@ def compute_work_done( 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: + # When the user has a valid in-time, but no known out time. + # In such a case we must assume the work done. + # If the punch date is today's date, we assume the user is yet working till 'now'. + # If the punch date is one from the past, we assume the user worked till his minimum daily hours: if first_in is not None and last_out is None: - # last_out = first_in + min_work_seconds - # work_seconds = min_work_seconds + if first_in >= today_ts: + last_out = now_ts + work_seconds = now_ts - first_in + else: + last_out = first_in + min_work_seconds + work_seconds = min_work_seconds work_ot_seconds = 0.0 # When the user has neither an in-time, nor an out-time, @@ -644,12 +659,12 @@ def compute_work_done( # 'OT' ---> Overtime # --- work_hours = work_seconds / (60 * 60) - # --- + # --- [Multi-Layered Logic]: # if work_hours > 10.0: work_status = "OT" # elif 7.5 < work_hours <= 10.0: work_status = "P" # elif 4.5 < work_hours <= 7.5: work_status = "HD1" # else: work_status = "A" - # --- + # --- [Simple Present/Absent Logic]: if first_in: work_status = "P" else: work_status = "A"