diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1320e33 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bower_components/ +node_modules/ +pycomm.log diff --git a/public/src/controllers.coffee b/public/src/controllers.coffee index db7b575..d4faaa8 100644 --- a/public/src/controllers.coffee +++ b/public/src/controllers.coffee @@ -1,1640 +1,1540 @@ -wellCtrls = angular.module 'wellCtrls', ['n3-line-chart', 'ui.bootstrap', 'ngAnimate', 'ngJustGage'] +wellCtrls = angular.module('wellCtrls', [ + 'n3-line-chart' + 'ui.bootstrap' + 'ngAnimate' + 'ngJustGage' + 'googlechart' +]) +wellCtrls.value 'googleChartApiConfig', + version: '1.1' + optionalSettings: + packages: [ 'timeline' ] + language: 'en' dateConversion = (raw) -> - converted = raw.slice(4, 6) + '/' + raw.slice(6, 8) + '/' + raw.slice(0, 4) - x = - conv: converted, - unconv: raw - x + converted = raw.slice(4, 6) + '/' + raw.slice(6, 8) + '/' + raw.slice(0, 4) + { + conv: converted + unconv: raw + } pad = (str, max) -> - str = str.toString() - if str.length < max - ret = pad('0' + str, max); - else - ret = str; - ret - -maxPos = (card) -> - card.map (x) -> - x.position - .reduce (y,z)-> - Math.max y,z - -minPos = (card) -> - card.map (x) -> - x.position - .reduce (y,z)-> - Math.min y,z - -maxLoad = (card) -> - card.map (x) -> - x.load - .reduce (y,z)-> - Math.max y,z - -minLoad = (card) -> - card.map (x) -> - x.load - .reduce (y,z)-> - Math.min y,z + str = str.toString() + if str.length < max + pad '0' + str, max + else + str getCardGraphOptions = (surface, downhole) -> + limits = + sMaxPos: surface.map((x) -> + x.position + ).reduce((y, z) -> + Math.max y, z + ) + 20 + sMinPos: surface.map((x) -> + x.position + ).reduce((y, z) -> + Math.min y, z + ) - 20 + sMaxLoad: surface.map((x) -> + x.load + ).reduce((y, z) -> + Math.max y, z + ) + 2000 + sMinLoad: surface.map((x) -> + x.load + ).reduce((y, z) -> + Math.min y, z + ) - 2000 + dMaxLoad: downhole.map((x) -> + x.load + ).reduce((y, z) -> + Math.max y, z + ) + 2000 + dMinLoad: downhole.map((x) -> + x.load + ).reduce((y, z) -> + Math.min y, z + ) - 2000 + surfaceOptions = + axes: + x: + key: 'position' + labelFunction: (value) -> + value + type: 'linear' + min: limits.sMinPos + max: limits.sMaxPos + ticks: 7 + y: + type: 'linear' + min: limits.sMinLoad + max: limits.sMaxLoad + ticks: 5 + series: [ { + axis: 'y' + key: 'load' + dataset: 'surface' + color: 'steelblue' + type: [ + 'line' + 'area' + ] + striped: true + label: 'Surface Card' + id: 'surfaceCard' + } ] + grid: + x: true + y: true + downholeOptions = + axes: + x: + key: 'position' + labelFunction: (value) -> + value + type: 'linear' + min: limits.sMinPos + max: limits.sMaxPos + ticks: 7 + y: + type: 'linear' + min: limits.dMinLoad + max: limits.dMaxLoad + ticks: 5 + series: [ { + axis: 'y' + key: 'load' + dataset: 'downhole' + color: 'steelblue' + type: [ + 'line' + 'area' + ] + label: 'Downhole Card' + id: 'downholeCard' + } ] + grid: + x: true + y: true + { + surf: surfaceOptions + down: downholeOptions + } + +wellCtrls.factory 'Page', ($log) -> + title = 'default' + page = 'default' + { + title: -> + title + setTitle: (newTitle) -> + title = newTitle + return + page: -> + page + setPage: (newPage) -> + page = newPage + return + + } +wellCtrls.factory 'Alerts', ($log) -> + alerts = [] + { + add: (alt) -> + alerts.push alt + return + remove: (indx) -> + alerts.splice indx, 1 + return + clear: -> + alerts = [] + return + get: -> + alerts + + } +wellCtrls.factory 'json', ($q, $http, $log) -> + + getDateList = -> + deferred = $q.defer() + $http.get('/json/all/').success (data) -> + dateList = data.dates.sort().reverse() + dates = dateList.map((x) -> + dateConversion x + ) + deferred.resolve dates: dates + return + deferred.promise + + getGaugeOffData = -> + deferred = $q.defer() + $http.get('/json/history/all').success (data) -> + deferred.resolve gaugeOffData: data.hist + return + deferred.promise + + getWellTestData = -> + deferred = $q.defer() + $http.get('/json/well_test/all').success (data) -> + deferred.resolve wellTestData: data.wellTest + return + deferred.promise + + getEventsData = -> + deferred = $q.defer() + $http.get('/json/event_list').success (data) -> + deferred.resolve eventsData: data.events + return + deferred.promise + + getSetup = -> + deferred = $q.defer() + $http.get('/json/setup').success (data) -> + deferred.resolve setup: data.setup + return + deferred.promise + + getPythonStatus = -> + deferred = $q.defer() + $http.get('/json/pythonStatus').success (data) -> + deferred.resolve status: data.status + return + deferred.promise + + restartPythonScripts = -> + deferred = $q.defer() + $http.get('/json/pythonRestart').success (data) -> + deferred.resolve success: data.success + return + deferred.promise + + getFilePage = (date, pageNumber, numPerPage) -> + deferred = $q.defer() + $http.get('/json/page/' + date + '/' + pageNumber + '/' + numPerPage).success (data) -> + deferred.resolve files: data.cards + return + deferred.promise + + getCardCount = (date) -> + deferred = $q.defer() + $http.get('/json/count/' + date).success (data) -> + deferred.resolve count: data.count + return + deferred.promise + + getFileList = (date) -> + deferred = $q.defer() + $http.get('/json/all/' + date).success (data) -> + deferred.resolve files: data.cards + return + deferred.promise + + getLatestCard = -> + deferred = $q.defer() + $http.get('/json/latestcard/').success (data) -> + deferred.resolve data: data + return + deferred.promise + + getCard = (id) -> + deferred = $q.defer() + $http.get('/json/card/' + id.toString()).success (data) -> + deferred.resolve data: data + return + deferred.promise + + getTotals = -> + deferred = $q.defer() + $http.get('/json/totals').success (data) -> + totalRet = {} + vals = data.totals + i = 0 + while i < vals.length + totalRet[vals[i].name] = vals[i].value + i++ + deferred.resolve totals: totalRet + return + deferred.promise + + getNotes = -> + deferred = $q.defer() + $http.get('/json/notes/get').success (data) -> + deferred.resolve notes: data.notes + return + deferred.promise + + getNoteTypes = -> + deferred = $q.defer() + $http.get('/json/notes/get/types').success (data) -> + deferred.resolve types: data.types + return + deferred.promise + + pushNote = (author, note, type, stroke_associated) -> + $http.post('/json/notes/post', + author: author + note: note + type: type + stroke_associated: stroke_associated).success (data) -> + data + return + + deleteNote = (noteID) -> + $http.post('/json/notes/delete', id: noteID).success (data) -> + data + return + + undeleteNote = (noteID) -> + $http.post('/json/notes/undelete', id: noteID).success (data) -> + data + return + + updateNote = (id, author, note, type, stroke_associated) -> + $http.post('/json/notes/update', + id: id + author: author + note: note + type: type + stroke_associated: stroke_associated).success (data) -> + data + return + + getDeletedNotes = -> + deferred = $q.defer() + $http.get('/json/notes/get/deleted').success (data) -> + deferred.resolve notes: data.notes + return + deferred.promise + + getFluidShots = -> + deferred = $q.defer() + $http.get('/json/fluid_shot/get').success (data) -> + deferred.resolve fluid_shots: data.fluid_shots + return + deferred.promise + + pushFluidShot = (shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by) -> + $http.post('/json/fluid_shot/post', + shot_datetime: shot_datetime + pump_intake_pressure: pump_intake_pressure + fluid_gradient: fluid_gradient + friction: friction + taken_by: taken_by).success (data) -> + data + return + + deleteFluidShot = (shotID) -> + $http.post('/json/fluid_shot/delete', id: shotID).success (data) -> + data + return + + undeleteFluidShot = (shotID) -> + $http.post('/json/fluid_shot/undelete', id: shotID).success (data) -> + data + return + + updateFluidShot = (id, shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by) -> + $http.post('/json/fluid_shot/update', + id: id + shot_datetime: shot_datetime + pump_intake_pressure: pump_intake_pressure + fluid_gradient: fluid_gradient + friction: friction + taken_by: taken_by).success (data) -> + data + return + + getDeletedFluidShots = -> + deferred = $q.defer() + $http.get('/json/fluid_shot/get/deleted').success (data) -> + deferred.resolve fluid_shots: data.fluid_shots + return + deferred.promise + + #Well Test Functions + + getWellTests = -> + deferred = $q.defer() + $http.get('/json/well_test/get').success (data) -> + deferred.resolve well_tests: data.well_tests + return + deferred.promise + + pushWellTest = (shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by) -> + $http.post('/json/well_test/post', + shot_datetime: shot_datetime + pump_intake_pressure: pump_intake_pressure + fluid_gradient: fluid_gradient + friction: friction + taken_by: taken_by).success (data) -> + data + return + + deleteWellTest = (shotID) -> + $http.post('/json/well_test/delete', id: testID).success (data) -> + data + return + + undeleteWellTest = (shotID) -> + $http.post('/json/well_test/undelete', id: testID).success (data) -> + data + return + + updateWellTest = (id, shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by) -> + $http.post('/json/well_test/update', + id: id + shot_datetime: shot_datetime + pump_intake_pressure: pump_intake_pressure + fluid_gradient: fluid_gradient + friction: friction + taken_by: taken_by).success (data) -> + data + return + + getDeletedWellTests = -> + deferred = $q.defer() + $http.get('/json/well_test/get/deleted').success (data) -> + deferred.resolve well_tests: data.well_tests + return + deferred.promise + + getCurrentTagValues = -> + deferred = $q.defer() + $http.get('/json/tagvalues').success (data) -> + deferred.resolve data: data + return + deferred.promise + + getTagsAtTime = (unixTS) -> + deferred = $q.defer() + $http.get('/json/tagvalues/' + unixTS).success (data) -> + deferred.resolve data: data + return + deferred.promise + + getCurrentStatus = -> + deferred = $q.defer() + $http.get('/json/status').success (data) -> + deferred.resolve data: data + return + deferred.promise + + getStatusAtTime = (unixTS) -> + deferred = $q.defer() + $http.get('/json/status/' + unixTS).success (data) -> + deferred.resolve data: data + return + deferred.promise + + { + getDateList: getDateList + getGaugeOffData: getGaugeOffData + getWellTestData: getWellTestData + getEventsData: getEventsData + getSetup: getSetup + getPythonStatus: getPythonStatus + restartPythonScripts: restartPythonScripts + getFileList: getFileList + getLatestCard: getLatestCard + getCard: getCard + getFilePage: getFilePage + getCardCount: getCardCount + getTotals: getTotals + getNotes: getNotes + getNoteTypes: getNoteTypes + pushNote: pushNote + deleteNote: deleteNote + undeleteNote: undeleteNote + updateNote: updateNote + getDeletedNotes: getDeletedNotes + getFluidShots: getFluidShots + pushFluidShot: pushFluidShot + deleteFluidShot: deleteFluidShot + undeleteFluidShot: undeleteFluidShot + updateFluidShot: updateFluidShot + getDeletedFluidShots: getDeletedFluidShots + getWellTests: getWellTests + pushWellTest: pushWellTest + deleteWellTest: deleteWellTest + undeleteWellTest: undeleteWellTest + updateWellTest: updateWellTest + getDeletedWellTests: getDeletedWellTests + getCurrentTagValues: getCurrentTagValues + getTagsAtTime: getTagsAtTime + getCurrentStatus: getCurrentStatus + getStatusAtTime: getStatusAtTime + } +wellCtrls.factory 'multipleCards', -> + mCardData = undefined + retrieve = undefined + store = undefined + mCardData = {} + + store = (data) -> + mCardData = data + return + + retrieve = -> + mCardData + + { + store: store + retrieve: retrieve + } +wellCtrls.factory 'statusTimeline', ($q, $http) -> + + getStatusBetween = (sDateTime, eDateTime) -> + deferred = $q.defer() + $http.get('/json/status/' + sDateTime + '/' + eDateTime).success (data) -> + if data.status == 'OK' + if data.run_status.length > 1 + run_statuses = data.run_status + uniqueRunStatuses = [ run_statuses[0] ] + i = 1 + while i < run_statuses.length + if uniqueRunStatuses.slice(-1)[0].status != run_statuses[i].status + uniqueRunStatuses.push run_statuses[i] + i++ + j = 0 + while j < uniqueRunStatuses.length - 1 + uniqueRunStatuses[j].end_dtime = uniqueRunStatuses[j + 1].dtime + j++ + deferred.resolve uniqueRunStatuses + return + deferred.promise + + prepareTimelineData = (sDateTime, eDateTime) -> + deferred = $q.defer() + getData = getStatusBetween(sDateTime, eDateTime) + getData.then (d) -> + statusData = d + timelineData = + 'cssStyle': 'height:300px;width:100%;' + 'type': 'Timeline' + 'data': + 'cols': [ + { + type: 'string' + id: 'Run Status' + } + { + type: 'string' + id: 'Bar Label' + } + { + type: 'date' + id: 'Start' + } + { + type: 'date' + id: 'End' + } + ] + 'rows': [] + 'options': + timeline: + colorByRowLabel: false + groupByRowLabel: true + backgroundColor: '#ffffff' + tooltip: isHtml: true + if statusData.length > 0 + statusData.slice(-1)[0].end_dtime = eDateTime + i = 0 + while i < statusData.length + timelineData.data.rows.push c: [ + { 'v': statusData[i].status } + { 'v': statusData[i].status } + { 'v': new Date(statusData[i].dtime * 1000) } + { 'v': new Date(statusData[i].end_dtime * 1000) } + ] + i++ + deferred.resolve timelineData + return + deferred.promise + + { prepareTimelineData: prepareTimelineData } +wellCtrls.factory 'tags', ($q, $http) -> + { + set: (tag, value) -> + deferred = $q.defer() + $http.get('/json/tags/set/' + tag + '/' + value).success (data) -> + deferred.resolve tag: data + return + deferred.promise + get: (tag, value) -> + deferred = $q.defer() + $http.get('/json/tags/get/' + tag).success (data) -> + deferred.resolve tag: data + return + deferred.promise + getAllTags: (tag) -> + deferred = undefined + deferred = $q.defer() + $http.get('/json/tags/get/status').success (data) -> + deferred.resolve tags: data.tags + return + deferred.promise + + } +wellCtrls.controller 'mainCtrl', ($scope, Page, Alerts) -> + $scope.Page = Page + $scope.Alerts = Alerts + return +wellCtrls.controller 'fileListPreviousCtrl', ($scope, $http, $routeParams, json, Page, $log, multipleCards, $location) -> + Page.setTitle 'File List' + Page.setPage 'fileList' + $scope.currentPage = 1 + $scope.numPerPage = 100 + $scope.maxSize = 9 + paramDate = $routeParams.date + $scope.currentDate = dateConversion(paramDate) + getDateList = json.getDateList() + getDateList.then (data) -> + $scope.dates = data.dates + return + getCardCount = json.getCardCount(paramDate) + getCardCount.then (cdata) -> + $scope.numCards = cdata.count + $scope.numPages = Math.ceil(cdata.count / $scope.numPerPage) + return + + $scope.switchPage = (page) -> + $scope.currentPage = page + $scope.pageLoading = true + getFileList = json.getFilePage(paramDate, page, $scope.numPerPage) + getFileList.then (data) -> + data.files = data.files.map((x) -> + x.Stroke_Time = new Date(x.Stroke_Time) + x + ) + $scope.filteredFiles = data.files + $scope.pageLoading = false + return + return + + $scope.switchPage 1 + $scope.$watch 'currentPage', -> + $scope.switchPage $scope.currentPage + return + + $scope.selectFiles = -> + ids = $scope.filteredFiles.filter((x) -> + x.selected + ).map((y) -> + y.id + ) + $http.post('/json/cards', ids: ids).success((data, status, headers, config) -> + multipleCards.store data.cards + $location.path '/card/compare' + return + ).error (data, status, headers, config) -> + $log.info 'Data', data + $log.info 'Status', status + $log.info 'Headers', headers + $log.info 'Config', config + return + return + + return +wellCtrls.controller 'fileListTodayCtrl', ($scope, $http, $routeParams, json, Page, $log, multipleCards, $location) -> + Page.setTitle 'File List' + Page.setPage 'fileList' + $scope.currentPage = 1 + $scope.numPerPage = 100 + $scope.maxSize = 9 + getDateList = json.getDateList() + getDateList.then (data) -> + $scope.dates = data.dates + $scope.currentDate = $scope.dates[0] + $log.info $scope.currentDate + getCardCount = json.getCardCount($scope.currentDate.unconv) + getCardCount.then (cdata) -> + $scope.numCards = cdata.count + $scope.numPages = Math.ceil(cdata.count / $scope.numPerPage) + return + $scope.switchPage 1 + return + + $scope.switchPage = (page) -> + $scope.currentPage = page + $scope.pageLoading = true + getFileList = json.getFilePage($scope.currentDate.unconv, page, $scope.numPerPage) + getFileList.then (data) -> + data.files = data.files.map((x) -> + x.Stroke_Time = new Date(x.Stroke_Time) + x + ) + $scope.filteredFiles = data.files + $scope.pageLoading = false + return + return + + $scope.$watch 'currentPage', -> + $scope.switchPage $scope.currentPage + return + + $scope.selectFiles = -> + ids = $scope.filteredFiles.filter((x) -> + x.selected + ).map((y) -> + y.id + ) + $http.post('/json/cards', ids: ids).success((data, status, headers, config) -> + multipleCards.store data.cards + $location.path '/card/compare' + return + ).error (data, status, headers, config) -> + $log.info 'Data', data + $log.info 'Status', status + $log.info 'Headers', headers + $log.info 'Config', config + return + return + + return +wellCtrls.controller 'dashboardCtrl', ($scope, $route, $http, $routeParams, json, Page, Alerts, $log, statusTimeline) -> + Page.setTitle 'Dashboard' + Page.setPage 'dashboard' + $scope.dateListLoading = true + getDateList = json.getDateList() + getDateList.then (data) -> + $scope.dateListLoading = false + $scope.dates = data.dates + $scope.currentDate = $scope.dates[0] + return + + $scope.dashboard = -> + getCurrentTagValues = json.getCurrentTagValues() + getCurrentTagValues.then (d) -> + data = d.data + if data.status == 'OK' + $scope.tagValues = {} + i = 0 + while i < data.vals.length + $scope.tagValues[data.vals[i].name] = data.vals[i] + i++ + return + now = Date.now() / 1000 + earlier = now - (24 * 60 * 60) + gettimelineData = statusTimeline.prepareTimelineData(earlier, now) + gettimelineData.then (tData) -> + console.log tData + $scope.timelineData = tData + return + getCurrentStatus = json.getCurrentStatus() + getCurrentStatus.then (s) -> + sData = s.data + sData.datetime = new Date(sData.datetime * 1000) + $scope.status = sData.run_status + $scope.status_datetime = new Date(sData.datetime) + return + getLatestCard = json.getLatestCard() + getLatestCard.then (cData) -> + cData = cData.data + $scope.cardData = cData.card_data[0] + #$scope.cardData.dateTime = new Date($scope.cardData.localtime.replace(" ","T")); + $scope.surface = cData.card_data[0].Surface_Position.map((a, i) -> + { + position: cData.card_data[0].Surface_Position[i] + load: cData.card_data[0].Surface_Load[i] + } + ) + $scope.surface.push $scope.surface[0] + $scope.downhole = cData.card_data[0].Downhole_Position.map((a, i) -> + { + position: cData.card_data[0].Downhole_Position[i] + load: cData.card_data[0].Downhole_Load[i] + } + ) + $scope.downhole.push $scope.downhole[0] + $scope.card_graph_data = + surface: $scope.surface + downhole: $scope.downhole + graphOptions = getCardGraphOptions($scope.surface, $scope.downhole) + $scope.surfaceOptions = graphOptions.surf + $scope.downholeOptions = graphOptions.down + return + # var getTotals = json.getTotals(); + # getTotals.then(function(data){ + # $scope.totals = data.totals; + # }); + return + + $scope.dashboard() + return +wellCtrls.controller 'totalsCtrl', ($scope, json, Page, $log) -> + Page.setTitle 'Totals' + Page.setPage 'dashboard' + # $scope.currentPage = 1; + # $scope.numPerPage = 10; + # $scope.maxSize = 9; + $scope.dateListLoading = true + $scope.totalsLoading = true + getDateList = json.getDateList() + getDateList.then (data) -> + $scope.dateListLoading = false + $scope.dates = data.dates + $scope.currentDate = $scope.dates[0] + # $scope.numPages = function() { + # return Math.ceil($scope.dates.length / $scope.numPerPage); + # }; + # $scope.$watch('currentPage + numPerPage', function() { + # var begin = ($scope.currentPage - 1) * $scope.numPerPage; + # var end = begin + $scope.numPerPage; + # $scope.filteredDates = $scope.dates.slice(begin, end); + # }); + return + + $scope.refresh = -> + getTotals = json.getTotals() + getTotals.then (tdata) -> + $scope.totals = tdata.totals + $scope.totalsLoading = false + return + return + + $scope.refresh() + return +wellCtrls.controller 'cardDataCtrl', ($scope, $http, $routeParams, json, Page, $log) -> + $scope.loading = true + Page.setTitle 'Card Data' + Page.setPage 'cardData' + $scope.id = $routeParams.id + getDateList = json.getDateList() + getDateList.then (data) -> + $scope.dates = data.dates + $scope.currentDate = $scope.dates[0] + return + getCard = json.getCard($routeParams.id) + getCard.then (cData) -> + cData = cData.data + $scope.cardData = cData.card_data + $scope.cardData.Stroke_Time = new Date($scope.cardData.Stroke_Time) + #$scope.cardData.dateTime = new Date($scope.cardData.localtime.replace(" ","T")); + $scope.surface = cData.card_data.Surface_Position.map((a, i) -> + { + position: cData.card_data.Surface_Position[i] + load: cData.card_data.Surface_Load[i] + } + ) + $scope.surface.push $scope.surface[0] + $scope.downhole = cData.card_data.Downhole_Position.map((a, i) -> + { + position: cData.card_data.Downhole_Position[i] + load: cData.card_data.Downhole_Load[i] + } + ) + $scope.downhole.push $scope.downhole[0] + $scope.card_graph_data = + surface: $scope.surface + downhole: $scope.downhole + graphOptions = getCardGraphOptions($scope.surface, $scope.downhole) + $scope.surfaceOptions = graphOptions.surf + $scope.downholeOptions = graphOptions.down + getTagsAtTime = json.getTagsAtTime($scope.cardData.Stroke_Time.getTime() / 1000) + getTagsAtTime.then (d) -> + data = d.data + if data.status == 'OK' + $scope.loading = false + $scope.tagData = {} + i = 0 + while i < data.vals.length + $scope.tagData[data.vals[i].name] = data.vals[i] + i++ + return + return + return +wellCtrls.controller 'gaugeOffCtrl', ($scope, Page, json) -> + Page.setTitle 'Gauge Off' + Page.setPage 'gaugeOff' + getGaugeOffData = json.getGaugeOffData() + getGaugeOffData.then (data) -> + i = undefined + $scope.gaugeOffData = data.gaugeOffData + i = 0 + while i < $scope.gaugeOffData.length - 1 + $scope.gaugeOffData[i].delta = {} + $scope.gaugeOffData[i].delta.percent_run = ((parseFloat($scope.gaugeOffData[i].percent_run) - parseFloat($scope.gaugeOffData[i + 1].percent_run)) / parseFloat($scope.gaugeOffData[i + 1].percent_run) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.kWh = ((parseFloat($scope.gaugeOffData[i].kWh) - parseFloat($scope.gaugeOffData[i + 1].kWh)) / parseFloat($scope.gaugeOffData[i + 1].kWh) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.kWh_regen = ((parseFloat($scope.gaugeOffData[i].kWh_regen) - parseFloat($scope.gaugeOffData[i + 1].kWh_regen)) / parseFloat($scope.gaugeOffData[i + 1].kWh_regen) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.electricity_cost = ((parseFloat($scope.gaugeOffData[i].electricity_cost) - parseFloat($scope.gaugeOffData[i + 1].electricity_cost)) / parseFloat($scope.gaugeOffData[i + 1].electricity_cost) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.peak_load = ((parseFloat($scope.gaugeOffData[i].peak_load) - parseFloat($scope.gaugeOffData[i + 1].peak_load)) / parseFloat($scope.gaugeOffData[i + 1].peak_load) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.min_load = ((parseFloat($scope.gaugeOffData[i].min_load) - parseFloat($scope.gaugeOffData[i + 1].min_load)) / parseFloat($scope.gaugeOffData[i + 1].min_load) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.average_SPM = ((parseFloat($scope.gaugeOffData[i].average_SPM) - parseFloat($scope.gaugeOffData[i + 1].average_SPM)) / parseFloat($scope.gaugeOffData[i + 1].average_SPM) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.production_calculated = ((parseFloat($scope.gaugeOffData[i].production_calculated) - parseFloat($scope.gaugeOffData[i + 1].production_calculated)) / parseFloat($scope.gaugeOffData[i + 1].production_calculated) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.polished_rod_HP = ((parseFloat($scope.gaugeOffData[i].polished_rod_HP) - parseFloat($scope.gaugeOffData[i + 1].polished_rod_HP)) / parseFloat($scope.gaugeOffData[i + 1].polished_rod_HP) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.lifting_cost = ((parseFloat($scope.gaugeOffData[i].lifting_cost) - parseFloat($scope.gaugeOffData[i + 1].lifting_cost)) / parseFloat($scope.gaugeOffData[i + 1].lifting_cost) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.full_card_production = ((parseFloat($scope.gaugeOffData[i].full_card_production) - parseFloat($scope.gaugeOffData[i + 1].full_card_production)) / parseFloat($scope.gaugeOffData[i + 1].full_card_production) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.fluid_above_pump = ((parseFloat($scope.gaugeOffData[i].fluid_above_pump) - parseFloat($scope.gaugeOffData[i + 1].fluid_above_pump)) / parseFloat($scope.gaugeOffData[i + 1].fluid_above_pump) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.pump_intake_pressure = ((parseFloat($scope.gaugeOffData[i].pump_intake_pressure) - parseFloat($scope.gaugeOffData[i + 1].pump_intake_pressure)) / parseFloat($scope.gaugeOffData[i + 1].pump_intake_pressure) * 100).toFixed(2) + $scope.gaugeOffData[i].delta.inflow_rate = ((parseFloat($scope.gaugeOffData[i].inflow_rate) - parseFloat($scope.gaugeOffData[i + 1].inflow_Rate)) / parseFloat($scope.gaugeOffData[i + 1].inflow_rate) * 100).toFixed(2) + i++ + return + $scope.show = + PctRun: true + kWh: true + kWhRegen: false + CostToOperate: true + LiftingCost: false + PeakLoad: false + MinLoad: false + AvgSPM: true + CalcProduction: true + ProjProduction: false + PolishedRodHP: false + FluidLevel: true + PumpIntakePressure: false + InflowRate: false + return +wellCtrls.controller 'wellTestCtrl', ($scope, Page, json) -> + Page.setTitle 'Well Test' + Page.setPage 'wellTest' + getWellTestData = json.getWellTestData() + getWellTestData.then (data) -> + $scope.wellTestData = data.wellTestData + return + return +wellCtrls.controller 'eventsCtrl', ($scope, Page, json) -> + Page.setTitle 'Events' + Page.setPage 'events' + getEventsData = json.getEventsData() + getEventsData.then (data) -> + $scope.eventsData = data.eventsData + return + return +wellCtrls.controller 'setupCtrl', ($scope, Page, json, $log) -> + Page.setTitle 'Setup' + Page.setPage 'setup' + + $scope.getPythonStatus = -> + $scope.gettingStatus = true + getPythonStatus = json.getPythonStatus() + getPythonStatus.then (pyData) -> + $scope.gettingStatus = false + if pyData.status.alarmLogger == true and pyData.status.dataLogger == true + $scope.pythonStatus = 'OK' + else + $scope.pythonStatus = 'NOT OK' + $log.info pyData + return + return + + getSetup = json.getSetup() + getSetup.then (data) -> + $scope.setup = data.setup + $scope.getPythonStatus() + return + + $scope.restartPython = -> + $scope.resetting = true + restartPython = json.restartPythonScripts() + restartPython.then (response) -> + $scope.resetting = false + $scope.getPythonStatus() + return + return + + return +wellCtrls.controller 'cardIDCtrl', ($scope, $http, $routeParams, json, Page) -> + Page.setTitle 'Card Data' + Page.setPage 'cardData' + $scope.folder = $routeParams.date + getDateList = json.getDateList() + getDateList.then (data) -> + $scope.dates = data.dates + $scope.currentDate = $scope.dates[0] + return + $http.get('/json/byID/' + $routeParams.date + '/' + $routeParams.card_id).success (cData) -> + $scope.cardData = cData.contents + $scope.surface = [] + $scope.downhole = [] + $scope.surface = cData.s.map((a) -> + { + position: a[0] + load: a[1] + } + ) + $scope.surface.push $scope.surface[0] + $scope.downhole = cData.d.map((a) -> + { + position: a[0] + load: a[1] + } + ) + $scope.downhole.push $scope.downhole[0] limits = - sMaxPos: minPos(surface) + 20 - sMinPos: maxPos(surface) - 20 - sMaxLoad: maxLoad(surface) + 2000 - sMinLoad: minLoad(surface) - 2000 - dMaxLoad: maxLoad(downhole) + 2000 - dMinLoad: minLoad(downhole) - 2000 - - - surfaceOptions = { - axes: { - x: { - key: 'position', - labelFunction: function(value) { - return value; - }, - type: 'linear', - min: limits.sMinPos, - max: limits.sMaxPos, - ticks: 7 - }, - y: { - type: 'linear', - min: limits.sMinLoad, - max: limits.sMaxLoad, - ticks: 5 - } - }, - series: [ - { - axis:"y", - key: 'load', - dataset: 'surface', - color: 'steelblue', - type: ['line', 'area'], - striped: true, - label: 'Surface Card', - id: "surfaceCard" - } - ], - grid: { - x: true, - y: true - } - }; - var downholeOptions = { - axes: { - x: { - key: 'position', - labelFunction: function(value) { - return value; - }, - type: 'linear', - min: limits.sMinPos, - max: limits.sMaxPos, - ticks: 7 - }, - y: { - type: 'linear', - min: limits.dMinLoad, - max: limits.dMaxLoad, - ticks: 5 - } - }, - series: [ - { - axis:"y", - key: 'load', - dataset: 'downhole', - color: 'steelblue', - type: ['line', 'area'], - label: 'Downhole Card', - id: "downholeCard", - } - ], - grid: { - x: true, - y: true - } - }; - return({surf: surfaceOptions, down: downholeOptions}); -}; - -wellCtrls.factory('Page', function($log) { - var title = 'default'; - var page = 'default'; - return { - title: function() { - return title; - }, - setTitle: function(newTitle) { - title = newTitle; - }, - page: function() { - return page; - }, - setPage: function(newPage) { - page = newPage; - } - }; -}); - -wellCtrls.factory('Alerts', function($log) { - var alerts = []; - return { - add: function(alt) { - alerts.push(alt); - }, - remove: function(indx) { - alerts.splice(indx, 1); - }, - clear: function() { - alerts = []; - }, - get: function() { - return alerts; - } - }; -}); - -wellCtrls.factory('json',function($q, $http, $log){ - var getDateList = function() { - var deferred = $q.defer(); - $http.get('/json/all/').success(function(data) { - var dateList = data.dates.sort().reverse(); - var dates = dateList.map(function(x){return dateConversion(x);}); - deferred.resolve({ - dates: dates - }); - }); - return deferred.promise; - }; - - var getGaugeOffData = function() { - var deferred = $q.defer(); - $http.get('/json/history/all').success(function(data) { - deferred.resolve({ - gaugeOffData: data.hist - }); - }); - return deferred.promise; - }; - - var getWellTestData = function() { - var deferred = $q.defer(); - $http.get('/json/well_test/all').success(function(data) { - deferred.resolve({ - wellTestData: data.wellTest - }); - }); - return deferred.promise; - }; - - var getEventsData = function() { - var deferred = $q.defer(); - $http.get('/json/event_list').success(function(data) { - deferred.resolve({ - eventsData: data.events - }); - }); - return deferred.promise; - }; - - var getSetup = function() { - var deferred = $q.defer(); - $http.get('/json/setup').success(function(data) { - deferred.resolve({ - setup: data.setup - }); - }); - return deferred.promise; - }; - - var getPythonStatus = function() { - var deferred = $q.defer(); - $http.get('/json/pythonStatus').success(function(data) { - deferred.resolve({ - status: data.status - }); - }); - return deferred.promise; - }; - - var restartPythonScripts = function() { - var deferred = $q.defer(); - $http.get('/json/pythonRestart').success(function(data) { - deferred.resolve({ - success: data.success - }); - }); - return deferred.promise; - }; - - var getFilePage = function(date, pageNumber, numPerPage){ - var deferred = $q.defer(); - $http.get('/json/page/'+date+"/"+pageNumber+"/"+numPerPage).success(function(data) { - deferred.resolve({ - files:data.cards - }); - }); - return deferred.promise; - }; - - var getCardCount = function(date){ - var deferred = $q.defer(); - $http.get('/json/count/'+date).success(function(data) { - deferred.resolve({ - count:data.count - }); - }); - return deferred.promise; - }; - - var getFileList = function(date) { - var deferred = $q.defer(); - $http.get('/json/all/' + date).success(function(data) { - deferred.resolve({ - files: data.cards - }); - }); - return deferred.promise; - }; - - var getLatestCard = function() { - var deferred = $q.defer(); - $http.get('/json/latestcard/').success(function(data) { - deferred.resolve({ - data: data - }); - }); - return deferred.promise; - }; - - var getCard = function(id) { - var deferred = $q.defer(); - $http.get('/json/card/'+ id.toString()).success(function(data) { - deferred.resolve({ - data: data - }); - }); - return deferred.promise; - }; - - var getTotals = function() { - var deferred = $q.defer(); - $http.get('/json/totals').success(function(data) { - var totalRet = {}; - var vals = data.totals; - i=0; - while (i < vals.length){ - totalRet[vals[i].name] = vals[i].value; - i++; - } - - deferred.resolve({ - totals: totalRet - }); - }); - return deferred.promise; - }; - - var getNotes = function(){ - var deferred = $q.defer(); - $http.get('/json/notes/get').success(function(data) { - deferred.resolve({ - notes: data.notes - }); - }); - return deferred.promise; - }; - - var getNoteTypes = function(){ - var deferred = $q.defer(); - $http.get('/json/notes/get/types').success(function(data) { - deferred.resolve({ - types: data.types - }); - }); - return deferred.promise; - }; - - var pushNote = function(author, note, type, stroke_associated){ - $http.post('/json/notes/post', { - author:author, - note:note, - type:type, - stroke_associated:stroke_associated - }).success(function(data){ - return data; - }); - }; - - var deleteNote = function(noteID){ - $http.post('/json/notes/delete', {id:noteID}).success(function(data){ - return data; - }); - }; - - var undeleteNote = function(noteID){ - $http.post('/json/notes/undelete', {id:noteID}).success(function(data){ - return data; - }); - }; - - var updateNote = function(id,author, note, type, stroke_associated){ - $http.post('/json/notes/update', { - id:id, - author:author, - note:note, - type:type, - stroke_associated:stroke_associated - }).success(function(data){ - return data; - }); - }; - - var getDeletedNotes = function(){ - var deferred = $q.defer(); - $http.get('/json/notes/get/deleted').success(function(data) { - deferred.resolve({ - notes: data.notes - }); - }); - return deferred.promise; - }; - - var getFluidShots = function(){ - var deferred = $q.defer(); - $http.get('/json/fluid_shot/get').success(function(data) { - deferred.resolve({ - fluid_shots: data.fluid_shots - }); - }); - return deferred.promise; - }; - - var pushFluidShot = function(shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by){ - $http.post('/json/fluid_shot/post', { - shot_datetime:shot_datetime, - pump_intake_pressure:pump_intake_pressure, - fluid_gradient:fluid_gradient, - friction:friction, - taken_by:taken_by - }).success(function(data){ - return data; - }); - }; - - var deleteFluidShot = function(shotID){ - $http.post('/json/fluid_shot/delete', {id:shotID}).success(function(data){ - return data; - }); - }; - - var undeleteFluidShot = function(shotID){ - $http.post('/json/fluid_shot/undelete', {id:shotID}).success(function(data){ - return data; - }); - }; - - var updateFluidShot = function(id, shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by){ - $http.post('/json/fluid_shot/update', { - id:id, - shot_datetime:shot_datetime, - pump_intake_pressure:pump_intake_pressure, - fluid_gradient:fluid_gradient, - friction:friction, - taken_by:taken_by - }).success(function(data){ - return data; - }); - }; - - var getDeletedFluidShots = function(){ - var deferred = $q.defer(); - $http.get('/json/fluid_shot/get/deleted').success(function(data) { - deferred.resolve({ - fluid_shots: data.fluid_shots - }); - }); - return deferred.promise; - }; - - //Well Test Functions - var getWellTests = function(){ - var deferred = $q.defer(); - $http.get('/json/well_test/get').success(function(data) { - deferred.resolve({ - well_tests: data.well_tests - }); - }); - return deferred.promise; - }; - - var pushWellTest = function(shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by){ - $http.post('/json/well_test/post', { - shot_datetime:shot_datetime, - pump_intake_pressure:pump_intake_pressure, - fluid_gradient:fluid_gradient, - friction:friction, - taken_by:taken_by - }).success(function(data){ - return data; - }); - }; - - var deleteWellTest = function(shotID){ - $http.post('/json/well_test/delete', {id:testID}).success(function(data){ - return data; - }); - }; - - var undeleteWellTest = function(shotID){ - $http.post('/json/well_test/undelete', {id:testID}).success(function(data){ - return data; - }); - }; - - var updateWellTest = function(id, shot_datetime, pump_intake_pressure, fluid_gradient, friction, taken_by){ - $http.post('/json/well_test/update', { - id:id, - shot_datetime:shot_datetime, - pump_intake_pressure:pump_intake_pressure, - fluid_gradient:fluid_gradient, - friction:friction, - taken_by:taken_by - }).success(function(data){ - return data; - }); - }; - - var getDeletedWellTests = function(){ - var deferred = $q.defer(); - $http.get('/json/well_test/get/deleted').success(function(data) { - deferred.resolve({ - well_tests: data.well_tests - }); - }); - return deferred.promise; - }; - - var getCurrentTagValues = function(){ - var deferred = $q.defer(); - $http.get('/json/tagvalues').success(function(data) { - deferred.resolve({ - data: data - }); - }); - return deferred.promise; - }; - - var getTagsAtTime = function(unixTS){ - var deferred = $q.defer(); - $http.get('/json/tagvalues/' + unixTS).success(function(data) { - deferred.resolve({ - data: data - }); - }); - return deferred.promise; - }; - - var getCurrentStatus = function(){ - var deferred = $q.defer(); - $http.get('/json/status').success(function(data) { - deferred.resolve({ - data: data - }); - }); - return deferred.promise; - }; - - var getStatusAtTime = function(unixTS){ - var deferred = $q.defer(); - $http.get('/json/status/' + unixTS).success(function(data) { - deferred.resolve({ - data: data - }); - }); - return deferred.promise; - }; - - - - - return { - getDateList: getDateList, - getGaugeOffData: getGaugeOffData, - getWellTestData: getWellTestData, - getEventsData: getEventsData, - getSetup: getSetup, - getPythonStatus: getPythonStatus, - restartPythonScripts: restartPythonScripts, - getFileList: getFileList, - getLatestCard: getLatestCard, - getCard: getCard, - getFilePage: getFilePage, - getCardCount: getCardCount, - getTotals: getTotals, - - // Notes Functions - getNotes: getNotes, - getNoteTypes: getNoteTypes, - pushNote: pushNote, - deleteNote: deleteNote, - undeleteNote: undeleteNote, - updateNote: updateNote, - getDeletedNotes: getDeletedNotes, - - // Fluit Shot Functions - getFluidShots: getFluidShots, - pushFluidShot: pushFluidShot, - deleteFluidShot: deleteFluidShot, - undeleteFluidShot: undeleteFluidShot, - updateFluidShot: updateFluidShot, - getDeletedFluidShots: getDeletedFluidShots, - - // Well Test Functions - getWellTests: getWellTests, - pushWellTest: pushWellTest, - deleteWellTest: deleteWellTest, - undeleteWellTest: undeleteWellTest, - updateWellTest: updateWellTest, - getDeletedWellTests: getDeletedWellTests, - - // Tag Data Functions - getCurrentTagValues: getCurrentTagValues, - getTagsAtTime: getTagsAtTime, - - getCurrentStatus: getCurrentStatus, - getStatusAtTime: getStatusAtTime - }; -}); - -wellCtrls.factory('multipleCards', function() { - var mCardData, retrieve, store; - mCardData = {}; - store = function(data) { - mCardData = data; - }; - retrieve = function() { - return mCardData; - }; - return { - store: store, - retrieve: retrieve - }; -}); - -wellCtrls.factory('tags', function($q, $http) { - return { - set: function(tag,value) { - var deferred = $q.defer(); - $http.get('/json/tags/set/' + tag + "/" + value).success(function(data) { - deferred.resolve({ - tag: data - }); - }); - return deferred.promise; - }, - get: function(tag,value) { - var deferred = $q.defer(); - $http.get('/json/tags/get/' + tag).success(function(data) { - deferred.resolve({ - tag: data - }); - }); - return deferred.promise; - }, - getAllTags: function(tag) { - var deferred; - deferred = $q.defer(); - $http.get('/json/tags/get/status').success(function(data) { - deferred.resolve({ - tags: data.tags - }); - }); - return deferred.promise; - } - }; -}); - -wellCtrls.controller('mainCtrl', function($scope, Page, Alerts) { - $scope.Page = Page; - $scope.Alerts = Alerts; -}); - -wellCtrls.controller('fileListPreviousCtrl', function($scope, $http, $routeParams, json, Page, $log, multipleCards, $location) { - Page.setTitle('File List'); - Page.setPage('fileList'); - $scope.currentPage = 1; - $scope.numPerPage = 100; - $scope.maxSize = 9; - var paramDate = $routeParams.date; - $scope.currentDate = dateConversion(paramDate); - var getDateList = json.getDateList(); - getDateList.then(function(data) { - $scope.dates = data.dates; - }); - var getCardCount = json.getCardCount(paramDate); - getCardCount.then(function(cdata){ - $scope.numCards = cdata.count; - $scope.numPages = Math.ceil(cdata.count / $scope.numPerPage); - }); - $scope.switchPage = function(page){ - $scope.currentPage = page; - $scope.pageLoading = true; - var getFileList = json.getFilePage(paramDate, page, $scope.numPerPage); - getFileList.then(function(data) { - $scope.filteredFiles = data.files; - $scope.pageLoading = false; - }); - }; - $scope.switchPage(1); - - $scope.$watch('currentPage', function() { - $scope.switchPage($scope.currentPage); - }); - - $scope.selectFiles = function() { - var ids = $scope.filteredFiles.filter(function(x){ - return x.selected; - }).map(function(y){ - return y.id; - }); - $http.post('/json/cards', { - ids: ids - }).success(function(data, status, headers, config) { - multipleCards.store(data.cards); - $location.path('/card/compare'); - }).error(function(data, status, headers, config) { - $log.info('Data', data); - $log.info('Status', status); - $log.info('Headers', headers); - $log.info('Config', config); - }); - }; -}); - -wellCtrls.controller('fileListTodayCtrl', function($scope, $http, $routeParams, json, Page, $log, multipleCards, $location) { - Page.setTitle('File List'); - Page.setPage('fileList'); - $scope.currentPage = 1; - $scope.numPerPage = 100; - $scope.maxSize = 9; - var getDateList = json.getDateList(); - getDateList.then(function(data) { - $scope.dates = data.dates; - $scope.currentDate = $scope.dates[0]; - $scope.switchPage(1); - }); - var getCardCount = json.getCardCount(paramDate); - getCardCount.then(function(cdata){ - $scope.numCards = cdata.count; - $scope.numPages = Math.ceil(cdata.count / $scope.numPerPage); - }); - - $scope.switchPage = function(page){ - $scope.currentPage = page; - $scope.pageLoading = true; - var getFileList = json.getFilePage($scope.currentDate.unconv, page, $scope.numPerPage); - getFileList.then(function(data) { - $scope.filteredFiles = data.files; - $scope.pageLoading = false; - }); - }; - $scope.$watch('currentPage', function() { - $scope.switchPage($scope.currentPage); - }); - - $scope.selectFiles = function() { - var ids = $scope.filteredFiles.filter(function(x){ - return x.selected; - }).map(function(y){ - return y.id; - }); - $http.post('/json/cards', { - ids: ids - }).success(function(data, status, headers, config) { - multipleCards.store(data.cards); - $location.path('/card/compare'); - }).error(function(data, status, headers, config) { - $log.info('Data', data); - $log.info('Status', status); - $log.info('Headers', headers); - $log.info('Config', config); - }); - }; -}); - -wellCtrls.controller('dashboardCtrl', function($scope, $route, $http, $routeParams, json, Page, Alerts, $log) { - Page.setTitle('Dashboard'); - Page.setPage('dashboard'); - $scope.dateListLoading = true; - var getDateList = json.getDateList(); - getDateList.then(function(data) { - $scope.dateListLoading = false; - $scope.dates = data.dates; - $scope.currentDate = $scope.dates[0]; - }); - $scope.dashboard = function() { - var getCurrentTagValues = json.getCurrentTagValues(); - getCurrentTagValues.then(function(d){ - var data = d.data; - if (data.status == "OK"){ - $scope.tagValues = {}; - for(var i=0; i < data.vals.length; i++){ - $scope.tagValues[data.vals[i].name] = data.vals[i]; - } - } - }); - - 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); - }); - - - var getLatestCard = json.getLatestCard(); - getLatestCard.then(function(cData){ - cData = cData.data; - $scope.cardData = cData.card_data[0]; - //$scope.cardData.dateTime = new Date($scope.cardData.localtime.replace(" ","T")); - - $scope.surface = cData.card_data[0].Surface_Position.map(function(a, i){ - return {position:cData.card_data[0].Surface_Position[i], load:cData.card_data[0].Surface_Load[i]}; - }); - $scope.surface.push($scope.surface[0]); - - $scope.downhole = cData.card_data[0].Downhole_Position.map(function(a, i){ - return {position:cData.card_data[0].Downhole_Position[i], load:cData.card_data[0].Downhole_Load[i]}; - }); - $scope.downhole.push($scope.downhole[0]); - - $scope.card_graph_data = { - surface: $scope.surface, - downhole: $scope.downhole - }; - var graphOptions = getCardGraphOptions($scope.surface, $scope.downhole); - $scope.surfaceOptions = graphOptions.surf; - $scope.downholeOptions = graphOptions.down; - }); - - var getTotals = json.getTotals(); - getTotals.then(function(data){ - $scope.totals = data.totals; - }); - }; - $scope.dashboard(); -}); - -wellCtrls.controller('totalsCtrl', function($scope, json, Page, $log){ - Page.setTitle('Totals'); - Page.setPage('dashboard'); - // $scope.currentPage = 1; - // $scope.numPerPage = 10; - // $scope.maxSize = 9; - $scope.dateListLoading = true; - $scope.totalsLoading = true; - var getDateList = json.getDateList(); - getDateList.then(function(data) { - $scope.dateListLoading = false; - $scope.dates = data.dates; - $scope.currentDate = $scope.dates[0]; - // $scope.numPages = function() { - // return Math.ceil($scope.dates.length / $scope.numPerPage); - // }; - // $scope.$watch('currentPage + numPerPage', function() { - // var begin = ($scope.currentPage - 1) * $scope.numPerPage; - // var end = begin + $scope.numPerPage; - // $scope.filteredDates = $scope.dates.slice(begin, end); - // }); - }); - - $scope.refresh = function(){ - var getTotals = json.getTotals(); - getTotals.then(function(tdata){ - $scope.totals = tdata.totals; - $scope.totalsLoading = false; - }); - }; - $scope.refresh(); -}); - -wellCtrls.controller('cardDataCtrl', function($scope, $http, $routeParams, json, Page, $log) { - $scope.loading = true; - Page.setTitle('Card Data'); - Page.setPage('cardData'); - $scope.id = $routeParams.id; - var getDateList = json.getDateList(); - getDateList.then(function(data) { - $scope.dates = data.dates; - $scope.currentDate = $scope.dates[0]; - }); - - var getCard = json.getCard($routeParams.id); - getCard.then(function(cData){ - cData = cData.data; - $scope.cardData = cData.card_data; - $scope.cardData.Stroke_Time = new Date($scope.cardData.Stroke_Time); - //$scope.cardData.dateTime = new Date($scope.cardData.localtime.replace(" ","T")); - - $scope.surface = cData.card_data.Surface_Position.map(function(a, i){ - return {position:cData.card_data.Surface_Position[i], load:cData.card_data.Surface_Load[i]}; - }); - $scope.surface.push($scope.surface[0]); - - $scope.downhole = cData.card_data.Downhole_Position.map(function(a, i){ - return {position:cData.card_data.Downhole_Position[i], load:cData.card_data.Downhole_Load[i]}; - }); - $scope.downhole.push($scope.downhole[0]); - - $scope.card_graph_data = { - surface: $scope.surface, - downhole: $scope.downhole - }; - var graphOptions = getCardGraphOptions($scope.surface, $scope.downhole); - $scope.surfaceOptions = graphOptions.surf; - $scope.downholeOptions = graphOptions.down; - - var getTagsAtTime = json.getTagsAtTime($scope.cardData.Stroke_Time.getTime() / 1000); - getTagsAtTime.then(function(d){ - var data = d.data; - if (data.status == "OK"){ - $scope.loading = false; - $scope.tagData = {}; - for(var i=0; i < data.vals.length; i++){ - $scope.tagData[data.vals[i].name] = data.vals[i]; - } - } - }); - }); -}); - -wellCtrls.controller('gaugeOffCtrl', function($scope, Page, json) { - Page.setTitle('Gauge Off'); - Page.setPage('gaugeOff'); - var getGaugeOffData = json.getGaugeOffData(); - getGaugeOffData.then(function(data) { - var i; - $scope.gaugeOffData = data.gaugeOffData; - i = 0; - - - - - while (i < $scope.gaugeOffData.length - 1) { - $scope.gaugeOffData[i].delta = {}; - $scope.gaugeOffData[i].delta.percent_run = ((parseFloat($scope.gaugeOffData[i].percent_run) - parseFloat($scope.gaugeOffData[i + 1].percent_run)) / parseFloat($scope.gaugeOffData[i + 1].percent_run) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.kWh = ((parseFloat($scope.gaugeOffData[i].kWh) - parseFloat($scope.gaugeOffData[i + 1].kWh)) / parseFloat($scope.gaugeOffData[i + 1].kWh) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.kWh_regen = ((parseFloat($scope.gaugeOffData[i].kWh_regen) - parseFloat($scope.gaugeOffData[i + 1].kWh_regen)) / parseFloat($scope.gaugeOffData[i + 1].kWh_regen) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.electricity_cost = ((parseFloat($scope.gaugeOffData[i].electricity_cost) - parseFloat($scope.gaugeOffData[i + 1].electricity_cost)) / parseFloat($scope.gaugeOffData[i + 1].electricity_cost) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.peak_load = ((parseFloat($scope.gaugeOffData[i].peak_load) - parseFloat($scope.gaugeOffData[i + 1].peak_load)) / parseFloat($scope.gaugeOffData[i + 1].peak_load) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.min_load = ((parseFloat($scope.gaugeOffData[i].min_load) - parseFloat($scope.gaugeOffData[i + 1].min_load)) / parseFloat($scope.gaugeOffData[i + 1].min_load) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.average_SPM = ((parseFloat($scope.gaugeOffData[i].average_SPM) - parseFloat($scope.gaugeOffData[i + 1].average_SPM)) / parseFloat($scope.gaugeOffData[i + 1].average_SPM) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.production_calculated = ((parseFloat($scope.gaugeOffData[i].production_calculated) - parseFloat($scope.gaugeOffData[i + 1].production_calculated)) / parseFloat($scope.gaugeOffData[i + 1].production_calculated) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.polished_rod_HP = ((parseFloat($scope.gaugeOffData[i].polished_rod_HP) - parseFloat($scope.gaugeOffData[i + 1].polished_rod_HP)) / parseFloat($scope.gaugeOffData[i + 1].polished_rod_HP) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.lifting_cost = ((parseFloat($scope.gaugeOffData[i].lifting_cost) - parseFloat($scope.gaugeOffData[i + 1].lifting_cost)) / parseFloat($scope.gaugeOffData[i + 1].lifting_cost) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.full_card_production = ((parseFloat($scope.gaugeOffData[i].full_card_production) - parseFloat($scope.gaugeOffData[i + 1].full_card_production)) / parseFloat($scope.gaugeOffData[i + 1].full_card_production) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.fluid_above_pump = ((parseFloat($scope.gaugeOffData[i].fluid_above_pump) - parseFloat($scope.gaugeOffData[i + 1].fluid_above_pump)) / parseFloat($scope.gaugeOffData[i + 1].fluid_above_pump) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.pump_intake_pressure = ((parseFloat($scope.gaugeOffData[i].pump_intake_pressure) - parseFloat($scope.gaugeOffData[i + 1].pump_intake_pressure)) / parseFloat($scope.gaugeOffData[i + 1].pump_intake_pressure) * 100).toFixed(2); - $scope.gaugeOffData[i].delta.inflow_rate = ((parseFloat($scope.gaugeOffData[i].inflow_rate) - parseFloat($scope.gaugeOffData[i + 1].inflow_Rate)) / parseFloat($scope.gaugeOffData[i + 1].inflow_rate) * 100).toFixed(2); - i++; - } - }); - $scope.show = { - PctRun: true, - kWh: true, - kWhRegen: false, - CostToOperate: true, - LiftingCost: false, - PeakLoad: false, - MinLoad: false, - AvgSPM: true, - CalcProduction: true, - ProjProduction: false, - PolishedRodHP: false, - FluidLevel: true, - PumpIntakePressure: false, - InflowRate: false - }; -}); - -wellCtrls.controller('wellTestCtrl', function($scope, Page, json) { - Page.setTitle('Well Test'); - Page.setPage('wellTest'); - var getWellTestData = json.getWellTestData(); - getWellTestData.then(function(data) { - $scope.wellTestData = data.wellTestData; - }); -}); - -wellCtrls.controller('eventsCtrl', function($scope, Page, json) { - Page.setTitle('Events'); - Page.setPage('events'); - var getEventsData = json.getEventsData(); - getEventsData.then(function(data) { - $scope.eventsData = data.eventsData; - }); -}); - -wellCtrls.controller('setupCtrl', function($scope, Page, json, $log) { - Page.setTitle('Setup'); - Page.setPage('setup'); - $scope.getPythonStatus = function() { - $scope.gettingStatus = true; - var getPythonStatus = json.getPythonStatus(); - getPythonStatus.then(function(pyData) { - $scope.gettingStatus = false; - if (pyData.status.alarmLogger === true && pyData.status.dataLogger === true){ - $scope.pythonStatus = 'OK'; - } else { - $scope.pythonStatus = 'NOT OK'; - } - $log.info(pyData); - }); - }; - var getSetup = json.getSetup(); - getSetup.then(function(data) { - $scope.setup = data.setup; - $scope.getPythonStatus(); - }); - $scope.restartPython = function() { - $scope.resetting = true; - var restartPython = json.restartPythonScripts(); - restartPython.then(function(response) { - $scope.resetting = false; - $scope.getPythonStatus(); - }); - }; -}); - -wellCtrls.controller('cardIDCtrl', function($scope, $http, $routeParams, json, Page) { - Page.setTitle('Card Data'); - Page.setPage('cardData'); - $scope.folder = $routeParams.date; - var getDateList = json.getDateList(); - getDateList.then(function(data) { - $scope.dates = data.dates; - $scope.currentDate = $scope.dates[0]; - }); - $http.get('/json/byID/' + $routeParams.date + '/' + $routeParams.card_id).success(function(cData) { - $scope.cardData = cData.contents; - $scope.surface = []; - $scope.downhole = []; - - $scope.surface = cData.s.map(function(a){ - return {position:a[0], load:a[1]}; - }); - $scope.surface.push($scope.surface[0]); - $scope.downhole = cData.d.map(function(a){ - return {position:a[0], load:a[1]}; - }); - $scope.downhole.push($scope.downhole[0]); - var limits = { - sMaxPos: $scope.surface.map(function(x){return x.position;}).reduce(function(y,z){return Math.max(y,z);})+ 20, - sMinPos: $scope.surface.map(function(x){return x.position;}).reduce(function(y,z){return Math.min(y,z);})- 20, - sMaxLoad: $scope.surface.map(function(x){return x.load;}).reduce(function(y,z){return Math.max(y,z);})+ 2000, - sMinLoad: $scope.surface.map(function(x){return x.load;}).reduce(function(y,z){return Math.min(y,z);})- 2000, - dMaxLoad: $scope.downhole.map(function(x){return x.load;}).reduce(function(y,z){return Math.max(y,z);})+ 2000, - dMinLoad: $scope.downhole.map(function(x){return x.load;}).reduce(function(y,z){return Math.min(y,z);})- 2000, - }; - $scope.limits = limits; - $scope.surfaceOptions = { - axes: { - x: { - key: 'position', - labelFunction: function(value) { - return value; - }, - type: 'linear', - min: limits.sMinPos, - max: limits.sMaxPos, - ticks: 7 - }, - y: { - type: 'linear', - min: limits.sMinLoad, - max: limits.sMaxLoad, - ticks: 5 - } - }, - series: [ - { - y: 'load', - color: 'steelblue', - thickness: '2px', - type: 'area', - striped: true, - label: 'Surface Card' - } - ], - lineMode: 'linear', - tension: 0.7, - tooltip: { - mode: 'scrubber', - formatter: function(x, y, series) { - return 'Position: ' + x + ' in., Load: ' + y + ' lb.'; - } - }, - drawLegend: true, - drawDots: true, - columnsHGap: 5 - }; - $scope.downholeOptions = { - axes: { - x: { - key: 'position', - labelFunction: function(value) { - return value; - }, - type: 'linear', - min: limits.sMinPos, - max: limits.sMaxPos, - ticks: 7 - }, - y: { - type: 'linear', - min: limits.dMinLoad, - max: limits.dMaxLoad, - ticks: 5 - } - }, - series: [ - { - y: 'load', - color: 'steelblue', - thickness: '2px', - type: 'area', - striped: true, - label: 'Downhole Card' - } - ], - lineMode: 'linear', - tension: 0.7, - tooltip: { - mode: 'scrubber', - formatter: function(x, y, series) { - return 'Position: ' + x + ' in., Load: ' + y + ' lb.'; - } - }, - drawLegend: true, - drawDots: true, - columnsHGap: 5 - }; - $scope.surfaceData = $scope.surface; - $scope.downholeData = $scope.downhole; - switch (parseInt($scope.cardData.card_type)) { - case 0: - $scope.cardType = 'Normal'; - break; - case 1: - $scope.cardType = 'Shutdown'; - break; - case 2: - $scope.cardType = 'Alarm'; - break; - default: - $scope.cardType = 'Unknown'; - break; - } - $scope.cardData.dateTime = new Date($scope.cardData.utctime.replace(" ","T")); - }); -}); - -wellCtrls.controller('cardCompareCtrl', function($scope, $http, $routeParams, json, Page, multipleCards, $log) { - var ddTemp, i, j, sdTemp, series, x; - Page.setTitle('Card Data'); - Page.setPage('cardData'); - $scope.cards = multipleCards.retrieve(); - $scope.cardData = []; - $scope.surface = []; - $scope.downhole = []; - $scope.surfacePos = []; - $scope.surfaceLoad = []; - $scope.downholePos = []; - $scope.downholeLoad = []; - $scope.limits = []; - $scope.cardType = []; - $scope.surfaceData = []; - $scope.downholeData = []; - var getDateList = json.getDateList(); - getDateList.then(function(data) { - $scope.dates = data.dates; - }); - $scope.surfaceOptions = { - axes: { - x: { - key: 'position', - labelFunction: function(value) { - return value; - }, - type: 'linear', - ticks: 7 - }, - y: { - type: 'linear', - ticks: 5 - } - }, - series: [], - lineMode: 'linear', - tension: 0.7, - tooltip: { - mode: 'scrubber', - formatter: function(x, y, series) { - return 'Position: ' + x + ' in., Load: ' + y + ' lb.'; - } - }, - drawLegend: true, - drawDots: true, - columnsHGap: 5 - }; - $scope.downholeOptions = { - axes: { - x: { - key: 'position', - labelFunction: function(value) { - return value; - }, - type: 'linear', - ticks: 7 - }, - y: { - type: 'linear', - ticks: 5 - } - }, - series: [], - lineMode: 'linear', - tension: 0.7, - tooltip: { - mode: 'scrubber', - formatter: function(x, y, series) { - return 'Position: ' + x + ' in., Load: ' + y + ' lb.'; - } - }, - drawLegend: true, - drawDots: true, - columnsHGap: 5 - }; - - - x = 0; - while (x < $scope.cards.length) { - $scope.cardData.push($scope.cards[x]); -// $scope.surface.push([]); -// $scope.downhole.push([]); -// $scope.surfacePos.push([]); -// $scope.surfaceLoad.push([]); -// $scope.downholePos.push([]); -// $scope.downholeLoad.push([]); - series = { - y: 'load' + x + '', - color: '#' + (0x1000000 + Math.random() * 0xffffff).toString(16).substr(1, 6), - striped: true, - thickness: '2px', - type: 'line', - axis: 'y', - label: $scope.cardData[x].Card_ID - }; - $scope.surfaceOptions.series.push(series); - $scope.downholeOptions.series.push(series); - i = 0; - while (i < $scope.cards[x].Surface_Position.length) { - if (!isNaN($scope.cards[x].Surface_Position[i]) && !isNaN($scope.cards[x].Surface_Load[i])) { -// $scope.surfacePos[x].push($scope.cards[x].Surface_Position[i]); -// $scope.surfaceLoad[x].push($scope.cards[x].s[i][1]); -// $scope.surface[x].push({ -// position: $scope.cards[x].Surface_Position[i], -// load: $scope.cards[x].Surface_Load[i] -// }); - sdTemp = {}; - sdTemp.position = $scope.cards[x].Surface_Position[i]; - sdTemp['load' + x] = $scope.cards[x].Surface_Load[i]; - $scope.surfaceData.push(sdTemp); - } - i++; - } -// $scope.surface[x].push({ -// position: $scope.cards[x].s[0][0], -// load: $scope.cards[x].s[0][1] -// }); - j = 0; - while (j < $scope.cards[x].Downhole_Position.length) { - if (!isNaN($scope.cards[x].Downhole_Position[j]) && !isNaN($scope.cards[x].Downhole_Position[j])) { -// $scope.downholePos[x].push($scope.cards[x].d[j][0]); -// $scope.downholeLoad[x].push($scope.cards[x].d[j][1]); -// $scope.downhole[x].push({ -// position: $scope.cards[x].d[j][0], -// load: $scope.cards[x].d[j][1] -// }); - ddTemp = {}; - ddTemp.position = $scope.cards[x].Downhole_Position[j]; - ddTemp['load' + x] = $scope.cards[x].Downhole_Load[j]; - $scope.downholeData.push(ddTemp); - } - j++; - } -// $scope.downhole[x].push({ -// position: $scope.cards[x].d[0][0], -// load: $scope.cards[x].d[0][1] -// }); - x++; - } -}); - -wellCtrls.controller('tagCtrl', function($scope, $http, $routeParams, tags, Page, $log) { - $scope.selectedTag = ""; - Page.setTitle('Tags'); - Page.setPage('tags'); - $scope.currentPage = 1; - var getStatusTags = tags.getAllTags(); - getStatusTags.then(function(data) { - $scope.tagsAvailable = data.tags; - $scope.getValue = function(tagName){ - var getTag = tags.get(tagName); - getTag.then(function(data) { - return data; - }); - }; - - $scope.setValue = function(tagName, value){ - var setTag = tags.set(tagName, value); - setTag.then(function(data) { - return data; - }); - }; - $scope.$watch('selectedTag', function() { - if ($scope.selectedTag !== ""){ - $scope.loadingTag = true; - var getTag = tags.get($scope.selectedTag); - getTag.then(function(data) { - $scope.tagValue = data.tag; - $scope.loadingTag = false; - }); - } - }); - }); -}); - -wellCtrls.controller('notesCtrl', function($scope, json, Page, $log){ - Page.setTitle('Notes'); - Page.setPage('notes'); - $scope.showDeletedNotes = false; - - var getNotes = function(){ - $scope.newNote.author = null; - $scope.newNote.note = null; - $scope.newNote.stroke_associated = null; - $scope.newNote.type = null; - - var getNotes = json.getNotes(); - getNotes.then(function(data){ - $scope.notes = data.notes; - }); - - var getNoteTypes = json.getNoteTypes(); - getNoteTypes.then(function(data){ - $scope.noteTypes = data.types; - }); - }; - - $scope.message = null; - $scope.newNote = {}; - $scope.newNote.author = null; - $scope.newNote.note = null; - $scope.newNote.stroke_associated = null; - $scope.newNote.type = null; - - - $scope.addNote = function(){ - if(!$scope.newNote.author){ - $scope.message = "No author provided."; - } else if(!$scope.newNote.note){ - $scope.message = "No note provided."; - } else if(!$scope.newNote.type){ - $scope.message = "No type selected."; - } else { - $scope.message = json.pushNote($scope.newNote.author, $scope.newNote.note, $scope.newNote.type, $scope.newNote.stroke_associated); - getNotes(); - } - - }; - - $scope.deleteNote = function(id){ - json.deleteNote(id); - getNotes(); - if ($scope.showDeletedNotes){ - getDeletedNotes(); - } - }; - - $scope.undeleteNote = function(id){ - json.undeleteNote(id); - getNotes(); - if ($scope.showDeletedNotes){ - getDeletedNotes(); - } - - }; - - $scope.toggleDeleted = function(){ - if ($scope.showDeletedNotes){ - $scope.showDeletedNotes = false; - } else { - $scope.showDeletedNotes = true; - getDeletedNotes(); - } - }; - - var getDeletedNotes = function(){ - $scope.showDeletedNotes = true; - var getDeletedNotes = json.getDeletedNotes(); - getDeletedNotes.then(function(data){ - $scope.deletedNotes = data.notes; - }); - }; - - $scope.startEditNote = function(id){ - $scope.message = null; - var editNoteTarget = $scope.notes.filter(function(x){ - return (x.id == id); - })[0]; - - $scope.editNote = { - id: editNoteTarget.id, - author: editNoteTarget.author, - type: editNoteTarget.ntypeval, - date_time: editNoteTarget.date_time, - stroke_associated: editNoteTarget.stroke, - note: editNoteTarget.note - }; - }; - - $scope.submitEditedNote = function(){ - if(!$scope.editNote.author){ - $scope.message = "No author provided."; - } else if(!$scope.editNote.note){ - $scope.message = "No note provided."; - } else if(!$scope.editNote.type){ - $scope.message = "No type selected."; - } else { - $scope.message = json.updateNote($scope.editNote.id, $scope.editNote.author, $scope.editNote.note, $scope.editNote.type, $scope.editNote.stroke_associated); - } - getNotes(); - }; - - getNotes(); - -}); - - -wellCtrls.controller('fluidShotCtrl', function($scope, json, Page, $log){ - Page.setTitle('Fluid Shot'); - Page.setPage('fluidshot'); - $scope.showDeletedShots = false; - - var getFluidShots = function(){ - $scope.newShot = { - shot_datetime:null, - pump_intake_pressure:null, - fluid_gradient:null, - friction:null, - taken_by:null - }; - - var getFluidShots = json.getFluidShots(); - getFluidShots.then(function(data){ - $scope.fluidShots = data.fluid_shots; - }); - }; - - /* - CREATE TABLE `WellData`.`fluid_shot` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `shot_datetime` datetime DEFAULT NULL, - `pump_intake_pressure` float DEFAULT NULL, - `fluid_gradient` float DEFAULT NULL, - `friction` float DEFAULT NULL, - `taken_by` varchar(128) DEFAULT NULL, - `deleted` int(11) DEFAULT NULL, - PRIMARY KEY (`id`) - ) - */ - - $scope.message = null; - $scope.newShot = { - shot_datetime:null, - pump_intake_pressure:null, - fluid_gradient:null, - friction:null, - taken_by:null - }; - - - $scope.addFluidShot = function(){ - if(!$scope.newShot.shot_datetime){ - $scope.message = "No Date/Time provided."; - } else if(!$scope.newShot.pump_intake_pressure){ - $scope.message = "No Pump Intake Pressure provided."; - } else if(!$scope.newShot.taken_by){ - $scope.message = "No Taken By provided."; - } else { - $scope.message = json.pushFluidShot($scope.newShot.shot_datetime, $scope.newShot.pump_intake_pressure, $scope.newShot.fluid_gradient, $scope.newShot.friction, $scope.newShot.taken_by); - getFluidShots(); - } - - }; - - $scope.deleteFluidShot = function(id){ - json.deleteFluidShot(id); - getFluidShots(); - if ($scope.showDeletedFluidShots){ - getDeletedFluidShots(); - } - }; - - $scope.undeleteFluidShot = function(id){ - json.undeleteFluidShot(id); - getFluidShots(); - if ($scope.showDeletedFluidShots){ - getDeletedFluidShots(); - } - - }; - - $scope.toggleDeleted = function(){ - if ($scope.showDeletedFluidShots){ - $scope.showDeletedFluidShots = false; - } else { - $scope.showDeletedFluidShots = true; - getDeletedFluidShots(); - } - }; - - var getDeletedFluidShots = function(){ - $scope.showDeletedFluidShots = true; - var getDeletedFluidShots = json.getDeletedFluidShots(); - getDeletedFluidShots.then(function(data){ - $scope.deletedFluidShots = data.fluid_shots; - }); - }; - - $scope.startEditFluidShot = function(id){ - $scope.message = null; - var editShotTarget = $scope.fluidShots.filter(function(x){ - return (x.id == id); - })[0]; - - $scope.editShot = { - id:editShotTarget.id, - shot_datetime:editShotTarget.shot_datetime, - pump_intake_pressure:editShotTarget.pump_intake_pressure, - fluid_gradient:editShotTarget.fluid_gradient, - friction:editShotTarget.friction, - taken_by:editShotTarget.taken_by - }; - }; - - $scope.submitEditedShot = function(){ - if(!$scope.editShot.shot_datetime){ - $scope.message = "No Date/Time provided."; - } else if(!$scope.editShot.pump_intake_pressure){ - $scope.message = "No Pump Intake Pressure provided."; - } else if(!$scope.editShot.taken_by){ - $scope.message = "No Taken By provided."; - } else { - $scope.message = json.updateFluidShot($scope.editShot.id, $scope.editShot.shot_datetime, $scope.editShot.pump_intake_pressure, $scope.editShot.fluid_gradient, $scope.editShot.friction, $scope.editShot.taken_by); - getFluidShots(); - } - }; - getFluidShots(); -}); - -wellCtrls.controller('wellTestCtrl', function($scope, json, Page, $log){ - Page.setTitle('Well Test'); - Page.setPage('well_Test'); - var getWellTests = function(){ - $scope.newTest = { - shot_datetime:null, - pump_intake_pressure:null, - fluid_gradient:null, - friction:null, - taken_by:null - }; - - var getWellTests = json.getWellTests(); - getFluidShots.then(function(data){ - $scope.wellTests = data.well_tests; - }); - }; - - /* - CREATE TABLE `WellData`.`fluid_shot` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `shot_datetime` datetime DEFAULT NULL, - `pump_intake_pressure` float DEFAULT NULL, - `fluid_gradient` float DEFAULT NULL, - `friction` float DEFAULT NULL, - `taken_by` varchar(128) DEFAULT NULL, - `deleted` int(11) DEFAULT NULL, - PRIMARY KEY (`id`) - ) - */ - - $scope.message = null; - $scope.newTest = { - shot_datetime:null, - pump_intake_pressure:null, - fluid_gradient:null, - friction:null, - taken_by:null - }; - - - $scope.addWellTest = function(){ - if(!$scope.newTest.shot_datetime){ - $scope.message = "No Date/Time provided."; - } else if(!$scope.newTest.pump_intake_pressure){ - $scope.message = "No Pump Intake Pressure provided."; - } else if(!$scope.newTest.taken_by){ - $scope.message = "No Taken By provided."; - } else { - $scope.message = json.pushFluidShot($scope.newTest.shot_datetime, $scope.newTest.pump_intake_pressure, $scope.newTest.fluid_gradient, $scope.newTest.friction, $scope.newTest.taken_by); - getWellTests(); - } - - }; - - $scope.deleteWellTest = function(id){ - json.deleteWellTest(id); - getWellTests(); - if ($scope.ShowDeletedTests){ - getDeletedWellTests(); - } - }; - - $scope.undeleteFluidShot = function(id){ - json.undeleteFluidShot(id); - getFluidShots(); - if ($scope.showDeletedFluidShots){ - getDeletedFluidShots(); - } - - }; - - $scope.toggleDeleted = function(){ - if ($scope.showDeletedFluidShots){ - $scope.showDeletedFluidShots = false; - } else { - $scope.showDeletedFluidShots = true; - getDeletedFluidShots(); - } - }; - - var getDeletedFluidShots = function(){ - $scope.showDeletedFluidShots = true; - var getDeletedFluidShots = json.getDeletedFluidShots(); - getDeletedFluidShots.then(function(data){ - $scope.deletedFluidShots = data.fluid_shots; - }); - }; - - $scope.startEditFluidShot = function(id){ - $scope.message = null; - var editShotTarget = $scope.fluidShots.filter(function(x){ - return (x.id == id); - })[0]; - - $scope.editShot = { - id:editShotTarget.id, - shot_datetime:editShotTarget.shot_datetime, - pump_intake_pressure:editShotTarget.pump_intake_pressure, - fluid_gradient:editShotTarget.fluid_gradient, - friction:editShotTarget.friction, - taken_by:editShotTarget.taken_by - }; - }; - - $scope.submitEditedShot = function(){ - if(!$scope.editShot.shot_datetime){ - $scope.message = "No Date/Time provided."; - } else if(!$scope.editShot.pump_intake_pressure){ - $scope.message = "No Pump Intake Pressure provided."; - } else if(!$scope.editShot.taken_by){ - $scope.message = "No Taken By provided."; - } else { - $scope.message = json.updateFluidShot($scope.editShot.id, $scope.editShot.shot_datetime, $scope.editShot.pump_intake_pressure, $scope.editShot.fluid_gradient, $scope.editShot.friction, $scope.editShot.taken_by); - getFluidShots(); - } - }; - getFluidShots(); -}); + sMaxPos: $scope.surface.map((x) -> + x.position + ).reduce((y, z) -> + Math.max y, z + ) + 20 + sMinPos: $scope.surface.map((x) -> + x.position + ).reduce((y, z) -> + Math.min y, z + ) - 20 + sMaxLoad: $scope.surface.map((x) -> + x.load + ).reduce((y, z) -> + Math.max y, z + ) + 2000 + sMinLoad: $scope.surface.map((x) -> + x.load + ).reduce((y, z) -> + Math.min y, z + ) - 2000 + dMaxLoad: $scope.downhole.map((x) -> + x.load + ).reduce((y, z) -> + Math.max y, z + ) + 2000 + dMinLoad: $scope.downhole.map((x) -> + x.load + ).reduce((y, z) -> + Math.min y, z + ) - 2000 + $scope.limits = limits + $scope.surfaceOptions = + axes: + x: + key: 'position' + labelFunction: (value) -> + value + type: 'linear' + min: limits.sMinPos + max: limits.sMaxPos + ticks: 7 + y: + type: 'linear' + min: limits.sMinLoad + max: limits.sMaxLoad + ticks: 5 + series: [ { + y: 'load' + color: 'steelblue' + thickness: '2px' + type: 'area' + striped: true + label: 'Surface Card' + } ] + lineMode: 'linear' + tension: 0.7 + tooltip: + mode: 'scrubber' + formatter: (x, y, series) -> + 'Position: ' + x + ' in., Load: ' + y + ' lb.' + drawLegend: true + drawDots: true + columnsHGap: 5 + $scope.downholeOptions = + axes: + x: + key: 'position' + labelFunction: (value) -> + value + type: 'linear' + min: limits.sMinPos + max: limits.sMaxPos + ticks: 7 + y: + type: 'linear' + min: limits.dMinLoad + max: limits.dMaxLoad + ticks: 5 + series: [ { + y: 'load' + color: 'steelblue' + thickness: '2px' + type: 'area' + striped: true + label: 'Downhole Card' + } ] + lineMode: 'linear' + tension: 0.7 + tooltip: + mode: 'scrubber' + formatter: (x, y, series) -> + 'Position: ' + x + ' in., Load: ' + y + ' lb.' + drawLegend: true + drawDots: true + columnsHGap: 5 + $scope.surfaceData = $scope.surface + $scope.downholeData = $scope.downhole + switch parseInt($scope.cardData.card_type) + when 0 + $scope.cardType = 'Normal' + when 1 + $scope.cardType = 'Shutdown' + when 2 + $scope.cardType = 'Alarm' + else + $scope.cardType = 'Unknown' + break + $scope.cardData.dateTime = new Date($scope.cardData.utctime.replace(' ', 'T')) + return + return +wellCtrls.controller 'cardCompareCtrl', ($scope, $http, $routeParams, json, Page, multipleCards, $log) -> + ddTemp = undefined + i = undefined + j = undefined + sdTemp = undefined + series = undefined + x = undefined + Page.setTitle 'Card Data' + Page.setPage 'cardData' + $scope.cards = multipleCards.retrieve() + $scope.cardData = [] + $scope.surface = [] + $scope.downhole = [] + $scope.surfacePos = [] + $scope.surfaceLoad = [] + $scope.downholePos = [] + $scope.downholeLoad = [] + $scope.limits = [] + $scope.cardType = [] + $scope.surfaceData = [] + $scope.downholeData = [] + getDateList = json.getDateList() + getDateList.then (data) -> + $scope.dates = data.dates + return + $scope.surfaceOptions = + axes: + x: + key: 'position' + labelFunction: (value) -> + value + type: 'linear' + ticks: 7 + y: + type: 'linear' + ticks: 5 + series: [] + lineMode: 'linear' + tension: 0.7 + tooltip: + mode: 'scrubber' + formatter: (x, y, series) -> + 'Position: ' + x + ' in., Load: ' + y + ' lb.' + drawLegend: true + drawDots: true + columnsHGap: 5 + $scope.downholeOptions = + axes: + x: + key: 'position' + labelFunction: (value) -> + value + type: 'linear' + ticks: 7 + y: + type: 'linear' + ticks: 5 + series: [] + lineMode: 'linear' + tension: 0.7 + tooltip: + mode: 'scrubber' + formatter: (x, y, series) -> + 'Position: ' + x + ' in., Load: ' + y + ' lb.' + drawLegend: true + drawDots: true + columnsHGap: 5 + x = 0 + while x < $scope.cards.length + $scope.cardData.push $scope.cards[x] + # $scope.surface.push([]); + # $scope.downhole.push([]); + # $scope.surfacePos.push([]); + # $scope.surfaceLoad.push([]); + # $scope.downholePos.push([]); + # $scope.downholeLoad.push([]); + series = + y: 'load' + x + '' + color: '#' + (0x1000000 + Math.random() * 0xffffff).toString(16).substr(1, 6) + striped: true + thickness: '2px' + type: 'line' + axis: 'y' + label: $scope.cardData[x].Card_ID + $scope.surfaceOptions.series.push series + $scope.downholeOptions.series.push series + i = 0 + while i < $scope.cards[x].Surface_Position.length + if !isNaN($scope.cards[x].Surface_Position[i]) and !isNaN($scope.cards[x].Surface_Load[i]) + # $scope.surfacePos[x].push($scope.cards[x].Surface_Position[i]); + # $scope.surfaceLoad[x].push($scope.cards[x].s[i][1]); + # $scope.surface[x].push({ + # position: $scope.cards[x].Surface_Position[i], + # load: $scope.cards[x].Surface_Load[i] + # }); + sdTemp = {} + sdTemp.position = $scope.cards[x].Surface_Position[i] + sdTemp['load' + x] = $scope.cards[x].Surface_Load[i] + $scope.surfaceData.push sdTemp + i++ + # $scope.surface[x].push({ + # position: $scope.cards[x].s[0][0], + # load: $scope.cards[x].s[0][1] + # }); + j = 0 + while j < $scope.cards[x].Downhole_Position.length + if !isNaN($scope.cards[x].Downhole_Position[j]) and !isNaN($scope.cards[x].Downhole_Position[j]) + # $scope.downholePos[x].push($scope.cards[x].d[j][0]); + # $scope.downholeLoad[x].push($scope.cards[x].d[j][1]); + # $scope.downhole[x].push({ + # position: $scope.cards[x].d[j][0], + # load: $scope.cards[x].d[j][1] + # }); + ddTemp = {} + ddTemp.position = $scope.cards[x].Downhole_Position[j] + ddTemp['load' + x] = $scope.cards[x].Downhole_Load[j] + $scope.downholeData.push ddTemp + j++ + # $scope.downhole[x].push({ + # position: $scope.cards[x].d[0][0], + # load: $scope.cards[x].d[0][1] + # }); + x++ + return +wellCtrls.controller 'tagCtrl', ($scope, $http, $routeParams, tags, Page, $log) -> + $scope.selectedTag = '' + Page.setTitle 'Tags' + Page.setPage 'tags' + $scope.currentPage = 1 + getStatusTags = tags.getAllTags() + getStatusTags.then (data) -> + $scope.tagsAvailable = data.tags + + $scope.getValue = (tagName) -> + getTag = tags.get(tagName) + getTag.then (data) -> + data + return + + $scope.setValue = (tagName, value) -> + setTag = tags.set(tagName, value) + setTag.then (data) -> + data + return + + $scope.$watch 'selectedTag', -> + if $scope.selectedTag != '' + $scope.loadingTag = true + getTag = tags.get($scope.selectedTag) + getTag.then (data) -> + $scope.tagValue = data.tag + $scope.loadingTag = false + return + return + return + return +wellCtrls.controller 'notesCtrl', ($scope, json, Page, $log) -> + Page.setTitle 'Notes' + Page.setPage 'notes' + $scope.showDeletedNotes = false + + getNotes = -> + `var getNotes` + $scope.newNote.author = null + $scope.newNote.note = null + $scope.newNote.stroke_associated = null + $scope.newNote.type = null + getNotes = json.getNotes() + getNotes.then (data) -> + $scope.notes = data.notes + return + getNoteTypes = json.getNoteTypes() + getNoteTypes.then (data) -> + $scope.noteTypes = data.types + return + return + + $scope.message = null + $scope.newNote = {} + $scope.newNote.author = null + $scope.newNote.note = null + $scope.newNote.stroke_associated = null + $scope.newNote.type = null + + $scope.addNote = -> + if !$scope.newNote.author + $scope.message = 'No author provided.' + else if !$scope.newNote.note + $scope.message = 'No note provided.' + else if !$scope.newNote.type + $scope.message = 'No type selected.' + else + $scope.message = json.pushNote($scope.newNote.author, $scope.newNote.note, $scope.newNote.type, $scope.newNote.stroke_associated) + getNotes() + return + + $scope.deleteNote = (id) -> + json.deleteNote id + getNotes() + if $scope.showDeletedNotes + getDeletedNotes() + return + + $scope.undeleteNote = (id) -> + json.undeleteNote id + getNotes() + if $scope.showDeletedNotes + getDeletedNotes() + return + + $scope.toggleDeleted = -> + if $scope.showDeletedNotes + $scope.showDeletedNotes = false + else + $scope.showDeletedNotes = true + getDeletedNotes() + return + + getDeletedNotes = -> + `var getDeletedNotes` + $scope.showDeletedNotes = true + getDeletedNotes = json.getDeletedNotes() + getDeletedNotes.then (data) -> + $scope.deletedNotes = data.notes + return + return + + $scope.startEditNote = (id) -> + $scope.message = null + editNoteTarget = $scope.notes.filter((x) -> + x.id == id + )[0] + $scope.editNote = + id: editNoteTarget.id + author: editNoteTarget.author + type: editNoteTarget.ntypeval + date_time: editNoteTarget.date_time + stroke_associated: editNoteTarget.stroke + note: editNoteTarget.note + return + + $scope.submitEditedNote = -> + if !$scope.editNote.author + $scope.message = 'No author provided.' + else if !$scope.editNote.note + $scope.message = 'No note provided.' + else if !$scope.editNote.type + $scope.message = 'No type selected.' + else + $scope.message = json.updateNote($scope.editNote.id, $scope.editNote.author, $scope.editNote.note, $scope.editNote.type, $scope.editNote.stroke_associated) + getNotes() + return + + getNotes() + return +wellCtrls.controller 'fluidShotCtrl', ($scope, json, Page, $log) -> + Page.setTitle 'Fluid Shot' + Page.setPage 'fluidshot' + $scope.showDeletedShots = false + + getFluidShots = -> + `var getFluidShots` + $scope.newShot = + shot_datetime: null + pump_intake_pressure: null + fluid_gradient: null + friction: null + taken_by: null + getFluidShots = json.getFluidShots() + getFluidShots.then (data) -> + $scope.fluidShots = data.fluid_shots + return + return + + ### + CREATE TABLE `WellData`.`fluid_shot` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `shot_datetime` datetime DEFAULT NULL, + `pump_intake_pressure` float DEFAULT NULL, + `fluid_gradient` float DEFAULT NULL, + `friction` float DEFAULT NULL, + `taken_by` varchar(128) DEFAULT NULL, + `deleted` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) + ) + ### + + $scope.message = null + $scope.newShot = + shot_datetime: null + pump_intake_pressure: null + fluid_gradient: null + friction: null + taken_by: null + + $scope.addFluidShot = -> + if !$scope.newShot.shot_datetime + $scope.message = 'No Date/Time provided.' + else if !$scope.newShot.pump_intake_pressure + $scope.message = 'No Pump Intake Pressure provided.' + else if !$scope.newShot.taken_by + $scope.message = 'No Taken By provided.' + else + $scope.message = json.pushFluidShot($scope.newShot.shot_datetime, $scope.newShot.pump_intake_pressure, $scope.newShot.fluid_gradient, $scope.newShot.friction, $scope.newShot.taken_by) + getFluidShots() + return + + $scope.deleteFluidShot = (id) -> + json.deleteFluidShot id + getFluidShots() + if $scope.showDeletedFluidShots + getDeletedFluidShots() + return + + $scope.undeleteFluidShot = (id) -> + json.undeleteFluidShot id + getFluidShots() + if $scope.showDeletedFluidShots + getDeletedFluidShots() + return + + $scope.toggleDeleted = -> + if $scope.showDeletedFluidShots + $scope.showDeletedFluidShots = false + else + $scope.showDeletedFluidShots = true + getDeletedFluidShots() + return + + getDeletedFluidShots = -> + `var getDeletedFluidShots` + $scope.showDeletedFluidShots = true + getDeletedFluidShots = json.getDeletedFluidShots() + getDeletedFluidShots.then (data) -> + $scope.deletedFluidShots = data.fluid_shots + return + return + + $scope.startEditFluidShot = (id) -> + $scope.message = null + editShotTarget = $scope.fluidShots.filter((x) -> + x.id == id + )[0] + $scope.editShot = + id: editShotTarget.id + shot_datetime: editShotTarget.shot_datetime + pump_intake_pressure: editShotTarget.pump_intake_pressure + fluid_gradient: editShotTarget.fluid_gradient + friction: editShotTarget.friction + taken_by: editShotTarget.taken_by + return + + $scope.submitEditedShot = -> + if !$scope.editShot.shot_datetime + $scope.message = 'No Date/Time provided.' + else if !$scope.editShot.pump_intake_pressure + $scope.message = 'No Pump Intake Pressure provided.' + else if !$scope.editShot.taken_by + $scope.message = 'No Taken By provided.' + else + $scope.message = json.updateFluidShot($scope.editShot.id, $scope.editShot.shot_datetime, $scope.editShot.pump_intake_pressure, $scope.editShot.fluid_gradient, $scope.editShot.friction, $scope.editShot.taken_by) + getFluidShots() + return + + getFluidShots() + return +wellCtrls.controller 'wellTestCtrl', ($scope, json, Page, $log) -> + Page.setTitle 'Well Test' + Page.setPage 'well_Test' + + getWellTests = -> + `var getWellTests` + $scope.newTest = + shot_datetime: null + pump_intake_pressure: null + fluid_gradient: null + friction: null + taken_by: null + getWellTests = json.getWellTests() + getWellTests.then (data) -> + $scope.wellTests = data.well_tests + return + return + + $scope.message = null + $scope.newTest = + shot_datetime: null + pump_intake_pressure: null + fluid_gradient: null + friction: null + taken_by: null + + $scope.addWellTest = -> + if !$scope.newTest.shot_datetime + $scope.message = 'No Date/Time provided.' + else if !$scope.newTest.pump_intake_pressure + $scope.message = 'No Pump Intake Pressure provided.' + else if !$scope.newTest.taken_by + $scope.message = 'No Taken By provided.' + else + $scope.message = json.pushFluidShot($scope.newTest.shot_datetime, $scope.newTest.pump_intake_pressure, $scope.newTest.fluid_gradient, $scope.newTest.friction, $scope.newTest.taken_by) + getWellTests() + return + + $scope.deleteWellTest = (id) -> + json.deleteWellTest id + getWellTests() + if $scope.ShowDeletedTests + getDeletedWellTests() + return + + $scope.undeleteFluidShot = (id) -> + json.undeleteFluidShot id + getFluidShots() + if $scope.showDeletedFluidShots + getDeletedFluidShots() + return + + $scope.toggleDeleted = -> + if $scope.showDeletedFluidShots + $scope.showDeletedFluidShots = false + else + $scope.showDeletedFluidShots = true + getDeletedFluidShots() + return + + getDeletedFluidShots = -> + `var getDeletedFluidShots` + $scope.showDeletedFluidShots = true + getDeletedFluidShots = json.getDeletedFluidShots() + getDeletedFluidShots.then (data) -> + $scope.deletedFluidShots = data.fluid_shots + return + return + + $scope.startEditFluidShot = (id) -> + $scope.message = null + editShotTarget = $scope.fluidShots.filter((x) -> + x.id == id + )[0] + $scope.editShot = + id: editShotTarget.id + shot_datetime: editShotTarget.shot_datetime + pump_intake_pressure: editShotTarget.pump_intake_pressure + fluid_gradient: editShotTarget.fluid_gradient + friction: editShotTarget.friction + taken_by: editShotTarget.taken_by + return + + $scope.submitEditedShot = -> + if !$scope.editShot.shot_datetime + $scope.message = 'No Date/Time provided.' + else if !$scope.editShot.pump_intake_pressure + $scope.message = 'No Pump Intake Pressure provided.' + else if !$scope.editShot.taken_by + $scope.message = 'No Taken By provided.' + else + $scope.message = json.updateFluidShot($scope.editShot.id, $scope.editShot.shot_datetime, $scope.editShot.pump_intake_pressure, $scope.editShot.fluid_gradient, $scope.editShot.friction, $scope.editShot.taken_by) + getFluidShots() + return + + getWellTests() + return