Skip to content
Snippets Groups Projects
Commit f55cc42f authored by Brian Moe's avatar Brian Moe
Browse files

Merge branch 'ratechart'

parents 7cbfb0f5 5fed23e7
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,10 @@ from django.template import RequestContext
from django.shortcuts import render_to_response
from django.conf import settings
import os
from gracedb.models import Event
from django.db.models import Q
import os, datetime, json, time
def histo(request):
......@@ -36,6 +39,45 @@ def histo(request):
{'table': table,
'ifar' : ifar,
'uptime' : uptime,
'rate' : json.dumps(rate_data(request)),
},
context_instance=RequestContext(request))
def rate_data(request):
# XXX there is a better way -- should be using group_by or something.
# WAAY too many queries (~300) going on here.
now = datetime.datetime.now()
day = datetime.timedelta(1)
ts_min = now - 60 * day
ts_max = now
ts_step = day
window_size = day
types = [
("LM", Q(analysisType="LM")),
("Omega", Q(analysisType="Omega")),
("CWB", Q(analysisType="CWB")),
("MBTA", Q(analysisType="MBTA")),
("total", Q()),
]
ts = ts_min
n = 1
series = dict([(name, []) for (name,_) in types])
while ts <= ts_max:
for atype, q in types:
series[atype].append(
{
"x": ts.strftime("%s"),
"y": Event.objects.filter(q).filter(created__range=(ts, ts+day)).exclude(group__name="Test").count(),
})
ts += ts_step
n += 1
# [ (ts, event_count( ts - window_size, ts) / window_size)
# for ts in range(ts_min, ts_max, ts_step) ]
return series
......@@ -16,11 +16,71 @@ function toggle(id) {
}
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js"
data-dojo-config="async: true, isDebug: false, parseOnLoad: true">
</script>
<script>
{% if rate %}
timeData = {{ rate|safe }};
{% else %}
timeData = [
{ x: 1, y: 1 },
{ x: 2, y: 3 },
{ x: 3, y: 2 },
{ x: 4, y: 4 },
{ x: 5, y: 5 },
{ x: 6, y: 6 },
{ x: 7, y: 7 }
];
{% endif %}
require([
"dojo/parser",
"dojox/charting/Chart",
"dojox/charting/themes/Claro", // Shrooms, Tom
"dojox/charting/plot2d/Lines",
"dojox/charting/widget/Legend",
"dojox/charting/axis2d/Default",
"dojo/domReady!"
], function (parser, Chart, theme, Lines, Legend ) {
var chart = new Chart("CN");
function xlabel(n) {
console.log("Got: " + n);
var dt = new Date();
dt.setTime(1000*n);
return (dt.getMonth()+1)+"/"+dt.getDate()+"/"+dt.getFullYear();
};
chart.setTheme(theme);
chart.addPlot("default", {
type: Lines,
});
chart.addAxis("x", {labelFunc:xlabel});
chart.addAxis("y", { vertical: true });
chart.addSeries("Total", timeData['total']);
chart.addSeries("Low Mass", timeData['LM']);
chart.addSeries("Omega", timeData['Omega']);
chart.addSeries("MBTA", timeData['MBTA']);
chart.addSeries("cWB", timeData['CWB']);
chart.render();
var legend = new Legend({ chart: chart }, "leg1");
}
);
</script>
{% endblock %}
{% block content %}
<br/>
<a name="latency" href="javascript:toggle('latency');"><h3>Latency</h3></a>
<div id="latency" style="display:none;">
......@@ -59,6 +119,18 @@ function toggle(id) {
{% endif %}
</div>
<br/>
<br/>
<a name="rate" href="javascript:toggle('rate');"><h3>Submission Rates</h3></a>
<div id="rate" style="display: block;">
{% if rate %}
<div id="CN" style="width: 750px; height: 450px;"></div>
<div id="leg1"></div>
{% else %}
No rate charts.
{% endif %}
</div>
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment