public void TestAdd() { var currency = new DummyCurrency(); var a = new Price <DummyCurrency>(1, currency); var b = new Price <DummyCurrency>(2, currency); Assert.Equal(3, a.Add(b).Value); Assert.Equal(currency, a.Add(b).Currency); Assert.Equal(3, b.Add(a).Value); Assert.Equal(3, (a + b).Value); Assert.Equal(3, (b + a).Value); }
private async Task SavePrice() { List <Task <bool> > tasks = new List <Task <bool> >(); if (PartIds.Any()) { foreach (PartPrice Price in Prices) { tasks.Add(Task.Run(() => Price.Add())); } var res = await Task.WhenAll <bool>(tasks); if (res.Any(i => i == false)) { int number = res.Count(i => i == false); string msgText = "Serwer zwrócił błąd podczas aktualizacji ceny, cena nie została zaktualizowana.."; if (number > 1) { msgText = $"Próba zaktualizowania ceny zakończyła się niepowodzeniem w przypadku {number} części.."; } MessageBox.Show(msgText, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show($"Zaktualizowano cenę. Nowa cena będzie obowiązywać od {Prices.FirstOrDefault().ValidFrom}.", "Powodzenie", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private async void GetCoinsDetail(HttpClient client, Array coins) { foreach (Coins coin in coins) { string response = await client.GetStringAsync(GetCoinURL(coin)); // json 데이터 가져오기 var data = JsonConvert.DeserializeObject <Rootobject>(response); data.Coin = coin; if (Price.Contains(data)) { Price[Price.IndexOf(data)] = data; } else { Price.Add(data); } if (!initFirst && coin == Coins.btc_krw) { SelectedCoin = CoinNameDictionary[coin]; BuyingLast = data.last; SellLast = data.last; initFirst = true; } } }
public void Add(long t, double p, double v) { Time.Add(t); Price.Add(p); Volume.Add(v); DataAdded?.Invoke(this, Symbol, t, p, v); }
public Price GetTotalPrice() { Price totalPrice = Price.Create(0); OrderItems.ToList().ForEach(x => totalPrice = Price.Add(totalPrice, x.GetTotalPrice())); return(totalPrice); }
public void Add() { Price price1 = Price.Create(new decimal(10)); Price price2 = Price.Create(new decimal(10.50)); Price priceCombined = Price.Add(price1, price2); Assert.Equal(new decimal(20.50), priceCombined.Amount); }
public ApiTransactionProduct AddPrice(decimal price) { Price ??= new List <ApiTransactionPrice>(); Price.Add(new ApiTransactionPrice() { Price = price }); return(this); }
public void It_can_add_a_discount() { var unit = new Price(100); var discount = new Discount(50); var expectedPrice = unit.AsCurrency() + discount.InCurrency(); var actualPrice = unit.Add(discount); Assert.That(actualPrice.AsCurrency(), Is.EqualTo(expectedPrice)); }
public void It_can_add_another_Price() { var unit = new Price(100); var other = new Price(200); var expectedPrice = unit.AsCurrency() + other.AsCurrency(); var actualPrice = unit.Add(other); Assert.That(actualPrice.AsCurrency(), Is.EqualTo(expectedPrice)); }
public static Price CalcHexPrice(HexTileData hexTileData) { Price ans = new Price(); ans.Init(); foreach (var hexEdgeData in hexTileData.HexEdgesData) { ans.Add(CalcHexEdgePrice(hexEdgeData)); } return(ans); }
private static Price CalculateAutoClosePrice(Order order, PriceType priceType) { Debug.Assert(order.IsOpen); SpecialTradePolicyDetail policy = order.Owner.SpecialTradePolicyDetail(); Settings.Instrument instrument = order.Owner.SettingInstrument(); OrderLevelRiskBase autoCloseBase = priceType == PriceType.Limit ? policy.AutoLimitBase : policy.AutoStopBase; decimal autoCloseThreshold = priceType == PriceType.Limit ? policy.AutoLimitThreshold : policy.AutoStopThreshold; if (autoCloseBase == OrderLevelRiskBase.None) { return(null); } else if (autoCloseBase == OrderLevelRiskBase.Necessary) { return(CalculateForOrderLevelRiskNecessay(order, autoCloseThreshold, instrument, priceType)); } else { Price basePrice = order.ExecutePrice; if (autoCloseBase == OrderLevelRiskBase.SettlementPrice) { TradeDay tradeDay = Settings.Setting.Default.GetTradeDay(); if (order.Owner.ExecuteTime > tradeDay.BeginTime) { return(null); } else { basePrice = (order.IsBuy ? instrument.DayQuotation.Buy : instrument.DayQuotation.Sell); } } int autoClosePips = (int)autoCloseThreshold; if (order.SetPriceMaxMovePips > 0 && order.SetPriceMaxMovePips < autoClosePips) { autoClosePips = order.SetPriceMaxMovePips; } if (order.IsBuy == (priceType == PriceType.Limit)) { return(Price.Add(basePrice, autoClosePips, !instrument.IsNormal)); } else { return(Price.Subtract(basePrice, autoClosePips, !instrument.IsNormal)); } } }
public static Invoice Create <TCurrency>(IEnumerable <EquipmentOrder> orderLines, RentalFees <TCurrency> fees) where TCurrency : Currency, new() { Price <TCurrency> total = new Price <TCurrency>(0, new TCurrency()); int loyaltyPoints = 0; var lines = orderLines.Select(orderLine => { var price = orderLine.CalculatePrice(fees); total = total.Add(price); // TODO: this logic is a part of "LoyaltyPoints" type loyaltyPoints += orderLine.CalculateLoyaltyPoints(); return(price.Print()); }).ToList(); return(new Invoice(total.Print(), loyaltyPoints, lines)); }
public void SumCityPayAndReward() { foreach (var city in MyCities) { var bill = new Price(); bill.Init(); var resourceType = city.CityResourceType; var rentPrice = Configuration.Singleton.GetPricePerTurnOfType(resourceType); var addReward = Configuration.Singleton.GetRewardPerTurnOfType(resourceType); bill.Add(addReward); bill.Reduce(rentPrice); bill.MultiplyPrice(city.CitySize); PlayerResources.Add(bill); } }
public void addItem(JewelryItemsViewModel item) { Jewelries.Add(item); if (Categories.Where(x => x.Id == item.JewelryCategories.Id).Count() == 0) { Categories.Add(item.JewelryCategories); Weight.Add(item.JewelryCategories.Name, 0); Price.Add(item.JewelryCategories.Name, 0); Quantity.Add(item.JewelryCategories.Name, 0); } Weight[item.JewelryCategories.Name] += item.Weight.Value * item.Quantity; Price[item.JewelryCategories.Name] += item.Price.Value * item.Quantity; Quantity[item.JewelryCategories.Name] += item.Quantity; Weight["Total"] += item.Weight.Value * item.Quantity; Price["Total"] += item.Price.Value * item.Quantity; Quantity["Total"] += item.Quantity; }
protected override decimal ComputeNextValue(IndicatorDataPoint input) { Price.Add(input); if (Price.Samples > 2) { // From Ehlers page 16 equation 2.9 var it = (a - ((a / 2) * (a / 2))) * Price[0].Value + ((a * a) / 2) * Price[1].Value - (a - (3 * (a * a) / 4)) * Price[2].Value + 2 * (1 - a) * Trend[0].Value - ((1 - a) * (1 - a)) * Trend[1].Value; Trend.Add(new IndicatorDataPoint(input.Time, it)); } else { Trend.Add(new IndicatorDataPoint(input.Time, Price[0].Value)); } return(Trend[0].Value); }
public TimeSeries() { InitializeComponent(); Constants.RawData data = Constants.Item.GetRawData(); int n = Constants.Item.GetCount(); var Ewma = DataPreparer.Weighter(data, 0.5); YFormatter = value => value.ToString("C"); List <double> BuyQ = data.BuyQuantity.Select <int, double>(i => i).ToList(); List <double> BuyP = data.BuyPrice.Select <int, double>(i => i).ToList(); List <double> SellQ = data.SellQuantity.Select <int, double>(i => i).ToList(); List <double> SellP = data.SellPrice.Select <int, double>(i => i).ToList(); for (int i = 0; i < BuyQ.Count(); i++) { EWMAPrice.Add(new ObservablePoint(i, Ewma._strdBuyPrice.ElementAt(i))); Price.Add(new ObservablePoint(i, BuyP.ElementAt(i))); } DataContext = this; }
private static Price CalculateForOrderLevelOpenPrice(Order order, decimal autoCloseThreshold, Settings.Instrument instrument, PriceType priceType) { Price basePrice = order.ExecutePrice; int autoClosePips = (int)autoCloseThreshold; int setPriceMaxMovePips = order.SetPriceMaxMovePips; if (setPriceMaxMovePips > 0 && setPriceMaxMovePips < autoClosePips) { autoClosePips = setPriceMaxMovePips; } bool isLimit = priceType == PriceType.Limit; if (order.IsBuy == isLimit) { return(Price.Add(basePrice, autoClosePips, !instrument.IsNormal)); } else { return(Price.Subtract(basePrice, autoClosePips, !instrument.IsNormal)); } }
public HandSetFeatures(BsonDocument bsonElements) : this() { string key, data; DateTime result; int batteryLifeInHours, counter = 0; double cameraResolutionMPixels; int xRes, yRes, megs, gigs, generic; double weight, price, res; ImageURL = "https://image.freepik.com/free-icon/not-available-abbreviation-inside-a-circle_318-33662.jpg"; keyValuePairs = new Dictionary <string, string>(); foreach (var element in bsonElements) { ++counter; if (element == null) { throw new Exception($"the element #{counter} is null"); } if (element.Name == null) { throw new Exception($"the element #{counter} has a null name"); } if (element.Value == null) { throw new Exception($"The eleement #{counter} has a null value"); } key = element.Name.ToString(); data = element.Value.ToString(); keyValuePairs.Add(key, element.Value.ToString()); if (key == "Brand") { Brand = data; } else if (key == "Model") { Model = data.Replace('-', ' ').Replace("be you", "beyou"); // To avoid problems with hyphens } else if ((key == "Release date") && DateTime.TryParse(data, out result)) // Release date { ReleaseDate = result; } else if (key == "FM Radio") // FM Radio { HasFMRadio = "No" != data; } else if (key == "4G Connectivity") { Connectivity_4G = data == "Yes"; } else if (key.StartsWith("Battery life") && int.TryParse(data, out batteryLifeInHours)) { BatteryLife = batteryLifeInHours; } else if ((key.StartsWith("Camera") && double.TryParse(data, out cameraResolutionMPixels))) { Camera = cameraResolutionMPixels; } else if (key.StartsWith("Be You") && double.TryParse(data, out price)) { Price.Add(key, price); } else if (key == "Color") { Colors.Add(data.ToLower()); } else if (key == "Dual Camara") { if (double.TryParse(data, out res)) { DualCamera = res; } else { DualCamera = 0; } } else if (key == "Dual SIM") { DualSIM = "No" != data; } else if (key == "Expandable memory") { ExpandableMemory = "No" != data; } else if (key == "Face Id") { FaceId = "Yes" == data; } else if (key == "GPS / Wifi") { GPS = "Yes" == data; WiFi = "Yes" == data; } else if (key == "HD Voice") { HDVoice = "Yes" == data; } else if (key == "Resolution") // Screen resolution { string[] tokens = data.Split(' '); bool xCoordinateValid, yCoordinateValid; if (tokens.Length >= 3) { xCoordinateValid = int.TryParse(tokens[0], out xRes); yCoordinateValid = int.TryParse(tokens[2], out yRes); if (xCoordinateValid && yCoordinateValid && (tokens[1].ToLower() == "x")) { DisplayResolution = new double[] { xRes, yRes } } ; } } else if (key == "Memory / Storage (GB)") { int index; if ((index = data.IndexOf("MB")) != -1) { if (int.TryParse(data.Substring(0, index), out megs)) { MemoryMB = megs; } } else if (int.TryParse(data, out gigs)) { MemoryMB = 1024 * gigs; } } else if (key == "OS") { OS = data; } else if (key.StartsWith("Screen size ")) { if (double.TryParse(data, out res)) { ScreenSize = res; } } else if (key.StartsWith("Secondary Camera")) { if (double.TryParse(data, out res)) { SecondaryCamera = res; } else { SecondaryCamera = 0; } } else if (key.StartsWith("Dimensions")) // We expect it in the form a x b x c { string[] tokens = data.ToLower().Split('x'), tokens2; if (tokens.Length >= 3) { for (int i = 0; i < 3; ++i) { tokens2 = tokens[i].Split('.'); if (tokens2.Length >= 3) { tokens[i] = tokens2[0] + "." + tokens2[1]; } if (double.TryParse(tokens[i], out res)) { BodySize[i] = res; } else { BodySize[i] = 1000; } } } } else if (key.Equals("Water resistance")) { WaterResist = (data.ToLower() == "yes"); } else if (key.StartsWith("Weight")) { if (double.TryParse(data, out weight)) { Weight = weight; } } else if (key.Equals("Type")) { IsSmartphone = ("Smartphone" == data); } else if (key.Equals("MadCalm-Picture")) { MadCalmPicUrl = data; } else if (key == "Picture URL") { PhonePictureUrl = data; } else if (key == "Detailed Feature URL") { SpecsUrl = data; } else if (key == "Reviews URL") { Uri uri; if (Uri.TryCreate(data, UriKind.Absolute, out uri) && ((uri.Scheme == Uri.UriSchemeHttp) || (uri.Scheme == Uri.UriSchemeHttps))) { ReviewsUrl = data; } else { ReviewsUrl = null; } } else if (key == "RAM (GB)") { if (double.TryParse(data, out res)) { RamSize = res; } else { RamSize = 0; } } else if (key == "N Sales") { if (int.TryParse(data, out generic)) { SalesNumber = generic; } else { SalesNumber = 0; } } } } HandSetFeatures() { ReleaseDate = new DateTime(2017, 1, 1); BatteryLife = 0; Camera = 0; Price = new Dictionary <string, double>(); DisplayResolution = new double[] { 2, 2 }; MemoryMB = 1; // Just one MB ScreenSize = 1; // Just one inch BodySize = new double[] { 1000, 1000, 1000 }; // one cubic meter Colors = new List <string>(); }
public MainForm() { this.InitializeComponent(); SettingsPage.Text = ServiceLocator.LanguageCatalog.GetString("Settings"); var f = new Panel(); f.BorderStyle = BorderStyle.FixedSingle; f.Visible = true; var undoBtn = new RadButtonElement(); undoBtn.Image = Resources.Undo_icon; undoBtn.Name = "undoBtn"; undoBtn.ShowBorder = false; undoBtn.Enabled = false; undoBtn.Click += (s, e) => UndoRedoManager.Undo(); var redoBtn = new RadButtonElement(); redoBtn.Image = Resources.Redo_icon; redoBtn.Name = "redoBtn"; redoBtn.ShowBorder = false; redoBtn.Enabled = false; redoBtn.Click += (s, e) => UndoRedoManager.Redo(); UndoRedoManager.CommandDone += (s, e) => { undoBtn.Enabled = UndoRedoManager.CanUndo; redoBtn.Enabled = UndoRedoManager.CanRedo; }; this.FormElement.TitleBar.SystemButtons.Children.Insert(0, undoBtn); this.FormElement.TitleBar.SystemButtons.Children.Insert(1, redoBtn); this.host = DesignerHost.CreateHost(f, null, (sender, e) => { this.propertyGrid.SelectedObject = sender; }, false); this.host.AddControl(new Button()); this.radPanel1.Controls.Add(this.host); this.ProductsView.Groups.Clear(); Price.PriceChanged += (s, e) => { this.priceLbl.DigitText = Price.Value; this.historyView1.Invalidate(); }; this.productsView1.DataSource = DbContext.ProductCollection; this.productsView1.BestFitColumns(); foreach (var pc in DbContext.ProductCategoryCollection.FindAll()) { var tmp = new TileGroupElement() { Name = pc.Name, Visibility = Telerik.WinControls.ElementVisibility.Visible, Text = pc.Name, Tag = pc.id }; foreach (var p in DbContext.ProductCollection.FindAll()) { var tmpItem = new RadTileElement() { Text = p.ID, Image = Image.FromStream(new MemoryStream(p.Image)), Name = p.ID, Tag = p.TotalPrice, Visibility = Telerik.WinControls.ElementVisibility.Visible }; tmpItem.Click += (s, e) => { Price.Add(p); ServiceLocator.ProductHistory.Add(p); }; tmp.Items.Add(tmpItem); } this.ProductsView.Groups.Add(tmp); } #if DEBUG Cursor.Show(); #else Cursor.Hide(); #endif PluginLoader.AddObject("ui", new UiClass(this)); PluginLoader.AddObject("import", new Action <string>(c => { var ass = Assembly.LoadFile(c); foreach (var t in ass.GetTypes()) { PluginLoader.AddType(t.Name, t); } })); }