Skip to content

Commit

Permalink
fix threading problem, add all current things from zmq bus onto graphs.
Browse files Browse the repository at this point in the history
  • Loading branch information
eastein committed Sep 12, 2012
1 parent 2eded1a commit eea565d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
36 changes: 27 additions & 9 deletions interface.html
Expand Up @@ -18,25 +18,40 @@
<script type="text/javascript"> <script type="text/javascript">


function init() { function init() {
$.ajax({
url: '/trace',
dataType: 'json',
success: function(data) {
trace_set = data.data;
for (var tracetype in trace_set) {
var tl = new SmoothieChart({ millisPerPixel: 4500, grid: { strokeStyle: '#555555', lineWidth: 1, millisPerLine: 300000, verticalSections: 4 }});
traces = trace_set[tracetype];
for (var id in traces) {
setup_traces(tl, tracetype, traces[id], id);
}
}
}
});
}

function setup_traces(tl, tracetype, tracename, id) {
var dataset = new TimeSeries(); var dataset = new TimeSeries();


var now = new Date().getTime(); var rgb = ['rgba(255, 0, 0, 1)', 'rgba(0, 255, 0, 1)', 'rgba(0, 0, 255, 1)', 'rgba(220, 0, 220, 1)', 'rgba(2, 183, 98, 1)']


// Every second, get the total trace // Every second, get the total trace
setInterval(function() { setInterval(function() {
update_dataset(dataset); update_dataset(dataset, tracetype, tracename);
}, 1000); }, 1000);


var timeline = new SmoothieChart({ millisPerPixel: 4500, grid: { strokeStyle: '#555555', lineWidth: 1, millisPerLine: 300000, verticalSections: 4 }}); tl.addTimeSeries(dataset, {strokeStyle: rgb[id], fillStyle: 'rgba(10, 10, 10, 0.1)', lineWidth: 2});


timeline.addTimeSeries(dataset, { strokeStyle: 'rgba(255, 0, 0, 1)', fillStyle: 'rgba(255, 0, 0, 0.1)', lineWidth: 3 }); tl.streamTo(document.getElementById(tracetype), 1000);

timeline.streamTo(document.getElementById('temps'), 1000);
} }


function update_dataset(dataset) { function update_dataset(dataset, tt, tn) {
$.ajax({ $.ajax({
url: '/trace/all', url: '/trace/' + tt + '/' + tn,
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
dataset.data = data['data']; dataset.data = data['data'];
Expand All @@ -53,7 +68,10 @@
<h1>Chillmon</h1> <h1>Chillmon</h1>


<h4>Temps</h4> <h4>Temps</h4>
<canvas id="temps" width="800" height="100"></canvas> <canvas id="temps" width="900" height="200"></canvas>

<h4>PID States</h4>
<canvas id="pidstate" width="900" height="200"></canvas>
</body> </body>
</html> </html>


25 changes: 17 additions & 8 deletions web.py
Expand Up @@ -44,12 +44,11 @@ def __init__(self, sock, sample_cap=3600) :
def stop(self) : def stop(self) :
self.ok = False self.ok = False


@property def get_trace(self, a, b) :
def temps(self) :
r = [] r = []
for samp in self.samples : for samp in self.samples :
ts, sample = samp ts, sample = samp
r.append((ts, sample['temps']['beer'])) r.append((ts, sample[a][b]))
return r return r


def run(self) : def run(self) :
Expand Down Expand Up @@ -147,21 +146,27 @@ def handle_response(self, result) :


self.wj(status, resp) self.wj(status, resp)


class TraceListHandler(JSONHandler):
def process_request(self):
ts, i = self.application.__traces__.samples[0]
return dict([(k,i[k].keys()) for k in i])

class TraceHandler(JSONHandler): class TraceHandler(JSONHandler):
def process_request(self, tracename): def process_request(self, tracetype, tracename):
return self.application.__traces__[tracename].temps return self.application.__traces__.get_trace(tracetype, tracename)


if __name__ == '__main__' : if __name__ == '__main__' :
handler_set = [ handler_set = [
(r"/$", InterfaceHandler), (r"/$", InterfaceHandler),
(r"/([a-z0-9\.\-]+\.js)$", JSHandler), (r"/([a-z0-9\.\-]+\.js)$", JSHandler),
(r"/trace/([a-z0-9\.\-]+)$", TraceHandler) (r"/trace$", TraceListHandler),
(r"/trace/([a-z0-9\.\-]+)/([a-z0-9\.\-]+)$", TraceHandler)
] ]


sock = zmqsub.JSONZMQSub(sys.argv[1]) sock = zmqsub.JSONZMQSub(sys.argv[1])
tt = TraceThread(sock) tt = TraceThread(sock)
tt.start() tt.start()
traces = {'all' : tt} traces = tt


application = tornado.web.Application(handler_set) application = tornado.web.Application(handler_set)
application.__traces__ = traces application.__traces__ = traces
Expand All @@ -170,4 +175,8 @@ def process_request(self, tracename):
application.listen(8000) application.listen(8000)


application.__io_instance__ = tornado.ioloop.IOLoop.instance() application.__io_instance__ = tornado.ioloop.IOLoop.instance()
application.__io_instance__.start()
try :
application.__io_instance__.start()
finally :
tt.stop()

0 comments on commit eea565d

Please sign in to comment.