Last active
May 7, 2017 16:40
-
-
Save ryantuck/2903df7e07ea8f6401f5a3b333418b9d to your computer and use it in GitHub Desktop.
nashville bookie calcs
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
processing split transactions | |
who | total | each | what | |
tuck | 130 | 14.44 | Groceries | |
tuck | 11 | 1.22 | Uber back from groceries | |
sara | 47 | 7.83 | Dommy doms | |
tuck | 18 | 3.6 | Lyft to smellrose | |
sara | 7 | 2.33 | Uber | |
tuck | 18 | 3.6 | Lyft from santas | |
tuck | 70 | 10.0 | Lunch | |
mc | 52 | 5.78 | Beer | |
tuck | 22 | 5.5 | Ubers climbing | |
ben | 115 | 12.78 | Hot chicken | |
cb | 15 | 5.0 | Lyft to Twin Kegs | |
cb | 18 | 9.0 | Lyft Twin Kegs to Wilhagan's | |
sara | 38 | 7.6 | 11 am dominos | |
mc | 113 | 12.56 | beer/food at Greek Rose | |
mc | 23 | 4.6 | Lyft from Wilhagan's | |
frank | 13 | 3.25 | Lyft to office with rapper guy | |
frank | 15 | 5.0 | Lyft from Hermitage cafe to office | |
frank | 14 | 4.67 | Lyft to 3crow where i said love you | |
marisa | 33 | 3.67 | Grocery run | |
processing house | |
who | nights | total owed | |
tuck | 5 | 362 | |
cb | 5 | 362 | |
ben | 5 | 362 | |
marisa | 4 | 290 | |
camcam | 4 | 290 | |
sara | 4 | 290 | |
mc | 4 | 290 | |
frank | 4 | 290 | |
grecs | 2 | 145 | |
processing payments | |
from | to | amt | |
grecs | tuck | 17 | |
sara | tuck | 312 | |
mc | tuck | 312 | |
grecs | tuck | 156 | |
grecs | ben | 13 | |
grecs | cb | 5 | |
grecs | sara | 10 | |
grecs | mc | 13 | |
grecs | mc | 16 | |
mc | tuck | 15 | |
mc | ben | 12.78 | |
mc | cb | 14 | |
mc | frank | 12.92 | |
mc | marisa | 4 | |
mc | sara | 16 | |
camcam | tuck | 363.71 | |
cb | tuck | 450.89 | |
tuck | mc | 169.64 | |
tuck | grecs | 17.36 | |
ben | tuck | 361.09 | |
frank | tuck | 353.91 | |
marisa | tuck | 333.54 | |
transaction balances | |
ben | 26.69 | |
camcam | -73.71 | |
cb | -69.89 | |
frank | -50.99 | |
grecs | -67.64 | |
marisa | -39.54 | |
mc | 101.94 | |
sara | 2.34 | |
tuck | 170.82 | |
total balance: 0.02 | |
house balances | |
ben | -362 | |
camcam | -290 | |
cb | -362 | |
frank | -290 | |
grecs | -145 | |
marisa | -290 | |
mc | -290 | |
sara | -290 | |
tuck | 2320 | |
total balance: 1 | |
payment balances | |
ben | 335.31 | |
camcam | 363.71 | |
cb | 431.89 | |
frank | 340.99 | |
grecs | 212.64 | |
marisa | 329.54 | |
mc | 188.06 | |
sara | 286.0 | |
tuck | -2488.14 | |
total balance: 0.0 | |
overall balances | |
ben | 0.0 | |
camcam | 0.0 | |
cb | 0.0 | |
frank | 0.0 | |
grecs | 0.0 | |
marisa | 0.0 | |
mc | 0.0 | |
sara | -1.66 | |
tuck | 2.68 | |
total balance: 1.02 |
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
who | what | how much | between who | standardized | |
---|---|---|---|---|---|
tuck | Groceries | 130 | all | all | |
tuck | Uber back from groceries | 11 | all | all | |
sara | Dommy doms | 47 | tuck Cb MC Sara Frank Ben | tuck cb mc sara frank ben | |
tuck | Lyft to smellrose | 18 | tuck Cb Sara Frank Ben | tuck cb sara frank ben | |
sara | Uber | 7 | Sara Ben Mike | sara ben mc | |
tuck | Lyft from santas | 18 | tuck Cb Ben Frank cam | tuck cb ben frank camcam | |
tuck | Lunch | 70 | tuck MC Sara Ben Frank cam Cb | tuck mc sara ben frank camcam cb | |
mc | Beer | 52 | All | all | |
tuck | Ubers climbing | 22 | tuck Cb Marisa Ben | tuck cb marisa ben | |
ben | Hot chicken | 115 | All | all | |
cb | Lyft to Twin Kegs | 15 | CB, CamCam, Grecs | cb camcam grecs | |
cb | Lyft Twin Kegs to Wilhagan's | 18 | CB, RisRis | cb marisa | |
sara | 11 am dominos | 38 | Sara, MC, Marissa, Steve, anyone else? | sara mc marisa grecs tuck | |
mc | beer/food at Greek Rose | 113 | all | all | |
mc | Lyft from Wilhagan's | 23 | MC, tuck, Sara, Frank, Grecs | mc tuck sara frank grecs | |
frank | Lyft to office with rapper guy | 13 | MC, tuck, Sara, Frank, CB (i think?) | mc sara frank cb | |
frank | Lyft from Hermitage cafe to office | 15 | Frank, Ben, Tuck (i think?) | frank ben tuck | |
frank | Lyft to 3crow where i said love you | 14 | Frank, CB, Cam | frank cb camcam | |
marisa | Grocery run | 33 | ? everyone ? | all |
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
employee | nights | owes | |
---|---|---|---|
tuck | 5 | $362 | |
cb | 5 | $362 | |
ben | 5 | $362 | |
marisa | 4 | $290 | |
camcam | 4 | $290 | |
sara | 4 | $290 | |
mc | 4 | $290 | |
frank | 4 | $290 | |
grecs | 2 | $145 |
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
from | to | amount | |
---|---|---|---|
grecs | tuck | 17 | |
sara | tuck | 312 | |
mc | tuck | 312 | |
grecs | tuck | 156 | |
grecs | ben | 13 | |
grecs | cb | 5 | |
grecs | sara | 10 | |
grecs | mc | 13 | |
grecs | mc | 16 | |
mc | tuck | 15 | |
mc | ben | 12.78 | |
mc | cb | 14 | |
mc | frank | 12.92 | |
mc | marisa | 4 | |
mc | sara | 16 | |
camcam | tuck | 363.71 | |
cb | tuck | 450.89 | |
tuck | mc | 169.64 | |
tuck | grecs | 17.36 | |
ben | tuck | 361.09 | |
frank | tuck | 353.91 | |
marisa | tuck | 333.54 |
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
import csv | |
all_people = [ | |
'tuck', 'cb', 'frank', 'ben', 'camcam', | |
'grecs', 'marisa', 'sara', 'mc', | |
] | |
def split_payment(record): | |
# get meaningful info | |
between_who = record['standardized'] | |
tot_paid = int(record['how much']) | |
paid_by = record['who'] | |
# determine who to split it with | |
if between_who == 'all': | |
ppl = all_people | |
else: | |
ppl = between_who.split(' ') | |
# what each person owes | |
amt_owed = tot_paid / len(ppl) | |
print('{who: <10} | {tot: >6} | {ea: >6} | {what}'.format( | |
who=paid_by, | |
tot=tot_paid, | |
ea=round(amt_owed, 2), | |
what=record['what'], | |
)) | |
# return a set of balances for this record | |
record_bal = {p: 0-amt_owed for p in ppl} | |
record_bal[paid_by] += tot_paid | |
return record_bal | |
def process_split_transactions(): | |
trans_balances = {p: 0 for p in all_people} | |
# read in records | |
with open('bookie.tsv') as f: | |
reader = csv.DictReader(f, delimiter='\t') | |
records = [r for r in reader] | |
# process records babay | |
print('{who: <10} | {tot: >6} | {ea: >6} | {what}'.format( | |
who='who', | |
tot='total', | |
ea='each', | |
what='what', | |
)) | |
for record in records: | |
record_bal = split_payment(record) | |
for p,b in record_bal.items(): | |
trans_balances[p] += b | |
return trans_balances | |
def process_house(): | |
# read in records | |
with open('nights.tsv') as f: | |
reader = csv.DictReader(f, delimiter='\t') | |
records = [r for r in reader] | |
house_balances = {p: 0 for p in all_people} | |
# i paid for the house | |
house_balances['tuck'] += 2682 | |
# update balances from airbnb | |
print('{who: <10} | {n: >10} | {t: >10}'.format( | |
who='who', | |
n='nights', | |
t='total owed', | |
)) | |
for record in records: | |
who = record['employee'] | |
owes = int(record['owes'].strip('$')) | |
print('{who: <10} | {n: >10} | {t: >10}'.format( | |
who=who, | |
n=record['nights'], | |
t=owes, | |
)) | |
house_balances[who] -= owes | |
return house_balances | |
def process_payment(record): | |
print('{f: <10} | {t: <10} | {a: >6}'.format( | |
f=record['from'], | |
t=record['to'], | |
a=record['amount'], | |
)) | |
return { | |
record['from']: float(record['amount']), | |
record['to']: 0-float(record['amount']), | |
} | |
def process_payments(): | |
payment_balances = {p: 0 for p in all_people} | |
# read in records | |
with open('payments.tsv') as f: | |
reader = csv.DictReader(f, delimiter='\t') | |
records = [r for r in reader] | |
print('{f: <10} | {t: <10} | {a: >6}'.format( | |
f='from', | |
t='to', | |
a='amt', | |
)) | |
for record in records: | |
payment_bal = process_payment(record) | |
for p,b in payment_bal.items(): | |
payment_balances[p] += b | |
return payment_balances | |
def print_balances(bals): | |
for p, b in sorted(bals.items()): | |
print('{p: <10} | {b: >10}'.format(p=p, b=b)) | |
print('total balance: {}'.format(round(sum(bals.values()), 2))) | |
def main(): | |
# create balance sheet | |
balances = {p: 0 for p in all_people} | |
# process transactions, house, and payments | |
print('') | |
print('processing split transactions') | |
trans_bals = process_split_transactions() | |
print('') | |
print('processing house') | |
house_bals = process_house() | |
print('') | |
print('processing payments') | |
payment_bals = process_payments() | |
# round balances | |
for p, b in trans_bals.items(): | |
trans_bals[p] = round(b, 2) | |
for p, b in house_bals.items(): | |
house_bals[p] = round(b, 2) | |
for p, b in payment_bals.items(): | |
payment_bals[p] = round(b, 2) | |
# output results | |
print('') | |
print('transaction balances') | |
print_balances(trans_bals) | |
print('') | |
print('house balances') | |
print_balances(house_bals) | |
print('') | |
print('payment balances') | |
print_balances(payment_bals) | |
# summarize all balances | |
for p, b in balances.items(): | |
balances[p] += trans_bals.get(p, 0) | |
balances[p] += house_bals.get(p, 0) | |
balances[p] += payment_bals.get(p, 0) | |
balances[p] = round(balances[p], 2) | |
print('') | |
print('overall balances') | |
print_balances(balances) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment