Пример #1
0
        public bool TestMedalCalculation()
        {
            var passed = true;

            var numChecked = 0;
            var numPassed  = 0;
            var numFailed  = 0;

            var dbHelper = new DbHelper(new SqlConnection(Log), Log);
            List <MedalComparisonModel> testMedalData = dbHelper.GetMedalTestData();

            foreach (var medalComparisonModel in testMedalData)
            {
                IMedalCalulator calulator;
                switch (medalComparisonModel.MedalType)
                {
                case MedalType.Limited:
                    calulator = new OfflineLImitedMedalCalculator(DB, Log);
                    break;

                case MedalType.OnlineLimited:
                    calulator = new OnlineLImitedMedalCalculator(DB, Log);
                    break;

                case MedalType.NonLimited:
                    calulator = new NonLimitedMedalCalculator(DB, Log);
                    break;

                case MedalType.SoleTrader:
                    calulator = new SoleTraderMedalCalculator(DB, Log);
                    break;

                default:
                    Log.Debug("Skipping medal calc for {0} NoMedal", medalComparisonModel.CustomerId);
                    continue;
                }
                numChecked++;
                DateTime companyDate;
                DateTime regDate;
                DateTime calcTime = medalComparisonModel.CalculationTime;
                int      businessSeniority;
                decimal  ezbobSeniority;
                if (
                    !DateTime.TryParseExact(medalComparisonModel.BusinessSeniority.Value,
                                            new[] { "yyyy-MM-dd HH:mm:ss" }, null, DateTimeStyles.AdjustToUniversal,
                                            out companyDate))
                {
                    businessSeniority = 0;
                }
                else
                {
                    businessSeniority = (int)(calcTime - companyDate).TotalDays / 365;
                }

                if (
                    !DateTime.TryParseExact(medalComparisonModel.EzbobSeniority.Value,
                                            new[] { "yyyy-MM-dd HH:mm:ss" }, null, DateTimeStyles.AdjustToUniversal,
                                            out regDate))
                {
                    ezbobSeniority = 0;
                }
                else
                {
                    ezbobSeniority = (decimal)(calcTime - regDate).TotalDays / (365.0M / 12.0M);
                }
                var model = new MedalInputModel {
                    AnnualTurnover           = decimal.Parse(medalComparisonModel.AnnualTurnover.Value),
                    TangibleEquity           = decimal.Parse(medalComparisonModel.TangibleEquity.Value),
                    BusinessScore            = int.Parse(medalComparisonModel.BusinessScore.Value),
                    FirstRepaymentDatePassed = medalComparisonModel.FirstRepaymentDatePassed,
                    BusinessSeniority        = businessSeniority,
                    MaritalStatus            = (MaritalStatus)Enum.Parse(typeof(MaritalStatus), medalComparisonModel.MaritalStatus.Value),
                    EzbobSeniority           = ezbobSeniority,
                    NetWorth           = decimal.Parse(medalComparisonModel.NetWorth.Value),
                    NumOfEarlyPayments = int.Parse(medalComparisonModel.NumOfEarlyRepayments.Value),
                    NumOfLatePayments  = int.Parse(medalComparisonModel.NumOfLateRepayments.Value),
                    NumOfOnTimeLoans   = int.Parse(medalComparisonModel.NumOfLoans.Value),
                    NumOfStores        = int.Parse(medalComparisonModel.NumOfStores.Value),
                    PositiveFeedbacks  = int.Parse(medalComparisonModel.PositiveFeedbacks.Value),
                    FreeCashFlow       = decimal.Parse(medalComparisonModel.FreeCashFlow.Value),

                    ConsumerScore = int.Parse(medalComparisonModel.ConsumerScore.Value),
                    HasHmrc       = medalComparisonModel.NumOfHmrcMps > 0
                };

                var medal = calulator.CalculateMedal(model);

                if (Math.Abs(medal.NormalizedScore - medalComparisonModel.TotalScoreNormalized) > 0.009M)
                {
                    Log.Debug("{0}", medal);
                    if (medal.Medal != medalComparisonModel.Medal)
                    {
                        passed = false;
                        Log.Error("Medal Mismatch for customerid {0} 1st {1} 2nd {2}", medalComparisonModel.CustomerId,
                                  medalComparisonModel.Medal, medal.Medal);
                    }
                    numFailed++;
                    passed = false;
                    Log.Error("Medal Normalized Score Mismatch for customerid {0} 1st {1} 2nd {2}", medalComparisonModel.CustomerId,
                              medalComparisonModel.TotalScoreNormalized, medal.NormalizedScore);

                    PrintComparisonMedal(medalComparisonModel);
                }
                else
                {
                    numPassed++;
                }
            }

            Log.Debug("Test run on {0}, passed: {1}, failed: {2}", numChecked, numPassed, numFailed);
            return(passed);
        }
Пример #2
0
        }         // constructor

        /// <summary>
        ///     Determines which medal to calculate and calculates it.
        ///     Which medal type to choose logic:
        ///     https://drive.google.com/open?id=0B1Io_qu9i44SVzVqV19nbnMxRW8&amp;authuser=0
        /// </summary>
        /// <param name="customerId">Customer ID.</param>
        /// <param name="calculationDate">
        ///     Optional. Leave empty to calculate based on current data
        ///     or specify date to calculate medal based on data available on that date.
        /// </param>
        /// <returns>Calculated medal model.</returns>
        public MedalOutputModel GetMedal(int customerId, DateTime calculationDate)
        {
            var turnoverCalc = new TurnoverCalculator(customerId, calculationDate, DB, Log);

            string errorMsg;
            var    type = turnoverCalc.GetMedalType(out errorMsg);

            if (!string.IsNullOrWhiteSpace(errorMsg))
            {
                return(new MedalOutputModel {
                    MedalType = MedalType.NoMedal,
                    Medal = Medal.NoClassification,
                    TurnoverType = null,
                    Error = errorMsg,
                    CustomerId = customerId,
                });
            }             // if

            IMedalCalulator medalCalulator;

            switch (type)
            {
            case MedalType.Limited:
                medalCalulator = new OfflineLImitedMedalCalculator(this.DB, this.Log);
                break;

            case MedalType.NonLimited:
                medalCalulator = new NonLimitedMedalCalculator(this.DB, this.Log);
                break;

            case MedalType.OnlineLimited:
                medalCalulator = new OnlineLImitedMedalCalculator(this.DB, this.Log);
                break;

            case MedalType.SoleTrader:
                medalCalulator = new SoleTraderMedalCalculator(this.DB, this.Log);
                break;

            case MedalType.OnlineNonLimitedNoBusinessScore:
                medalCalulator = new OnlineNonLimitedNoBusinessScoreMedalCalculator(this.DB, this.Log);
                break;

            case MedalType.OnlineNonLimitedWithBusinessScore:
                medalCalulator = new OnlineNonLimitedWithBusinessScoreMedalCalculator(this.DB, this.Log);
                break;

            default:
                return(new MedalOutputModel {
                    MedalType = type,
                    Medal = Medal.NoClassification,
                    TurnoverType = null,
                    Error = "None of the medals match the criteria for medal calculation",
                    CustomerId = customerId
                });
            }             // switch

            MedalInputModel data = medalCalulator.GetInputParameters(customerId, calculationDate);

            MedalOutputModel medal = medalCalulator.CalculateMedal(data);

            SetOfferedAmount(
                medal,
                turnoverCalc.MinApprovalAmount
                );

            return(medal);
        }         // GetMedal