private string Sum_Values(bool squareValues) { double value = 0; bool isDouble = false; foreach (string data in _currentStatValues) { if (CalcHelpers.isDouble(data)) { isDouble = true; } if (squareValues) { value += Math.Pow(double.Parse(data), 2); } else { value += double.Parse(data); } } if (isDouble) { return(value.ToString()); } else { return(((int)value).ToString()); } }
public void Function_Button_Click(object sender, RoutedEventArgs e) { _funcVisible = !_funcVisible; // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
public void Stat_Add_Button_Click(object sender, RoutedEventArgs e) { string text = _mainPage.GetMainText(); // get the text block TextBlock tb = new TextBlock(); tb.Text = text; tb.FontSize = 60; tb.Foreground = Utilities.Helpers.GetBrush(Utilities.Helpers.Colors.DarkGray); tb.FontFamily = new Windows.UI.Xaml.Media.FontFamily("Segoe UI Light"); tb.FontWeight = Windows.UI.Text.FontWeights.Light; Viewbox vb = new Viewbox(); vb.Height = TemplateStatButtonHeight.ActualHeight; vb.Child = tb; vb.Margin = new Thickness(0, 0, 20, 0); AddToGrid(vb, text); _mainPage.Stat_Add_Button_Click(_currentStatValues.Count.ToString()); // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
public void Function_Button_Click(object sender, RoutedEventArgs e) { // standard buttons SinButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; CosButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; TanButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; NatLogButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; SinhButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; CoshButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; TanhButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; EXButton.Visibility = !_funcVisible ? Visibility.Collapsed : Visibility.Visible; // function buttons SinButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; CosButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; TanButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; NatLogButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; SinhButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; CoshButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; TanhButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; EXButtonF.Visibility = _funcVisible ? Visibility.Collapsed : Visibility.Visible; _funcVisible = !_funcVisible; // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
private void Average_Button_Click(object sender, RoutedEventArgs e) { try { _mainPage.SetMainText(Average_Values().ToString()); } catch { _mainPage.initCalcError(); } // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
private void Summation_Squared_Button_Click(object sender, RoutedEventArgs e) { try { _mainPage.SetMainText(Sum_Values(true)); } catch { _mainPage.initCalcError(); } // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
private void Population_Standard_Deviation_Button_Click(object sender, RoutedEventArgs e) { try { _mainPage.SetMainText(Math.Sqrt(Variance(true)).ToString()); } catch { _mainPage.initCalcError(); } // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
public void SimpleSubtraction() { Mouse.Click(CalcWindow.CalculatorButton("2")); Mouse.Click(CalcWindow.CalculatorButton(Subtract)); Mouse.Click(CalcWindow.CalculatorButton("1")); Mouse.Click(CalcWindow.CalculatorButton(EqualButton)); Assert.IsTrue(CalcHelpers.VerifyResults("1"), "Calculator showed incorrect result"); Assert.IsFalse(CalcHelpers.VerifyResults("0"), "Result never changed from default 0"); }
public void DecimalCheck() { Mouse.Click(CalcWindow.CalculatorButton("1")); Mouse.Click(CalcWindow.CalculatorButton(Decimal)); Mouse.Click(CalcWindow.CalculatorButton("2")); Mouse.Click(CalcWindow.CalculatorButton("5")); Mouse.Click(CalcWindow.CalculatorButton(Add)); Mouse.Click(CalcWindow.CalculatorButton("1")); Mouse.Click(CalcWindow.CalculatorButton(Decimal)); Mouse.Click(CalcWindow.CalculatorButton("5")); Mouse.Click(CalcWindow.CalculatorButton(EqualButton)); Assert.IsTrue(CalcHelpers.VerifyResults("2.75"), "Calculator showed incorrect result"); Assert.IsFalse(CalcHelpers.VerifyResults("0"), "Result never changed from default 0"); }
private void Average_Squared_Button_Click(object sender, RoutedEventArgs e) { try { double sum = Sum_Values(); double avg = sum / _currentStatValues.Count; avg = Math.Pow(avg, 2); _mainPage.SetMainText(avg.ToString()); } catch { _mainPage.initCalcError(); } // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
public void Stat_Add_Button_Click(object sender, RoutedEventArgs e) { string text = _mainPage.GetMainText(); // get the text block TextBlock tb = new TextBlock(); tb.Text = text; tb.FontSize = 60; Viewbox vb = new Viewbox(); vb.Height = TemplateStatButtonHeight.ActualHeight; vb.Child = tb; AddToGrid(vb, text); _mainPage.Stat_Add_Button_Click(_currentStatValues.Count.ToString()); // reset the equals key focus when we change view CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
public static int Max(List <int> numbers) { return(CalcHelpers.FindMax(numbers)); }
public static int Sum(List <int> numbers) { return(CalcHelpers.FindSum(numbers)); }
public static decimal Avg(List <int> numbers) { return(CalcHelpers.FindAverage(numbers)); }
public static int Duplicate(List <int> numbers) { return(CalcHelpers.FindDuplicate(numbers)); }
public static bool Contains(List <int> numbers, int number) { return(CalcHelpers.Conatains(numbers, number)); }
public static int Abs(int number) { return(CalcHelpers.FindAbsolute(number)); }
public static decimal FahToCel(decimal number) { return(CalcHelpers.FahToCel(number)); }
public static decimal CelToFah(decimal number) { return(CalcHelpers.CellToFah(number)); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { CalcHelpers.equalsKeyFocus(_mainPage.currentView.GetEqualsKey()); }
public NewLoanResponseModel Calculate(NewLoanRequestModel requestModel, String cookieValue) { RequestHistoryResponseModel requestHistory = null; if (cookieValue != null) { UserRequestModel user = _jWTService.decodeJWTAsync(cookieValue).Result; requestHistory = new RequestHistoryResponseModel(); requestHistory.Request_Time = DateTime.Now; requestHistory.Calculator_Type = "credit"; requestHistory.User = user; } var validated = _newLoanValidator.Validate(requestModel); if (!validated.IsValid) { _logger.Error($"New Loan BadRequest! {validated}"); return(new NewLoanResponseModel { Status = HttpStatusCode.BadRequest, ErrorMessage = validated.ToString() }); } try { var plan = requestModel.InstallmentType == Installments.AnnuityInstallment ? CalcHelpers.GetAnuityPlan(requestModel).ToList() : CalcHelpers.GetDecreasingPlan(requestModel).ToList(); var totalFeesCost = plan.Sum(x => x.Fees); var totalMonthlyInstallmentsCost = plan.Sum(x => x.MonthlyInstallment); var totalInterestCost = plan.Sum(x => x.InterestInstallment); NewLoanResponseModel newLoanResponse = new NewLoanResponseModel { Status = HttpStatusCode.OK, //AnnualPercentCost = CalcHelpers.CalculateAPR(totalFeesCost, totalInterestCost, requestModel.LoanAmount, requestModel.Period), AnnualPercentCost = 0, TotalCost = totalMonthlyInstallmentsCost + totalFeesCost, FeesCost = totalFeesCost, InterestsCost = totalInterestCost, InstallmentsCost = totalMonthlyInstallmentsCost, RepaymentPlan = plan }; if (requestHistory != null) { requestHistory.Calculation_Result = "Input:" + requestModel.ToString().Trim() + "Result: " + newLoanResponse.ToString().Trim(); requestHistory.User_Agent = requestModel.UserAgent; _requestHistoryDataService.insertRequest(requestHistory); } return(newLoanResponse); } catch (Exception ex) { _logger.Error($"An error occured while trying to calculate new loan.\nInput: {requestModel}\nMessage: {ex.Message}"); return(new NewLoanResponseModel { Status = HttpStatusCode.InternalServerError, ErrorMessage = "Something went wrong. Please contact our support team." }); } }
public LeasingLoanResponseModel Calculate(LeasingLoanRequestModel requestModel, string cookieValue) { RequestHistoryResponseModel requestHistory = null; if (cookieValue != null) { UserRequestModel user = _jWTService.decodeJWTAsync(cookieValue).Result; requestHistory = new RequestHistoryResponseModel(); requestHistory.Request_Time = DateTime.Now; requestHistory.Calculator_Type = "leasing"; requestHistory.User = user; } var validated = _leasingLoanValidator.Validate(requestModel); if (!validated.IsValid) { _logger.Error($"Leasing Loan BadRequest! {validated}"); return(new LeasingLoanResponseModel { Status = HttpStatusCode.BadRequest, ErrorMessage = validated.ToString() }); } //TO DO: AnnualPercentCost how to calculate ? try { var totalFees = CalcHelpers.GetFeeCost(requestModel.StartingFee, requestModel.ProductPrice); var totalCost = totalFees + requestModel.StartingInstallment + requestModel.Period * requestModel.MonthlyInstallment; if (totalCost < requestModel.ProductPrice) { return(new LeasingLoanResponseModel { Status = HttpStatusCode.BadRequest, ErrorMessage = "You cannot have a leasing loan with these parameters." }); } LeasingLoanResponseModel leasingLoanResponse = new LeasingLoanResponseModel { Status = HttpStatusCode.OK, //AnnualPercentCost TotalCost = totalCost, TotalFees = totalFees }; if (requestHistory != null) { requestHistory.Calculation_Result = "Input: " + requestModel.ToString().Trim() + " Result: " + leasingLoanResponse.ToString().Trim(); requestHistory.User_Agent = requestModel.UserAgent; _requestHistoryDataService.insertRequest(requestHistory); } return(leasingLoanResponse); } catch (Exception ex) { _logger.Error($"An error occured while trying to calculate leasing loan.\nInput: {requestModel}\nMessage: {ex.Message}"); return(new LeasingLoanResponseModel { Status = HttpStatusCode.InternalServerError, ErrorMessage = "Something went wrong. Please contact our support team." }); } }
public RefinancingLoanResponseModel Calculate(RefinancingLoanRequestModel requestModel, String cookieValue) { RequestHistoryResponseModel requestHistory = null; if (cookieValue != null) { UserRequestModel user = _jWTService.decodeJWTAsync(cookieValue).Result; requestHistory = new RequestHistoryResponseModel(); requestHistory.Request_Time = DateTime.Now; requestHistory.Calculator_Type = "refinance"; requestHistory.User = user; } var validated = _refinancingLoanValidator.Validate(requestModel); if (!validated.IsValid) { _logger.Error($"Refinancing Loan BadRequest! {validated}"); return(new RefinancingLoanResponseModel { Status = HttpStatusCode.BadRequest, ErrorMessage = validated.ToString() }); } try { var plan = CalcHelpers.GetAnuityPlan(new NewLoanRequestModel { LoanAmount = requestModel.LoanAmount, Period = requestModel.Period, Interest = requestModel.Interest, InstallmentType = Installments.AnnuityInstallment }).ToList(); var periodLeft = requestModel.Period - requestModel.CountOfPaidInstallments; var monthlyInstallmentCurrentLoan = plan.First(x => x.Id == 1).MonthlyInstallment; var moneyLeftToBePaid = requestModel.LoanAmount - plan.Where(x => x.Id <= requestModel.CountOfPaidInstallments).Sum(x => x.PrincipalInstallment); var earlyInstallmentsFeeInCurrency = CalcHelpers.GetFeeCost(requestModel.EarlyInstallmentsFee, moneyLeftToBePaid); var newPlan = CalcHelpers.GetAnuityPlan(new NewLoanRequestModel { LoanAmount = Math.Floor(moneyLeftToBePaid), Period = periodLeft, Interest = requestModel.NewInterest, InstallmentType = Installments.AnnuityInstallment, Fees = new List <FeeModel> { new FeeModel { Type = FeeType.StartingApplicationFee, Value = requestModel.StartingFeesCurrency, ValueType = FeeValueType.Currency }, new FeeModel { Type = FeeType.OtherStartingFees, Value = requestModel.StartingFeesPercent, ValueType = FeeValueType.Percent } } }).ToList(); var monthlyInstallmentNewLoan = newPlan.First(x => x.Id == 1).MonthlyInstallment; var totalCostNewLoan = periodLeft * monthlyInstallmentNewLoan + earlyInstallmentsFeeInCurrency + requestModel.StartingFeesCurrency + requestModel.StartingFeesPercent + CalcHelpers.GetFeeCost(requestModel.StartingFeesPercent, moneyLeftToBePaid); RefinancingLoanResponseModel refinancingLoanResponse = new RefinancingLoanResponseModel { Status = HttpStatusCode.OK, CurrentLoan = new RefinancingLoanHelperModel { Interest = requestModel.Interest, Period = requestModel.Period, EarlyInstallmentsFee = earlyInstallmentsFeeInCurrency, MonthlyInstallment = monthlyInstallmentCurrentLoan, Total = periodLeft * monthlyInstallmentCurrentLoan }, NewLoan = new RefinancingLoanHelperModel { Interest = requestModel.NewInterest, Period = periodLeft, MonthlyInstallment = monthlyInstallmentNewLoan, Total = totalCostNewLoan } }; if (requestHistory != null) { requestHistory.Calculation_Result = "Input: " + requestModel.ToString().Trim() + "Result: " + refinancingLoanResponse.ToString().Trim(); requestHistory.User_Agent = requestModel.UserAgent; _requestHistoryDataService.insertRequest(requestHistory); } return(refinancingLoanResponse); } catch (Exception ex) { _logger.Error($"An error occured while trying to calculate new loan.\nInput: {requestModel}\nMessage: {ex.Message}"); return(new RefinancingLoanResponseModel { Status = HttpStatusCode.InternalServerError, ErrorMessage = "Something went wrong. Please contact our support team." }); } }