Skip to main content

Flexible Interval Computation Documentation

This code provides functionality to compute flexible intervals for attendance logs. It includes various functions and types to handle the computation of intervals, pairing of check-in and check-out logs, and summarizing attendance data.

Constants

const (
INTERVAL_UNDER_DURATION = "under duration minimum"
INTERVAL_UNDER_GAP_DURATION = "under gap duration minimum"
)

These constants are used to indicate reasons why an interval might not be considered valid.

Types

IntervalDuration

type IntervalDuration struct {
Log *entity.AttendanceLogTable
Index int
DurationToNext float64
Candidate string
First bool
Last bool
PrevDuration float64
IntervalNum int
}

Represents the duration between two attendance logs.

Intervals

type Intervals struct {
Index int
Ci *IntervalDuration
Co *IntervalDuration
CiLog *entity.AttendanceLogTable
CoLog *entity.AttendanceLogTable
CiTime string
CoTime string
Duration float64
LessOrMore float64
IntervalToNext float64
IsCalculated bool
CalculatedReason string
}

Represents a pair of check-in and check-out intervals.

IntervalPairs

type IntervalPairs []*Intervals

A slice of Intervals representing multiple pairs.

Functions

isMinutesInDurationTreshold

func isMinutesInDurationTreshold(minutes, duration, treshold float64) bool

Checks if the given minutes are within the duration threshold.

PrintAll

func (p IntervalPairs) PrintAll()

Prints all interval pairs for debugging purposes.

IsCompletePair

func (i *Intervals) IsCompletePair() bool

Checks if an interval pair is complete (both check-in and check-out are present).

IsInTreshold

func (id *IntervalDuration) IsInTreshold(duration, treshold float64) bool

Checks if the duration to the next interval is within the threshold.

getPairsSequentially

func getPairsSequentially(scanLogs []*entity.AttendanceLogTable, duration, treshold float64) IntervalPairs

Generates pairs of check-in and check-out logs sequentially based on the given duration and threshold.

getDurationToNext

func getDurationToNext(scanLogs []*entity.AttendanceLogTable) []IntervalDuration

Calculates the duration to the next log for each log in the scan logs.

CreateSummaryFlexibleInterval

func CreateSummaryFlexibleInterval(summary *AttendanceSummariesCompute, scanLogs []*entity.AttendanceLogTable, cache *caching.AllCacheStruct)

Creates a summary of flexible intervals based on the scan logs and cache.

CreateDetailsFromPairs

func CreateDetailsFromPairs(summary *AttendanceSummariesCompute, pairs IntervalPairs)

Creates summary details from the interval pairs.

CreateSummaryHeaderFromPairs

func CreateSummaryHeaderFromPairs(summary *AttendanceSummariesCompute, pairs IntervalPairs, cache *caching.AllCacheStruct)

Creates a summary header from the interval pairs and cache.

checkAction

func checkAction(summary *AttendanceSummariesCompute, action string, ruleDetail *entity.RuleDetailTable, diff float64)

Checks and applies the appropriate action based on the rule detail and difference.

checkDuration

func checkDuration(actualDuration float64, minimumDuration float64) (string, float64)

Checks the duration and returns the case (less or more) and the difference.

diffIsMatchWithTheRule

func diffIsMatchWithTheRule(diff, minimum float64, durCase string, settings *entity.CompanyTable) bool

Checks if the difference matches the rule based on the company settings.

CreateSummaryFlexible

func CreateSummaryFlexible(summary *AttendanceSummariesCompute, calcDate string, curUser *entity.UserProfileTable, cache *caching.AllCacheStruct, scans []*entity.AttendanceLogTable)

Creates a summary for a flexible shift based on the scan logs and cache.

GetFirstAndLastPair

func GetFirstAndLastPair(summary *AttendanceSummariesCompute, scanLogs []*entity.AttendanceLogTable) *Intervals

Returns an interval based on the first and last scan logs.

GetFinalPairOfTheDay

func GetFinalPairOfTheDay(summary *AttendanceSummariesCompute, scanLogs []*entity.AttendanceLogTable, calcDate string, duration float64) *Intervals

Returns the best pair of scan logs for the day.

getMinAndMaxTimeThreshold

func getMinAndMaxTimeThreshold(log *entity.AttendanceLogTable, threshold float64, duration float64) (time.Time, time.Time, time.Time)

Returns the minimum and maximum time thresholds based on the log, threshold, and duration.

findScanLogInThresholdDuration

func findScanLogInThresholdDuration(currentLog *entity.AttendanceLogTable, logs []*entity.AttendanceLogTable, min time.Time, max time.Time, exacDuration float64) (*entity.AttendanceLogTable, float64, float64)

Finds a scan log within the threshold duration.

getRuleMaxOvertime

func getRuleMaxOvertime(rules []*entity.RuleDetailTable) int

Returns the maximum overtime allowed based on the rules.

Usage Example

// Example usage of CreateSummaryFlexibleInterval
summary := &AttendanceSummariesCompute{}
scanLogs := []*entity.AttendanceLogTable{
// Populate with attendance logs
}
cache := &caching.AllCacheStruct{}
CreateSummaryFlexibleInterval(summary, scanLogs, cache)

This documentation provides an overview of the functions and types used in the flexible interval computation. By understanding these components, you can effectively utilize and extend the functionality for attendance management.