aboutsummaryrefslogtreecommitdiff
path: root/tanken.py
diff options
context:
space:
mode:
Diffstat (limited to 'tanken.py')
-rw-r--r--tanken.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/tanken.py b/tanken.py
index 2ca80bd..b7064cd 100644
--- a/tanken.py
+++ b/tanken.py
@@ -1,8 +1,9 @@
#!/bin/env python3
# cost should be given in cents
-def tanken(drives, cost):
+def tanken(drives, cost, service_charge=0):
passengers = {}
+ service_charges = {}
distance = 0.
drives = [d.split(' ') for d in drives]
@@ -18,19 +19,27 @@ def tanken(drives, cost):
# collect distances per passenger
for p in d[1:]:
if p not in passengers:
- passengers[p] = [d[0],0]
+ passengers[p] = {"distance": d[0],
+ "cost": 0,
+ "service_charge": 0}
else:
- passengers[p][0] += d[0]
+ passengers[p]["distance"] += d[0]
# calculate cost per kilometer
if distance <= 0:
return None, "Driven distance must be greater than 0!"
+
c = cost/distance
for d in drives:
- # calculate cost per drive split through passengers
+ # calculate cost per drive split among passengers
c_d = int(c * d[0] / (len(d) - 1))
for p in d[1:]:
- passengers[p][1] += c_d
+ passengers[p]["cost"] += c_d
+
+ # calculate service charge per drive split among passengers
+ sc_d = int(service_charge * d[0] / (len(d) - 1))
+ for p in d[1:]:
+ passengers[p]["service_charge"] += sc_d
return passengers, None