Azure 使用率按比例定价

Azure Usage Scaled Rates Pricing

我尝试计算已调整费率的 meterID 的价格。我用这个 作为算法的指南( public static double computeRatedUsagePerMeter(Dictionary rates, double usage) ) https://github.com/PartnerCenterSamples/Commerce-API-DotNet/blob/master/Usage.cs

与 azure 定价计算器的价格相比,如果我在计算器中询问数量 X 的价格,它等于我通过上述方法计算的价格,但数量 X - 1。

所以我很困惑微软提供的方法是否完整,或者只是一个正确方向的提示。


 private static decimal computeRatedUsagePerMeter(Dictionary<decimal, decimal> rates, decimal usage)
        {
            decimal total = Decimal.Zero;

            if (rates.Count == 0)
                return Decimal.Zero;
            else if (rates.Count == 1)
                return (usage * rates.Values.FirstOrDefault());

            var remainingUsage = usage;

            while (rates.Count > 0)
            {
                decimal LastKey = rates.Keys.Last();

                if (remainingUsage > LastKey)
                {
                    decimal LastKeyValue = Decimal.Zero;
                    if (rates.TryGetValue(LastKey, out LastKeyValue))
                    {
                        total = total + ((remainingUsage - LastKey + 1) * LastKeyValue); // remainingUsage - LastKey +1  because tiered pricing is exclusive
                        remainingUsage = LastKey - 1;
                    }
                    rates.Remove(LastKey);
                }
                else if (remainingUsage <= LastKey)
                {
                    rates.Remove(LastKey);
                }
            }
            return total;
        }

{
      "MeterId": "d23a5753-ff85-4ddf-af28-8cc5cf2d3882",
      "MeterName": "Standard IO - Page Blob/Disk (GB)",
      "MeterCategory": "Storage",
      "MeterSubCategory": "Locally Redundant",
      "Unit": "GB",
      "MeterTags": [],
      "MeterRegion": "",
      "MeterRates": {
        "0": 0.042165,
        "1024": 0.0421650,
        "51200": 0.0421650,
        "512000": 0.0421650,
        "1024000": 0.0379485,
        "5120000": 0.0312021
      },
      "EffectiveDate": "2014-02-01T00:00:00Z",
      "IncludedQuantity": 0.0
    }

根据上面 link 提供的方法,数量 1 的价格 = 0.084330 而 azure 定价计算器给出 0.04 (价格以欧元为单位)

另一个例子:假设数量为 100。

方法:4.258665 欧元

Azure 计算器 = 4.22 欧元

99 数量的方法 = 4.216500,四舍五入为 4.22 欧元。 也无法检查价格 < 1.00 让我们说 0.5 数量(在这种情况下,它以 GB 为单位,所以 0.5 GB 是完全合理的数量)因为定价计算器不允许小数。

According to the method provided by the link above the price for quantity 1 = 0.084330 while azure pricing calculator gives 0.04 ( the prices are in EUR )

查看上面的代码,我认为代码本身存在问题。本质上,您正在尝试找到 1 GB 存储的价格,该价格将落在 0 - 1023 范围内,或者换句话说,LastKey 的值是 0。所以当下面的代码执行时:

total = total + ((remainingUsage - LastKey + 1) * LastKeyValue);

它总共给你 0.084330 (0 + (1 - 0 + 1) * 0.042165).

Also cannot check the prices < 1.00 lets say 0.5 quantity ( in this case its measured in GB so 0,5 GB is perfectly reasonable quantity ) cause pricing calculator doesn't allow decimal.

我相信 Microsoft 的某个人会就他们设计计算器的原因提供正确的答案。