summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2020-08-29 11:39:43 +0200
committermakefu <github@syntax-fehler.de>2020-08-29 11:39:49 +0200
commitee694e9e7e65877403d1df1f2e47118c388bd634 (patch)
tree54c5cf8283c90037261233e6136d52e197379658
parent23219dde69ff95191f77c22331f7ac2ad4971a1e (diff)
add probabilities to !choose and !list
-rw-r--r--kalauerbot/bot.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/kalauerbot/bot.py b/kalauerbot/bot.py
index 912584a..de95ade 100644
--- a/kalauerbot/bot.py
+++ b/kalauerbot/bot.py
@@ -104,8 +104,15 @@ class Kalauerbot(MatrixBot):
weights.append(entity['weight'])
log.debug(names)
log.debug(weights)
- db["__chosen__"] = chosen = random.choices(names,weights=weights)[0]
- say(f"{chosen} was chosen to be the next kalauer könig, congratulations!")
+ chosen = random.choices(names,weights=weights)[0]
+ chosen_weight = db[chosen]['weight']
+ all_weight = sum(weights)
+ prob = round(chosen_weight / all_weight * 100,1)
+ crosscheck = random.choices(names,weights=weights,k=100000)
+ say(f"{chosen} was chosen with a probability of {prob}% to be the next kalauer könig, congratulations!\n" +
+ f"cross-check: { crosscheck.count(chosen):,} out of 100,000 rolls were {chosen}")
+
+ db["__chosen__"] = chosen
self.save_db()
elif command in ["!who","!wer", "!current"]:
@@ -147,10 +154,11 @@ class Kalauerbot(MatrixBot):
say(f"the name '{name}' does not exist in the database, add the user before demanding a kalauer from him")
self.save_db()
elif command == "!list":
+ all_weight = sum([db[a]["weight"] for a in db if a != "__chosen__"])
txt = "Kalauer roster:\n\n"
for name,entry in db.items():
if name == '__chosen__': continue
- txt += f"* {name} - {entry['weight']} weight - {entry['total']} total {'(active)' if entry['active'] else '(inactive)'}\n"
+ txt += f"* {name} - {entry['weight']} weight ({round(entry['weight']/all_weight * 100,1)}%) - {entry['total']} total {'(active)' if entry['active'] else '(inactive)'}\n"
say(txt)
elif command == "!kill":
name = args.strip()