Created
July 26, 2011 22:09
-
-
Save urschrei/1108195 to your computer and use it in GitHub Desktop.
Basic commission payment thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Assume a target number and an actual number | |
| Assume a range of commission payments based upon the percentage achieved | |
| What is the amount of commission due? | |
| """ | |
| from decimal import Decimal | |
| def commission_due(ach, targ, com): | |
| """ calculate commission due | |
| args: achieved number, target number, dict w/commission bands and amounts | |
| """ | |
| if ach <= 0: | |
| return 0 | |
| # work out the percentage achieved | |
| perc = int(round((float(ach) / float(targ)) * 100, 0)) | |
| for k in sorted(com.iterkeys(), reverse = True): | |
| if perc < k: | |
| # we haven't reached a matching band yet | |
| continue | |
| # found a band >= perc, or the highest key value | |
| else: | |
| return ach * com[k] | |
| # return the lowest band | |
| return ach * com[min(com.iterkeys())] | |
| commissions = { | |
| 110: Decimal(12), | |
| 100: Decimal(10), | |
| 75: Decimal(7.50), | |
| 50: Decimal(5), | |
| 20: Decimal(2)} | |
| target = 456 | |
| achieved = 3 | |
| print commission_due(achieved, target, commissions) | |
| # 68%, '50%' band, commission: 1560 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment