How to calculate parking rates for several days when rates are indicated daily?

I need to calculate the total amounts for cardholders, for card access to parking lots. My betting structure looks like this. Each zone in the parking lot will have a priority list of these prices.

public partial class HourlyPrice { public int Id { get; set; } public int DayId { get; set; } public DateTime StartTime { get; set; } public DateTime EndTime { get; set; } public int MinHour { get; set; } public int MaxHour { get; set; } public decimal Price { get; set; } } 

DayId allows, for example, "free on Sundays from 13:00." MinNour and 'MaxHour' allow from 0 to 2 hours for free, where from 5 to 6 hours costs R11.00. StartTime and EndTime allow "after 18:00 costs R7.00, fixed rate."

I am concerned about the lack of a multi-day price. When a car enters one price structure on one day and leaves under another on another day. It seems to me that I will have to visit every hour, parked by car, and accumulate the required amount. This seems like a very expensive way to do things.

Any advice on such an endevour would be greatly appreciated.

+6
source share
2 answers

I think this library should solve all your problems:

http://www.codeproject.com/Articles/168662/Time-Period-Library-for-NET

+3
source

You can save the pricing policy for each specific day in the interval tree. A tree should store all hours of the day. Along with the hourly boundaries, you need to save some information:

  • Boolean apartment: is the price estimated? (e.g. R7.00 for the entire period of the interval)
  • Whole price: the cost of an hour in a period. If flat set to true, this will be the cost of the entire period.

You get parking entries in the input. I assume that these are timestamps for the arrival and outgoing time for the car. The first two hours are free, so you increase your arrival time by two hours. From the resulting timestamps, you can build a sequence of triplets (day, start time, end time). It may be empty (if the car owner is parked in less than two hours), this case is trivial: costs R0.00

Now the algorithm processing the sequence should look like this:

 cost <- 0 while (NOT is_empty(sequence)) { dayTriplet <- pop(sequence) down <- dayTriplet.StartTime up <- dayTriplet.EndTime pricingTree <- getPriceTree(dayTriplet.dayId) while (down < up) { node <- findNode(pricingTree, down) nbHours <- min(up, node.up) - down if (node.flat) { cost <- cost + node.price } else { cost <- cost + nbHours*node.price } down <- down + nbHours } } 

The algorithm is a bit wrong, but I felt that the ideas behind it were worth the shot. For example, if the car is parked after 18:00 for one day until 4:00 the next day, this algorithm will analyze (d, 18, 24) and (d + 1, 0, 4), and thus, the owner should bill twice per apartment pace of the period, and not just once. A similar system should do the trick for this problem. I just did not integrate it to leave a relatively clear algorithm.

0
source

All Articles