Skip to content

Commit

Permalink
remove client side cookie parse
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaconDesperado committed Jun 12, 2024
1 parent 265c89b commit 19469b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
3 changes: 2 additions & 1 deletion flask_mab/debug_panels.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
30 changes: 10 additions & 20 deletions flask_mab/templates/panels/mab-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;}

Expand Down Expand Up @@ -62,7 +63,7 @@
</table>

{% for name,bandit in bandits %}
<h4>{{name}}:</h4>
<h4>{{name}}</h4>
Green table rows are values for this request
<table class="mab-op-table">
<colgroup>
Expand All @@ -80,7 +81,14 @@ <h4>{{name}}:</h4>
</tr>
</thead>
{% for arm in bandit.arms %}
<tr id="bandit-{{name}}-{{arm}}" class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<tr id="bandit-{{name}}-{{arm}}"
{% if arm == assigned[name][0] %}
class="winner"
{% else %}
class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}"
{% endif %}
>

<td>{{ arm }}</td>
<td>{{bandit[arm]['pulls']}}</td>
<td>{{bandit[arm]['reward']}}</td>
Expand All @@ -89,21 +97,3 @@ <h4>{{name}}:</h4>
{% endfor %}
</table>
{% endfor %}

<script type="text/javascript" src="/_debug_toolbar/static/js/jquery.js"></script>
<script>
(function($) {

function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}

var mab_cookie = JSON.parse(eval(getCookie("{{cookie_name}}")));
for(var name in mab_cookie){
$('#bandit-'+name+'-'+mab_cookie[name]).addClass("winner");
}

})(jQuery.noConflict(true));
</script>

0 comments on commit 19469b2

Please sign in to comment.