Example #1
0
        /// <summary>
        /// Calculates how many Violations of whoch kind are located in this cell
        /// </summary>
        private void CalculateOccurances()
        {
            hasMultiple = 0;
            //Checks how many violations of what type appear in this location
            Array.Clear(RuleOccurrences, 0, RuleOccurrences.Length - 1);
            foreach (Violation violation in Violations.Where(violation => violation != null))
            {
                switch (violation.Rule.Type)
                {
                case Rule.RuleType.DYNAMIC:
                    RuleOccurrences[0]++;
                    hasMultiple = 10;
                    break;

                case Rule.RuleType.STATIC:
                    RuleOccurrences[1]++;
                    hasMultiple = 10;
                    break;

                case Rule.RuleType.SANITY:
                    RuleOccurrences[2]++;
                    hasMultiple = 10;
                    break;

                case Rule.RuleType.COMPOSITE:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Example #2
0
        private void Process()
        {
            NeedsRegularization = false;

            IsHoliday = CheckIfHoliday();
            IsWeekEnd = AppliedPolicy.IsWeekend(Date);
            if (IsHoliday && IsPresent)
            {
                Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.WorkingOnHoliday, AllAccessEvents));
            }
            if (IsWeekEnd && IsPresent)
            {
                Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.WorkingOnWeekend, AllAccessEvents));
            }
            if (IsHoliday || IsWeekEnd)
            {
                return;
            }

            if (IsPresent)
            {
                CalculateTimeSpan_Gym();
                CalculateTimeSpan_Recreation();
                CalculateTimeSpan_OutsidePremises();
                CompensateForApprovedLeave();
                CompensateForBlockRegularization();

                //Calculation of work time should be after all the other calculations
                CalculateTimeSpan_Work();

                AppliedPolicy.Validate(WorkTimeRules.GymnasiumUsageRule);
                AppliedPolicy.Validate(WorkTimeRules.RecreationUsageRule);
                AppliedPolicy.Validate(WorkTimeRules.TotalWorkHoursPerDayRule);
                AppliedPolicy.Validate(WorkTimeRules.WorkStartEndTimingRule);
            }
            else
            {
                if (ApprovedLeave == null)
                {
                    //No leave applied yet and is absent
                    Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.AbsentWithoutLeave));
                }
                if (ApprovedLeave != null && ApprovedLeave.IsHalfDay)
                {
                    //Half day leave applied and is absent
                    Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.AbsentWithHalfDayLeave));
                }
            }
            FlaggedForSevereViolation = Violations.Where(v => v.Level == ViolationLevel.Severe).ToList().Count > 0;
        }
Example #3
0
        private void CalculateTimeSpan_Work()
        {
            var violationsNeedingRegularizations = Violations.Where(v => v.Level == ViolationLevel.Severe || v.Level == ViolationLevel.Medium).ToList();

            if (violationsNeedingRegularizations.Count > 0)
            {
                NeedsRegularization = true;
            }

            var combinedDurationOfLunchAndRecreation = OutsidePremisesTimeSpan + RecreationTimeSpan;
            var excess = combinedDurationOfLunchAndRecreation - TimeSpan.FromMinutes(45.0);

            if (excess < TimeSpan.FromMinutes(0))
            {
                excess = TimeSpan.FromMinutes(0);
            }
            WorkTime = TotalDuration + LeaveTimeCompensation + BlockRegularizationCompensation - (excess + GymnasiumTimeSpan);
        }