moves all collections to class variables

This commit is contained in:
Patrick McDonagh
2017-03-03 18:08:23 -06:00
parent bb1323e146
commit 361d3dc93a
2 changed files with 56 additions and 99 deletions

14
.idea/workspace.xml generated
View File

@@ -2,13 +2,7 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="28cc251f-c94f-44ee-a66d-77aaab6e3483" name="Default" comment=""> <list default="true" id="28cc251f-c94f-44ee-a66d-77aaab6e3483" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java" afterPath="$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java" afterPath="$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/www/pocwww/pocwww/__init__.py" afterPath="$PROJECT_DIR$/www/pocwww/pocwww/__init__.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/www/pocwww/pocwww/json.py" afterPath="$PROJECT_DIR$/www/pocwww/pocwww/json.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/www/pocwww/pocwww/view_helpers.py" afterPath="$PROJECT_DIR$/www/pocwww/pocwww/view_helpers.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/www/pocwww/setup.py" afterPath="$PROJECT_DIR$/www/pocwww/setup.py" />
</list> </list>
<ignored path="$PROJECT_DIR$/target/" /> <ignored path="$PROJECT_DIR$/target/" />
<ignored path="$PROJECT_DIR$/.gradle/" /> <ignored path="$PROJECT_DIR$/.gradle/" />
@@ -418,8 +412,8 @@
<file leaf-file-name="Database.java" pinned="false" current-in-tab="true"> <file leaf-file-name="Database.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java"> <entry file="file://$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="240"> <state relative-caret-position="559">
<caret line="40" column="79" lean-forward="false" selection-start-line="40" selection-start-column="79" selection-end-line="40" selection-end-column="79" /> <caret line="302" column="19" lean-forward="true" selection-start-line="302" selection-start-column="19" selection-end-line="302" selection-end-column="19" />
<folding /> <folding />
</state> </state>
</provider> </provider>
@@ -2265,8 +2259,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java"> <entry file="file://$PROJECT_DIR$/src/main/java/com/henrypump/poc/Database.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="240"> <state relative-caret-position="559">
<caret line="40" column="79" lean-forward="false" selection-start-line="40" selection-start-column="79" selection-end-line="40" selection-end-column="79" /> <caret line="302" column="19" lean-forward="true" selection-start-line="302" selection-start-column="19" selection-end-line="302" selection-end-column="19" />
<folding /> <folding />
</state> </state>
</provider> </provider>

View File

@@ -33,31 +33,41 @@ public class Database {
private String pocDatabase = "poc"; private String pocDatabase = "poc";
private MongoClient mongoClient; private MongoClient mongoClient;
private MongoDatabase database; private MongoDatabase database;
private MongoCollection<Document> cardCollection, wellDataCollection, gaugeOffCollection, wellTestCollection,
fluidShotsCollection, runStatusCollection, wellConfigCollection, setpointCollection;
public void initCollections(){
cardCollection = database.getCollection("cards");
cardCollection.createIndex(Indexes.ascending("timestamp", "strokeNumber"));
wellDataCollection = database.getCollection("wellData");
wellDataCollection.createIndex(Indexes.ascending("timestamp", "tagName"));
gaugeOffCollection = database.getCollection("gaugeOff");
gaugeOffCollection.createIndex(Indexes.ascending("timestamp", "tagName"));
wellTestCollection = database.getCollection("wellTests");
wellTestCollection.createIndex(Indexes.ascending("testStartTime"));
fluidShotsCollection = database.getCollection("fluidShots");
fluidShotsCollection.createIndex(Indexes.ascending("timestamp"));
runStatusCollection = database.getCollection("runStatus");
runStatusCollection.createIndex(Indexes.ascending("timestamp"));
wellConfigCollection = database.getCollection("wellConfiguration");
wellConfigCollection.createIndex(Indexes.ascending("timestamp"));
setpointCollection = database.getCollection("setpoints");
}
Database(){ Database(){
mongoClient = new MongoClient(); mongoClient = new MongoClient();
database = mongoClient.getDatabase(pocDatabase); database = mongoClient.getDatabase(pocDatabase);
MongoCollection<Document> cardCollection = database.getCollection("cards");
cardCollection.createIndex(Indexes.ascending("timestamp", "strokeNumber"));
MongoCollection<Document> wellDataCollection = database.getCollection("wellData"); initCollections();
wellDataCollection.createIndex(Indexes.ascending("timestamp", "tagName"));
MongoCollection<Document> gaugeOffCollection = database.getCollection("gaugeOff");
gaugeOffCollection.createIndex(Indexes.ascending("timestamp", "tagName"));
MongoCollection<Document> wellTestCollection = database.getCollection("wellTests");
wellTestCollection.createIndex(Indexes.ascending("testStartTime"));
MongoCollection<Document> fluidShotsCollection = database.getCollection("fluidShots");
fluidShotsCollection.createIndex(Indexes.ascending("timestamp"));
MongoCollection<Document> runStatusCollection = database.getCollection("runStatus");
runStatusCollection.createIndex(Indexes.ascending("timestamp"));
MongoCollection<Document> wellConfigCollection = database.getCollection("wellConfiguration");
wellConfigCollection.createIndex(Indexes.ascending("timestamp"));
} }
@@ -65,27 +75,12 @@ public class Database {
Database(String dbHostname){ Database(String dbHostname){
mongoClient = new MongoClient(dbHostname); mongoClient = new MongoClient(dbHostname);
database = mongoClient.getDatabase(pocDatabase); database = mongoClient.getDatabase(pocDatabase);
MongoCollection<Document> cardCollection = database.getCollection("cards");
cardCollection.createIndex(Indexes.ascending("timestamp"));
MongoCollection<Document> wellDataCollection = database.getCollection("wellData"); initCollections();
wellDataCollection.createIndex(Indexes.ascending("timestamp", "tagName")); }
MongoCollection<Document> gaugeOffCollection = database.getCollection("gaugeOff"); public void close(){
gaugeOffCollection.createIndex(Indexes.ascending("timestamp", "tagName")); mongoClient.close();
MongoCollection<Document> wellTestCollection = database.getCollection("wellTests");
wellTestCollection.createIndex(Indexes.ascending("testStartTime"));
MongoCollection<Document> fluidShotsCollection = database.getCollection("fluidShots");
fluidShotsCollection.createIndex(Indexes.ascending("timestamp"));
MongoCollection<Document> runStatusCollection = database.getCollection("runStatus");
runStatusCollection.createIndex(Indexes.ascending("timestamp"));
MongoCollection<Document> wellConfigCollection = database.getCollection("wellConfiguration");
wellConfigCollection.createIndex(Indexes.ascending("timestamp"));
} }
public long getLastStrokeNum(){ public long getLastStrokeNum(){
@@ -112,7 +107,7 @@ public class Database {
} }
public long newCard(Card inpCard){ public long newCard(Card inpCard){
MongoCollection<Document> collection = database.getCollection("cards");
List<Double> s_p = new ArrayList<Double>(); List<Double> s_p = new ArrayList<Double>();
List<Double> s_l = new ArrayList<Double>(); List<Double> s_l = new ArrayList<Double>();
List<Double> d_p = new ArrayList<Double>(); List<Double> d_p = new ArrayList<Double>();
@@ -135,16 +130,13 @@ public class Database {
.append("downhole_position", d_p) .append("downhole_position", d_p)
.append("downhole_load", d_l) .append("downhole_load", d_l)
.append("timestamp", Date.from(ZonedDateTime.now().toInstant())); .append("timestamp", Date.from(ZonedDateTime.now().toInstant()));
collection.insertOne(doc); cardCollection.insertOne(doc);
System.out.println("Stored stroke number " + inpCard.getStrokeNumber() + " as " + doc.getObjectId("_id")); System.out.println("Stored stroke number " + inpCard.getStrokeNumber() + " as " + doc.getObjectId("_id"));
return collection.count(); return cardCollection.count();
}
public void close(){
mongoClient.close();
} }
public long newMeasurement(Measurement inpMeasurement){ public long newMeasurement(Measurement inpMeasurement){
MongoCollection<Document> collection = database.getCollection("wellData");
Document doc = new Document("tagname", inpMeasurement.getTagName()) Document doc = new Document("tagname", inpMeasurement.getTagName())
.append("currentValue", inpMeasurement.getCurrentValue()) .append("currentValue", inpMeasurement.getCurrentValue())
.append("maxDailyValue", inpMeasurement.getDailyMax()) .append("maxDailyValue", inpMeasurement.getDailyMax())
@@ -153,14 +145,13 @@ public class Database {
.append("dailyTotal", inpMeasurement.getTotal()) .append("dailyTotal", inpMeasurement.getTotal())
.append("numMeasurements", inpMeasurement.getNumMeasurements()) .append("numMeasurements", inpMeasurement.getNumMeasurements())
.append("timestamp", Date.from(ZonedDateTime.now().toInstant())); .append("timestamp", Date.from(ZonedDateTime.now().toInstant()));
collection.insertOne(doc); wellDataCollection.insertOne(doc);
System.out.println("Stored " + inpMeasurement.getCurrentValue() + " for " + inpMeasurement.getTagName()); System.out.println("Stored " + inpMeasurement.getCurrentValue() + " for " + inpMeasurement.getTagName());
return collection.count(); return wellDataCollection.count();
} }
public Document getLastStoredMeasurement(String tagName){ public Document getLastStoredMeasurement(String tagName){
MongoCollection<Document> collection = database.getCollection("wellData"); MongoCursor<Document> cursor = wellDataCollection.find(eq("tagname", tagName)).sort(Sorts.descending("timestamp")).limit(1).iterator();
MongoCursor<Document> cursor = collection.find(eq("tagname", tagName)).sort(Sorts.descending("timestamp")).limit(1).iterator();
Document lastStoredDoc = new Document(); Document lastStoredDoc = new Document();
try { try {
while (cursor.hasNext()) { while (cursor.hasNext()) {
@@ -173,7 +164,6 @@ public class Database {
} }
public long newDailyTotal(Measurement inpMeasurement){ public long newDailyTotal(Measurement inpMeasurement){
MongoCollection<Document> collection = database.getCollection("gaugeOff");
Document doc = new Document("tagname", inpMeasurement.getTagName()) Document doc = new Document("tagname", inpMeasurement.getTagName())
.append("currentValue", inpMeasurement.getCurrentValue()) .append("currentValue", inpMeasurement.getCurrentValue())
.append("maxDailyValue", inpMeasurement.getDailyMax()) .append("maxDailyValue", inpMeasurement.getDailyMax())
@@ -181,14 +171,13 @@ public class Database {
.append("dailyAverage", inpMeasurement.getAverage()) .append("dailyAverage", inpMeasurement.getAverage())
.append("dailyTotal", inpMeasurement.getTotal()) .append("dailyTotal", inpMeasurement.getTotal())
.append("timestamp", Date.from(ZonedDateTime.now().toInstant())); .append("timestamp", Date.from(ZonedDateTime.now().toInstant()));
collection.insertOne(doc); gaugeOffCollection.insertOne(doc);
return collection.count(); return gaugeOffCollection.count();
} }
public double getPreviousDailyTotal(ZonedDateTime inpDateTime){ public double getPreviousDailyTotal(ZonedDateTime inpDateTime){
String isoInpDateTime = inpDateTime.toString(); String isoInpDateTime = inpDateTime.toString();
MongoCollection<Document> wellTestCollection = database.getCollection("gaugeOff");
MongoCursor<Document> cursor = wellTestCollection.find(and(eq("tagname", "Fluid Produced"), lte("timestamp", isoInpDateTime))) MongoCursor<Document> cursor = wellTestCollection.find(and(eq("tagname", "Fluid Produced"), lte("timestamp", isoInpDateTime)))
.sort(Sorts.descending("timestamp")).limit(1).iterator(); .sort(Sorts.descending("timestamp")).limit(1).iterator();
double lastTotal = -1.0; double lastTotal = -1.0;
@@ -203,7 +192,6 @@ public class Database {
}; };
public long newWellTest(WellTest inp){ public long newWellTest(WellTest inp){
MongoCollection<Document> collection = database.getCollection("wellTests");
Document doc = new Document("testStartTime", Date.from(inp.getTestStart().toInstant())) Document doc = new Document("testStartTime", Date.from(inp.getTestStart().toInstant()))
.append("testHours", inp.getTestHours()) .append("testHours", inp.getTestHours())
.append("testTotalBBL", inp.getTotalFluidBBL()) .append("testTotalBBL", inp.getTotalFluidBBL())
@@ -214,12 +202,11 @@ public class Database {
.append("oilRatio", inp.getOilRatio()) .append("oilRatio", inp.getOilRatio())
.append("waterRatio", inp.getWaterRatio()) .append("waterRatio", inp.getWaterRatio())
.append("gasMCFRatio", inp.getGasMCFRatio()); .append("gasMCFRatio", inp.getGasMCFRatio());
collection.insertOne(doc); wellTestCollection.insertOne(doc);
return collection.count(); return wellTestCollection.count();
} }
public Document getPreviousWellTest(ZonedDateTime inpDateTime){ public Document getPreviousWellTest(ZonedDateTime inpDateTime){
MongoCollection<Document> wellTestCollection = database.getCollection("wellTests");
MongoCursor<Document> cursor = wellTestCollection.find(lte("testStartTime", Date.from(inpDateTime.toInstant()))) MongoCursor<Document> cursor = wellTestCollection.find(lte("testStartTime", Date.from(inpDateTime.toInstant())))
.sort(Sorts.descending("testStartTime")).limit(1).iterator(); .sort(Sorts.descending("testStartTime")).limit(1).iterator();
Document lastTest = new Document("kFactor", (Double) 1.0); Document lastTest = new Document("kFactor", (Double) 1.0);
@@ -234,7 +221,6 @@ public class Database {
}; };
public double getLatestKFactor(){ public double getLatestKFactor(){
MongoCollection<Document> wellTestCollection = database.getCollection("wellTests");
MongoCursor<Document> cursor = wellTestCollection.find().sort(Sorts.descending("testStartTime")).limit(1).iterator(); MongoCursor<Document> cursor = wellTestCollection.find().sort(Sorts.descending("testStartTime")).limit(1).iterator();
double kFactor = 1.0; double kFactor = 1.0;
try { try {
@@ -249,18 +235,16 @@ public class Database {
public long newFluidShot(FluidShot inp){ public long newFluidShot(FluidShot inp){
String df = ZonedDateTime.now().toString(); String df = ZonedDateTime.now().toString();
MongoCollection<Document> collection = database.getCollection("fluidShots");
Document doc = new Document("timestamp", Date.from(ZonedDateTime.now().toInstant())) Document doc = new Document("timestamp", Date.from(ZonedDateTime.now().toInstant()))
.append("fluidLevel", inp.getFluidLevel()) .append("fluidLevel", inp.getFluidLevel())
.append("pumpIntakePressure", inp.getPumpIntakePressure()) .append("pumpIntakePressure", inp.getPumpIntakePressure())
.append("frictionEstimate", inp.getFrictionEstimate()); .append("frictionEstimate", inp.getFrictionEstimate());
collection.insertOne(doc); fluidShotsCollection.insertOne(doc);
return collection.count(); return fluidShotsCollection.count();
} }
public double getLatestFrictionEstimate(){ public double getLatestFrictionEstimate(){
MongoCollection<Document> wellTestCollection = database.getCollection("fluidShots"); MongoCursor<Document> cursor = fluidShotsCollection.find().sort(Sorts.descending("timestamp")).limit(1).iterator();
MongoCursor<Document> cursor = wellTestCollection.find().sort(Sorts.descending("timestamp")).limit(1).iterator();
double frictionEstimate = -1; double frictionEstimate = -1;
try { try {
while (cursor.hasNext()) { while (cursor.hasNext()) {
@@ -273,34 +257,14 @@ public class Database {
} }
public long newRunStatus(String runStatus, String initiator){ public long newRunStatus(String runStatus, String initiator){
MongoCollection<Document> collection = database.getCollection("runStatus");
Document doc = new Document("status", runStatus) Document doc = new Document("status", runStatus)
.append("initiator", initiator) .append("initiator", initiator)
.append("timestamp", Date.from(ZonedDateTime.now().toInstant())); .append("timestamp", Date.from(ZonedDateTime.now().toInstant()));
collection.insertOne(doc); runStatusCollection.insertOne(doc);
return collection.count(); return runStatusCollection.count();
}
static String readFile(String file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
try {
while((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(ls);
}
return stringBuilder.toString();
} finally {
reader.close();
}
} }
public long storeWellSetup(Well thisWell){ public long storeWellSetup(Well thisWell){
MongoCollection<Document> collection = database.getCollection("wellConfiguration");
ArrayList<Document> taperArr = new ArrayList<Document>(); ArrayList<Document> taperArr = new ArrayList<Document>();
for (int i = 1; i <= thisWell.getNumTapers(); i++){ for (int i = 1; i <= thisWell.getNumTapers(); i++){
Document tap = new Document("length", thisWell.getRodLength(i)) Document tap = new Document("length", thisWell.getRodLength(i))
@@ -325,12 +289,11 @@ public class Database {
.append("tapers", taperArr) .append("tapers", taperArr)
.append("storedBy", "poc"); .append("storedBy", "poc");
collection.insertOne(doc); wellConfigCollection.insertOne(doc);
return collection.count(); return wellConfigCollection.count();
} }
public Document getLatestWellConfiguration(){ public Document getLatestWellConfiguration(){
MongoCollection<Document> wellConfigCollection = database.getCollection("wellConfiguration");
MongoCursor<Document> cursor = wellConfigCollection.find().sort(Sorts.descending("timestamp")).limit(1).iterator(); MongoCursor<Document> cursor = wellConfigCollection.find().sort(Sorts.descending("timestamp")).limit(1).iterator();
Document lastConfig = new Document(); Document lastConfig = new Document();
try { try {