-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreporter.py
76 lines (61 loc) · 2.27 KB
/
reporter.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys
import csv
from config import *
NEW_VAT_PROCESSING = True
kurzy = {}
appsStats = {}
#configuration - fill your apps info here
def getDataForApp(appName):
if appName in apps:
appId = appName
if not appId in appsStats:
appsStats[appId] = {"withvat": {"downloads": 0, "vat": 0, "charged": 0, "google": 0}, "nonvat":{"downloads": 0, "vat": 0, "charged": 0, "google": 0}}
return appsStats[appId]
else:
print "Unknown app %s" % appName
sys.exit()
return None
def processStats(fileName):
# loads CSV with stats
csvData = csv.reader(open(fileName, 'r'))
counter = 0
for row in csvData:
if row[0][:5].isdigit():
appData = getDataForApp(row[7])
if (appData <> None):
vat = float(row[12])
if (vat <> 0):
toChange =appData ["withvat"]
else:
toChange =appData ["nonvat"]
toChange["downloads"] += 1
exRate = 1
if row[15] != "":
exRate = float(row[15])
vat = float(row[12]) * exRate
recievedWithoutVAT = float(row[16]) - vat
toChange["vat"] += vat
toChange["charged"] += recievedWithoutVAT
price = row[11]
price = price.replace(",","")
if len(row[15]) == 0:
row[15] = 0
toChange["google"] += recievedWithoutVAT * (3.0/7.0)
counter += 1
# display results
print "Name;Items;Charged (inc. VAT and Google provision);VAT;Profit (exc. VAT);Google part"
for appId in appsStats:
dict = appsStats[appId]
name = apps[appId]
for typ in ("withvat", "nonvat"):
print "%s;%d;%f;%f;%f;%f" % (name, dict[typ]["downloads"],dict[typ]["charged"] + dict[typ]["google"] + dict[typ]["vat"], dict[typ]["vat"], dict[typ]["charged"], dict[typ]["google"])
def main():
if len(sys.argv) == 1:
print "No filename specified"
else:
fileToImport = sys.argv[1]
processStats(fileToImport)
if __name__ == "__main__":
main()