basically i'm creating a tariff calculator for a utility company in my country, based on a progressive rates table, an example given below
2.(a) In any one month for less than 1,001 gallons a fee of ………………………..… $9.23
(b) Proportionate fee for every gallon thereafter up to 2,000 gallons inclusive at the rate per 1,000 gallons of ………………..$15.89
(c) Proportionate fee for every gallon above 2,000 gallons and up to 3,000 gallons inclusive at the rate per 1,000 gallons of .………..$17.43
(d) Proportionate fee for every gallon above 3,000 gallons and up to 4,000 gallons inclusive at the rate per 1,000 gallons of .………..$18.45
(e) Proportionate fee for every gallon above 4,000 gallons and up to 5,000 gallons inclusive at the rate per 1,000 gallons of .………..$19.48
(f) Proportionate fee for every gallon above 5,000 gallons and up to 6,000 gallons inclusive at the rate per 1,000 gallons of .………..$20.50
(g) Proportionate fee for every gallon above 6,000 gallons and up to 7,000 gallons inclusive at the rate per 1,000 gallons of .………..$21.01
(h) Proportionate fee for every gallon above 7,000 gallons and up to 8,000 gallons inclusive at the rate per 1,000 gallons of .………..$21.53
(i) Proportionate fee for every gallon above 8,000 at the rate per 1,000 gallons of ...$22.04
I'm thinking of doing a Rate model with the following fields:
- area of supply
- description
- from_gallons (starting range of gallons)
- to_gallons (end range of gallons)
- rate_per_1000g
my view would accept post from a form with the amount of gallons, area of supply and should post back the usage calculated from the rate table.
i would do something like this in the view
from models import Rate
def tarrif_calc(request,gallons,area):
rate = Rate.objects.get(area_of_supply=area, from_gallons >= gallons, to_gallons <= gallons)
rate_per_gal = rate.rate_per_1000g/1000
usage = gallons * rate_per_gal
return usage
this is the most simple e.g i can think of, however i'm not sure how i would handle the progressive rates... any ideas? am i on the right track?