public OfficialRatesModel(OfficialRates record, OfficialRatesModel previous, OfficialRatesModel annual) { Date = record.Date; TodayRates = record; YesterdayNbRbRates = previous?.TodayRates.NbRates; UsdStr = TodayRates.NbRates.Usd.Value.ToString("#,#.####", new CultureInfo("ru-RU")); EuroStr = TodayRates.NbRates.Euro.Value.ToString("#,#.####", new CultureInfo("ru-RU")); RurStr = TodayRates.NbRates.Rur.Value.ToString("#,#.####", new CultureInfo("ru-RU")); UsdBrush = YesterdayNbRbRates == null || YesterdayNbRbRates.Usd.Value.Equals(TodayRates.NbRates.Usd.Value) ? Brushes.Black : YesterdayNbRbRates.Usd.Value > TodayRates.NbRates.Usd.Value ? Brushes.LimeGreen : Brushes.Red; Basket = BelBaskets.Calculate(record); _yesterdayBasket = previous == null ? 0 : previous.Date.Year == 1999 && record.Date.Year == 2000 ? previous.Basket / 1000 : previous.Basket; SetBasketStr(); SetBasketBreakStr(previous); SetUsdAnnualStr(annual); SetBasketAnnualStr(annual); RurUsdStr = TodayRates.CbrRate.Usd.Value.Equals(0) ? "" : TodayRates.CbrRate.Usd.Value.ToString("#,#.##", new CultureInfo("ru-RU")); }
private void SetBasketBreakStr(OfficialRatesModel previous) { if (previous == null) { return; } if (BasketDelta * previous.BasketDelta >= 0) // no break { _procBasketBreak = previous._procBasketBreak + ProcBasketDelta; BasketAfterBreakStr = $"{_procBasketBreak:+0.##;-0.##;0}%"; BasketBreakBrush = _procBasketBreak < 0 ? Brushes.LimeGreen : Brushes.Red; } else { _procBasketBreak = ProcBasketDelta; BasketAfterBreakStr = ""; } }
private void SetBasketAnnualStr(OfficialRatesModel annual) { if (annual == null || annual.Basket.Equals(0)) { return; } var lastYear = Date.Year == 2000 ? annual.Basket / 1000 : Date > new DateTime(2016, 06, 30) && Date < new DateTime(2017, 1, 1) ? annual.Basket / 10000 : annual.Basket; var delta = Basket - lastYear; _procBasketAnnual = delta / lastYear * 100; BasketAnnualStr = $"{_procBasketAnnual:+0.##;-0.##;0}%"; BasketAnnualBrush = _procBasketAnnual < 0 ? Brushes.LimeGreen : Brushes.Red; }
private void SetUsdAnnualStr(OfficialRatesModel annual) { if (annual == null) { return; } var lastYear = Date.Year == 2000 ? annual.TodayRates.NbRates.Usd.Value / 1000 : Date > new DateTime(2016, 06, 30) && Date < new DateTime(2017, 1, 1) ? annual.TodayRates.NbRates.Usd.Value / 10000 : annual.TodayRates.NbRates.Usd.Value; var delta = TodayRates.NbRates.Usd.Value - lastYear; var proc = delta / lastYear * 100; UsdAnnualStr = $"{delta.ToString("#,0.####", new CultureInfo("ru-RU"))} ({proc:+0.##;-0.##;0}%)"; UsdAnnualBrush = proc < 0 ? Brushes.LimeGreen : Brushes.Red; }
private void Init() { Rows = new ObservableCollection <OfficialRatesModel>(); OfficialRatesModel annual = null; OfficialRatesModel previous = null; foreach (var record in _rates) { var current = new OfficialRatesModel(record, previous, annual); Application.Current.Dispatcher.Invoke(() => Rows.Add(current)); if (!current.BasketDelta.Equals(0)) { previous = current; } if (current.Date.Day == 31 && current.Date.Month == 12) { annual = current; } } }
public async void Download() { IsDownloadEnabled = false; using (new WaitCursor()) { var date = Rows.Last().Date.AddDays(1); var annual = Rows.Last(r => r.Date.Day == 31 && r.Date.Month == 12); while (date <= DateTime.Today.Date.AddDays(1)) { var nbRbRates = await NbRbRatesDownloader.GetRatesForDate(date); if (nbRbRates == null) { break; } var officialRates = new OfficialRates() { Date = date, NbRates = nbRbRates }; var usd2Rur = await CbrRatesDownloader.GetRateForDate(date); officialRates.CbrRate.Usd = new OneRate() { Unit = 1, Value = usd2Rur }; _rates.Add(officialRates); var line = new OfficialRatesModel(officialRates, Rows.Last(), annual); Rows.Add(line); if (date.Date.Day == 31 && date.Date.Month == 12) { annual = line; } date = date.AddDays(1); } } IsDownloadEnabled = true; }