diff --git a/flask_mab/bandits.py b/flask_mab/bandits.py index 9384b60..18bc2a3 100644 --- a/flask_mab/bandits.py +++ b/flask_mab/bandits.py @@ -1,5 +1,5 @@ from random import random, choice, uniform, betavariate -from math import log, exp, expm1 +from math import log, exp class Bandit(object): @@ -178,7 +178,7 @@ def __init__(self, tau=0.1): def _compute_weights(self): weights = [] total_reward = sum([exp(x / self.tau) for x in self.confidence]) - for ind, n in enumerate(self.pulls): + for ind, _ in enumerate(self.pulls): weights.append(exp(self.confidence[ind] / self.tau) / total_reward) return weights diff --git a/flask_mab/debug_panels.py b/flask_mab/debug_panels.py index bc79ce5..fd4a52c 100644 --- a/flask_mab/debug_panels.py +++ b/flask_mab/debug_panels.py @@ -1,4 +1,4 @@ -from flask import current_app +from flask import current_app, request from flask_debugtoolbar.panels import DebugPanel from jinja2 import PackageLoader, ChoiceLoader import json @@ -45,4 +45,5 @@ def content(self): context["storage_engine"] = current_app.config.get("MAB_STORAGE_ENGINE") context["storage_opts"] = current_app.config.get("MAB_STORAGE_OPTS", tuple()) context["bandits"] = current_app.extensions["mab"].bandits.items() + context["assigned"] = request.bandits return self.render("panels/mab-panel.html", context) diff --git a/flask_mab/templates/panels/mab-panel.html b/flask_mab/templates/panels/mab-panel.html index b0f6123..8143027 100644 --- a/flask_mab/templates/panels/mab-panel.html +++ b/flask_mab/templates/panels/mab-panel.html @@ -29,6 +29,7 @@ #flDebug .panelContent .mab-op-table, #flDebug .panelContent .mab-stack-trace table { display: table;} + .mab-op-table td.fifty {width: 50%; word-wrap: break-word;} .mab-op-table td.thirty {width: 30%; word-wrap: break-word;} @@ -62,7 +63,7 @@ {% for name,bandit in bandits %} -

{{name}}:

+

{{name}}

Green table rows are values for this request @@ -80,7 +81,14 @@

{{name}}:

{% for arm in bandit.arms %} - + + @@ -89,21 +97,3 @@

{{name}}:

{% endfor %}
{{ arm }} {{bandit[arm]['pulls']}} {{bandit[arm]['reward']}}
{% endfor %} - - -