Commit 531b70d4 by Braden MacDonald

Report average for numeric blocks

parent 8633044e
......@@ -120,6 +120,11 @@ class DashboardBlock(StudioEditableXBlockMixin, XBlock):
"value": value,
"color": self.color_codes.get(value),
})
# If the values are numeric, display an average:
numeric_values = [float(mcq['value']) for mcq in block['mcqs'] if mcq['value'] and mcq['value'].isnumeric()]
if numeric_values:
block['average'] = sum(numeric_values) / len(numeric_values)
block['has_average'] = True
blocks.append(block)
return loader.render_template('templates/html/dashboard.html', {
......
......@@ -3,6 +3,11 @@
border-collapse: collapse;
}
.pb-dashboard table th {
padding-top: 0.6em;
font-weight: bold;
}
.pb-dashboard table td {
border: 1px solid black;
padding: 0.2em;
......@@ -24,3 +29,8 @@
-1px 1px 1px rgba(255,255,255,0.7),
1px 1px 1px rgba(255,255,255,0.7);
}
.pb-dashboard table .avg-row td {
background-color: #ddd;
text-align: right;
}
{% load i18n %}
<div class="pb-dashboard">
<h1>{{display_name}}</h1>
<table>
......@@ -14,6 +15,12 @@
</td>
</tr>
{% endfor %}
{% if block.has_average %}
<tr class="avg-row">
<td>{% trans "Average" %}</td>
<td>{{ block.average|floatformat }}</td>
</tr>
{% endif %}
</tbody>
{% endfor %}
</table>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment