Skip to main content

NewAttendanceSummariesCompute Function

Overview

The NewAttendanceSummariesCompute function is responsible for creating new attendance summaries based on calendar schedules and shifts. It does not recalculate existing summaries but instead generates them using provided basic information, including schedules, shifts, flags, and holidays. If the necessary calendar schedule does not exist, the function triggers its creation.


Function Signature

func NewAttendanceSummariesCompute(
curUser *entity.UserProfileTable,
calcDate string,
force, cacheFollowForce bool,
cache *caching.AllCacheStruct,
) []AttendanceSummariesCompute

Parameters

ParameterTypeDescription
curUser*entity.UserProfileTableThe user profile for which the attendance summaries are to be generated.
calcDatestringThe date for which attendance summaries should be computed.
forceboolWhether to force the creation or recalculation of the calendar schedule.
cacheFollowForceboolWhether cache operations should follow the force flag.
cache*caching.AllCacheStructCached data structure to optimize data access during computation.

Returns

  • []AttendanceSummariesCompute:
    A slice of attendance summaries computed for the given user and date.

Workflow

  1. Fetch Calendar Schedule

    • Invokes getCalendarSchedule with the provided parameters to retrieve the calendar schedule.
    • If the schedule does not exist, it triggers the schedule creation.
  2. Process Calendar Schedule

    • If the calendar schedule exists:
      • Iterates through the CalendarScheduleDetails of the fetched schedule.
      • For each valid (non-deleted) detail, creates an attendance summary using createSummaryFromCalendarDetail.
  3. Return Results

    • Returns a slice of attendance summaries generated from the schedule details.

Key Operations

  1. Logging and Timing

    • Prints elapsed time for key operations, such as fetching the calendar schedule and creating summaries, for performance monitoring.
  2. Conditional Logic

    • Ensures that only valid (non-deleted) calendar details are processed.

Example Usage

curUser := &entity.UserProfileTable{ID: 1, Name: "John Doe"}
calcDate := "2024-12-01"
force := true
cacheFollowForce := false
cache := &caching.AllCacheStruct{}

attendanceSummaries := NewAttendanceSummariesCompute(curUser, calcDate, force, cacheFollowForce, cache)

for _, summary := range attendanceSummaries {
fmt.Println(summary)
}

Notes

  • The function assumes that getCalendarSchedule and createSummaryFromCalendarDetail are properly implemented and handle their respective tasks.
  • The logic relies on CalendarScheduleDetails[idx].DeleteThis to exclude unwanted details. Ensure this field is accurately set in the data source.
  • Performance optimizations rely heavily on the caching mechanism. The cache parameter must be properly initialized to maximize efficiency.