public static int GetAdjustmentValue(this AutopilotRule rule, AutopilotPassType passType)
        {
            if (rule == null)
            {
                return(0);
            }

            switch (passType)
            {
            case AutopilotPassType.TightenALot:
                return(rule.TightenLot);

            case AutopilotPassType.TightenABit:
                return(rule.TightenBit);

            case AutopilotPassType.LoosenABit:
                return(rule.LoosenBit);

            case AutopilotPassType.LoosenALot:
                return(rule.LoosenLot);

            default:
                throw new ArgumentOutOfRangeException(nameof(passType), passType, "Unknown pass type provided");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Builds autopilot pass using rules and adjustment values
        /// </summary>
        /// <param name="basePass"></param>
        /// <param name="autopilotRules"></param>
        /// <param name="passType"></param>
        /// <param name="createDateTime"></param>
        /// <param name="passName"></param>
        /// <returns>Pass with adjusted rule values</returns>
        private static AutopilotPassModel BuildAutopilotPass(AutopilotPassModel basePass,
                                                             IReadOnlyDictionary <int, List <AutopilotRule> > autopilotRules, AutopilotPassType passType,
                                                             DateTime createDateTime, string passName)
        {
            var newPass = (AutopilotPassModel)basePass.Clone();

            newPass.Id            = 0;
            newPass.Name          = passName;
            newPass.DateCreated   = createDateTime;
            newPass.AutopilotType = passType;

            var generalRules = autopilotRules[(int)RuleCategory.General];
            var slottingLimitsRuleEnabled = autopilotRules[(int)RuleCategory.SlottingLimits].First().Enabled;

            foreach (var generalRule in generalRules)
            {
                var rule = newPass.General.FirstOrDefault(tpg => tpg.RuleId == generalRule.RuleId);
                if (rule is null)
                {
                    continue;
                }

                rule.Value = UpdateRuleValue(rule.Value, generalRule.GetAdjustmentValue(passType));
            }

            foreach (var toleranceRule in autopilotRules[(int)RuleCategory.Tolerances])
            {
                var rule = newPass.Tolerances.FirstOrDefault(tpg => tpg.RuleId == toleranceRule.RuleId);
                if (rule is null)
                {
                    continue;
                }

                var adjustmentValue = toleranceRule.GetAdjustmentValue(passType);

                switch (passType)
                {
                case AutopilotPassType.TightenALot:
                case AutopilotPassType.TightenABit:
                    rule.Under = UpdateRuleValue(rule.Under, adjustmentValue);
                    rule.Over  = UpdateRuleValue(rule.Over, -adjustmentValue);
                    break;

                case AutopilotPassType.LoosenABit:
                case AutopilotPassType.LoosenALot:
                    rule.Under = UpdateRuleValue(rule.Under, -adjustmentValue);
                    rule.Over  = UpdateRuleValue(rule.Over, adjustmentValue);
                    break;
                }
            }

            foreach (var rulesRule in autopilotRules[(int)RuleCategory.Rules])
            {
                var rule = newPass.Rules.FirstOrDefault(tpg => tpg.RuleId == rulesRule.RuleId);
                if (rule is null)
                {
                    continue;
                }

                var adjustmentValue = rulesRule.GetAdjustmentValue(passType);

                rule.Value     = UpdateRuleValue(rule.Value, adjustmentValue);
                rule.PeakValue = UpdateRuleValue(rule.PeakValue, adjustmentValue);
            }

            if (slottingLimitsRuleEnabled)
            {
                var generalMinimumEfficiency         = generalRules.FirstOrDefault(gr => gr.RuleId == 1)?.GetAdjustmentValue(passType) ?? 0;
                var generalMaximumRank               = generalRules.FirstOrDefault(gr => gr.RuleId == 2)?.GetAdjustmentValue(passType) ?? 0;
                var generalDemographBandingTolerance = generalRules.FirstOrDefault(gr => gr.RuleId == 3)?.GetAdjustmentValue(passType) ?? 0;

                foreach (var slRule in newPass.SlottingLimits)
                {
                    slRule.MinimumEfficiency = UpdateRuleValue(slRule.MinimumEfficiency, generalMinimumEfficiency);
                    slRule.MaximumEfficiency = UpdateRuleValue(slRule.MaximumEfficiency, generalMaximumRank);
                    slRule.BandingTolerance  = UpdateRuleValue(slRule.BandingTolerance, generalDemographBandingTolerance);
                }
            }

            return(newPass);
        }