From be830d953125dd7f627e4a582c334f7160644afe Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Thu, 31 Mar 2016 14:53:01 -0500 Subject: [PATCH] Added run status for previous 24 hours --- bower.json | 3 +- public/js/controllers.js | 102 ++++++++++++++++++++++++++++++--- public/partials/dashboard.html | 4 ++ routes/json_sqlite.coffee | 5 +- views/angularIndex.html | 5 +- 5 files changed, 106 insertions(+), 13 deletions(-) diff --git a/bower.json b/bower.json index dc5e8f3..c7c7499 100644 --- a/bower.json +++ b/bower.json @@ -31,8 +31,7 @@ "ngQuickDate": "^1.3.4", "angular-animate-css": "ng-animate-css#^0.0.4", "angular-bootstrap": "^1.2.5", - "angular-google-chart":"*" - + "angular-google-chart": "angular-google-charts#^0.0.11" }, "resolutions": { "angular": "^1.5.2" diff --git a/public/js/controllers.js b/public/js/controllers.js index c260337..5ba614b 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -575,6 +575,86 @@ wellCtrls.factory('multipleCards', function() { }; }); +wellCtrls.factory('statusTimeline', function($q, $http){ + var getStatusBetween = function(sDateTime, eDateTime){ + var deferred = $q.defer(); + $http.get('/json/status/' + sDateTime + "/" + eDateTime).success(function(data) { + + if (data.status == "OK"){ + if (data.run_status.length > 1){ + var run_statuses = data.run_status; + var uniqueRunStatuses = [run_statuses[0]]; + for (var i = 1; i < run_statuses.length; i++){ + if (uniqueRunStatuses.slice(-1)[0].status != run_statuses[i].status){ + uniqueRunStatuses.push(run_statuses[i]); + } + } + for (var j = 0; j < uniqueRunStatuses.length - 1; j++){ + uniqueRunStatuses[j].end_dtime = uniqueRunStatuses[j+1].dtime; + } + deferred.resolve(uniqueRunStatuses); + } + } + }); + return deferred.promise; + }; + + var prepareTimelineData = function(sDateTime, eDateTime){ + var deferred = $q.defer(); + var getData = getStatusBetween(sDateTime, eDateTime); + getData.then(function(d){ + var statusData = d; + var timelineData = { + "cssStyle" : "height:300px;width:100%;", + "type": "Timeline", + "data": { + "cols": [ + {type: 'string', id: 'Run Status'}, + {type: 'string', id: 'Bar Label'}, + // {type: 'string', role: 'tooltip', p: {'html': true}}, + {type: 'date', id: 'Start'}, + {type: 'date', id: 'End'} + ], + "rows": [], + }, + "options" : { + timeline: { + //singleColor: '#00f', + colorByRowLabel: false, + groupByRowLabel: true, + // rowLabelStyle: {fontName: 'Helvetica', fontSize: 14, color: '#442' }, + // barLabelStyle: { fontName: 'Garamond', fontSize: 14 } + }, + backgroundColor: '#ffffff', + tooltip: { + isHtml: true + } + } + }; + if (statusData.length > 0){ + statusData.slice(-1)[0].end_dtime = eDateTime; + for (var i=0; i < statusData.length; i++){ + timelineData.data.rows.push({ + c:[ + {"v": statusData[i].status}, + {"v": statusData[i].status}, + // {"v": "" + statusData[i].status +""}, + {"v": new Date(statusData[i].dtime * 1000)}, + {"v": new Date(statusData[i].end_dtime * 1000)} + ] + }); + } + deferred.resolve(timelineData); + } + }); + return deferred.promise; + }; + return { + prepareTimelineData: prepareTimelineData + }; + +}); + wellCtrls.factory('tags', function($q, $http) { return { set: function(tag,value) { @@ -726,7 +806,7 @@ wellCtrls.controller('fileListTodayCtrl', function($scope, $http, $routeParams, }; }); -wellCtrls.controller('dashboardCtrl', function($scope, $route, $http, $routeParams, json, Page, Alerts, $log) { +wellCtrls.controller('dashboardCtrl', function($scope, $route, $http, $routeParams, json, Page, Alerts, $log, statusTimeline) { Page.setTitle('Dashboard'); Page.setPage('dashboard'); $scope.dateListLoading = true; @@ -748,12 +828,20 @@ wellCtrls.controller('dashboardCtrl', function($scope, $route, $http, $routePara } }); + var now = Date.now() / 1000; + var earlier = now - (24 * 60 * 60); + var gettimelineData = statusTimeline.prepareTimelineData(earlier, now); + gettimelineData.then(function(tData){ + console.log(tData); + $scope.timelineData = tData; + }); + + + var getCurrentStatus = json.getCurrentStatus(); getCurrentStatus.then(function(s){ var sData = s.data; sData.datetime = new Date(sData.datetime * 1000); - console.log(sData); - $scope.status = sData.run_status; $scope.status_datetime = new Date(sData.datetime); }); @@ -784,10 +872,10 @@ wellCtrls.controller('dashboardCtrl', function($scope, $route, $http, $routePara $scope.downholeOptions = graphOptions.down; }); - var getTotals = json.getTotals(); - getTotals.then(function(data){ - $scope.totals = data.totals; - }); + // var getTotals = json.getTotals(); + // getTotals.then(function(data){ + // $scope.totals = data.totals; + // }); }; $scope.dashboard(); }); diff --git a/public/partials/dashboard.html b/public/partials/dashboard.html index f4058ba..ba433f7 100644 --- a/public/partials/dashboard.html +++ b/public/partials/dashboard.html @@ -1,4 +1,7 @@
+
+
+
@@ -19,6 +22,7 @@

Dashboard - Stroke {{cardData.Card_ID}}

+
diff --git a/routes/json_sqlite.coffee b/routes/json_sqlite.coffee index 80fd567..b95052c 100644 --- a/routes/json_sqlite.coffee +++ b/routes/json_sqlite.coffee @@ -1,5 +1,6 @@ fileLocation = '/mnt/usb' dbFile = '/mnt/usb/data.db' +# dbFile = '/Users/patrickjmcd/Desktop/data.db' # HELPER FUNCTIONS pad = (num) -> @@ -1372,9 +1373,9 @@ exports.statusBetween = (req, res) -> sqlite3 = require('sqlite3').verbose() db = new sqlite3.Database(dbFile) db.serialize ()-> - query = "SELECT * FROM run_status WHERE dtime => ? AND dtme <= ?" + query = "SELECT * FROM run_status WHERE dtime >= ? AND dtime <= ?" prepQuery = db.prepare(query) - prepQuery.all req.params.startDTime, req.params.endDTime, (err, rows) -> + prepQuery.all req.params.startDTime, endDTime, (err, rows) -> prepQuery.finalize() db.close() if err diff --git a/views/angularIndex.html b/views/angularIndex.html index df43dec..fb9358e 100644 --- a/views/angularIndex.html +++ b/views/angularIndex.html @@ -15,8 +15,9 @@ - - + + +