-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrevenue.py
43 lines (35 loc) · 1.24 KB
/
revenue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import csv
from dateutil.parser import parse
revenue={}
def run():
process_file()
print_revenue()
def process_file():
with open('payout.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
update_revenue(row)
def update_revenue(row):
date = row['Charge Date']
if date:
date = date.split(' ')[0]
date = parse(date)
date = str(date.month) + '/1/' + str(date.year)
else:
date = None
if date:
if not date in revenue:
revenue[date]={}
revenue[date]['revenue']=0
revenue[date]['legacyrevenue']=0
if 'Charge' in row['Transaction Type'] or 'Customer Refund' in row['Transaction Type']:
if 'Hourly Pricing' in row['SKU']:
revenue[date]['revenue']+=float(row['Payout Amount (PC)'])
else:
revenue[date]['legacyrevenue']+=float(row['Payout Amount (PC)'])
def print_revenue():
print('Month, Revenue, Legacy Revenue, Total Revenue')
for date in revenue:
total = revenue[date]['revenue']+revenue[date]['legacyrevenue']
print(date + ', ' + str(revenue[date]['revenue']) + ', ' + str(revenue[date]['legacyrevenue']) + ', ' + str(total))
run()