Skip to main content

create-summary-flexible-interval


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. If nil, 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

  1. Logs Processing:
    • The function uses log.TimeStamp instead of log.TimeStampOriginal to process logs.
  2. 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

  1. Office Presence Check
    • If scanLogs is empty, the function calls CheckIsInOffice to flag the absence of the user.
  2. Validation
    • If summary or summary.Shift is nil, the function terminates without computation.
  3. Interval Pair Generation
    • Uses getPairsSequentially to form pairs of logs based on the configured interval duration and gap.
  4. Handle Absence
    • If no pairs are generated, the function invokes checkLeave to handle potential leave cases.
  5. Details Creation
    • Calls CreateDetailsFromPairs to generate details from the computed pairs.
  6. Summary Header Creation
    • Generates the summary header and performs rule checks by calling CreateSummaryHeaderFromPairs.
  7. 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

  1. Error Handling:
    • Improve error handling for nil inputs (e.g., summary == nil).
  2. Debugging:
    • Currently includes several debug statements (commented out). These can be enabled for diagnostic purposes.
  3. Threshold Calculation:
    • Consider refining threshold calculations when intervalGap is non-zero to ensure accurate pairing.

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.