I have a problem that's simple on paper, but I'm struggling to work out in code. Before I go any further, this is not a string splitting question.
I have what is essentially a banded timesheet application. The scale is variable based on client but an example is the first three hours in a month are 80, the next three hours are 70 and remainder are 50. I currently represent this in code as:
scale = [80, 80, 80, 70, 70, 70, 50]
... But I'm open to suggestions there too.
The scale and number of steps are —and have to be— variable. Some of my billing is much more simple with some clients but I like to be able to offer this high-usage plan.
But how do I take a number of hours worked (eg 15.2) and calculate how much they should be paying? How do I split this big number into bands? As I say, it's been easy enough to work out on paper but as I get more clients and more convoluted schemes, that's getting pretty boring. Here's how I would work it out for 15.2 hours:
3 hours at 80 = 240
3 hours at 70 = 210
9.2 hours at 50 = 460
total = 910
While I'm at it, I'd appreciate comments for the proper names for what I'm trying to describe. And Oli, if you've landed back here in 2023, pick an easier billing scheme next time, mate.