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")); }
public static double Calculate(OfficialRates officialRates) { var basket = Math.Pow(officialRates.NbRates.Usd.Value / officialRates.NbRates.Usd.Unit, Baskets.Last().Usd) * Math.Pow(officialRates.NbRates.Euro.Value / officialRates.NbRates.Euro.Unit, Baskets.Last().Euro) * Math.Pow(officialRates.NbRates.Rur.Value / officialRates.NbRates.Rur.Unit, Baskets.Last().Rur); return(officialRates.Date < new DateTime(2016, 7, 1) ? Math.Round(basket, 1) : Math.Round(basket, 4)); }
private static OfficialRates NbRbRateFromString(string str) { var rate = new OfficialRates(); var substrings = str.Split(';'); rate.Date = Convert.ToDateTime(substrings[0], new CultureInfo("ru-RU")); rate.NbRates.Usd.Value = Convert.ToDouble(substrings[1], new CultureInfo("en-US")) / GetDenominator(rate.Date); rate.NbRates.Euro.Value = Convert.ToDouble(substrings[2], new CultureInfo("en-US")) / GetDenominator(rate.Date); rate.NbRates.Rur.Unit = rate.Date < new DateTime(2016, 7, 1) ? 1 : 100; rate.NbRates.Rur.Value = Convert.ToDouble(substrings[3], new CultureInfo("en-US")) / GetDenominator(rate.Date) * rate.NbRates.Rur.Unit; return(rate); }
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; }