Added run status for previous 24 hours
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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": "<strong>" + statusData[i].status +"</strong>"},
|
||||
{"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();
|
||||
});
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div google-chart chart="timelineData"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
<div ng-if="dateListLoading" class="well"><img src="/img/loading.gif" /></div>
|
||||
@@ -19,6 +22,7 @@
|
||||
</ul>
|
||||
|
||||
<h1 style="text-align:center;">Dashboard - Stroke {{cardData.Card_ID}}</h1>
|
||||
|
||||
<div style="text-align:center;"><button class="btn btn-primary active" id="refreshButton" ng-click="dashboard()">Refresh Data</button></div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
<script src='/bower_components/raphael/raphael-min.js'></script>
|
||||
<script src='/bower_components/justgage-toorshia/justgage.js'></script>
|
||||
<script src='/bower_components/angular-justgage/ng-justgage.js'></script>
|
||||
<script src="/node_modules/n3-charts/node_modules/d3/d3.min.js"></script>
|
||||
<script src="/node_modules/n3-charts/build/LineChart.js"></script>
|
||||
<script src='/bower_components/angular-google-chart/ng-google-chart.js'></script>
|
||||
<script src='/node_modules/d3/d3.min.js'></script>
|
||||
<script src='/node_modules/n3-charts/build/LineChart.js'></script>
|
||||
<link rel="stylesheet" href="/node_modules/n3-charts/build/LineChart.css">
|
||||
|
||||
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user