added user-count history api (just demo-data)

added rickshaw graph using that user-count api
This commit is contained in:
Lucas Pleß 2013-10-22 01:40:57 +02:00
parent 319f828c84
commit 82f8867161
16 changed files with 3538 additions and 48 deletions

View File

@ -47,6 +47,12 @@ var IpPoll = function(switchaddr, hostsaddr) {
} }
}); });
}; };
this.getHistory = function(start, end, callback) {
callback(data);
};
}; };
util.inherits(IpPoll, EventEmitter); util.inherits(IpPoll, EventEmitter);

View File

@ -4,13 +4,14 @@
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"dependencies": { "dependencies": {
"express": "3.*", "express": "3.4",
"connect-flash": "0.1.1", "connect-flash": "0.1.1",
"net-snmp": "*", "net-snmp": "1.1.8",
"redis": "*", "redis": "0.8.5",
"underscore": "*", "underscore": "1.5.2",
"jade": "*", "jade": "0.35",
"socket.io": "*" "socket.io": "0.9.16",
"moment": "2.3.1"
}, },
"main": "index" "main": "index"
} }

1
node/public/css/rickshaw.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,15 @@
background-image: url("/img/yellow.png"); background-image: url("/img/yellow.png");
} }
.members { h2 {
margin-top: 8pt; font-weight: bold;
/*padding: 0;*/ color: #555;
font-size: 13pt;
margin-bottom: 0.7em;
} }
#graph {
max-width: 400px;
height: 200px;
margin-top: 0;
}

View File

@ -61,4 +61,7 @@ angular.module('roomstateapp.statusfilter', []).filter('statustostring', functio
}; };
}); });
angular.module('roomstateapp', ['roomstateapp.controllers', 'roomstateapp.services', 'roomstateapp.statusfilter']); angular.module('roomstateapp', ['roomstateapp.controllers', 'roomstateapp.services', 'roomstateapp.statusfilter']);

38
node/public/js/graph.js Normal file
View File

@ -0,0 +1,38 @@
$(function() {
$.getJSON("/api/usercount", function(data, textStatus, jqXHR) {
var offset = new Date().getTimezoneOffset();
var newData = [];
for (var i = 0; i < data.datapoints.length; i++) {
var date = moment(data.datapoints[i].at).unix() - offset * 60;
var value = parseFloat(data.datapoints[i].value);
newData.push({x: date, y: value});
}
var graph = new Rickshaw.Graph( {
element: document.querySelector("#graph"),
renderer: 'bar',
series: [ {
data: newData,
name: 'Benutzer',
color: 'steelblue'
} ]
} );
new Rickshaw.Graph.Axis.Time({graph: graph}).render();
new Rickshaw.Graph.Axis.Y({graph: graph}).render();
graph.render();
});
});

File diff suppressed because one or more lines are too long

2
node/public/js/vendor/d3.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

6
node/public/js/vendor/moment.min.js vendored Normal file

File diff suppressed because one or more lines are too long

3388
node/public/js/vendor/rickshaw.js vendored Normal file

File diff suppressed because it is too large Load Diff

2
node/public/js/vendor/rickshaw.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -4,39 +4,36 @@ var express = require('express'),
server = require('http').createServer(app), server = require('http').createServer(app),
io = require('socket.io').listen(server); io = require('socket.io').listen(server);
var flash = require('connect-flash'); var flash = require('connect-flash');
var moment = require('moment');
var SnmpMac = require("./snmp-mac"); var SnmpMac = require("./snmp-mac");
var IpPoll = require("./ip-poll"); var IpPoll = require("./ip-poll");
var routes = require("./routes"); var routes = require("./routes");
var spaceanswer = { var spaceanswer = {
"api": "0.13", api: "0.13",
"space": "Chaostreff Dortmund", space: "Chaostreff Dortmund",
"logo": "http://www.chaostreff-dortmund.de/logo.jpg", logo: "http://www.chaostreff-dortmund.de/logo.jpg",
"url": "http://www.chaostreff-dortmund.de/", url: "http://www.chaostreff-dortmund.de/",
"location": { location: {
"address": "Braunschweiger Str 22, 44145 Dortmund, Germany", address: "Braunschweiger Str 22, 44145 Dortmund, Germany",
"lon": 7.4649449, lon: 7.4649449,
"lat": 51.527611 lat: 51.527611
}, },
"contact": { contact: {
"phone": "+49231 8 404 777", phone: "+49231 8 404 777",
"irc": "irc://irc.hackint.eu/#ctdo", irc: "irc://irc.hackint.eu/#ctdo",
"ml": "ccc@chaostreff-dortmund.de", ml: "ccc@chaostreff-dortmund.de",
"twitter": "@ctdo", twitter: "@ctdo",
"issue_mail": "server-admin@chaostreff-dortmund.de" issue_mail: "server-admin@chaostreff-dortmund.de"
}, },
"issue_report_channels": [ "issue_email" ], issue_report_channels: [ "issue_email" ],
"state": { state: {
"open": null, open: null,
"lastchange": 0 lastchange: 0
} }
}; };
var simpleanswer = { state: "unknown", count: 0, names: [], lastchange: 0 };
var simpleanswer = { "state": "unknown", var usercountanswer = { at: 0, current_value: 0, datapoints: [ { at : 0, value: 0 } ]};
"count": 0,
"names": [],
"lastchange": 0
};
var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23"); var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.20-62 195.160.169.70-126"); var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.20-62 195.160.169.70-126");
@ -49,7 +46,7 @@ snmpMac.on('done', function (res) {
ippoll.on('doneCount', function (num) { ippoll.on('doneCount', function (num) {
simpleanswer.count = num; simpleanswer.count = num;
simpleanswer.lastchange = new Date(); simpleanswer.lastchange = new Date();
io.sockets.emit('sdata', { "data": simpleanswer }); io.sockets.emit('sdata', { data: simpleanswer });
}); });
ippoll.on('doneState', function (state) { ippoll.on('doneState', function (state) {
@ -58,7 +55,7 @@ ippoll.on('doneState', function (state) {
simpleanswer.state = state; simpleanswer.state = state;
simpleanswer.lastchange = spaceanswer.state.lastchange; simpleanswer.lastchange = spaceanswer.state.lastchange;
io.sockets.emit('sdata', { "data": simpleanswer }); io.sockets.emit('sdata', { data: simpleanswer });
}); });
io.configure(function () { io.configure(function () {
@ -70,6 +67,7 @@ function work() {
snmpMac.poll(); snmpMac.poll();
ippoll.pollCount(); ippoll.pollCount();
ippoll.pollState(); ippoll.pollState();
// simpleanswer.names.length = 0; // simpleanswer.names.length = 0;
// for(var i=0;i<4+Math.random() * 100;i++) { // for(var i=0;i<4+Math.random() * 100;i++) {
// simpleanswer.names.push("nickname"+i); // simpleanswer.names.push("nickname"+i);
@ -102,6 +100,20 @@ app.get('/api/spaceapi/v13', function (req, res) {
app.get('/api/simple/v2', function (req, res) { app.get('/api/simple/v2', function (req, res) {
res.send(simpleanswer); res.send(simpleanswer);
}); });
app.get('/api/usercount', function (req, res) {
//TODO: respect query params "start", "end", "interval" (s) and "limit" (like Xively)
// maybe skip "interval" if code gets too complex :)
usercountanswer.datapoints.length = 0;
usercountanswer.at = simpleanswer.lastchange;
usercountanswer.current_value = simpleanswer.count;
for(var i=100; i > 0;i--) {
usercountanswer.datapoints.push( { at: moment().subtract("minute", i), value: parseInt(Math.random()*20) } );
}
res.send(usercountanswer);
});
app.get('/db', routes.db); app.get('/db', routes.db);
app.post('/form', routes.form); app.post('/form', routes.form);

View File

@ -22,7 +22,7 @@ block content
.control-group.required.validation .control-group.required.validation
label(for='label') Label (Nickname) label(for='label') Label (Nickname)
.control .control
input(id='label',type='text',value='',placeholder='',name='label').ink-fv-required input(id='label',type='text',value='',placeholder='',name='label')
fieldset.column-group.gutters fieldset.column-group.gutters
.control-group.large-50.medium-50.small-100 .control-group.large-50.medium-50.small-100
@ -38,4 +38,8 @@ block content
.control .control
button(id='sndbtn').ink-button Mach es button(id='sndbtn').ink-button Mach es
.status #{status} .status #{status}
block scripts
script(type="text/javascript",src="/js/vendor/ink.formvalidator.js")
script(type="text/javascript",src="/js/vendor/ink-ui.min.js")

View File

@ -22,12 +22,23 @@ block content
.large-80.small-100 .large-80.small-100
dl h2 Anzahl Geräte:
dt Personen Anwesend:
dd
span(ng-repeat="name in simple.names")
{{name}}
span(ng-show=" ! $last ") #graph
| , <!-- -->
h2 Personen Anwesend:
span(ng-repeat="name in simple.names")
{{name}}
span(ng-show=" ! $last ")
| , <!-- -->
block scripts
script(type="text/javascript",src="/js/vendor/d3.min.js")
script(type="text/javascript",src="/js/vendor/d3.layout.min.js")
script(type="text/javascript",src="/js/vendor/rickshaw.min.js")
script(type="text/javascript",src="/js/vendor/moment.min.js")
script(type="text/javascript",src="/js/graph.js")

View File

@ -9,6 +9,7 @@ html(ng-app="roomstateapp")
script(type="text/javascript",src="/socket.io/socket.io.js") script(type="text/javascript",src="/socket.io/socket.io.js")
link(rel='stylesheet', href='/css/ink-min.css') link(rel='stylesheet', href='/css/ink-min.css')
link(rel='stylesheet', href='/css/rickshaw.min.css')
link(rel='stylesheet', href='/css/style.css') link(rel='stylesheet', href='/css/style.css')
body body
@ -25,7 +26,7 @@ html(ng-app="roomstateapp")
nav.ink-navigation nav.ink-navigation
ul.menu.horizontal ul.menu.horizontal
li: a(href="/") Raumstatus li: a(href="/") Raumstatus
li: a(href='/db') Manage MAC Addresses li: a(href='/db') Name Verwalten
li: a(href="//www.chaostreff-dortmund.de/") CTDO Webseite li: a(href="//www.chaostreff-dortmund.de/") CTDO Webseite
li: a(href="//wiki.ctdo.de/") CTDO Wiki li: a(href="//wiki.ctdo.de/") CTDO Wiki
li: a(href="http://repos.ctdo.de/git/?p=raumstatus.git;a=summary") Source li: a(href="http://repos.ctdo.de/git/?p=raumstatus.git;a=summary") Source
@ -33,11 +34,12 @@ html(ng-app="roomstateapp")
script(type="text/javascript",src="/js/vendor/jquery-1.9.1.min.js")
script(type="text/javascript",src="/js/vendor/ink.min.js") script(type="text/javascript",src="/js/vendor/ink.min.js")
script(type="text/javascript",src="/js/vendor/autoload.js") script(type="text/javascript",src="/js/vendor/autoload.js")
script(type="text/javascript",src="/js/vendor/html5shiv.js") script(type="text/javascript",src="/js/vendor/html5shiv.js")
script(type="text/javascript",src="/js/vendor/ink.formvalidator.js")
script(type="text/javascript",src="/js/vendor/ink-ui.min.js")
//script(type="text/javascript",src="/js/vendor/prettify.js") //script(type="text/javascript",src="/js/vendor/prettify.js")
//script(type="text/javascript",src="/js/vendor/modernizr.js") //script(type="text/javascript",src="/js/vendor/modernizr.js")
script(type="text/javascript",src="/js/app.js") script(type="text/javascript",src="/js/app.js")
block scripts