only build history once in karma graph, do history

This commit is contained in:
Brian S. Stephan 2016-03-30 18:04:19 -05:00
parent 08da8ea9f3
commit 50f2b12c18
3 changed files with 23 additions and 4 deletions

View File

@ -26,7 +26,7 @@
});
var ctx = $("#karma_history").get(0).getContext("2d");
var data = {
labels: ["EPOCH", {% for x in entry.history %}"{{ x.0 }}", {% endfor %}],
labels: ["EPOCH", {% for x in entry_history %}"{{ x.0 }}", {% endfor %}],
datasets: [
{
label: "{{ entry.key }}",
@ -36,17 +36,32 @@
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [0, {% for x in entry.history %}{{ x.2 }}, {% endfor %}]
data: [0, {% for x in entry_history %}{{ x.2 }}, {% endfor %}]
}
]
};
var myLineChart = new Chart(ctx).AltLine(data, {
pointDot: false,
{% if entry.history|length > 100 %}
{% if entry_history|length > 100 %}
showTooltips: false,
scaleShowVerticalLines: false,
{% endif %}
tooltipEvents: ["click"]
});
</script>
<h5>Log</h5>
<table border="1px">
<tr>
<th>Date</th>
<th>Delta</th>
<th>Score</th>
</tr>
{% for delta in entry_history %}
<tr>
<td>{{ delta.0 }}</td>
<td>{{ delta.1 }}</td>
<td>{{ delta.2 }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -14,4 +14,4 @@ def key_detail(request, karma_key):
entry = get_object_or_404(KarmaKey, key=karma_key)
return render(request, 'karma/karma_key.html', {'entry': entry})
return render(request, 'karma/karma_key.html', {'entry': entry, 'entry_history': entry.history()})

View File

@ -9,3 +9,7 @@ html, body {
padding: 0 25px;
padding-top: 75px;
}
table tr, table th, table td {
padding: 5px;
}