/// <summary>
        /// Returns -1 no conflict, Return 0 ignore first Return 1 ignore 2nd
        /// </summary>
        private static int IsConflictOrOverLap(ICongestionRate cp1, ICongestionRate cp2, Day day, VehicleType type)
        {
            var cr1DateRange = new DateRange(cp1.Start, cp1.End);
            var cr2DateRange = new DateRange(cp2.Start, cp2.End);

            var intersect = DateTimeIntersect.FindIntersect(cr1DateRange, cr2DateRange);

            if (intersect == null) return -1;

            return SelectTheMoreSpecific(cp1, cp2, day, type);
        }
        private static int SelectTheMoreSpecific(ICongestionRate cp1, ICongestionRate cp2, Day day, VehicleType type)
        {
            //Check Vehicle
            if (cp1.Vehicle == type) return 1;
            if (cp2.Vehicle == type) return 0;

            //Check Day of the week
            if (cp1.Day == day) return 1;
            if (cp2.Day == day) return 0;

            //OtherWise ignore the 2nd
            return 1;
        }
Esempio n. 3
0
        private static ChargeSummary BuildSummary(DateTime start, DateTime end, ICongestionRate rate)
        {
            decimal charge = 0m;
            var time = new TimeSpan(0,0,0,0);
            var intersectingTime = GetIntersectingTime(start, end, rate);

            if (intersectingTime != null)
            {
               time = intersectingTime.End - intersectingTime.Start;
                charge = CalculateRate(time, rate);
            }

            return new ChargeSummary
                {
                    Cost = charge,
                    TimeSpent = time,
                    RateDescription = rate.Description
                };
        }
Esempio n. 4
0
        private static decimal CalculateRate(TimeSpan chargeableTime, ICongestionRate rate)
        {
            decimal charge = 0m;

            if (chargeableTime.Days > 0)
            {
                charge += chargeableTime.Days * (rate.Rate * 24);
            }

            if (chargeableTime.Hours > 0)
            {
                charge += chargeableTime.Hours*rate.Rate;
            }

            if (chargeableTime.Minutes > 0)
            {
                var convert = (decimal) chargeableTime.Minutes/60;

                charge += convert * rate.Rate;
            }

            return charge;
        }
Esempio n. 5
0
 private static DateRange GetIntersectingTime(DateTime start, DateTime end, ICongestionRate rate)
 {
     var timeSpent = new DateRange(start, end);
     var congestionRateRange = new DateRange(AddDatePartToCongestionTime(start, rate.Start), AddDatePartToCongestionTime(start, rate.End, true));
     return DateTimeIntersect.FindIntersect(timeSpent, congestionRateRange);
 }