예제 #1
0
        public int MilesChargedInTimeSpan(ChargerBase charger, int soc, TimeSpan duration, int?ratedWhMiles = null)
        {
            if (ratedWhMiles != null && ratedWhMiles <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(ratedWhMiles), "rated consumption must be greater than 0");
            }

            int rwhMiles = ratedWhMiles ?? RatedWhMile;

            if (soc < 0 || soc > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(soc));
            }

            if (!ChargingCurves.ContainsKey(charger.CurrentType))
            {
                throw new ArgumentException("this type of current is not compatible", nameof(charger));
            }

            ChargingCurve curve        = ChargingCurves[charger.CurrentType];
            int           totalSeconds = 0;
            decimal       totalKwh     = 0m;
            decimal       kwhPct       = BatteryCapacity / 100m;

            for (int i = soc; i < 100; i++)
            {
                decimal maxPower = curve.GetMaxChargeRateForSOC(i);
                if (maxPower > charger.MaxPower)
                {
                    maxPower = charger.MaxPower;
                }

                int secondsToCharge = (int)(kwhPct / maxPower * HourInSeconds);
                if (totalSeconds + secondsToCharge > duration.TotalSeconds)
                {
                    break;
                }

                totalKwh     += kwhPct;
                totalSeconds += secondsToCharge;
            }

            return((int)(totalKwh / (rwhMiles / 1000m)));
        }