create-summary-flexible-interval
sidebar_position: 8
CreateSummaryFlexibleInterval
Function
Overview
The CreateSummaryFlexibleInterval
function computes a summary for attendance records based on flexible intervals. It processes attendance logs and generates details, headers, and rule checks while considering various configurations related to intervals and gaps.
Function Definition
func CreateSummaryFlexibleInterval(
summary *AttendanceSummariesCompute,
scanLogs []*entity.AttendanceLogTable,
cache *caching.AllCacheStruct,
)
Parameters
summary
(AttendanceSummariesCompute):A summary object that contains attendance data and shift information. Ifnil
, computation is skipped.
scanLogs
([]AttendanceLogTable
):The list of attendance logs to process. If empty, the function determines that the user is not in the office.
cache
(AllCacheStruct):A cache object used for storing temporary or auxiliary data during computation.
Behavior and Key Logic
Pre-Conditions
- Logs Processing:
- The function uses
log.TimeStamp
instead oflog.TimeStampOriginal
to process logs.
- The function uses
- Interval Configuration:
MinWorkDurationMinutes
(required): Defines the duration of each interval.MinIntervalDurationMinutes
(optional): Specifies the gap between consecutive intervals.StartTime
(optional): Sets the starting time of the interval shift.DurationMinutes
(optional): Limits the maximum duration for the shift.
Steps
- Office Presence Check
- If
scanLogs
is empty, the function callsCheckIsInOffice
to flag the absence of the user.
- If
- Validation
- If
summary
orsummary.Shift
isnil
, the function terminates without computation.
- If
- Interval Pair Generation
- Uses
getPairsSequentially
to form pairs of logs based on the configured interval duration and gap.
- Uses
- Handle Absence
- If no pairs are generated, the function invokes
checkLeave
to handle potential leave cases.
- If no pairs are generated, the function invokes
- Details Creation
- Calls
CreateDetailsFromPairs
to generate details from the computed pairs.
- Calls
- Summary Header Creation
- Generates the summary header and performs rule checks by calling
CreateSummaryHeaderFromPairs
.
- Generates the summary header and performs rule checks by calling
- Debugging Support
- Includes debug statements (commented out) for deeper inspection of interval duration, gaps, and thresholds.
Auxiliary Functions
CheckIsInOffice
Determines whether the user is present in the office based on the provided logs.
getPairsSequentially
Generates sequential pairs of log entries, adhering to interval duration and gap rules.
CreateDetailsFromPairs
Processes the generated pairs and adds detailed records to the summary.
CreateSummaryHeaderFromPairs
Constructs the summary header and performs any required rule checks.
checkLeave
Handles scenarios where no pairs exist, potentially marking the user as on leave.
Notes and TODOs
- Error Handling:
- Improve error handling for
nil
inputs (e.g.,summary == nil
).
- Improve error handling for
- Debugging:
- Currently includes several debug statements (commented out). These can be enabled for diagnostic purposes.
- Threshold Calculation:
- Consider refining threshold calculations when
intervalGap
is non-zero to ensure accurate pairing.
- Consider refining threshold calculations when
Example Usage
var summary AttendanceSummariesCompute
var logs []*entity.AttendanceLogTable
var cache caching.AllCacheStruct
CreateSummaryFlexibleInterval(&summary, logs, &cache)
This function call processes logs
based on the configurations in summary.Shift
and updates the summary
with attendance details and headers.