aboutsummaryrefslogtreecommitdiff
path: root/tanken.py
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-11-09 16:45:24 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-11-09 16:51:15 +0100
commit503400e976eb130e2d00148164fb9ca3febc6909 (patch)
treebec737419253f5ed2339ce384329bf1744e01667 /tanken.py
parent080b3f81df692fc0761353814c629ace53f0e3c9 (diff)
downloadgeldschieberbot-503400e976eb130e2d00148164fb9ca3febc6909.tar.gz
geldschieberbot-503400e976eb130e2d00148164fb9ca3febc6909.zip
adjust tanken to cents and improve it
geldschieberbot: convert commandline to lower case tanken: fix spelling tanken: do less int conversions tanken: return ints
Diffstat (limited to 'tanken.py')
-rw-r--r--tanken.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/tanken.py b/tanken.py
index 501978b..a9468b0 100644
--- a/tanken.py
+++ b/tanken.py
@@ -1,26 +1,34 @@
#!/bin/env python3
+# cost should be given in cents
def tanken(drives, cost):
- passagers = {}
+ passengers = {}
distance = 0.
drives = [d.split(' ') for d in drives]
for d in drives:
try:
- distance += int(d[0])
+ d[0] = int(d[0])
except:
return None, "Lines have to start with the driven distance!"
+
+ # calculate overall distance
+ distance += d[0]
+
+ # collect distances per passenger
for p in d[1:]:
- if p not in passagers:
- passagers[p] = [int(d[0]),0]
+ if p not in passengers:
+ passengers[p] = [d[0],0]
else:
- passagers[p][0] += int(d[0])
+ passengers[p][0] += d[0]
- c = cost/distance
+ # calculate cost per kilometer
+ c = cost/distance
for d in drives:
- c_d = c * int(d[0]) / (len(d) - 1)
+ # calculate cost per drive split through passengers
+ c_d = int(c * d[0] / (len(d) - 1))
for p in d[1:]:
- passagers[p][1] += c_d
+ passengers[p][1] += c_d
- return passagers, None
+ return passengers, None