/// <summary> /// Initializes a new <see cref="RateReminder"/> instance. /// </summary> public RateReminder() { // Defaults TryReminderOnLoad = true; // Create helper rateHelper = new RateHelper(); // Subscribe to events rateHelper.TryReminderCompleted += rateHelper_TryReminderCompleted; this.Loaded += Control_Loaded; }
public ResampleAudioSampleProvider(IAudioSampleProvider source, int newSampleRate) { _outFormat = new AudioFormat(newSampleRate, 2, 16); _converter = RateHelper.MakeRateConverter(source.AudioFormat.SampleRate, newSampleRate, source.AudioFormat.Channels == 2, false); _stream = new AudioSampleProviderToAudioStream(source); }
private void addSwaps(YieldCurveSegment segment, RateHelper instruments) { }
public void Test_With_Correct_RateType_3_Nights() { var result = RateHelper.Calculate("PerNight", 3, 200); Assert.Equal <double>(600, result); }
public CheckResult Check(IUnitOfWork db, long orderId, IList <ListingOrderDTO> orderItems, IList <OrderShippingInfoDTO> shippings, DTOMarketOrder marketOrder) { if (!orderItems.Any() || !shippings.Any()) { return new CheckResult() { IsSuccess = false } } ; if (marketOrder.UpgradeLevel > 0) { return new CheckResult() { IsSuccess = false } } ; if (marketOrder.Market == (int)MarketType.Groupon) { return new CheckResult() { IsSuccess = false } } ; CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); culture.NumberFormat.CurrencyNegativePattern = 1; decimal paidShppingCost = orderItems.Sum(i => i.ShippingPrice); string currency = orderItems.First().ShippingPriceCurrency; paidShppingCost = PriceHelper.RougeConvertToUSD(currency, paidShppingCost); if (marketOrder.OrderType == (int)OrderTypeEnum.Prime) { paidShppingCost += orderItems.Sum(oi => AmazonPrimeHelper.GetShippingAmount(oi.Weight)); } decimal?actualShippingsCost = null; if (shippings != null && shippings.Any(sh => sh.IsActive)) { actualShippingsCost = shippings.Where(sh => sh.IsActive && sh.ShippingMethodId != ShippingUtils.FedexSmartPost).Sum(sh => sh.StampsShippingCost ?? 0); } _log.Info("CheckIsExceededShippingCost: paid=" + paidShppingCost + " < actual=" + actualShippingsCost); if (shippings != null) { //"Excessive shipping cost. Because priority flat went up I get lots of “excesive” in cases like. We need to ignore those cases…" var activeShipping = shippings.FirstOrDefault(sh => sh.IsActive); if (activeShipping != null && activeShipping.ShippingMethod != null && activeShipping.ShippingMethod.Id == ShippingUtils.PriorityFlatShippingMethodId) { return new CheckResult() { IsSuccess = false } } ; } #region New Checking //price/1.17-shipping price-product cost-2 > -exc if (actualShippingsCost != null) { decimal totalThreashold = 0; decimal totalCost = 0; bool allHaveCost = true; foreach (var item in orderItems) { decimal?styleThreashold = null; if (item.StyleId.HasValue) { var featureValue = db.StyleFeatureTextValues.GetFeatureValueByStyleIdByFeatureId( item.StyleId.Value, StyleFeatureHelper.EXCESSIVE_SHIPMENT); if (featureValue != null && !String.IsNullOrEmpty(featureValue.Value)) { styleThreashold = StringHelper.TryGetDecimal(featureValue.Value); } var cost = db.StyleItemCaches.GetAllAsDto().Select(i => new { i.Id, i.Cost }).FirstOrDefault(i => i.Id == item.StyleItemId)?.Cost; if (cost.HasValue) { totalCost += cost.Value * item.QuantityOrdered; } else { allHaveCost = false; } } if (styleThreashold.HasValue) { totalThreashold += styleThreashold.Value * item.QuantityOrdered; } } if (allHaveCost) { var totalPaid = PriceHelper.RougeConvertToUSD(currency, orderItems.Sum(i => i.ShippingPrice + i.ItemPrice)); //Please ignore income disparity<1 like 180-111-825-1659 / 381-205-041-7263 if (totalThreashold < 1) { totalThreashold = 1; } var isValid = totalPaid / 1.17M - actualShippingsCost - totalCost - 2 > -totalThreashold; if (!isValid) { var excpectIncome = totalPaid / 1.17M - actualShippingsCost.Value - totalCost - 2; _log.Info(String.Format("Added Income disparity, income: {0}, totalPaid: {1}, actualShippingCost: {2}, totalCost: {3}", excpectIncome.ToString("C", culture), totalPaid, actualShippingsCost, totalCost)); var message = String.Format("Income disparity, income: {0}", excpectIncome.ToString("C", culture)); db.OrderComments.Add(new OrderComment() { OrderId = orderId, Message = message, Type = (int)CommentType.System, CreateDate = _time.GetAppNowTime(), }); db.Commit(); return(new CheckResult() { IsSuccess = true }); } } } #endregion #region Old Checking //TASK: When order has 2 robes, and they sent as 2 First class (like 102-1792536-3635439) don’t show Excess ship. cost if (shippings.Where(sh => sh.IsActive).All(sh => sh.ShippingMethodId == ShippingUtils.AmazonFirstClassShippingMethodId || sh.ShippingMethodId == ShippingUtils.FirstClassShippingMethodId || sh.ShippingMethodId == ShippingUtils.DhlEComSMParcelGroundShippingMethodId || sh.ShippingMethodId == ShippingUtils.DhlEComSMParcelExpeditedShippingMethodId)) { if (orderItems.All( i => ItemStyleHelper.GetFromItemStyleOrTitle(i.ItemStyle, i.Title) == ItemStyleType.Robe)) { return(new CheckResult() { IsSuccess = false }); } } //NOTE: used default threashold: $1 //NOTE: if price disparity <$2 it's ok var threshold = 2.0M; //TASK: When order has 2 or more items and service "Standard" made threashold $2 if (orderItems.Sum(oi => oi.QuantityOrdered) >= 2 && ShippingUtils.IsServiceStandard(marketOrder.InitialServiceType)) { threshold = 2.5M; } var withEmptyThreashold = 0; var withNotEmptyThreashold = 0; foreach (var item in orderItems) { decimal?styleThreashold = null; if (item.StyleId.HasValue) { var featureValue = db.StyleFeatureTextValues.GetFeatureValueByStyleIdByFeatureId( item.StyleId.Value, StyleFeatureHelper.EXCESSIVE_SHIPMENT); if (featureValue != null && !String.IsNullOrEmpty(featureValue.Value)) { styleThreashold = StringHelper.TryGetDecimal(featureValue.Value); } } if (styleThreashold.HasValue) { threshold += styleThreashold.Value * item.QuantityOrdered; withNotEmptyThreashold++; } else { withEmptyThreashold++; } } //if (withEmptyThreashold > 0) // threshold += 1.0M; //if (withNotEmptyThreashold == 0) // threshold = 1.0M; if (actualShippingsCost > 0 && paidShppingCost > 0 && paidShppingCost + threshold < actualShippingsCost) { bool isOverchargeSkipped = false; decimal totalIntlListingPriceInUSD = 0M; decimal totalUsListingPrice = 0; if (ShippingUtils.IsInternational(marketOrder.FinalShippingCountry)) { #region Calc US Shipping Cost decimal?actualUsShippingCost = 0M; var shippingService = ShippingUtils.StandardServiceName; //ShippingUtils.InitialShippingServiceIncludeUpgrade(marketOrder.InitialServiceType.Replace("i:", ""), //convert to local //marketOrder.UpgradeLevel); decimal?paidUsShippingCost = ShippingUtils.GetRougePaidUSShippingAmount(shippingService, orderItems.Sum(i => i.QuantityOrdered)); var usRates = RateHelper.GetRougeChipestUSRate(_log, _stampsRateProvider, _fromAddress, marketOrder, shippingService, orderItems, orderItems); if (usRates.Any()) { actualUsShippingCost = usRates.Sum(r => r.Amount); } #endregion foreach (var orderItem in orderItems) { totalIntlListingPriceInUSD += PriceHelper.RougeConvertToUSD(orderItem.ItemPriceCurrency, orderItem.ItemPrice); var usListingPrice = GetUSListingPrice(db, orderItem); if (usListingPrice == null) { totalUsListingPrice = 0; break; } totalUsListingPrice += (usListingPrice * orderItem.QuantityOrdered) ?? 0; } decimal?usEarnedValue = ((totalUsListingPrice) + (paidUsShippingCost ?? 0) - (actualUsShippingCost ?? 0)); decimal?marketEarnedValue = (totalIntlListingPriceInUSD + paidShppingCost - actualShippingsCost.Value); decimal?howMachEarnedValue = null; if (actualUsShippingCost.HasValue && paidUsShippingCost.HasValue && totalUsListingPrice > 0 && actualShippingsCost.HasValue) { howMachEarnedValue = (totalIntlListingPriceInUSD + paidShppingCost - actualShippingsCost.Value) - //how much we have earned now (totalUsListingPrice + paidUsShippingCost.Value - actualUsShippingCost.Value); //how much we have earned if we sell it in US isOverchargeSkipped = howMachEarnedValue > -threshold; //NOTE: Threashold } if (!isOverchargeSkipped) { //var message = internationalOverchargeSkip ? "No Excessive Shipping cost" : "Excessive Shipping cost"; var message = ""; if (totalUsListingPrice > 0) { message = String.Format("Income disparity: {0}+{1}-{2}={3} vs {4} => income diff.: {5}", //MarketHelper.GetShortName((int)marketOrder.Market, marketOrder.MarketplaceId), (totalUsListingPrice).ToString("C", culture), (paidUsShippingCost ?? 0).ToString("C", culture), (actualUsShippingCost ?? 0).ToString("C", culture), usEarnedValue?.ToString("C", culture), marketEarnedValue?.ToString("C", culture), (howMachEarnedValue ?? 0).ToString("C", culture)); } else { isOverchargeSkipped = true; //SKIP message = "Excessive Shipping validation: no similar US listing"; } db.OrderComments.Add(new OrderComment() { OrderId = orderId, Message = message, Type = (int)CommentType.System, CreateDate = _time.GetAppNowTime(), }); db.Commit(); } } else { //сделай пока $3.02 threashold var localThreshold = Math.Max(threshold, 3.02M); if (paidShppingCost + localThreshold < actualShippingsCost) { var message = String.Format("Paid shipping ({0}) lower shipping cost ({1}) more than threshold ({2})", (paidShppingCost).ToString("C", culture), (actualShippingsCost ?? 0).ToString("C", culture), (localThreshold).ToString("C", culture)); db.OrderComments.Add(new OrderComment() { OrderId = orderId, Message = message, Type = (int)CommentType.System, CreateDate = _time.GetAppNowTime(), }); } else { //NOTE: Temp Do Nothing isOverchargeSkipped = true; } } if (!isOverchargeSkipped) { db.OrderNotifies.Add( ComposeNotify(orderId, (int)OrderNotifyType.OverchargedShpppingCost, 1, paidShppingCost + "<" + actualShippingsCost, _time.GetAppNowTime())); db.Commit(); } if (!isOverchargeSkipped) { foreach (var orderItem in orderItems) { if (orderItem.SourceListingId.HasValue) { var listing = db.Listings.Get(orderItem.SourceListingId.Value); if (listing != null) { SystemActionHelper.RequestPriceRecalculation(db, _actionService, listing.Id, null); if (listing.Market == (int)MarketType.Walmart) //NOTE: need to update Second Day flag { SystemActionHelper.RequestItemUpdate(db, _actionService, listing.Id, null); } } } } } return(new CheckResult() { IsSuccess = !isOverchargeSkipped }); } #endregion return(new CheckResult() { IsSuccess = false }); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RateHelper obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }
public static CallResult <IList <SelectListShippingOption> > Apply(IUnitOfWork db, ILogService log, ITime time, IWeightService weightService, long orderId, IList <IShipmentApi> ratePrividers, AddressDTO returnAddress, AddressDTO pickupAddress, IList <CustomShippingItemViewModel> customShippingItems, bool isFulfilmentUser) { var order = db.Orders.GetById(orderId); var correctedInitialShippingType = ShippingUtils.CorrectInitialShippingService(order.InitialServiceType, order.SourceShippingService, (OrderTypeEnum)order.OrderType); var shippingService = ShippingUtils.InitialShippingServiceIncludeUpgrade(correctedInitialShippingType, order.UpgradeLevel); var shippingProviderType = (ShipmentProviderType)db.Orders.GetById(orderId).ShipmentProviderType; var rateProvider = ratePrividers.FirstOrDefault(p => p.Type == shippingProviderType); var oldShippings = db.OrderShippingInfos.GetByOrderId(orderId).ToList(); var previousNumberInBatch = oldShippings.FirstOrDefault(sh => sh.IsActive)?.NumberInBatch; var items = db.OrderItems.GetWithListingInfo() .Where(oi => oi.OrderId == orderId) .Select(oi => new ListingOrderDTO() { ItemOrderId = oi.ItemOrderId, OrderItemEntityId = oi.OrderItemEntityId, Weight = oi.Weight }).ToList(); if (items.Any(i => !i.Weight.HasValue || i.Weight == 0)) { return(CallResult <IList <SelectListShippingOption> > .Fail("No rates. Order has items w/o weight.", null)); } var packageDict = new Dictionary <string, PackageInfo>(); foreach (var shippingItem in customShippingItems.OrderBy(sh => sh.PackageValue).ToList()) { var packageValue = shippingItem.PackageValue; var orderItem = items.FirstOrDefault(oi => oi.OrderItemEntityId == shippingItem.OrderItemId); var package = packageDict.ContainsKey(packageValue) ? packageDict[packageValue] : null; if (package == null) { var shippingMethodId = int.Parse(shippingItem.PackageValue.Split('-')[0]); var dbShippingMethod = db.ShippingMethods.GetAll().FirstOrDefault(m => m.Id == shippingMethodId); package = new PackageInfo { Items = new List <OrderItemRateInfo>(), RequiredServiceIdentifier = dbShippingMethod.ServiceIdentifier, ServiceTypeUniversal = ShippingUtils.GetShippingType(shippingMethodId), PackageTypeUniversal = ShippingUtils.GetPackageType(shippingMethodId), GroupId = RateHelper.CustomPartialGroupId, }; packageDict[packageValue] = package; } package.Items.Add(new OrderItemRateInfo() { Quantity = 1, ItemOrderId = orderItem.ItemOrderId, Weight = orderItem.Weight ?? 0, }); } var packages = packageDict.Values; var addressTo = db.Orders.GetAddressInfo(order.Id); var shipDate = db.Dates.GetOrderShippingDate(null); var rates = new List <RateDTO>(); foreach (var package in packages) { package.Weight = weightService.AdjustWeight(package.Items.Sum(i => i.Weight * i.Quantity), package.Items.Sum(i => i.Quantity)); GetRateResult rateResult = null; log.Info("GetSpecificLocalRate, orderId=" + orderId); rateResult = rateProvider.GetAllRate(returnAddress, pickupAddress, addressTo, shipDate, package.Weight ?? 1, package.GetDimension(), order.IsInsured ? order.TotalPrice : 0, order.IsSignConfirmation, new OrderRateInfo() { OrderNumber = order.AmazonIdentifier, Items = package.Items, SourceItems = package.Items, EstimatedShipDate = ShippingUtils.AlignMarketDateByEstDayEnd(order.LatestShipDate, (MarketType)order.Market), ShippingService = shippingService, TotalPrice = order.TotalPrice, Currency = order.TotalPriceCurrency, }, RetryModeType.Random); if (rateResult.Result != GetRateResultType.Success) { return(CallResult <IList <SelectListShippingOption> > .Fail("Error when get rates for package, serviceType=" + package.ServiceTypeUniversal.ToString() + ", packageType=" + package.PackageTypeUniversal.ToString(), null)); } var rate = rateResult.Rates.FirstOrDefault(r => r.ServiceIdentifier == package.RequiredServiceIdentifier); if (rate == null) { return(CallResult <IList <SelectListShippingOption> > .Fail("Not rates for package, serviceType=" + package.ServiceTypeUniversal.ToString() + ", packageType=" + package.PackageTypeUniversal.ToString(), null)); } rate.GroupId = RateHelper.CustomPartialGroupId; RateHelper.GroupPackageItems(package); rate.ItemOrderIds = package.Items.Select(i => new RateItemDTO() { OrderItemId = i.ItemOrderId, Quantity = i.Quantity }).ToList(); rates.AddRange(new List <RateDTO>() { rate }); } foreach (var rate in rates) { rate.IsDefault = true; rate.IsVisible = true; if (previousNumberInBatch.HasValue) { rate.NumberInBatch = previousNumberInBatch; previousNumberInBatch = null; } } //save var newShippings = new List <OrderShippingInfo>(); var shippingMethodList = db.ShippingMethods.GetAllAsDto().ToList(); var lastShippingNumber = oldShippings.Any() ? oldShippings.Max(sh => sh.ShippingNumber) ?? 0 : 0; var shippingNumber = lastShippingNumber; foreach (var rate in rates) { log.Debug("store rate, service" + rate.ServiceTypeUniversal + ", package=" + rate.PackageTypeUniversal + ", cost=" + rate.Amount + ", defualt=" + rate.IsDefault + ", visible=" + rate.IsVisible + ", groupId=" + rate.GroupId + ", shipDate=" + rate.ShipDate + ", deliveryDate=" + rate.DeliveryDate + ", daysInfo=" + rate.DeliveryDaysInfo + ", items=" + (rate.ItemOrderIds != null ? String.Join(", ", rate.ItemOrderIds.Select(i => (i.OrderItemId.ToString() + "-" + i.Quantity.ToString())).ToList()) : "")); var currentRate = rate; shippingNumber++; var method = shippingMethodList.FirstOrDefault(m => m.ServiceIdentifier == currentRate.ServiceIdentifier); if (method != null) { currentRate.DeliveryDays = time.GetBizDaysCount(currentRate.ShipDate, currentRate.DeliveryDate); var shippingInfo = db.OrderShippingInfos.CreateShippingInfo(currentRate, orderId, shippingNumber, method.Id); newShippings.Add(shippingInfo); if (currentRate.ItemOrderIds != null && currentRate.ItemOrderIds.Any()) { log.Debug("store partial, items=" + String.Join(", ", currentRate.ItemOrderIds.Select( i => (i.OrderItemId.ToString() + "-" + i.Quantity.ToString())).ToList())); db.ItemOrderMappings.StorePartialShippingItemMappings(shippingInfo.Id, currentRate.ItemOrderIds, items, time.GetAppNowTime()); } else { db.ItemOrderMappings.StoreShippingItemMappings(shippingInfo.Id, items, time.GetAppNowTime()); } } } foreach (var oldShipping in oldShippings) { if (oldShipping.ShippingGroupId == RateHelper.CustomPartialGroupId) { db.OrderShippingInfos.Remove(oldShipping); } else { oldShipping.IsActive = false; } } order.ShippingCalculationStatus = (int)ShippingCalculationStatusEnum.FullCalculation; db.Commit(); //Return actual values var allShippings = db.OrderShippingInfos.GetByOrderIdAsDto(orderId); var results = OrderViewModel.GetShippingOptions(allShippings, (MarketType)order.Market, order.IsSignConfirmation, order.IsInsured, isFulfilmentUser, showOptionsPrices: true, showProviderName: false); return(CallResult <IList <SelectListShippingOption> > .Success(results)); }
public void FillIBCRateTable() { using (var db = _dbFactory.GetRWDb()) { var newRateTable = new List <RateByCountryDTO>(); var addressList = new List <AddressDTO>() { //RateHelper.GetSampleUSAddress(), RateHelper.GetSampleCAAddress(), RateHelper.GetSampleUKAddress() }; var serviceFactory = new ServiceFactory(); var rateProviders = serviceFactory.GetShipmentProviders(_log, _time, _dbFactory, _weightService, _company.ShipmentProviderInfoList, null, null, null, null); var stampsRateProvider = rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.IBC); var companyAddress = new CompanyAddressService(_company); var shippingSizes = new string[] { //"S", "XL" }; var internationalPackages = new string[] { "", "" }; for (var oz = 1; oz < 50; oz++) { //International Package Type: Regular, Flat //Shipping Size: S, XL foreach (var address in addressList) { foreach (var shippingSize in shippingSizes) { var packageType = shippingSize == "XL" ? PackageTypeCode.Regular : (ShippingUtils.IsInternational(address.Country) ? PackageTypeCode.LargeEnvelopeOrFlat : PackageTypeCode.Flat); var shippintType = ShippingUtils.IsInternational(address.Country) ? ShippingTypeCode.IStandard : ShippingTypeCode.Standard; var rate = RateHelper.GetRougeChipestRate(_log, stampsRateProvider, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), address, oz, DateTime.Today, shippintType, packageType); if (rate != null && rate.Amount.HasValue) { _log.Info("Add rate: " + address.Country + ", " + oz + "oz, " + shippingSize + ", " + rate.Amount.Value + ", package=" + ((PackageTypeCode)rate.PackageTypeUniversal).ToString() + ", shippingType=" + ((ShippingTypeCode)rate.ServiceTypeUniversal).ToString()); newRateTable.Add(new RateByCountryDTO() { Cost = rate.Amount.Value, Country = address.Country, Weight = oz, PackageType = packageType.ToString(), //NOTE: need to use source package type, no matter what actual package is ((PackageTypeCode) rate.PackageTypeUniversal).ToString(), ShipmentProvider = stampsRateProvider.Type.ToString(), UpdateDate = _time.GetAppNowTime() }); } else { _log.Info("No rates: " + oz + "oz, " + shippingSize); } } } } var existRates = db.RateByCountries.GetAll(); foreach (var rate in newRateTable) { var exist = existRates.FirstOrDefault(r => r.Country == rate.Country && r.PackageType == rate.PackageType && r.Weight == rate.Weight); if (exist == null) { db.RateByCountries.Add(new RateByCountry() { Country = rate.Country, PackageType = rate.PackageType, Cost = rate.Cost, Weight = rate.Weight, ShipmentProvider = rate.ShipmentProvider, UpdateDate = rate.UpdateDate, }); } else { exist.Cost = rate.Cost; exist.ShipmentProvider = rate.ShipmentProvider; } } db.Commit(); } }
private void addCrossCcyBasisSwaps(YieldCurveSegment segment, RateHelper instruments) { }
public BootstrapError(PiecewiseYieldCurve curve, RateHelper helper, int segment) { _curve = curve; _helper = helper; _segment = segment; }
private void addFXForwards(YieldCurveSegment segment, RateHelper instruments) { }
private void addTenorBasisTwoSwaps(YieldCurveSegment segment, RateHelper instruments) { }
private void addAverageOISs(YieldCurveSegment segment, RateHelper instruments) { }
void do_mix(short[] data, int len) { int i; int dpos = 0; uint dlen; Array.Clear(data, 0, data.Length); while (len != 0) { if (_playproc != null) { dlen = _mixamt - _mixpos; if (_mixpos == 0) { _playproc(); } if (dlen <= len) { _mixpos = 0; len -= (int)dlen; } else { _mixpos = (uint)len; dlen = (uint)len; len = 0; } } else { dlen = (uint)len; len = 0; } for (i = 0; i < MOD_MAXCHANS; i++) { if (_channels[i].id != 0) { ushort vol_l = (ushort)((127 - _channels[i].pan) * _channels[i].vol / 127); ushort vol_r = (ushort)((127 + _channels[i].pan) * _channels[i].vol / 127); for (uint j = 0; j < dlen; j++) { // simple linear resample, unbuffered int delta = ((_channels[i].freq * 0x10000) / _sampleRate); ushort cfrac = (ushort)(~_channels[i].ctr & 0xFFFF); if (_channels[i].ctr + delta < 0x10000) { cfrac = (ushort)delta; } _channels[i].ctr += (uint)delta; int cpos = _channels[i].pos * cfrac / 0x10000; while (_channels[i].ctr >= 0x10000) { var sample = new short[1]; if (_channels[i].input.ReadBuffer(sample, 1) != 1) { // out of data StopChannel(_channels[i].id); goto skipchan; // exit 2 loops at once } _channels[i].pos = sample[0]; _channels[i].ctr -= 0x10000; if (_channels[i].ctr > 0x10000) { cpos += _channels[i].pos; } else { cpos += (int)(_channels[i].pos * (_channels[i].ctr & 0xFFFF)) / 0x10000; } } long pos = 0; // if too many samples play in a row, the calculation below will overflow and clip // so try and split it up into pieces it can manage comfortably while (cpos < -0x8000) { pos -= 0x80000000 / delta; cpos += 0x8000; } while (cpos > 0x7FFF) { pos += 0x7FFF0000 / delta; cpos -= 0x7FFF; } pos += cpos * 0x10000 / delta; RateHelper.ClampedAdd(ref data[(dpos + j) * 2 + 0], (int)(pos * vol_l / Mixer.MaxMixerVolume)); RateHelper.ClampedAdd(ref data[(dpos + j) * 2 + 1], (int)(pos * vol_r / Mixer.MaxMixerVolume)); } } skipchan: ; // channel ran out of data } dpos += (int)dlen; } }
public IActionResult Index() { ViewBag.Rate = RateHelper.GetStandardLaborRate(); return(View()); }
public BootstrapError(PiecewiseYieldCurve curve, RateHelper helper, int segment) { curve_ = curve; helper_ = helper; segment_ = segment; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RateHelper obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public static SwapRateHelper as_swapratehelper(RateHelper helper) { SwapRateHelper ret = new SwapRateHelper(NQuantLibcPINVOKE.as_swapratehelper(RateHelper.getCPtr(helper)), true); if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public MenuViewModel() { RateWebCommand = new Command(() => Device.OpenUri(new Uri(RateHelper.GetRateUrl()))); }
//public static void UpdateSalePrices(IUnitOfWork db, // long styleItemId, // long saleId, // decimal newSalePrice, // decimal? newSFPSalePrice) //{ // var rateForMarketplace = RateHelper.GetRatesByStyleItemId(db, styleItemId); // var marketPrices = db.StyleItemSaleToMarkets.GetAll().Where(s => s.SaleId == saleId).ToList(); // foreach (var marketPrice in marketPrices) // { // if (marketPrice.SalePrice.HasValue) // { // var marketListings = db.StyleItemSaleToListings.GetAll().Where(l => l.SaleToMarketId == ) // marketPrice.SalePrice = RateHelper.CalculateForMarket((MarketType) marketPrice.Market, // marketPrice.MarketplaceId, // newSalePrice, // rateForMarketplace[MarketplaceKeeper.AmazonComMarketplaceId], // rateForMarketplace[MarketplaceKeeper.AmazonCaMarketplaceId], // rateForMarketplace[MarketplaceKeeper.AmazonUkMarketplaceId], // rateForMarketplace[MarketplaceKeeper.AmazonAuMarketplaceId], // RateService.GetMarketShippingAmount(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId), // RateService.GetMarketShippingAmount((MarketType)marketPrice.Market, marketPrice.MarketplaceId), // RateService.GetMarketExtraAmount((MarketType)marketPrice.Market, marketPrice.MarketplaceId)); // } // } // db.Commit(); //} public static IList <MarketPriceEditViewModel> GetForStyleItemId(IUnitOfWork db, IDbFactory dbFactory, long styleItemId, decimal?initSalePrice, decimal?initSFPSalePrice) { var priceService = new PriceService(dbFactory); var results = new List <MarketPriceEditViewModel>(); var allMarketplaces = UIMarketHelper.GetSalesMarketplaces(); var allListings = db.Listings.GetListingsAsListingDto() .Where(l => l.StyleItemId == styleItemId) .ToList() .Where(l => !l.IsFBA) .ToList(); var rateForMarketplace = RateHelper.GetRatesByStyleItemId(db, styleItemId); var sale = db.StyleItemSales.GetAllAsDto().FirstOrDefault(s => s.StyleItemId == styleItemId && !s.IsDeleted); var checkedListings = new List <StyleItemSaleToListingDTO>(); if (sale != null) { checkedListings = db.StyleItemSaleToListings.GetAllAsDto().Where(s => s.SaleId == sale.Id).ToList(); } var checkedMarkets = new List <StyleItemSaleToMarketDTO>(); if (sale != null) { checkedMarkets = db.StyleItemSaleToMarkets.GetAllAsDto().Where(s => s.SaleId == sale.Id).ToList(); } foreach (var market in allMarketplaces) { var checkedMarket = checkedMarkets.FirstOrDefault(l => l.Market == (int)market.Market && (l.MarketplaceId == market.MarketplaceId || String.IsNullOrEmpty(market.MarketplaceId))); var marketListings = allListings .Where(l => l.Market == (int)market.Market && (l.MarketplaceId == market.MarketplaceId || String.IsNullOrEmpty(market.MarketplaceId))) .Select(l => new ListingPriceEditViewModel(l)) .ToList(); foreach (var listing in marketListings) { listing.IsChecked = sale == null ? ((listing.IsPrime || SkuHelper.IsPrime(listing.SKU)) ? initSFPSalePrice.HasValue : initSalePrice.HasValue) : checkedListings.Any(l => l.ListingId == listing.ListingId); } var defaultPrice = //sale == null && initSalePrice.HasValue && marketListings.Any() ? priceService.GetMarketDefaultPrice(initSalePrice.Value, market.Market, market.MarketplaceId, rateForMarketplace) : (decimal?)null; foreach (var marketListing in marketListings) { var newDefaultPrice = priceService.ApplyMarketSpecified(defaultPrice, initSFPSalePrice, market.Market, market.MarketplaceId, marketListing.Weight, marketListing.IsPrime, marketListing.IsFBA); if (newDefaultPrice != defaultPrice) { marketListing.OverrideSalePrice = newDefaultPrice; } } var saleToMarket = new MarketPriceEditViewModel() { Id = checkedMarket != null ? checkedMarket.Id : 0, Market = (MarketType)market.Market, MarketplaceId = market.MarketplaceId, MarketName = MarketHelper.GetMarketName((int)market.Market, market.MarketplaceId), MarketCurrency = PriceHelper.GetCurrencySymbol(market.Market, market.MarketplaceId), SalePrice = checkedMarket != null ? checkedMarket.SalePrice : defaultPrice, SFPSalePrice = market.MarketplaceId == MarketplaceKeeper.AmazonComMarketplaceId ? initSFPSalePrice : null, SalePercent = checkedMarket != null ? checkedMarket.SalePercent : null, ApplyToNewListings = checkedMarket != null ? checkedMarket.ApplyToNewListings : false, Listings = marketListings }; results.Add(saleToMarket); } return(results); }
public void StartMusic(int tuneId, int loopFlag) { if (!string.IsNullOrEmpty(_tuneList[tuneId])) { int newStream = 0; lock (_gate) { if (_handles[0].IsStreaming && _handles[1].IsStreaming) { int streamToStop; // Both streams playing - one must be forced to stop. if (_handles[0].Fading == 0 && _handles[1].Fading == 0) { // None of them are fading. Shouldn't happen, // so it doesn't matter which one we pick. streamToStop = 0; } else if (_handles[0].Fading != 0 && _handles[1].Fading == 0) { // Stream 0 is fading, so pick that one. streamToStop = 0; } else if (_handles[0].Fading == 0 && _handles[1].Fading != 0) { // Stream 1 is fading, so pick that one. streamToStop = 1; } else { // Both streams are fading. Pick the one that // is closest to silent. if (Math.Abs(_handles[0].Fading) < Math.Abs(_handles[1].Fading)) { streamToStop = 0; } else { streamToStop = 1; } } _handles[streamToStop].Stop(); } if (_handles[0].IsStreaming) { _handles[0].FadeDown(); newStream = 1; } else if (_handles[1].IsStreaming) { _handles[1].FadeDown(); newStream = 0; } _converter[newStream] = null; } /* The handle will load the music file now. It can take a while, so unlock * the mutex before, to have the soundthread playing normally. * As the corresponding _converter is NULL, the handle will be ignored by the playing thread */ if (SystemVars.Platform == Core.IO.Platform.PSX) { if (_handles[newStream].PlayPsx((ushort)tuneId, loopFlag != 0)) { lock (_gate) { _converter[newStream] = RateHelper.MakeRateConverter(_handles[newStream].Rate, _mixer.OutputRate, _handles[newStream].IsStereo, false); } } } else if (_handles[newStream].Play(_tuneList[tuneId], loopFlag != 0)) { lock (_gate) { _converter[newStream] = RateHelper.MakeRateConverter(_handles[newStream].Rate, _mixer.OutputRate, _handles[newStream].IsStereo, false); } } else { // TODO: //if (tuneId != 81) // file 81 was apparently removed from BS. // warning("Can't find music file %s", _tuneList[tuneId]); } } else { lock (_gate) { if (_handles[0].IsStreaming) { _handles[0].FadeDown(); } if (_handles[1].IsStreaming) { _handles[1].FadeDown(); } } } }
public static void CopyToMarketplaces(IUnitOfWork db, ICacheService cache, IBarcodeService barcodeService, ISystemActionService actionService, IAutoCreateListingService autoCreateListingService, IItemHistoryService itemHistoryService, int id, DateTime when, long?by, IList <ItemMarketViewModel> toMarketplaces, out IList <MessageString> messages) { var parent = db.ParentItems.GetAsDTO(id); messages = new List <MessageString>(); foreach (var toMarketplace in toMarketplaces) { var model = ItemEditViewModel.CreateFromParentASIN(db, autoCreateListingService, parent.ASIN, parent.Market, parent.MarketplaceId, false, //NOTE: false - ex.: exclude to copy FBP to Walmart out messages); model.Id = null; model.Market = toMarketplace.Market; model.MarketplaceId = toMarketplace.MarketplaceId; //model.OnHold = true; var parentBaseASIN = SkuHelper.RemoveSKULastIndex(model.ASIN); var parentIndex = 0; while (db.ParentItems.GetAsDTO(parentBaseASIN + ((parentIndex == 0) ? "" : "-" + parentIndex), (MarketType)toMarketplace.Market, toMarketplace.MarketplaceId) != null) { parentIndex++; } var parentSKU = parentBaseASIN + ((parentIndex == 0) ? "" : "-" + parentIndex); var forceReplace = model.VariationList.Any(s => (s.Size ?? "").Contains("/")); model.ASIN = parentSKU; foreach (var item in model.VariationList) { item.Id = null; if (model.Market == (int)MarketType.Walmart || model.Market == (int)MarketType.WalmartCA) { item.Barcode = null; item.AutoGeneratedBarcode = true; } if (item.StyleItemId.HasValue) { var sourceUSDPrice = item.Price; var fromCurrency = PriceHelper.GetCurrencyAbbr((MarketType)parent.Market, parent.MarketplaceId); if (fromCurrency != PriceHelper.USDSymbol) { sourceUSDPrice = PriceHelper.ConvertToUSD(item.Price, fromCurrency); } var rateForMarketplace = RateHelper.GetRatesByStyleItemId(db, item.StyleItemId.Value); var newPrice = RateHelper.CalculateForMarket((MarketType)toMarketplace.Market, toMarketplace.MarketplaceId, sourceUSDPrice, rateForMarketplace[MarketplaceKeeper.AmazonComMarketplaceId], rateForMarketplace[MarketplaceKeeper.AmazonCaMarketplaceId], rateForMarketplace[MarketplaceKeeper.AmazonUkMarketplaceId], rateForMarketplace[MarketplaceKeeper.AmazonAuMarketplaceId], RateService.GetMarketShippingAmount(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId), RateService.GetMarketShippingAmount((MarketType)toMarketplace.Market, toMarketplace.MarketplaceId), RateService.GetMarketExtraAmount((MarketType)toMarketplace.Market, toMarketplace.MarketplaceId)); if (newPrice.HasValue) { item.Price = newPrice.Value; } } if (db.Listings.CheckForExistenceSKU(item.SKU, (MarketType)toMarketplace.Market, toMarketplace.MarketplaceId)) { var baseSKU = item.StyleString + "-" + SizeHelper.PrepareSizeForSKU(item.StyleSize, forceReplace); var index = parentIndex; while (db.Listings.CheckForExistenceSKU(SkuHelper.SetSKUMiddleIndex(baseSKU, index), (MarketType)toMarketplace.Market, toMarketplace.MarketplaceId)) { index++; } item.SKU = SkuHelper.SetSKUMiddleIndex(baseSKU, index); } } model.Save(db, cache, barcodeService, actionService, itemHistoryService, when, by); } }
public void Test_With_False_RateType_And_4_Nights() { var result = RateHelper.Calculate("FalseRateTYPE", 4, 200); Assert.Equal <double>(200, result); }
public void Test_With_Correct_RateType_With_Different_Camelcase() { var result = RateHelper.Calculate("PERNight", 3, 200); Assert.Equal <double>(600, result); }
private void addFutures(YieldCurveSegment segment, RateHelper instruments) { }