Uses external MongoDB, uses dates instead of strings for timestamps
This commit is contained in:
@@ -27,7 +27,7 @@ public class Database {
|
||||
private MongoDatabase database;
|
||||
|
||||
Database(){
|
||||
mongoClient = new MongoClient();
|
||||
mongoClient = new MongoClient("10.20.155.202");
|
||||
database = mongoClient.getDatabase(pocDatabase);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Database {
|
||||
.append("surface_load", s_l)
|
||||
.append("downhole_position", d_p)
|
||||
.append("downhole_load", d_l)
|
||||
.append("timestamp", ZonedDateTime.now().toString());
|
||||
.append("timestamp", Date.from(ZonedDateTime.now().toInstant()));
|
||||
collection.insertOne(doc);
|
||||
System.out.println("Stored stroke number " + inpCard.getStrokeNumber() + " as " + doc.getObjectId("_id"));
|
||||
return collection.count();
|
||||
@@ -79,7 +79,6 @@ public class Database {
|
||||
}
|
||||
|
||||
public long newMeasurement(Measurement inpMeasurement){
|
||||
String df = ZonedDateTime.now().toString();
|
||||
MongoCollection<Document> collection = database.getCollection("wellData");
|
||||
Document doc = new Document("tagname", inpMeasurement.getTagName())
|
||||
.append("currentValue", inpMeasurement.getCurrentValue())
|
||||
@@ -88,7 +87,7 @@ public class Database {
|
||||
.append("dailyAverage", inpMeasurement.getAverage())
|
||||
.append("dailyTotal", inpMeasurement.getTotal())
|
||||
.append("numMeasurements", inpMeasurement.getNumMeasurements())
|
||||
.append("timestamp", df);
|
||||
.append("timestamp", Date.from(ZonedDateTime.now().toInstant()));
|
||||
collection.insertOne(doc);
|
||||
System.out.println("Stored " + inpMeasurement.getCurrentValue() + " for " + inpMeasurement.getTagName());
|
||||
return collection.count();
|
||||
@@ -109,7 +108,6 @@ public class Database {
|
||||
}
|
||||
|
||||
public long newDailyTotal(Measurement inpMeasurement){
|
||||
String df = ZonedDateTime.now().toString();
|
||||
MongoCollection<Document> collection = database.getCollection("gaugeOff");
|
||||
Document doc = new Document("tagname", inpMeasurement.getTagName())
|
||||
.append("currentValue", inpMeasurement.getCurrentValue())
|
||||
@@ -117,7 +115,7 @@ public class Database {
|
||||
.append("minDailyValue", inpMeasurement.getDailyMin())
|
||||
.append("dailyAverage", inpMeasurement.getAverage())
|
||||
.append("dailyTotal", inpMeasurement.getTotal())
|
||||
.append("timestamp", df);
|
||||
.append("timestamp", Date.from(ZonedDateTime.now().toInstant()));
|
||||
collection.insertOne(doc);
|
||||
return collection.count();
|
||||
|
||||
@@ -140,9 +138,9 @@ public class Database {
|
||||
};
|
||||
|
||||
public long newWellTest(WellTest inp){
|
||||
String df = ZonedDateTime.now().toString();
|
||||
MongoCollection<Document> collection = database.getCollection("wellTests");
|
||||
Document doc = new Document("testStartTime", df)
|
||||
|
||||
Document doc = new Document("testStartTime", Date.from(inp.getTestStart().toInstant()))
|
||||
.append("testHours", inp.getTestHours())
|
||||
.append("testTotalBBL", inp.getTotalFluidBBL())
|
||||
.append("testOilBBL", inp.getTestOilBBL())
|
||||
@@ -157,9 +155,8 @@ public class Database {
|
||||
}
|
||||
|
||||
public Document getPreviousWellTest(ZonedDateTime inpDateTime){
|
||||
String isoInpDateTime = inpDateTime.toString();
|
||||
MongoCollection<Document> wellTestCollection = database.getCollection("wellTests");
|
||||
MongoCursor<Document> cursor = wellTestCollection.find(lte("testStartTime", isoInpDateTime))
|
||||
MongoCursor<Document> cursor = wellTestCollection.find(lte("testStartTime", Date.from(inpDateTime.toInstant())))
|
||||
.sort(Sorts.descending("testStartTime")).limit(1).iterator();
|
||||
Document lastTest = new Document("kFactor", (Double) 1.0);
|
||||
try {
|
||||
@@ -189,7 +186,7 @@ public class Database {
|
||||
public long newFluidShot(FluidShot inp){
|
||||
String df = ZonedDateTime.now().toString();
|
||||
MongoCollection<Document> collection = database.getCollection("fluidShots");
|
||||
Document doc = new Document("timestamp", df)
|
||||
Document doc = new Document("timestamp", Date.from(ZonedDateTime.now().toInstant()))
|
||||
.append("fluidLevel", inp.getFluidLevel())
|
||||
.append("pumpIntakePressure", inp.getPumpIntakePressure())
|
||||
.append("frictionEstimate", inp.getFrictionEstimate());
|
||||
|
||||
@@ -48,20 +48,23 @@ public class IOControl implements Runnable {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (startBtn.read() == 1) startWell();
|
||||
if (stopBtn.read() == 1) stopWell();
|
||||
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
||||
exitPOC();
|
||||
System.out.println("Running the IOControl Loop");
|
||||
for (;;) {
|
||||
if (startBtn.read() == 1) startWell();
|
||||
if (stopBtn.read() == 1) stopWell();
|
||||
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
||||
exitPOC();
|
||||
}
|
||||
|
||||
pos = poc.thisWell.getCurrentSurfacePosition();
|
||||
runStatus = poc.thisWell.getRunStatus();
|
||||
led2.write(pos > 20.0 ? 1 : 0);
|
||||
led3.write(pos > 40.0 ? 1 : 0);
|
||||
led4.write(pos > 60.0 ? 1 : 0);
|
||||
led5.write(pos > 80.0 ? 1 : 0);
|
||||
|
||||
runningIndicator.write(runStatus == Well.RUNSTATUS_RUNNING ? 1 : 0);
|
||||
runCommand.write((runStatus == Well.RUNSTATUS_RUNNING || runStatus == Well.RUNSTATUS_STARTING) ? 1 : 0);
|
||||
}
|
||||
|
||||
pos = poc.thisWell.getCurrentSurfacePosition();
|
||||
runStatus = poc.thisWell.getRunStatus();
|
||||
led2.write(pos > 20.0 ? 1 : 0);
|
||||
led3.write(pos > 40.0 ? 1 : 0);
|
||||
led4.write(pos > 60.0 ? 1 : 0);
|
||||
led5.write(pos > 80.0 ? 1 : 0);
|
||||
|
||||
runningIndicator.write(runStatus==Well.RUNSTATUS_RUNNING ? 1 : 0);
|
||||
runCommand.write((runStatus == Well.RUNSTATUS_RUNNING || runStatus == Well.RUNSTATUS_STARTING) ? 1: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.henrypump.poc;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
@@ -44,7 +46,9 @@ public class Measurement {
|
||||
|
||||
Document lastStored = this.db.getLastStoredMeasurement(this.tagName);
|
||||
try {
|
||||
ZonedDateTime timestamp = ZonedDateTime.parse((CharSequence) lastStored.get("timestamp"));
|
||||
Date lastStoredTimestamp = (Date) lastStored.get("timestamp");
|
||||
ZonedDateTime timestamp = ZonedDateTime.ofInstant(lastStoredTimestamp.toInstant(),
|
||||
ZoneId.systemDefault());
|
||||
if (isToday(timestamp)){
|
||||
this.average = lastStored.getDouble("dailyAverage");
|
||||
this.total = lastStored.getDouble("dailyTotal");
|
||||
|
||||
Reference in New Issue
Block a user