Skip to content

Instantly share code, notes, and snippets.

@urschrei
Created July 26, 2011 22:09
Show Gist options
  • Select an option

  • Save urschrei/1108195 to your computer and use it in GitHub Desktop.

Select an option

Save urschrei/1108195 to your computer and use it in GitHub Desktop.
Basic commission payment thing
#!/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