Beispiel #1
0
 public AnalyzedDayBoss(AnalyzedDay day, int index)
 {
     boss   = (this.day = day).day.bosses[bossIndex = index];
     phases = SMAnalysis.AnalyzeDay(this, (StateMachineManager.FromText(boss.stateMachine) as PatternSM) !);
 }
Beispiel #2
0
        private AnalyzedDay AnalyzeDay(int WeekIndex, int DayIndex, int AdditionalLeaveThisWeek, String CarrierName)
        {
            var result = new AnalyzedDay();
            result.Action = DayAction.Grant;

            result.Week = WeekIndex;
            result.Day = DayIndex;

            var isAmazonOnlyDay = DayIndex == (int)DayOfWeek.Sunday || Chart.Weeks[WeekIndex].DailySchedules[DayIndex].IsHoliday;
            var carrierIsSub = Chart.Weeks[WeekIndex].Substitutes.Find(s => s.Name == CarrierName) != null;
            var carrierIsRegular = Chart.Weeks[WeekIndex].Regulars.Find(r => r.Name == CarrierName) != null;

            if (!carrierIsSub && !carrierIsRegular)
            {
                result.Action = DayAction.Skip;
                result.DenyReason = "Carrier does not exist in data for this date.";
                return result;
            }

            //Check for existing leave.
            var existingLeave = Chart.Weeks[WeekIndex].DailySchedules[DayIndex].ReliefDays.Find(rd => rd.Carrier == CarrierName);
            if (existingLeave != null)
            {
                result.Action = DayAction.Skip;
                result.DenyReason = String.Format("Carrier already off. Leave type: {0}", existingLeave.LeaveType);
            }
            else //The carrier does not already have leave.
            {
                //Check number of available substitutes.
                if (Chart.Weeks[WeekIndex].Substitutes.Count <= Chart.Weeks[WeekIndex].DailySchedules[DayIndex].ReliefDays.Count)
                {
                    result.Action = DayAction.Deny;
                    result.DenyReason = "No coverage - Day already full.";
                }
                else //There are enough substitutes.
                {
                    if (isAmazonOnlyDay)
                    {
                        if (carrierIsSub) // For subs, check to be sure we have at least as many subs as Amazon routes.
                        {
                            var subsOffCount = Chart.Weeks[WeekIndex].DailySchedules[DayIndex].ReliefDays.Count(rd => Chart.Weeks[WeekIndex].Substitutes.Find(s => s.Name == rd.Carrier) != null);

                            if (subsOffCount + Chart.Weeks[WeekIndex].LeavePolicy.AmazonRoutes >= Chart.Weeks[WeekIndex].Substitutes.Count)
                            {
                                result.Action = DayAction.Deny;
                                result.DenyReason = "No coverage for Sunday or Holiday Amazon.";
                            }
                        }
                        else // Regulars already get sundays and holidays off.
                        {
                            result.Action = DayAction.Skip;
                            result.DenyReason = DayIndex == 1 ? "Sunday" : "Holiday";
                        }
                    }
                }
            }

            // Check if we approved too many days this week, unless it's an amazon-only day.
            if (result.Action == DayAction.Grant && !isAmazonOnlyDay && (Chart.Weeks[WeekIndex].SumLeaveDays() + AdditionalLeaveThisWeek) >= (Chart.Weeks[WeekIndex].LeavePolicy.DaysPerSub * Chart.Weeks[WeekIndex].Substitutes.Count))
            {
                if (carrierIsSub)
                {
                    var existingSchedule = Chart.Weeks[WeekIndex].DailySchedules[DayIndex].ReliefDays.Find(rd => rd.Substitute == CarrierName);
                    if (existingSchedule == null) // The week is full, but this sub isn't scheduled.
                    {
                        result.DenyReason = "Double-check schedule before granting this substitute leave.";
                        result.Action = DayAction.Deny;
                    }
                    else
                    {
                        result.DenyReason = "Substitute is scheduled. Double-check schedule before granting leave.";
                        result.Action = DayAction.Deny;
                    }
                }
                else
                {
                    result.Action = DayAction.Deny;
                    result.DenyReason = "Substitutes already working maximum days per leave policy.";
                }
            }

            // Check if someone else has already been denied this day.
            if (Chart.Weeks[WeekIndex].DailySchedules[DayIndex].DeniedLeave.Count != 0)
            {
                result.Action = DayAction.Deny;
                result.DenyReason = "Leave has already been denied another carrier on this day.";
            }

            return result;
        }