Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getHistory moved to helper script.

  • Loading branch information...
commit 77ac6ea1b84efc95187219f2adc5bb7000c7b998 1 parent f98944f
@ahw authored
View
67 routes/helpers.js
@@ -0,0 +1,67 @@
+module.exports = function(app) {
+
+ getHistory = function(callback, startTime, endTime) {
+
+ var startTime = startTime ? startTime : 0;
+ var endTime = endTime ? endTime : 0;
+
+ var multi = db.multi();
+ multi.zrevrank(TIMESTAMPS, endTime);
+ multi.zrevrank(TIMESTAMPS, startTime);
+
+ multi.exec(function(error, replies) {
+ var startIndex = replies[0] ? replies[0] : 0;
+ var limit = replies[1] ? (replies[1] - startIndex) + 1 : -1;
+
+ // TODO Remove
+ console.log('History starting at = ' + startIndex);
+ console.log('History limiting to = ' + limit + ' results');
+
+ var history = [];
+ db.sort(TIMESTAMPS,
+ 'LIMIT', startIndex, limit,
+ 'DESC',
+ 'GET', '#',
+ 'GET', 'event:*->name',
+ 'GET', 'event:*->start',
+ 'GET', 'event:*->duration',
+ function(error, reply) {
+
+ for (var i = 0; i < (reply.length / 4); i++) {
+ var name = reply[4 * i + 1];
+ var start = parseInt(reply[4 * i + 2]);
+ var durationMillis = parseInt(reply[4 * i + 3]);
+ // Use MomentJS to format the start time to human-friendly.
+ var m = moment(start);
+ var startFormatted = m.format('ddd MMM Do, h:mm:ss a');
+ var durationHumanized;
+ if (durationMillis) {
+ durationHumanized = moment.duration(durationMillis, 'milliseconds').humanize(); // Thank you, MomentJS!
+ } else {
+ durationHumanized = 'Ongoing...';
+ }
+ history.push({
+ name : name,
+ duration : {
+ humanized : durationHumanized,
+ millis : durationMillis
+ },
+ start : {
+ millis : start,
+ formatted : startFormatted,
+ day : m.format('dddd'),
+ month : m.format('MMM'),
+ date : m.format('Do'),
+ hour : m.format('h'),
+ minute : m.format('mm'),
+ second : m.format('ss'),
+ amPm : m.format('a')
+ }
+ });
+ }
+ callback(history);
+ });
+ });
+ };
+
+}
View
64 routes/history.js
@@ -1,69 +1,5 @@
module.exports = function(app) {
- var getHistory = function(callback, startTime, endTime) {
-
- var startTime = startTime ? startTime : 0;
- var endTime = endTime ? endTime : 0;
-
- var multi = db.multi();
- multi.zrevrank(TIMESTAMPS, endTime);
- multi.zrevrank(TIMESTAMPS, startTime);
-
- multi.exec(function(error, replies) {
- var startIndex = replies[0] ? replies[0] : 0;
- var limit = replies[1] ? (replies[1] - startIndex) + 1 : -1;
-
- // TODO Remove
- console.log('GET /history starting at = ' + startIndex);
- console.log('GET /history limiting to = ' + limit + ' results');
-
- var history = [];
- db.sort(TIMESTAMPS,
- 'LIMIT', startIndex, limit,
- 'DESC',
- 'GET', '#',
- 'GET', 'event:*->name',
- 'GET', 'event:*->start',
- 'GET', 'event:*->duration',
- function(error, reply) {
-
- for (var i = 0; i < (reply.length / 4); i++) {
- var name = reply[4 * i + 1];
- var start = parseInt(reply[4 * i + 2]);
- var durationMillis = parseInt(reply[4 * i + 3]);
- // Use MomentJS to format the start time to human-friendly.
- var m = moment(start);
- var startFormatted = m.format('ddd MMM Do, h:mm:ss a');
- var durationHumanized;
- if (durationMillis) {
- durationHumanized = moment.duration(durationMillis, 'milliseconds').humanize(); // Thank you, MomentJS!
- } else {
- durationHumanized = 'Ongoing...';
- }
- history.push({
- name : name,
- duration : {
- humanized : durationHumanized,
- millis : durationMillis
- },
- start : {
- millis : start,
- formatted : startFormatted,
- day : m.format('dddd'),
- month : m.format('MMM'),
- date : m.format('Do'),
- hour : m.format('h'),
- minute : m.format('mm'),
- second : m.format('ss'),
- amPm : m.format('a')
- }
- });
- }
- callback(history);
- });
- });
- };
-
app.get('/history/:timestamp?', function(req, res) {
var startTime = req.params.timestamp ? req.params.timestamp : null;
View
61 routes/visualize.js
@@ -1,70 +1,11 @@
module.exports = function(app) {
- var getHistory = function(callback, startTime, endTime) {
-
- var startTime = startTime ? startTime : 0;
- var endTime = endTime ? endTime : 0;
-
- var multi = db.multi();
- multi.zrevrank(TIMESTAMPS, endTime);
- multi.zrevrank(TIMESTAMPS, startTime);
-
- multi.exec(function(error, replies) {
- var startIndex = replies[0] ? replies[0] : 0;
- var limit = replies[1] ? (replies[1] - startIndex) + 1 : -1;
-
- // TODO Remove
- console.log('GET /history starting at = ' + startIndex);
- console.log('GET /history limiting to = ' + limit + ' results');
-
- var history = [];
- db.sort(TIMESTAMPS,
- 'LIMIT', startIndex, limit,
- 'DESC',
- 'GET', '#',
- 'GET', 'event:*->name',
- 'GET', 'event:*->start',
- 'GET', 'event:*->duration',
- function(error, reply) {
-
- for (var i = 0; i < (reply.length / 4); i++) {
- var name = reply[4 * i + 1];
- var start = parseInt(reply[4 * i + 2]);
- var duration = parseInt(reply[4 * i + 3]);
- // Use MomentJS to format the start time to human-friendly.
- var m = moment(start);
- var timeFormatted = m.format('ddd MMM Do, h:mm:ss a');
- var durationString;
- if (duration) {
- durationString = moment.duration(duration, 'milliseconds').humanize(); // Thank you, MomentJS!
- } else {
- durationString = 'Ongoing...';
- }
- history.push({
- name : name,
- start : start,
- durationString : durationString,
- duration : duration,
- timeFormatted : timeFormatted,
- timeDay : m.format('dddd'),
- timeMonth : m.format('MMM'),
- timeDate : m.format('Do'),
- timeHour : m.format('h'),
- timeMinute : m.format('mm'),
- timeSecond : m.format('ss'),
- timeAmPm : m.format('a')
- });
- }
- callback(history);
- });
- });
- };
-
app.get('/visualize/stack', function(req, res) {
getHistory(function(history) {
var context = { history : history };
res.render('stack', context);
+ // res.json(history);
});
});
View
21 start-and-watch-server
@@ -1,21 +1,22 @@
#!/bin/bash
-node app.js &
-OLD_CONTENTS=`cat *.js`
-NEW_CONTENTS=`cat *.js`
+forever restart app.js
+OLD_CONTENTS=`cat *.js */*.js`
+NEW_CONTENTS=`cat *.js */*.js`
while [ true ]
do
- NEW_CONTENTS=`cat *.js`
+ NEW_CONTENTS=`cat *.js */*.js`
if [ "$OLD_CONTENTS" != "$NEW_CONTENTS" ]; then
# Assert: code has changed. Bounce server.
OLD_CONTENTS=$NEW_CONTENTS
echo "Bouncing server..."
- PID=`ps -a | grep node | grep -o \\[0-9\\]\\\+ | head -1`
- kill $PID
- node app.js &
- PID=`ps -a | grep node | grep -o \\[0-9\\]\\\+ | head -1`
- echo "PID = ${PID}"
+ forever restart app.js
+ # PID=`ps -a | grep node | grep -o \\[0-9\\]\\\+ | head -1`
+ # kill $PID
+ # node app.js &
+ # PID=`ps -a | grep node | grep -o \\[0-9\\]\\\+ | head -1`
+ # echo "PID = ${PID}"
fi
- sleep 1
+ sleep 5
done
View
12 views/stack.jade
@@ -12,10 +12,10 @@ block content
div.left-column(style="float:left; width:50%; display:block")
each item in history
- var scale;
- - if (item.duration) {
- - scale = parseInt(item.duration) / (24 * 60 * 60 * 1000);
+ - if (item.duration.millis) {
+ - scale = parseInt(item.duration.millis) / (24 * 60 * 60 * 1000);
- } else {
- - scale = (Date.now() - item.start) / (24 * 60 * 60 * 1000);
+ - scale = (Date.now() - item.start.millis) / (24 * 60 * 60 * 1000);
- }
- var scaledHeight = scale * 1000;
- var isEmpty = item.name == 'stop' || item.name == 'not:previous'? true : false;
@@ -27,10 +27,10 @@ block content
div.right-column(style="float:left; width:48%; padding:0 1%; display:block")
each item in history
- var scale;
- - if (item.duration) {
- - scale = parseInt(item.duration) / (24 * 60 * 60 * 1000);
+ - if (item.duration.millis) {
+ - scale = parseInt(item.duration.millis) / (24 * 60 * 60 * 1000);
- } else {
- - scale = (Date.now() - item.start) / (24 * 60 * 60 * 1000);
+ - scale = (Date.now() - item.start.millis) / (24 * 60 * 60 * 1000);
- }
- var scaledHeight = scale * 1000;
- var isEmpty = item.name == 'stop' || item.name == 'not:previous'? true : false;
View
7 views/visualize.jade
@@ -0,0 +1,7 @@
+extends layout
+
+block content
+ h1
+ a(href='/visualize') visualize
+ /
+ a(href='/visualize/stack') stack
Please sign in to comment.
Something went wrong with that request. Please try again.