Need help writing a universal equation involving time and stepping rates.

What's your programming environment? Are there any built-in date/time functions?
 
I’m using a mix of PHP and JavaScript. The JavaScript to to display the actual timers, counting up from the timestamp retrieved from the database, and the PHP is to store and retrieve information from the database. There’s plenty of built in commands including DateTime::diff which will find the difference between two times and output the result in hours, minutes, etc. The database automatically timestamps the current time and date when you add a new record into the “timein” column. The “timeout” column is NULL until checkout, at which point it adds the current time to that column and then this algorithm should be used at that time along with the “currentdeposit” column to calculate the “totaldeposit” column. Calculations are done at checkout, not while the program is running. I have all of the if, else, etc. statements. You can add more than one equation to make it return a single answer, e.g. if (4+3=7&&7+2=9) is true for both, so it would execute the code under it, but it it were a 5 instead of a 2, it would execute the code in the else block. There’s also != for not equal. Basically anything you need to write this is in it. If you have any experience in programming, this may be easy for you.
 
I’m using a mix of PHP and JavaScript …

… There’s plenty of built in commands including DateTime::diff which will find the difference between two times and output the result in hours, minutes, etc. …

… Basically anything you need to write this is in it. If you have any experience in programming, this may be easy for you.
Ah, sounds good.

Btw, my programming experience began before Bill Gates and Paul Allen started tinkering in that garage, on the other side of the lake. I used earlier languages, as well as scripting macros for dedicated hardware and within relational database software. Then, I started a new career just as the Internet began making itself available for mass consumption, so I never learned HTML or javascript. I think I remember the basics. ;)

I still ponder various aspects of your project, as thoughts occur, and I'll post it all when it reaches the top of my list.
 
Last edited:
That’s awesome. :) if you have any questions, just ask me. We can start a private chat if you’d like to talk more about the rest of the program. My first programming language was actually BASIC and I learned it at the age of 5. It taught me a lot about the concepts and I worked up from there.
 
Just wondering when you will have this finished?
Unfortunately, I've lost access time to computers because of forest fires. (In August, Seattle experienced the worst air quality ever recorded. This went on for days; I was forced to leave town more than once, during the last two weeks.)

Here's where I'm at, trying to understand your pricing system.

[01:05] or less means $3 or $5 (check-in times from 04:55 through 18:05 pay $3, otherwise $5)

More than [01:05] but less than [02:06] always means $5 (i.e., all check-in times)

More than [02:05] but less than [04:06] means $5 or $8 (check-in times from 02:05 through 16:05 pay $8, otherwise $5)

More than [04:05] becomes interesting; I still don't fully understand how the charge resets at 7am and 6pm play out. Consider customers who park 5 hours (ignore 5-min grace periods and overlapping endpoints, for this example). Your sign implies these customers pay $8, $10, $13 or $15, depending on check-in time.


Chg : Check-in range

$15 : 00:00 - 03:00
$ 8 : 03:00 - 04:00
$10 : 04:00 - 05:00
$13 : 05:00 - 07:00
$15 : 07:00 - 14:00
$13 : 14:00 - 16:00
$10 : 1600: - 17:00
$ 8 : 17:00 - 18:00
$15 : 18:00 - 24:00


Does this match what you've been doing by hand?

If not, can you say whether the charge is ever less than $15 for 5 hours of parking?

Cheers :cool:
 
Last edited:
Just wondering when you will have this finished?
Just FYI: The helpers here are volunteers who give of their time when and as they're able. They don't "do" students' homework for them, nor is there any expectation that they will write essays, construct software, or provide other professional services on any sort of on-demand basis. Instead, they try to help people learn how to succeed on their own. Thank you! ;)
 
Hey there. I'm going to introduce some more terminology, so we can discuss how price resets at 7am and 6pm affect the total charge.

I haven't mention it yet, but coding is easier if time intervals are expressed in minutes (instead of hours and minutes). So, I'll start writing ETmin instead of ET (i.e., ETmin is the total number of minutes a customer has parked). Previously, I used square brackets to denote time intervals, and I wrote time-of-day without brackets. I'm also dropping the colon in timestamps. Examples: [04:15] means 4hrs15min of elasped time and 0415 means 4:15am. (Based on the 24-hour clock starting at midnight, check-in and check-out will also be coded each as number of minutes from midnight.)

Okay. Sometimes, ETmin is broken into sections (i.e., blocks of time), and sometimes not. It depends on whether elapsed-time crosses a charge-reset boundary (at 0700 or 1800).

There are three situations where ETmin does not cross a charge-reset boundary:

1) ETmin lies entirely within 0000-0700
2) ETmin lies entirely within 0700-1800
3) ETmin lies entirely within 1800-0700

For such customers parking less than [04:06], the charge is easy to calculate (see post #26).

For those customers whose ETmin crosses a charge-reset boundary, I'm waiting to hear back from you. Easiest way from a coding perspective is to not have exceptions and charge everybody $15 for exceeding [04:05] regardless of whether the overage is 3 minutes or 3 hours or happens during a charge reset, but I want the algorithm to match all amounts you've been calculating by hand. (It's your pricing scheme, after all.)

Therefore, I'm going to break ETmin into (potentially) three blocks of time: pre-block, full-block and post-block.

Pre-block is elapsed time from check-in until the first reset boundary (0700 or 1800) or check-out, whichever comes first.

Full-blocks come in two flavors, and I've named them day-block and nite-block: day-block is the 11-hour interval from 0700 to 1800, and nite-block is the 13-hour interval from 1800 to 0700.

Post-block is elapsed time from the last charge-reset boundary until check-out time.

Using these descriptions, we have different cases.

Case 1) Customer has a pre-block only (i.e., they never reach a charge-reset boundary).

Case 2) Customer has a pre-block and post-block only (i.e., they cross only one charge-reset boundary; no full-block).

Case 3) Customer has a pre-block, followed by one or more full-blocks, with no post-block (i.e., check-out at 0700 or 1800).

Case 4) Customer has a pre-block, one or more full-blocks, and a post-block (i.e., they cross one or more charge-reset boundaries, and the final block is not full).

Case 1 is easy to calculate. Follow the algorithm in post #26, and charge $15 for anyone exceeding [04:05].

Case 2 is pending your explanation.

Case 3 is easy. Follow the algorithm in post #26 for the pre-block, and add $15 for each full-block.

Case 4 is easy. Follow the algorithm in post #26 for the pre-block and post-block (each), and add $15 for each full-block.

If this explanation is not clear, let me know. I can post various examples, maybe a diagram. Otherwise, please answer my questions in post #26. :cool:
 
Last edited:
… Easiest way from a coding perspective is to not have exceptions and charge everybody $15 for exceeding [04:05] regardless of whether the overage is 3 minutes or 3 hours or happens during a charge reset …
Hi. I take back the statement above; I realized yesterday that the coding approach in post #28 amounts to using the same algorithm for each customer. That is, each block could be processed (block hours summed, as tiered price determined for each) using the same loop, so the one-size-fits all pricing scheme above (versus strict adherence to the charge-reset boundaries -- encoded within the processing loop, anyway) doesn't have any benefit from a coding point of view. It also doesn't matter whether a customer starts with daily rates or nightly rates, or a full-block or partial-block, or what order the block charges are summed. I mispoke.

Charge = [pre-block? if yes, daily or nightly rates] + [full-block? if yes, charge for each] + [post-block? if yes, daily or nightly rates]
 
I'm honestly lost again, I think. 1 hour stayed would be $3, 2 hours is $5, and 4 hours is $8, and there's 5 minutes of leeway going over for each. In any case, more than 4 hours is $15 until the prices change at 6PM and 7AM, then it ticks back up to a $15 charge again after the 4 hours after the rollover has finished.

Lets say someone comes in at 4PM, and leaves at 11PM. It would result in 2 hours before 6PM, and 5 hours after. That's $5 for the two hours before the 6PM rollover, and 5 hours after. Since after it would be more than 4 hours, it costs them $15 plus the $5, being $20 total. the one hour leeway doesn't apply here, because there is more than an hour on each side of the rollover.

Let's say the 1 hour leeway only happens if they go past the rollover time by less than one hour. For instance, checking in at 5PM and out at 7PM would mean $5 (1 hour before 6PM being $3, plus $2, the difference between the 1 and 2 hour charge before 6PM), instead of the $8 that it would usually be (1 hour before 6PM being $3, and 1 hour after follows the flat rate of $5, which is inconvenient.)

If someone comes in at 1PM and leaves at 11PM, it would be $30. more than 4 hours on each side of the rollover.

Checking in at 5PM and out at 8PM, however, would be $8 with or without the leeway. 1 hour before (before 6 is $3,) and 2 after (which would be a $5 flat rate anyway.)


I also just realized that I mentioned a 2 hour leeway instead of a 1 hour leeway, and I'm not sure anymore which is better or why we picked 2 hours. Honestly, this whole thing is extremely confusing to me and refining isn't making this easier for me, I usually just think about what's fair for the person to pay. :???:

Checking in at 4PM and out at 8PM would result in $10 using the 1 hour leeway ($5 for two hours before, and flat $5 after,) that's the only thing I can think of. Is there any downsides to the 2 hour leeway you can think of?

Also, best of luck in Seattle. Sounds rough.
 
In any case, more than 4 hours is $15
Is that your answer to my second question in post #26? Here's the question again:

… can you say whether the charge is ever less than $15 for 5 hours of parking?



It seems like your statement above means: "No, exceeding 4 hours always results in a minimum charge of $15". But, I'm not sure because you haven't directly answered my questions in post #26.
 
Last edited:
… If someone comes in at 1PM and leaves at 11PM, it would be $30 …
That's $30 for 10 hours, and the $30 charge matches information on the sign (for that specific check-in).

The information on the sign also means that some people who stay 10 hours pay only $20 (eg: 1100-2100) while others pay only $15 (eg: 1900-0500). There could be other exceptions, for a 10-hour stay. (I didn't chart all possibilities.)
 
Last edited:
I'm honestly lost again …
I think you're lost because you don't actually have a set billing system. (I suspect your sign is incorrect.)


… I usually just think about what's fair …
A machine cannot do that. You need a concrete system, before thinking about coding it. You need to discover, and decide upon a charge, for each exception to your signage.


At this point, I suggest you draw a timeline (graph paper would be handy) and cut some index cards (to scale) matching specific intervals of parked time. Slide each card within the timeline (i.e., different check-in times, hour by hour), and calculate to see how check-in time affects total charge -- according to the sign. Record each case. Make a complete chart. (In post #26, I showed you a partial chart covering 5-hr stays only.)

Next, decide which charges (generated according to the sign) are fair, and then decide how you want to handle the charges which are not fair. For charges you deem unfair, maybe a single rational resolves them all or maybe you need a set of rationals.
 
I need to take a step back and go at this in a different approach, and set basic rules and not worry about the rest of it.

I want 5 minutes of leeway around each hour, so if they come back 5 minutes late, it won't charge them for that whole extra hour.

As for other leeways, lets kind of forget about the other ones we've talked about for now, and make it this simple one;
A person will pay $8 deposit when coming in before 6PM. If they come in before 6PM by no more than 2 hours (so if they come in between 4PM and 6PM,) it just adds $7 to bring it up to the $15 total for more than 4 hours after the deposit expires, if they exceed 4 hours (if not then it's the regular rate for the deposit charged.) For instance, checking in at 4PM and out at 7AM is $15 total. In at 4PM and out at 7PM is $8. Checking in at 3PM and checking out at 7AM would result in the entire over 4 hours past 6PM, plus whatever time before 6PM charged separately, so $23 (3 hours plus over 4 hours.)
The same is reflected at 7AM with a two hour leniency for the deposit, just a different deposit ($5, plus $10 more when exceeding 4 hours) when they check in.

Also to clarify, as for #26, the question about 4 hours, simply anything over 4 hours within the periods of 6PM to 7AM or 7AM to 6PM is $15 for that period.

Other than these exceptions, the sign should always be followed to a tee. The sign is all the information I have to go by, other than asking the guy that made the sign what should be done in certain scenarios. He gave me this way of explaining it so this time it wasn't so bad. Where i get wrapped up in all of this is when actually looking at all these numbers (some of the previous replies for instance) and my head just starts to shut down when the explanation gets too big. It's fine when I'm looking at just one person and just a single check in and check out time, but this is too much, that's why I came here for help.
 
Last edited:
… The sign is all the information I have to go by, other than asking the guy that made the sign what should be done in certain scenarios.
Do I understand this correctly? You own a parking lot, and a guy who paints signs is helping you figure out how to charge customers?
 
I'll need more time to study your latest exceptions description, but do you realize there will still be ranges of charges generated for the same length of stay?

One example: You say 3pm to 7am is $23 (16 hours), yet another person parks 16 hours but arrived 1 hour 15 minutes earlier and pays $30.

Is there a reason why you can't charge $15 every 12 hours (instead of alternating between 11- and 13-hour intervals)? You could charge each customer according to their own clock, instead of resetting rates at 0700 and 1800. This would also eliminate resetting charges in the middle of any $15 interval.

Customers checking in between 0700 and 1800 would start with $3-$5-$8, and over 4 hours it's $15 and then they're covered for 12 hours from time of check-in. In other words, a daytime check-in provides daytime pricing, regardless of when they check out.

Likewise, customers who check in between 1800 and 0700 would start with the $5, and over 4 hours it's $15 and now they're covered for 12 hours from time of check-in.

Continuing charging $15 for each 12-hour block, and when someone finishes with a partial block (4 hours or less) use daytime pricing if the leftover begins during the day, otherwise use night pricing.

This way, the sign is accurate for the first 12 hours of parking, you charge $15 for each additional 12 hours, and the sign also covers any final overage according to when it occurs.

After I understand your latest explanation, I'll write out some scenarios and compare the results to charging based on each customer having their own 12-hour timer instead, with no price resets at 0700 and 1800. Maybe it'll work out close to the same, over all.
 
Sorry, I got wrapped up in some other things. I don't actually own the lot, I help out by running it sometimes though. The sign is still accurate except for those two extra rules in #34. That's all we need for now, it's all we can think of that'd negatively affect pricing. We prefer rollover anyway, the less time they spend in the lot, the more money is made.
 
Top