Last active
August 8, 2018 03:41
-
-
Save gzxultra/230948d33b00e7ca08166fc111df6900 to your computer and use it in GitHub Desktop.
calc our daily expense
This file contains 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 datetime | |
class People: | |
def __init__(self, name): | |
self.name = name | |
class Transaction: | |
def __init__(self, from_people, to_people, amount, title, transaction_date=None): | |
self.from_people = from_people | |
self.to_people = to_people | |
self.amount = amount | |
self.title = title | |
self.transaction_date = transaction_date or datetime.datetime.now() | |
weizhe = People('Weizhe Chen') | |
hongwei = People('Hongwei Cai') | |
gzxultra = People('Zhixiang Gu') | |
all_people = [weizhe, hongwei, gzxultra] | |
all_trans = [] | |
def build_payment_transaction(pay_guy, amount, title='', excludes=None): | |
excludes = excludes or [] | |
print 'INFO', pay_guy.name, amount, title.decode('utf-8'), [i.name for i in excludes] or '' | |
balance = amount * 1.0 / (len(all_people) - len(excludes)) | |
for people in all_people: | |
if people == pay_guy or people in excludes: | |
continue | |
t = Transaction(people, pay_guy, balance, title) | |
all_trans.append(t) | |
def process_payment(): | |
d = {} | |
for t in all_trans: | |
# print('INFO', t.from_people.name, t.to_people.name, t.amount) | |
if d.get((t.from_people, t.to_people)): | |
d[(t.from_people, t.to_people)] += t.amount | |
else: | |
d[(t.from_people, t.to_people)] = t.amount | |
for from_people in all_people: | |
for to_people in all_people: | |
if from_people == to_people: | |
continue | |
p1, p2 = d.get((from_people, to_people), 0), d.get((to_people, from_people), 0) | |
if not p1 and not p2: | |
continue | |
tranfer = p1 - p2 | |
if tranfer > 0: | |
print('tranfer'.upper(), from_people.name, to_people.name, tranfer) | |
# build_payment_transaction(gzxultra, 142, '房费') | |
# build_payment_transaction(gzxultra, 30, '麦当劳早餐') | |
# build_payment_transaction(weizhe, 7, '牙刷') | |
# build_payment_transaction(weizhe, 3, '水费') | |
# build_payment_transaction(weizhe, 5, '酒店接机小费') | |
# build_payment_transaction(weizhe, 1, '酒店小费') | |
# build_payment_transaction(weizhe, 1, '酒店送机小费') | |
# build_payment_transaction(gzxultra, 75, '托运行李费') | |
# build_payment_transaction(weizhe, 8.47, '星巴克拿铁', excludes=[hongwei]) | |
# build_payment_transaction(gzxultra, 122.22, '租车') | |
# build_payment_transaction(hongwei, 40, '印第安纳波利斯中餐') | |
# build_payment_transaction(hongwei, 100, 'ATT 宽带') | |
# build_payment_transaction(weizhe, 359.44, 'walmart 购物') | |
# build_payment_transaction(gzxultra, 17.56, 'kroger 购物') | |
# build_payment_transaction(gzxultra, 216.87, 'Target 购物') | |
# build_payment_transaction(gzxultra, 5, 'Target 购物', excludes=[hongwei]) | |
# build_payment_transaction(weizhe, 15.14, '麦当劳1') | |
# build_payment_transaction(gzxultra, 9.9, '麦当劳2') | |
# build_payment_transaction(hongwei, 90.2, 'kroger 购物') | |
# build_payment_transaction(hongwei, 61.57, 'walmart 购物') | |
# build_payment_transaction(hongwei, 60, '二手家具1') | |
# build_payment_transaction(hongwei, 5, '二手家具1', excludes=[weizhe]) | |
# build_payment_transaction(gzxultra, 185.8, '房租') | |
# build_payment_transaction(hongwei, 30.21, 'btown international market') | |
# build_payment_transaction(gzxultra, 14.85, 'refueling') | |
# build_payment_transaction(gzxultra, 20, '买家具1') | |
# build_payment_transaction(gzxultra, 6, '买家具2', excludes=[hongwei, gzxultra]) | |
# build_payment_transaction(weizhe, 18.33, 'kroger 购物') | |
build_payment_transaction(gzxultra, 81.93, 'amazon 饭盒') | |
build_payment_transaction(weizhe, 12.43, 'lyft 打车') | |
build_payment_transaction(weizhe, 10.36, 'kroger 买理发器材') | |
build_payment_transaction(gzxultra, 79.98, 'amazon 买四件套', excludes=[hongwei]) | |
# END 08/07/2018 | |
process_payment() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment