diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0f0b5da..88a2231 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,15 @@ - + + + + + + + + + @@ -131,10 +139,121 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -151,6 +270,8 @@ + + @@ -166,11 +287,11 @@ - + - + @@ -294,16 +415,12 @@ - + - - - - - - - + + + @@ -338,6 +455,7 @@ fill arraycopy nT1 + index @@ -751,10 +869,10 @@ @@ -769,10 +887,9 @@ - @@ -790,7 +907,6 @@ - @@ -843,74 +959,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -1194,7 +1247,7 @@ - + @@ -1211,8 +1264,7 @@ - - + @@ -1226,6 +1278,7 @@ + @@ -1307,11 +1360,7 @@ - - - - - + @@ -1436,7 +1485,118 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1445,11 +1605,7 @@ - - - - - + @@ -1944,18 +2100,6 @@ - - - - - - - - - - - - @@ -1974,6 +2118,8 @@ + + @@ -1988,10 +2134,121 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1999,13 +2256,21 @@ - + + + + + + + + + diff --git a/README.md b/README.md index 7fe4890..7af1e47 100644 --- a/README.md +++ b/README.md @@ -75,12 +75,10 @@ systemctl enable mongod.service - sets the minutes of downtime after pumpoff to `newSetpoint` - returns `{"pumpOffDowntime": }` -## Endpoint `/command?` +## Endpoint `/command?cmd=&user=` -### `start=` -- if startCommand = `true`, the well will attempt to start. +### `start` - returns `{"startCommand: ", "status": }` -### `stop=` -- if stopCommand = `true`, the well will attempt to stop. +### `stop` - returns `{"stopCommand: ", "status": }` diff --git a/src/main/java/com/henrypump/poc/Database.java b/src/main/java/com/henrypump/poc/Database.java index d398654..75ba03e 100644 --- a/src/main/java/com/henrypump/poc/Database.java +++ b/src/main/java/com/henrypump/poc/Database.java @@ -12,6 +12,7 @@ import com.mongodb.client.MongoCollection; import com.mongodb.client.model.Accumulators; import com.mongodb.client.model.Aggregates; +import com.mongodb.client.model.Indexes; import com.mongodb.client.model.Sorts; import org.bson.Document; @@ -36,11 +37,55 @@ public class Database { Database(){ mongoClient = new MongoClient(); database = mongoClient.getDatabase(pocDatabase); + MongoCollection cardCollection = database.getCollection("cards"); + cardCollection.createIndex(Indexes.ascending("timestamp", "strokeNumber")); + + MongoCollection wellDataCollection = database.getCollection("wellData"); + wellDataCollection.createIndex(Indexes.ascending("timestamp", "tagName")); + + MongoCollection gaugeOffCollection = database.getCollection("gaugeOff"); + gaugeOffCollection.createIndex(Indexes.ascending("timestamp", "tagName")); + + + MongoCollection wellTestCollection = database.getCollection("wellTests"); + wellTestCollection.createIndex(Indexes.ascending("testStartTime")); + + MongoCollection fluidShotsCollection = database.getCollection("fluidShots"); + fluidShotsCollection.createIndex(Indexes.ascending("timestamp")); + + MongoCollection runStatusCollection = database.getCollection("runStatus"); + runStatusCollection.createIndex(Indexes.ascending("timestamp")); + + MongoCollection wellConfigCollection = database.getCollection("wellConfiguration"); + wellConfigCollection.createIndex(Indexes.ascending("timestamp")); + + } Database(String dbHostname){ mongoClient = new MongoClient(dbHostname); database = mongoClient.getDatabase(pocDatabase); + MongoCollection cardCollection = database.getCollection("cards"); + cardCollection.createIndex(Indexes.ascending("timestamp")); + + MongoCollection wellDataCollection = database.getCollection("wellData"); + wellDataCollection.createIndex(Indexes.ascending("timestamp", "tagName")); + + MongoCollection gaugeOffCollection = database.getCollection("gaugeOff"); + gaugeOffCollection.createIndex(Indexes.ascending("timestamp", "tagName")); + + + MongoCollection wellTestCollection = database.getCollection("wellTests"); + wellTestCollection.createIndex(Indexes.ascending("testStartTime")); + + MongoCollection fluidShotsCollection = database.getCollection("fluidShots"); + fluidShotsCollection.createIndex(Indexes.ascending("timestamp")); + + MongoCollection runStatusCollection = database.getCollection("runStatus"); + runStatusCollection.createIndex(Indexes.ascending("timestamp")); + + MongoCollection wellConfigCollection = database.getCollection("wellConfiguration"); + wellConfigCollection.createIndex(Indexes.ascending("timestamp")); } public long getLastStrokeNum(){ @@ -159,7 +204,6 @@ public class Database { public long newWellTest(WellTest inp){ MongoCollection collection = database.getCollection("wellTests"); - Document doc = new Document("testStartTime", Date.from(inp.getTestStart().toInstant())) .append("testHours", inp.getTestHours()) .append("testTotalBBL", inp.getTotalFluidBBL()) @@ -230,7 +274,6 @@ public class Database { public long newRunStatus(String runStatus, String initiator){ MongoCollection collection = database.getCollection("runStatus"); - Document doc = new Document("status", runStatus) .append("initiator", initiator) .append("timestamp", Date.from(ZonedDateTime.now().toInstant())); @@ -258,7 +301,6 @@ public class Database { public long storeWellSetup(Well thisWell){ MongoCollection collection = database.getCollection("wellConfiguration"); - ArrayList taperArr = new ArrayList(); for (int i = 1; i <= thisWell.getNumTapers(); i++){ Document tap = new Document("length", thisWell.getRodLength(i)) diff --git a/www/pocwww/pocwww/__init__.py b/www/pocwww/pocwww/__init__.py index baae079..82d7d9d 100644 --- a/www/pocwww/pocwww/__init__.py +++ b/www/pocwww/pocwww/__init__.py @@ -2,10 +2,12 @@ from pyramid.config import Configurator from pyramid.authentication import AuthTktAuthenticationPolicy from pyramid.authorization import ACLAuthorizationPolicy from datetime import datetime, date +from dateutil import tz from pyramid.renderers import JSON from bson.objectid import ObjectId from .pagination import Pagination + try: # for python 2 from urlparse import urlparse @@ -15,15 +17,19 @@ except ImportError: from pymongo import MongoClient +from_zone = tz.tzutc() +to_zone = tz.tzlocal() def format_datetime(inpDate, format='medium'): + inpDate = inpDate.replace(tzinfo=from_zone) + localDate = inpDate.astimezone(to_zone) if format == 'long': format = "%A, %B %d %Y at %I:%M:%S %p" elif format == 'medium': format = "%a, %b %d %Y %I:%M:%S %p" elif format == 'short': format = "%m/%d/%Y %I:%M:%S %p" - return inpDate.strftime(format) + return localDate.strftime(format) def format_dateString(inpDate, format='medium'): @@ -170,13 +176,17 @@ def main(global_config, **settings): config.add_route("json_singlevaluedaterange", "/json/values/tag/{tagname}/daterange") config.add_route("json_updateconfig", "/json/updateconfig", factory='pocwww.security.UserLoginFactory') + config.add_route("json_shake", '/json/cmd/shake', factory='pocwww.security.UserLoginFactory') + config.add_route("json_cmd", '/json/cmd/{action}', factory='pocwww.security.UserLoginFactory') - config.add_route("json_cmd_start", "/json/cmd/start", factory='pocwww.security.UserLoginFactory') - config.add_route("json_cmd_stop", "/json/cmd/stop", factory='pocwww.security.UserLoginFactory') - config.add_route("json_cmd_shake", "/json/cmd/shake", factory='pocwww.security.UserLoginFactory') + # config.add_route("json_cmd_start", "/json/cmd/start", factory='pocwww.security.UserLoginFactory') + # config.add_route("json_cmd_stop", "/json/cmd/stop", factory='pocwww.security.UserLoginFactory') + # config.add_route("json_cmd_shake", "/json/cmd/shake", factory='pocwww.security.UserLoginFactory') config.add_route("json_update_poc_address", "/json/updatepocaddress", factory='pocwww.security.UserLoginFactory') config.add_route("json_users", "/json/users", factory='pocwww.security.UserLoginFactory') + + config.scan() return config.make_wsgi_app() diff --git a/www/pocwww/pocwww/json.py b/www/pocwww/pocwww/json.py index 4e78494..3e4cd3d 100644 --- a/www/pocwww/pocwww/json.py +++ b/www/pocwww/pocwww/json.py @@ -160,27 +160,26 @@ def json_updateconfig(request): return {'new_config': request.json_body, 'stored_result': result, 'updated': pocCmdSts} -@view_config(route_name="json_cmd_start", renderer="prettyjson", permission="control") -def json_start(request): +@view_config(route_name="json_cmd", renderer="prettyjson", permission="edit") +def json_cmd(request): + action = request.matchdict['action'] address = get_poc_address(request) or 'localhost' - start_url = "http://{}:8000/command?cmd=start&user={}".format(address, request.authenticated_userid) - r = requests.get(start_url) + + java_url = {} + java_url['start'] = "http://{}:8000/command?cmd=start&user={}".format(address, request.authenticated_userid) + java_url['stop'] = "http://{}:8000/command?cmd=stop&user={}".format(address, request.authenticated_userid) + java_url['shake'] = "http://{}:8000/shake".format(address) + + r = requests.get(java_url[action]) return r.text if r.status_code == 200 else {"status": "failure sending command"} -@view_config(route_name="json_cmd_stop", renderer="prettyjson", permission="control") -def json_stop(request): - address = get_poc_address(request) or 'localhost' - stop_url = "http://{}:8000/command?cmd=stop&user={}".format(address, request.authenticated_userid) - r = requests.get(stop_url) - return r.text if r.status_code == 200 else {"status": "failure sending command"} - - -@view_config(route_name="json_cmd_shake", renderer="prettyjson", permission="view") +@view_config(route_name="json_shake", renderer="prettyjson", permission="view") def json_shake(request): address = get_poc_address(request) or 'localhost' - shake_url = "http://{}:8000/shake".format(address) - r = requests.get(shake_url) + url = "http://{}:8000/shake".format(address) + + r = requests.get(url) return r.text if r.status_code == 200 else {"status": "failure sending command"} diff --git a/www/pocwww/pocwww/view_helpers.py b/www/pocwww/pocwww/view_helpers.py index 47d8ef5..203d204 100644 --- a/www/pocwww/pocwww/view_helpers.py +++ b/www/pocwww/pocwww/view_helpers.py @@ -1,8 +1,12 @@ from datetime import datetime, timedelta from math import ceil from passlib.apps import custom_app_context as poc_pwd_context +from dateutil import tz from .pagination import Pagination +from_zone = tz.tzutc() +to_zone = tz.tzlocal() + def get_lastest_tag_values(request): latest_tag_values = [] @@ -42,7 +46,7 @@ def card_page(request): except KeyError: pass - cards_date_start = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) + cards_date_start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) try: cards_date_start = datetime.strptime(request.matchdict['cards_date'], "%Y-%m-%d") except KeyError: diff --git a/www/pocwww/setup.py b/www/pocwww/setup.py index 6021e62..dc0377d 100644 --- a/www/pocwww/setup.py +++ b/www/pocwww/setup.py @@ -15,7 +15,8 @@ requires = [ 'waitress', 'pymongo', 'requests', - 'passlib' + 'passlib', + 'python-dateutil', ] tests_require = [