From a9e9a28989c5f115b99530b45874357d89b0781d Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Fri, 18 Nov 2016 18:11:22 -0600 Subject: [PATCH] just kidding, it was working. adds a totals page --- app/datalogger/getDailyTotals.py | 40 +++++++++++++-------------- app/static/js/dashboard.controller.js | 15 +++++++++- app/static/js/router.js | 3 ++ app/static/js/tags.factory.js | 8 ++++++ app/static/templates/dashboard.html | 7 +++++ app/static/templates/totals.html | 31 +++++++++++++++++++++ 6 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 app/static/templates/totals.html diff --git a/app/datalogger/getDailyTotals.py b/app/datalogger/getDailyTotals.py index b3b4d16..69c7691 100644 --- a/app/datalogger/getDailyTotals.py +++ b/app/datalogger/getDailyTotals.py @@ -24,35 +24,33 @@ def readTag(addr, tag): def getTotals(): today_tags = [ - {'name':"Average SPM",'tag':"TODAY_Average_SPM"}, - {'name':"Downhole Net Stroke",'tag':"TODAY_Downhole_NetStroke"}, - {'name':"Electricity Cost",'tag':"TODAY_Electricity_Cost"}, - {'name':"Fluid Level",'tag':"TODAY_Fluid_Above_Pump"}, - {'name':"Inflow Rate",'tag':"TODAY_Inflow_Rate"}, - {'name':"kWh",'tag':"TODAY_kWh"}, - {'name':"kWh Regen",'tag':"TODAY_kWh_Regen"}, - {'name':"Lifting Cost",'tag':"TODAY_Lifting_Cost"}, - {'name':"Peak Load",'tag':"TODAY_Max_Load"}, - {'name':"Min Load",'tag':"TODAY_Min_Load"}, - {'name':"Percent Run",'tag':"TODAY_Percent_Run"}, - {'name':"Polished Rod HP",'tag':"TODAY_Polished_Rod_HP"}, - {'name':"Calculated Production",'tag':"TODAY_Production_Calculated"}, - {'name':"Projected Production",'tag':"TODAY_Production_Projected"}, - {'name':"Pump HP",'tag':"TODAY_Pump_HP"}, - {'name':"Pump Intake Presure",'tag':"TODAY_Pump_Intake_Pressure"}, - {'name':"Surface Stroke Length",'tag':"TODAY_Surface_StrokeLength"}, - {'name':"Tubing Movement",'tag':"TODAY_Tubing_Movement"} + {'name':"Average SPM",'tag':"TODAY_Average_SPM", 'min':0, 'max': 20, 'units':'PSI'}, + {'name':"Downhole Net Stroke",'tag':"TODAY_Downhole_NetStroke", 'min':0, 'max':150, 'units':'PSI'}, + {'name':"Electricity Cost",'tag':"TODAY_Electricity_Cost", 'min':0, 'max':100, 'units':'PSI'}, + {'name':"Fluid Level",'tag':"TODAY_Fluid_Above_Pump", 'min':0, 'max':10000, 'units':'PSI'}, + {'name':"Inflow Rate",'tag':"TODAY_Inflow_Rate", 'min':0, 'max':100, 'units':'PSI'}, + {'name':"kWh",'tag':"TODAY_kWh", 'min':0, 'max':100, 'units':'PSI'}, + {'name':"kWh Regen",'tag':"TODAY_kWh_Regen", 'min':0, 'max':100, 'units':'PSI'}, + {'name':"Lifting Cost",'tag':"TODAY_Lifting_Cost", 'min':0, 'max':100, 'units':'PSI'}, + {'name':"Peak Load",'tag':"TODAY_Max_Load", 'min':0, 'max':50000, 'units':'PSI'}, + {'name':"Min Load",'tag':"TODAY_Min_Load", 'min':0, 'max':50000, 'units':'PSI'}, + {'name':"Percent Run",'tag':"TODAY_Percent_Run", 'min':0, 'max':100, 'units':'PSI'}, + {'name':"Polished Rod HP",'tag':"TODAY_Polished_Rod_HP", 'min':0, 'max':25, 'units':'PSI'}, + {'name':"Calculated Production",'tag':"TODAY_Production_Calculated", 'min':0, 'max':500, 'units':'PSI'}, + {'name':"Projected Production",'tag':"TODAY_Production_Projected", 'min':0, 'max':500, 'units':'PSI'}, + {'name':"Pump HP",'tag':"TODAY_Pump_HP", 'min':0, 'max':25, 'units':'PSI'}, + {'name':"Pump Intake Presure",'tag':"TODAY_Pump_Intake_Pressure", 'min':0, 'max':5000, 'units':'PSI'}, + {'name':"Surface Stroke Length",'tag':"TODAY_Surface_StrokeLength", 'min':0, 'max':150, 'units':'PSI'}, + {'name':"Tubing Movement",'tag':"TODAY_Tubing_Movement", 'min':0, 'max':150, 'units':'PSI'} ] main_plc = getMainPLC() - print("PLC IP ADDRESS = {}".format(main_plc['address'])) outList = [] for tag in today_tags: try: val = readTag(main_plc['address'], tag['tag'])[0] - print("READING {}: {}".format(tag['tag'], val)) if not math.isnan(val): - outList.append({'name':tag['name'], 'value':val}) + outList.append({'name':tag['name'], 'value':val, 'max':tag['max'], 'min': tag['min'], 'units': tag['units']}) except Exception as e: print("Error while reading total: {}".format(e)) diff --git a/app/static/js/dashboard.controller.js b/app/static/js/dashboard.controller.js index 5534b91..f6e2284 100644 --- a/app/static/js/dashboard.controller.js +++ b/app/static/js/dashboard.controller.js @@ -1,5 +1,4 @@ poconsole.controller('dashboardCtrl', function($scope, $route, $http, Page, $log, Tag) { - $log.info("Opened Dashboard"); Page.setTitle('Dashboard'); Page.setPage('dashboard'); $scope.loadDashboard = function(){ @@ -35,3 +34,17 @@ poconsole.controller('dashboardCtrl', function($scope, $route, $http, Page, $log }); + +poconsole.controller('todaysTotalsCtrl', function($scope, $route, $http, Page, $log, Tag) { + Page.setTitle('Totals'); + Page.setPage('dashboard'); + $scope.loadTotals = function(){ + $scope.loading = true; + var getTodayTotals = Tag.getDailyTotals(); + getTodayTotals.then(function(d){ + $scope.loading = false; + $scope.total_values = d; + }); + }; + $scope.loadTotals(); +}); diff --git a/app/static/js/router.js b/app/static/js/router.js index c14a59b..c5b2089 100644 --- a/app/static/js/router.js +++ b/app/static/js/router.js @@ -34,6 +34,9 @@ tagserver.config([ }).when('/notes', { templateUrl: '/templates/notes.html', controller: 'notesCtrl' + }).when('/totals', { + templateUrl: '/templates/totals.html', + controller: 'todaysTotalsCtrl' }).when('/', { templateUrl: '/templates/dashboard.html', controller: 'dashboardCtrl' diff --git a/app/static/js/tags.factory.js b/app/static/js/tags.factory.js index af15dc5..3ee0488 100644 --- a/app/static/js/tags.factory.js +++ b/app/static/js/tags.factory.js @@ -145,5 +145,13 @@ poconsole.factory('Tag',function($q, $http, $log, dateConversion){ return deferred.promise; }; + service.getDailyTotals = function(){ + var deferred = $q.defer(); + $http.get('/api/today_totals').success(function(data) { + deferred.resolve(data); + }); + return deferred.promise; + }; + return service; }); diff --git a/app/static/templates/dashboard.html b/app/static/templates/dashboard.html index e058819..1287b15 100644 --- a/app/static/templates/dashboard.html +++ b/app/static/templates/dashboard.html @@ -19,7 +19,14 @@
+
+ +
Download All Data
diff --git a/app/static/templates/totals.html b/app/static/templates/totals.html new file mode 100644 index 0000000..30e4fe5 --- /dev/null +++ b/app/static/templates/totals.html @@ -0,0 +1,31 @@ +
+
+
+

Loading Totals...

+ +
+
+
+ +
+
+
+ +
+ +
+
+ +
+
{{ val.datetime | date: 'medium'}}
+ View Data +
+
+
+
+
+