nlp-qual-space / overview.py
maxspad's picture
finally figured out altair
f58c9c5
raw
history blame
2.35 kB
from matplotlib.cm import get_cmap
import plotly.graph_objects as go
class NQDOverview(object):
def __init__(self, parent, results,
dial_cmap='RdYlGn'):
self.p = parent
self.results = results
self.cmap = get_cmap(dial_cmap)
def _get_color(self):
color = self.cmap(self.results['qual']['label'] / 6.0)
color = f'rgba({int(color[0]*256)}, {int(color[1]*256)}, {int(color[2]*256)}, {int(color[3]*256)})'
return color
def _build_figure(self):
color = self._get_color()
fig = go.Figure(go.Indicator(
domain = {'x': [0, 1], 'y': [0, 1]},
value = self.results['qual']['label'],
mode = "gauge+number",
title = {'text': "QuAL"},
gauge = {'axis': {'range': [None, 5], 'showticklabels': True, 'ticks': ""},
'bgcolor': 'lightgray',
'bar': {'color': color, 'thickness': 1.0}
}
),
layout=go.Layout(margin=dict(t=0, b=135))
)
return fig
def draw(self):
st = self.p
fig = self._build_figure()
cols = st.columns([7, 3])
with cols[0]:
st.plotly_chart(fig, use_container_width=True)
with cols[1]:
q1lab = self.results['q1']['label']
if q1lab == 0:
md_str = 'πŸ˜₯ None'
elif q1lab == 1:
md_str = '😐 Low'
elif q1lab == 2:
md_str = '😊 Medium'
elif q1lab == 3:
md_str = '😁 High'
cols[1].metric('Level of Detail', md_str,
help='How specific was the evaluator in describing the behavior?')
q2lab = self.results['q2i']['label']
if q2lab == 0:
md_str = 'βœ… Yes'
else:
md_str = '❌ No'
cols[1].metric('Suggestion Given', (md_str),
help='Did the evaluator give a suggestion for improvement?')
q3lab = self.results['q3i']['label']
if q3lab == 0:
md_str = 'βœ… Yes'
else:
md_str = '❌ No'
cols[1].metric('Suggestion Linked', md_str,
help='Is the suggestion for improvement linked to the described behavior?')