aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--geldschieberbot.py5
-rw-r--r--tanken.py26
2 files changed, 20 insertions, 11 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index 4666acc..4274d32 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -126,7 +126,7 @@ def handle_input(inp):
if not_in_group:
continue
- w = body[0].split(' ')
+ w = body[0].lower().split(' ')
cmd = w[0]
@@ -225,6 +225,7 @@ def handle_input(inp):
except:
send("ERROR: amount musst be a number")
continue
+
if w[2] in name2num:
recipient = w[2]
else:
@@ -238,7 +239,7 @@ def handle_input(inp):
msg = ""
for p in parts.items():
- msg += p[0] + ": {}km = {}\n".format(p[1][0], p[1][1])
+ msg += p[0] + ": {}km = {}\n".format(p[1][0], to_euro(p[1][1]))
if p[0] != recipient:
if p[0] in name2num:
balance[recipient][p[0]] -= p[1][1]
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