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);

View File

@ -4,13 +4,14 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.*",
"express": "3.4",
"connect-flash": "0.1.1",
"net-snmp": "*",
"redis": "*",
"underscore": "*",
"jade": "*",
"socket.io": "*"
"net-snmp": "1.1.8",
"redis": "0.8.5",
"underscore": "1.5.2",
"jade": "0.35",
"socket.io": "0.9.16",
"moment": "2.3.1"
},
"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");
}
.members {
margin-top: 8pt;
/*padding: 0;*/
h2 {
font-weight: bold;
color: #555;
font-size: 13pt;
margin-bottom: 0.7em;
}
#graph {
max-width: 400px;
height: 200px;
margin-top: 0;
}

View File

@ -62,3 +62,6 @@ angular.module('roomstateapp.statusfilter', []).filter('statustostring', functio
});
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),
io = require('socket.io').listen(server);
var flash = require('connect-flash');
var moment = require('moment');
var SnmpMac = require("./snmp-mac");
var IpPoll = require("./ip-poll");
var routes = require("./routes");
var spaceanswer = {
"api": "0.13",
"space": "Chaostreff Dortmund",
"logo": "http://www.chaostreff-dortmund.de/logo.jpg",
"url": "http://www.chaostreff-dortmund.de/",
"location": {
"address": "Braunschweiger Str 22, 44145 Dortmund, Germany",
"lon": 7.4649449,
"lat": 51.527611
api: "0.13",
space: "Chaostreff Dortmund",
logo: "http://www.chaostreff-dortmund.de/logo.jpg",
url: "http://www.chaostreff-dortmund.de/",
location: {
address: "Braunschweiger Str 22, 44145 Dortmund, Germany",
lon: 7.4649449,
lat: 51.527611
},
"contact": {
"phone": "+49231 8 404 777",
"irc": "irc://irc.hackint.eu/#ctdo",
"ml": "ccc@chaostreff-dortmund.de",
"twitter": "@ctdo",
"issue_mail": "server-admin@chaostreff-dortmund.de"
contact: {
phone: "+49231 8 404 777",
irc: "irc://irc.hackint.eu/#ctdo",
ml: "ccc@chaostreff-dortmund.de",
twitter: "@ctdo",
issue_mail: "server-admin@chaostreff-dortmund.de"
},
"issue_report_channels": [ "issue_email" ],
"state": {
"open": null,
"lastchange": 0
issue_report_channels: [ "issue_email" ],
state: {
open: null,
lastchange: 0
}
};
var simpleanswer = { "state": "unknown",
"count": 0,
"names": [],
"lastchange": 0
};
var simpleanswer = { state: "unknown", count: 0, names: [], lastchange: 0 };
var usercountanswer = { at: 0, current_value: 0, datapoints: [ { at : 0, value: 0 } ]};
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");
@ -49,7 +46,7 @@ snmpMac.on('done', function (res) {
ippoll.on('doneCount', function (num) {
simpleanswer.count = num;
simpleanswer.lastchange = new Date();
io.sockets.emit('sdata', { "data": simpleanswer });
io.sockets.emit('sdata', { data: simpleanswer });
});
ippoll.on('doneState', function (state) {
@ -58,7 +55,7 @@ ippoll.on('doneState', function (state) {
simpleanswer.state = state;
simpleanswer.lastchange = spaceanswer.state.lastchange;
io.sockets.emit('sdata', { "data": simpleanswer });
io.sockets.emit('sdata', { data: simpleanswer });
});
io.configure(function () {
@ -70,6 +67,7 @@ function work() {
snmpMac.poll();
ippoll.pollCount();
ippoll.pollState();
// simpleanswer.names.length = 0;
// for(var i=0;i<4+Math.random() * 100;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) {
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.post('/form', routes.form);

View File

@ -22,7 +22,7 @@ block content
.control-group.required.validation
label(for='label') Label (Nickname)
.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
.control-group.large-50.medium-50.small-100
@ -39,3 +39,7 @@ block content
button(id='sndbtn').ink-button Mach es
.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
dl
dt Personen Anwesend:
dd
span(ng-repeat="name in simple.names")
{{name}}
h2 Anzahl Geräte:
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")
link(rel='stylesheet', href='/css/ink-min.css')
link(rel='stylesheet', href='/css/rickshaw.min.css')
link(rel='stylesheet', href='/css/style.css')
body
@ -25,7 +26,7 @@ html(ng-app="roomstateapp")
nav.ink-navigation
ul.menu.horizontal
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="//wiki.ctdo.de/") CTDO Wiki
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/autoload.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/modernizr.js")
script(type="text/javascript",src="/js/app.js")
block scripts