コード例 #1
0
        public void Analyse()
        {
            var compareToMonths = 3;

            var currentDate            = DateTime.Today;
            var currentExchangerate    = _list.Last().Value;
            var monthlyAverage         = GetMonthlyAverage();
            var lastThreeMonths        = GetLastMonths(compareToMonths);
            var lastThreeMonthsAverage = monthlyAverage.TakeLast(compareToMonths).Average(_ => _.Average);

            lastThreeMonths.Sort((a, b) => a.Value.CompareTo(b.Value));
            var lastThreeMonthsPeak = Math.Round(lastThreeMonths.Last().Value, 2);
            var lastThreeMonthLow   = Math.Round(lastThreeMonths.First().Value, 2);
            var isBelowAverage      = currentExchangerate < lastThreeMonthsAverage;
            var currentMonthAverage = Math.Round(GetMonthlyAverage(true).Last().Average, 2);

            var title   = isBelowAverage ? "Rate below average" : "Rate above average";
            var percent = isBelowAverage ? Math.Round((currentExchangerate / lastThreeMonthsAverage) * 100, 2) :
                          Math.Round((currentExchangerate / lastThreeMonthsAverage) * 100 - 100, 2);
            var scale = isBelowAverage ? "below" : "above";

            var e = new ExchangeRateEvent {
                Title   = title,
                Message = $"The current exchange rate ({_list.Currency}/{_list.CurrencyDenominator}) is {percent}% {scale} the average of the last {compareToMonths} months."
                          + Environment.NewLine + Environment.NewLine +
                          $"Last 3 month exchange rate peak: {lastThreeMonthsPeak} {_list.Unit}"
                          + Environment.NewLine +
                          $"Last 3 month exchange rate low:  {lastThreeMonthLow} {_list.Unit}"
                          + Environment.NewLine +
                          $"Current month average:           {currentMonthAverage} {_list.Unit}"
                          + Environment.NewLine + Environment.NewLine +
                          $"Current rate: {_list.Last().Value} {_list.Unit}/{_list.CurrencyDenominator}"
            };


            if (isBelowAverage)
            {
                RateBelowAverage?.Invoke(this, e);
            }
            else
            {
                RateAboveAverage?.Invoke(this, e);
            }
        }
コード例 #2
0
 private static void Analyser_RateAboveAverage(object sender, ExchangeRateEvent e)
 {
     _notificationManager.Send(e.Title, e.Message);
 }