diff --git a/.gradle/3.1/taskArtifacts/cache.properties.lock b/.gradle/3.1/taskArtifacts/cache.properties.lock
index 844d798..149cabd 100644
Binary files a/.gradle/3.1/taskArtifacts/cache.properties.lock and b/.gradle/3.1/taskArtifacts/cache.properties.lock differ
diff --git a/.gradle/3.1/taskArtifacts/fileHashes.bin b/.gradle/3.1/taskArtifacts/fileHashes.bin
index 659b144..d1babe8 100644
Binary files a/.gradle/3.1/taskArtifacts/fileHashes.bin and b/.gradle/3.1/taskArtifacts/fileHashes.bin differ
diff --git a/.gradle/3.1/taskArtifacts/fileSnapshots.bin b/.gradle/3.1/taskArtifacts/fileSnapshots.bin
index 33fb08e..0db1def 100644
Binary files a/.gradle/3.1/taskArtifacts/fileSnapshots.bin and b/.gradle/3.1/taskArtifacts/fileSnapshots.bin differ
diff --git a/.gradle/3.1/taskArtifacts/taskArtifacts.bin b/.gradle/3.1/taskArtifacts/taskArtifacts.bin
index c20f1a8..da5fef1 100644
Binary files a/.gradle/3.1/taskArtifacts/taskArtifacts.bin and b/.gradle/3.1/taskArtifacts/taskArtifacts.bin differ
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index f73e28e..0aed22f 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -6,11 +6,12 @@
-
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..05e5219
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__com_googlecode_json_simple_json_simple_1_1_1.xml b/.idea/libraries/Gradle__com_googlecode_json_simple_json_simple_1_1_1.xml
new file mode 100644
index 0000000..1e91ade
--- /dev/null
+++ b/.idea/libraries/Gradle__com_googlecode_json_simple_json_simple_1_1_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__de_vandermeer_asciilist_0_0_3.xml b/.idea/libraries/Gradle__de_vandermeer_asciilist_0_0_3.xml
new file mode 100644
index 0000000..ba9abcc
--- /dev/null
+++ b/.idea/libraries/Gradle__de_vandermeer_asciilist_0_0_3.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__de_vandermeer_asciitable_0_2_5.xml b/.idea/libraries/Gradle__de_vandermeer_asciitable_0_2_5.xml
new file mode 100644
index 0000000..d707e29
--- /dev/null
+++ b/.idea/libraries/Gradle__de_vandermeer_asciitable_0_2_5.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__io_mraa_mraa_1_5_1.xml b/.idea/libraries/Gradle__io_mraa_mraa_1_5_1.xml
new file mode 100644
index 0000000..aa3d3e1
--- /dev/null
+++ b/.idea/libraries/Gradle__io_mraa_mraa_1_5_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_10.xml b/.idea/libraries/Gradle__junit_junit_4_10.xml
new file mode 100644
index 0000000..1b0c3a2
--- /dev/null
+++ b/.idea/libraries/Gradle__junit_junit_4_10.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml b/.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml
new file mode 100644
index 0000000..f99c825
--- /dev/null
+++ b/.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_1.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_1.xml
new file mode 100644
index 0000000..932a17a
--- /dev/null
+++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_mongodb_bson_3_4_2.xml b/.idea/libraries/Gradle__org_mongodb_bson_3_4_2.xml
new file mode 100644
index 0000000..f0d651c
--- /dev/null
+++ b/.idea/libraries/Gradle__org_mongodb_bson_3_4_2.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_mongodb_mongodb_driver_3_4_2.xml b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_3_4_2.xml
new file mode 100644
index 0000000..2568589
--- /dev/null
+++ b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_3_4_2.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_mongodb_mongodb_driver_core_3_4_2.xml b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_core_3_4_2.xml
new file mode 100644
index 0000000..9374231
--- /dev/null
+++ b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_core_3_4_2.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 6ef8c4d..8a9882b 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,9 @@
-
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/poc-java.iml b/.idea/modules/poc-java.iml
new file mode 100644
index 0000000..7a7be7f
--- /dev/null
+++ b/.idea/modules/poc-java.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/poc-java_main.iml b/.idea/modules/poc-java_main.iml
new file mode 100644
index 0000000..3dfc202
--- /dev/null
+++ b/.idea/modules/poc-java_main.iml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/poc-java_test.iml b/.idea/modules/poc-java_test.iml
new file mode 100644
index 0000000..04909b9
--- /dev/null
+++ b/.idea/modules/poc-java_test.iml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..fce7f71 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 337a3e4..46bc685 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,14 +2,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -21,13 +50,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -35,23 +142,14 @@
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -60,30 +158,10 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -92,9 +170,11 @@
-
-
-
+
+
+
+
+
@@ -102,9 +182,11 @@
-
-
-
+
+
+
+
+
@@ -112,10 +194,32 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -141,6 +245,379 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -151,21 +628,22 @@
-
-
+
+
+
+
+
-
-
-
+
@@ -180,7 +658,7 @@
-
+
@@ -242,7 +720,7 @@
-
+
@@ -255,16 +733,17 @@
-
+
-
-
+
+
+
@@ -516,37 +995,38 @@
-
+
-
+
-
-
+
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
+
+
@@ -564,6 +1044,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -573,22 +1065,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
@@ -598,13 +1130,7 @@
-
-
-
-
-
-
-
+
@@ -633,6 +1159,8 @@
+
+
@@ -643,6 +1171,8 @@
+
+
@@ -661,14 +1191,7 @@
-
-
-
-
-
-
-
-
+
@@ -717,14 +1240,7 @@
-
-
-
-
-
-
-
-
+
@@ -735,16 +1251,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -757,7 +1263,6 @@
-
@@ -765,7 +1270,6 @@
-
@@ -783,19 +1287,32 @@
-
-
-
-
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -807,58 +1324,51 @@
-
+
-
-
-
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
+
+
+
-
+
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
@@ -867,60 +1377,50 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build.gradle b/build.gradle
index 4fc34d0..28b73bd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,8 +8,8 @@ version = '1.0-SNAPSHOT'
description = """poc-java"""
-sourceCompatibility = 1.5
-targetCompatibility = 1.5
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
@@ -64,7 +64,13 @@ task deploy << {
task runRemote << {
ssh.run {
session(remotes.edison) {
- execute 'java -cp .:/usr/lib/java/*:poc-java-all-1.0-SNAPSHOT.jar com.henrypump.poc.POC kiesha7265Well.json kiesha7265_card_147_surface.csv'
+ execute 'java -cp .:/usr/lib/java/*:poc-java-all-1.0-SNAPSHOT.jar com.henrypump.poc.POC kiesha7265Well.json kiesha7265_card_147_surface.csv true'
}
}
+}
+
+task runLocal(type: JavaExec) {
+ classpath sourceSets.main.runtimeClasspath
+ main = "com.henrypump.poc.POC"
+ args 'kiesha7265Well.json', 'kiesha7265_card_147_surface.csv', 'false'
}
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 230ef75..db5552d 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Feb 06 18:19:31 CST 2017
+#Wed Feb 08 13:46:23 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
diff --git a/poc-java.iml b/poc-java.iml
deleted file mode 100644
index 35d2624..0000000
--- a/poc-java.iml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/java/com/henrypump/poc/CLScanner.java b/src/main/java/com/henrypump/poc/CLScanner.java
new file mode 100644
index 0000000..f88525d
--- /dev/null
+++ b/src/main/java/com/henrypump/poc/CLScanner.java
@@ -0,0 +1,103 @@
+package com.henrypump.poc;
+
+import javax.sound.midi.Soundbank;
+import java.time.ZonedDateTime;
+import java.util.Scanner;
+
+/**
+ * Created by patrickjmcd on 2/8/17.
+ */
+class CLScanner implements Runnable {
+
+ private final POC poc;
+ CLScanner(POC poc){
+ this.poc = poc;
+ }
+
+ private void startWell(){
+ poc.thisWell.start("commandline");
+ }
+
+ private void stopWell(){
+ poc.thisWell.stop("commandline");
+ }
+
+ private void exitPOC(){
+ System.exit(99);
+ }
+
+ private void runStatus(){
+ System.out.println("Run Status: " + poc.thisWell.getRunStatusString());
+ }
+
+ private void showTapers(){
+ poc.thisWell.printTapers();
+ }
+
+ private void showTotals(){
+ poc.thisWell.printTotals();
+ }
+
+ private void help(){
+ System.out.println("");
+ System.out.println("== HELP MENU ==");
+ System.out.println("");
+ System.out.println("POSSIBLE COMMANDS");
+ System.out.println("start -- Issues the start command");
+ System.out.println("stop -- Issues the stop command");
+ System.out.println("status -- Gets the current run status");
+ System.out.println("showtapers -- Gets the current taper and well parameters");
+ System.out.println("showtotals -- Gets the current totals and averages");
+ System.out.println("exit -- Quits the program");
+ System.out.println("");
+ }
+
+
+
+ public void run() {
+ Scanner sc = new Scanner(System.in);
+ String input = "";
+ while (sc.hasNextLine()) {
+ input = sc.nextLine();
+ switch(input){
+ case "start":
+ startWell();
+ break;
+ case "stop":
+ stopWell();
+ break;
+ case "exit":
+ exitPOC();
+ break;
+ case "status":
+ runStatus();
+ break;
+ case "showtotals":
+ showTotals();
+ break;
+ case "showtapers":
+ showTapers();
+ break;
+ case "help":
+ help();
+ break;
+ default:
+ if (input.startsWith("welltest")){
+ String[] testParams = input.split(" ");
+ ZonedDateTime timestamp = ZonedDateTime.parse(testParams[1]);
+ poc.thisWell.wellTest = new WellTest(timestamp,
+ Double.parseDouble(testParams[2]), Double.parseDouble(testParams[3]),
+ Double.parseDouble(testParams[4]), Double.parseDouble(testParams[5]),
+ Double.parseDouble(testParams[6]), poc.thisWell.db.getPreviousDailyTotal(timestamp)
+ );
+ poc.thisWell.db.newWellTest(poc.thisWell.wellTest);
+ poc.thisWell.wellTest.print();
+ } else {
+ help();
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/henrypump/poc/Card.java b/src/main/java/com/henrypump/poc/Card.java
index fa05786..fb6e5c3 100644
--- a/src/main/java/com/henrypump/poc/Card.java
+++ b/src/main/java/com/henrypump/poc/Card.java
@@ -53,6 +53,7 @@ public class Card {
private double polishedRodHorsepower;
private double pumpHorsepower;
private double fluidBBLMoved;
+ private double fluidBBLMovedAdjusted;
private double waterBBLMoved;
private double oilBBLMoved;
private double gasMCFMoved;
@@ -184,6 +185,11 @@ public class Card {
return fluidBBLMoved;
}
+
+ public double getFluidBBLMovedAdjusted() {
+ return fluidBBLMovedAdjusted;
+ }
+
public double getWaterBBLMoved() {
return waterBBLMoved;
}
@@ -350,7 +356,8 @@ public class Card {
downholeNetStrokeLength = bottomCorner.getPosition() - downholePositionMin.getPosition();
fillageCalculated = (downholeNetStrokeLength / downholeAdjustedGrossStrokeLength) * 100.0;
fillageEstimated =(downholeNetStrokeLength / downholeGrossStrokeLength) * 100.0;
- fluidBBLMoved = downholeNetStrokeLength * pumpArea * 0.00010307 * kFactor;
+ fluidBBLMoved = downholeNetStrokeLength * pumpArea * 0.00010307;
+ fluidBBLMovedAdjusted = fluidBBLMoved * kFactor;
oilBBLMoved = fluidBBLMoved * oilBBLRatio;
waterBBLMoved = fluidBBLMoved * waterBBLRatio;
gasMCFMoved = fluidBBLMoved * gasMCFRatio;
diff --git a/src/main/java/com/henrypump/poc/Database.java b/src/main/java/com/henrypump/poc/Database.java
index c5d39d5..577bb88 100644
--- a/src/main/java/com/henrypump/poc/Database.java
+++ b/src/main/java/com/henrypump/poc/Database.java
@@ -12,18 +12,12 @@ import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.time.Instant;
-import java.util.Arrays;
+import java.time.ZonedDateTime;
import com.mongodb.client.MongoCursor;
-
-import static com.mongodb.client.model.Aggregates.limit;
import static com.mongodb.client.model.Filters.*;
-import com.mongodb.client.result.DeleteResult;
-import static com.mongodb.client.model.Updates.*;
-import com.mongodb.client.result.UpdateResult;
+
+import javax.print.Doc;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -76,6 +70,7 @@ public class Database {
.append("downhole_position", d_p)
.append("downhole_load", d_l);
collection.insertOne(doc);
+ System.out.println("Stored stroke number " + inpCard.getStrokeNumber() + " as " + doc.getObjectId("_id"));
return collection.count();
}
public void close(){
@@ -83,7 +78,7 @@ public class Database {
}
public long newMeasurement(Measurement inpMeasurement){
- String df = Date.from(Instant.now()).toString();
+ String df = ZonedDateTime.now().toString();
MongoCollection collection = database.getCollection("wellData");
Document doc = new Document("tagname", inpMeasurement.getTagName())
.append("currentValue", inpMeasurement.getCurrentValue())
@@ -91,13 +86,29 @@ public class Database {
.append("minDailyValue", inpMeasurement.getDailyMin())
.append("dailyAverage", inpMeasurement.getAverage())
.append("dailyTotal", inpMeasurement.getTotal())
+ .append("numMeasurements", inpMeasurement.getNumMeasurements())
.append("timestamp", df);
collection.insertOne(doc);
+ System.out.println("Stored " + inpMeasurement.getCurrentValue() + " for " + inpMeasurement.getTagName());
return collection.count();
}
+ public Document getLastStoredMeasurement(String tagName){
+ MongoCollection collection = database.getCollection("wellData");
+ MongoCursor cursor = collection.find(eq("tagname", tagName)).sort(Sorts.descending("timestamp")).limit(1).iterator();
+ Document lastStoredDoc = new Document();
+ try {
+ while (cursor.hasNext()) {
+ lastStoredDoc = cursor.next();
+ }
+ } finally {
+ cursor.close();
+ }
+ return lastStoredDoc;
+ }
+
public long newDailyTotal(Measurement inpMeasurement){
- String df = Date.from(Instant.now()).toString();
+ String df = ZonedDateTime.now().toString();
MongoCollection collection = database.getCollection("gaugeOffData");
Document doc = new Document("tagname", inpMeasurement.getTagName())
.append("currentValue", inpMeasurement.getCurrentValue())
@@ -111,7 +122,7 @@ public class Database {
}
- public double getPreviousDailyTotal(Date inpDateTime){
+ public double getPreviousDailyTotal(ZonedDateTime inpDateTime){
String isoInpDateTime = inpDateTime.toString();
MongoCollection wellTestCollection = database.getCollection("gaugeOffData");
MongoCursor cursor = wellTestCollection.find(and(eq("tagname", "Fluid Produced"), lte("timestamp", isoInpDateTime)))
@@ -128,7 +139,7 @@ public class Database {
};
public long newWellTest(WellTest inp){
- String df = Date.from(Instant.now()).toString();
+ String df = ZonedDateTime.now().toString();
MongoCollection collection = database.getCollection("wellTestData");
Document doc = new Document("testStartTime", df)
.append("testHours", inp.getTestHours())
@@ -144,7 +155,7 @@ public class Database {
return collection.count();
}
- public Document getPreviousWellTest(Date inpDateTime){
+ public Document getPreviousWellTest(ZonedDateTime inpDateTime){
String isoInpDateTime = inpDateTime.toString();
MongoCollection wellTestCollection = database.getCollection("wellTestData");
MongoCursor cursor = wellTestCollection.find(lte("testStartTime", isoInpDateTime))
diff --git a/src/main/java/com/henrypump/poc/DigitalOut.java b/src/main/java/com/henrypump/poc/DigitalOut.java
index 75f58eb..00bf032 100644
--- a/src/main/java/com/henrypump/poc/DigitalOut.java
+++ b/src/main/java/com/henrypump/poc/DigitalOut.java
@@ -49,6 +49,10 @@ public class DigitalOut {
}
}
+ public int getValue() {
+ return value;
+ }
+
public static void main(String[] args){
try {
DigitalOut testOut2 = new DigitalOut(2, 0);
diff --git a/src/main/java/com/henrypump/poc/Measurement.java b/src/main/java/com/henrypump/poc/Measurement.java
index b72e5fb..07230a3 100644
--- a/src/main/java/com/henrypump/poc/Measurement.java
+++ b/src/main/java/com/henrypump/poc/Measurement.java
@@ -1,5 +1,9 @@
package com.henrypump.poc;
+import org.bson.Document;
+
+import java.time.ZonedDateTime;
+
import static java.lang.Math.abs;
/**
@@ -37,6 +41,26 @@ public class Measurement {
this.sendDelta = sendDelta;
this.lastSentValue = 0.0;
this.sendTimeDelta = sendTimeDelta;
+
+ Document lastStored = this.db.getLastStoredMeasurement(this.tagName);
+ try {
+ ZonedDateTime timestamp = ZonedDateTime.parse((CharSequence) lastStored.get("timestamp"));
+ if (isToday(timestamp)){
+ this.average = lastStored.getDouble("dailyAverage");
+ this.total = lastStored.getDouble("dailyTotal");
+ this.lastSentValue = lastStored.getDouble("currentValue");
+ this.dailyMax = lastStored.getDouble("maxDailyValue");
+ this.dailyMin = lastStored.getDouble("minDailyValue");
+ this.lastSentTimestamp = timestamp.toEpochSecond();
+ this.numMeasurements = lastStored.getLong("numMeasurements");
+ System.out.println("Using stored value from " + timestamp.toString() + " for " + this.tagName);
+ } else {
+ System.out.println("Cannot use stored value from " + timestamp.toString() + " for " + this.tagName);
+ }
+ } catch (NullPointerException e){
+ System.out.println("There was no previous measurement in the database for " + this.tagName);
+ }
+
}
Measurement(String tagName, boolean storeInDatabase){
@@ -83,9 +107,17 @@ public class Measurement {
return dailyMin;
}
+ public static boolean isToday(ZonedDateTime inpZDT){
+ ZonedDateTime now = ZonedDateTime.now();
+ if (now.toLocalDate().equals(inpZDT.toLocalDate())){
+ return true;
+ }
+ return false;
+ };
+
public void update(double value)
{
- long currentTimestamp = System.currentTimeMillis();
+ long currentTimestamp = ZonedDateTime.now().toEpochSecond();
lastValue = currentValue;
currentValue = value;
@@ -101,6 +133,7 @@ public class Measurement {
currentTimestamp - lastSentTimestamp > (sendTimeDelta * 1000)){
long l = db.newMeasurement(this);
lastSentValue = currentValue;
+ lastSentTimestamp = currentTimestamp;
}
}
}
diff --git a/src/main/java/com/henrypump/poc/POC.java b/src/main/java/com/henrypump/poc/POC.java
index 8dc4e2d..8dc8a10 100644
--- a/src/main/java/com/henrypump/poc/POC.java
+++ b/src/main/java/com/henrypump/poc/POC.java
@@ -1,14 +1,12 @@
package com.henrypump.poc;
+import java.time.ZonedDateTime;
+
/**
* Created by patrickjmcd on 2/1/17.
* POC Class
*
*/
-import java.awt.*;
-import java.awt.event.*;
-import java.time.Instant;
-import java.util.Date;
public class POC implements Runnable{
protected Well thisWell;
@@ -19,16 +17,12 @@ public class POC implements Runnable{
private DigitalOut runIndicator;
private boolean ioEnabled;
- private boolean guiEnabled;
-
-
POC(String wellName, String wellSetupJsonFile, int simLoops){
ioEnabled = true;
- guiEnabled = false;
thisWell = new Well(wellName, 99, 99, 7);
thisWell.parseJSONFile(wellSetupJsonFile);
- thisWell.printTapers();
+// thisWell.printTapers();
this.simLoops = simLoops;
// IO
@@ -40,16 +34,11 @@ public class POC implements Runnable{
led5 = new DigitalOut(5, 0);
runIndicator = new DigitalOut(6,0);
-
- String headlessProp = !guiEnabled ? "true" : "false";
- System.setProperty("java.awt.headless", headlessProp);
- System.out.println(java.awt.GraphicsEnvironment.isHeadless());
}
POC(String wellName, String wellSetupJsonFile, String simFileName, boolean ioEnabled, int simLoops){
this.ioEnabled = ioEnabled;
if (this.ioEnabled) {
- guiEnabled = false;
thisWell = new Well(wellName, simFileName,99, 99, 7);
// IO
@@ -63,7 +52,6 @@ public class POC implements Runnable{
} else {
thisWell = new Well(wellName, simFileName,99, 99, 99);
- guiEnabled = true;
// IO
startBtn = new DigitalIn(99);
stopBtn = new DigitalIn(99);
@@ -74,12 +62,8 @@ public class POC implements Runnable{
runIndicator = new DigitalOut(99,0);
}
- String headlessProp = !guiEnabled ? "true" : "false";
- System.setProperty("java.awt.headless", headlessProp);
- System.out.println(java.awt.GraphicsEnvironment.isHeadless());
-
thisWell.parseJSONFile(wellSetupJsonFile);
- thisWell.printTapers();
+// thisWell.printTapers();
this.simLoops = simLoops;
}
@@ -91,14 +75,14 @@ public class POC implements Runnable{
}
public void run(){
- int loopCounter = 0, loopLimit = simLoops, led2out, led3out, led4out,led5out;
+ new Thread(new CLScanner(this)).start();
+ int led2out, led3out, led4out,led5out;
double pos;
- boolean newWellTest = true;
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
thisWell.setupFluidRatio(0.50, 0.50, 1.12);
thisWell.checkSafeties();
while (true) {
- while (loopCounter < loopLimit && (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING)) {
+ while (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING) {
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
if (startBtn.read() == 1) thisWell.start("startbutton");
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
@@ -123,22 +107,6 @@ public class POC implements Runnable{
e.printStackTrace();
}
}
- loopCounter++;
- }
-
- if (newWellTest){
- System.out.println("Previous kFactor = " + thisWell.db.getLatestKFactor());
- Date nowDate = Date.from(Instant.now());
- double lastProductionMeasured = thisWell.db.getPreviousDailyTotal(nowDate);
- thisWell.wellTest = new WellTest(nowDate, 24.0, .35, .20, .15, 1.25, lastProductionMeasured);
- thisWell.db.newWellTest(thisWell.wellTest);
- System.out.println("Well Test @ " + nowDate.toString());
- System.out.println("kFactor: " + thisWell.wellTest.getkFactor());
- System.out.println("oilRatio: " + thisWell.wellTest.getOilRatio());
- System.out.println("waterRatio: " + thisWell.wellTest.getWaterRatio());
- System.out.println("gasRatio: " + thisWell.wellTest.getGasMCFRatio());
- newWellTest = false;
- System.out.println("Last kFactor = " + thisWell.db.getLatestKFactor());
}
@@ -165,11 +133,11 @@ public class POC implements Runnable{
public static void main(String[] args) {
- final POC thisPOC = new POC("Barney", args[0], args[1], true, 100);
+ final POC thisPOC = new POC("Barney", args[0], args[1], args[2].equals("true"), 100);
thisPOC.start();
-
-
}
}
+
+
diff --git a/src/main/java/com/henrypump/poc/Well.java b/src/main/java/com/henrypump/poc/Well.java
index 4dc4dea..5ea0d42 100644
--- a/src/main/java/com/henrypump/poc/Well.java
+++ b/src/main/java/com/henrypump/poc/Well.java
@@ -19,6 +19,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.time.LocalDate;
+import java.time.ZonedDateTime;
/**
* Created by patrickjmcd on 1/31/17.
@@ -96,7 +97,7 @@ public class Well {
private double tubingCrossSectionalArea;
// Statuses
- private int runStatus;
+ private volatile int runStatus;
public static final int RUNSTATUS_STOPPED = 0;
public static final int RUNSTATUS_STARTING = 1;
public static final int RUNSTATUS_RUNNING = 2;
@@ -119,7 +120,7 @@ public class Well {
private int lastDirection = DIRECTION_UNKNOWN;
// Modes
- private int runMode;
+ private volatile int runMode;
public static final int RUNMODE_POC = 0;
public static final int RUNMODE_MANUAL = 1;
public static final int RUNMODE_TIMER = 2;
@@ -142,12 +143,13 @@ public class Well {
private double kFactor = 1.0;
// DATE & TIME PARAMETERS
- private LocalDate lastCheckedDate = null;
+ private ZonedDateTime now = ZonedDateTime.now();
private boolean isNewDay(){
- LocalDate today = LocalDate.now();
- boolean ret = lastCheckedDate == null || today.isAfter(lastCheckedDate);
- lastCheckedDate = today;
+
+ ZonedDateTime today = ZonedDateTime.now();
+ boolean ret = !(today.toLocalDate().equals(now.toLocalDate()));
+ now = today;
return ret;
}
@@ -164,6 +166,7 @@ public class Well {
private Measurement polishedRodHP;
private Measurement pumpHP;
private Measurement fluidProduced;
+ private Measurement fluidProducedAdjusted;
private Measurement oilProduced;
private Measurement waterProduced;
private Measurement gasProduced;
@@ -192,6 +195,7 @@ public class Well {
polishedRodHP = new Measurement("Polished Rod HP", true, db, 0.25, 600);
pumpHP = new Measurement("Pump HP", true, db, 0.25, 600);
fluidProduced = new Measurement("Fluid Produced", true, db, 1.0, 600);
+ fluidProducedAdjusted = new Measurement("Fluid Produced (adjusted)", true, db, 1.0, 600);
oilProduced = new Measurement("Oil Produced", true, db, 1.0, 600);
waterProduced = new Measurement("Water Produced", true, db, 1.0, 600);
gasProduced = new Measurement("Gas Produced", true, db, 1.0, 600);
@@ -222,6 +226,7 @@ public class Well {
polishedRodHP = new Measurement("Polished Rod HP", true, db, 0.25, 600);
pumpHP = new Measurement("Pump HP", true, db, 0.25, 600);
fluidProduced = new Measurement("Fluid Produced", true, db, 1.0, 600);
+ fluidProducedAdjusted = new Measurement("Fluid Produced (adjusted)", true, db, 1.0, 600);
oilProduced = new Measurement("Oil Produced", true, db, 1.0, 600);
waterProduced = new Measurement("Water Produced", true, db, 1.0, 600);
gasProduced = new Measurement("Gas Produced", true, db, 1.0, 600);
@@ -377,6 +382,25 @@ public class Well {
return runStatus;
}
+ public String getRunStatusString(){
+ switch(runStatus){
+ case RUNSTATUS_STOPPED:
+ return "Stopped";
+ case RUNSTATUS_STARTING:
+ return "Starting";
+ case RUNSTATUS_RUNNING:
+ return "Running";
+ case RUNSTATUS_PUMPEDOFF:
+ return "Pumped-Off";
+ case RUNSTATUS_FAULTED:
+ return "Faulted";
+ case RUNSTATUS_LOCKEDOUT:
+ return "Locked Out";
+ default:
+ return "Unknown";
+ }
+ }
+
public int getRunMode() {
return runMode;
}
@@ -902,7 +926,7 @@ public class Well {
cardStorage[j + 1] = cardStorage[j];
}
cardStorage[0] = currentCard;
- currentCard.printCard("csv", true);
+ currentCard.printCard("none", true);
strokesSinceStart++;
strokesToday++;
strokesLifetime++;
@@ -917,6 +941,7 @@ public class Well {
polishedRodHP.update(currentCard.getPolishedRodHorsepower());
pumpHP.update(currentCard.getPumpHorsepower());
fluidProduced.update(currentCard.getFluidBBLMoved());
+ fluidProducedAdjusted.update(currentCard.getFluidBBLMovedAdjusted());
oilProduced.update(currentCard.getOilBBLMoved());
waterProduced.update(currentCard.getWaterBBLMoved());
gasProduced.update(currentCard.getGasMCFMoved());
@@ -924,31 +949,12 @@ public class Well {
surfaceStrokeLength.update(currentCard.getSurfaceStrokeLength());
tubingMovement.update(currentCard.getTubingMovement());
+ db.newCard(currentCard);
currentCard = new Card(strokesLifetime);
pointCounter = -1;
if (strokesSinceStart > startupStrokes){
runStatus = RUNSTATUS_RUNNING;
}
- if(isNewDay()){
- strokeSpeed.endOfDay();
- downholeGrossStroke.endOfDay();
- downholeNetStroke.endOfDay();
- fluidLevel.endOfDay();
- fluidLoad.endOfDay();
- inflowRate.endOfDay();
- peakPolishedRodLoad.endOfDay();
- minPolishedRodLoad.endOfDay();
- percentRun.endOfDay();
- polishedRodHP.endOfDay();
- pumpHP.endOfDay();
- fluidProduced.endOfDay();
- oilProduced.endOfDay();
- waterProduced.endOfDay();
- gasProduced.endOfDay();
- pumpIntakePressure.endOfDay();
- surfaceStrokeLength.endOfDay();
- tubingMovement.endOfDay();
- }
}
@@ -957,12 +963,16 @@ public class Well {
currentSurfacePosition = inclinometer.readScaled();
currentSurfaceLoad = loadCell.readScaled();
LPStatus lastPoint = calc(currentSurfacePosition, currentSurfaceLoad);
+ if (lastPoint.getStatus() == GOOD_STATUS){
+ currentDownholePosition = lastPoint.getPosition();
+ currentDownholeLoad = lastPoint.getLoad();
+ }
if(runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING) {
if (lastPoint.getStatus() == GOOD_STATUS) {
currentCard.setSurfacePosition(pointCounter, currentSurfacePosition);
currentCard.setSurfaceLoad(pointCounter, currentSurfaceLoad);
- currentCard.setDownholePosition(pointCounter, lastPoint.getPosition());
- currentCard.setDownholeLoad(pointCounter, lastPoint.getLoad());
+ currentCard.setDownholePosition(pointCounter, currentDownholePosition);
+ currentCard.setDownholeLoad(pointCounter, currentDownholeLoad);
}
if (inclinometer.getHistory(0) > inclinometer.getHistory(1))
@@ -971,47 +981,18 @@ public class Well {
direction = DIRECTION_DOWN;
if (direction == DIRECTION_UP && lastDirection == DIRECTION_DOWN && pointCounter > 0) {
- currentCard.setNumPointsUsed(pointCounter + 1);
- currentCard.calcStrokeData(150, fluidGradient,
- rodDepthTotal, tubingAnchorDepth,
- tubingCrossSectionalArea, pumpArea,
- frictionEstimate, structuralRating, fluidWaterRatio, fluidOilRatio, fluidGasRatio);
- for (int j = 98; j >= 0; j--) {
- cardStorage[j + 1] = cardStorage[j];
- }
- cardStorage[0] = currentCard;
- currentCard.printCard("none", true);
- System.out.println("Cards in DB: " + db.newCard(currentCard));
- strokesSinceStart++;
- strokesToday++;
- strokesLifetime++;
-
- strokeSpeed.update(currentCard.getStrokeSpeed());
- downholeGrossStroke.update(currentCard.getDownholeGrossStrokeLength());
- downholeNetStroke.update(currentCard.getDownholeNetStrokeLength());
- fluidLevel.update(currentCard.getFluidLevel());
- fluidLoad.update(currentCard.getFluidLoad());
- peakPolishedRodLoad.update(currentCard.getSurfaceLoadMax().getLoad());
- minPolishedRodLoad.update(currentCard.getSurfaceLoadMin().getLoad());
- polishedRodHP.update(currentCard.getPolishedRodHorsepower());
- pumpHP.update(currentCard.getPumpHorsepower());
- fluidProduced.update(currentCard.getFluidBBLMoved());
- oilProduced.update(currentCard.getOilBBLMoved());
- waterProduced.update(currentCard.getWaterBBLMoved());
- gasProduced.update(currentCard.getGasMCFMoved());
- pumpIntakePressure.update(currentCard.getPumpIntakePressure());
- surfaceStrokeLength.update(currentCard.getSurfaceStrokeLength());
- tubingMovement.update(currentCard.getTubingMovement());
-
- currentCard = new Card(strokesLifetime);
- pointCounter = -1;
- if (strokesSinceStart > startupStrokes) {
- runStatus = RUNSTATUS_RUNNING;
- }
+ endOfStroke();
}
lastDirection = direction;
pointCounter++;
}
+
+ if (runStatus == RUNSTATUS_RUNNING || runStatus == RUNSTATUS_STARTING){
+ runCommand.write(1);
+ } else {
+ runCommand.write(0);
+ }
+
if(isNewDay()){
strokeSpeed.endOfDay();
downholeGrossStroke.endOfDay();
@@ -1025,6 +1006,7 @@ public class Well {
polishedRodHP.endOfDay();
pumpHP.endOfDay();
fluidProduced.endOfDay();
+ fluidProducedAdjusted.endOfDay();
oilProduced.endOfDay();
waterProduced.endOfDay();
gasProduced.endOfDay();
@@ -1071,6 +1053,28 @@ public class Well {
} else {
runCommand.write(0);
}
+
+ if(isNewDay()){
+ strokeSpeed.endOfDay();
+ downholeGrossStroke.endOfDay();
+ downholeNetStroke.endOfDay();
+ fluidLevel.endOfDay();
+ fluidLoad.endOfDay();
+ inflowRate.endOfDay();
+ peakPolishedRodLoad.endOfDay();
+ minPolishedRodLoad.endOfDay();
+ percentRun.endOfDay();
+ polishedRodHP.endOfDay();
+ pumpHP.endOfDay();
+ fluidProduced.endOfDay();
+ fluidProducedAdjusted.endOfDay();
+ oilProduced.endOfDay();
+ waterProduced.endOfDay();
+ gasProduced.endOfDay();
+ pumpIntakePressure.endOfDay();
+ surfaceStrokeLength.endOfDay();
+ tubingMovement.endOfDay();
+ }
}
public void printTotals(){
diff --git a/src/main/java/com/henrypump/poc/WellTest.java b/src/main/java/com/henrypump/poc/WellTest.java
index 7126eac..95e2372 100644
--- a/src/main/java/com/henrypump/poc/WellTest.java
+++ b/src/main/java/com/henrypump/poc/WellTest.java
@@ -1,6 +1,8 @@
package com.henrypump.poc;
import org.bson.Document;
+
+import java.time.ZonedDateTime;
import java.util.Date;
/**
@@ -8,13 +10,13 @@ import java.util.Date;
*/
public class WellTest {
private double testHours;
- private Date testStart;
+ private ZonedDateTime testStart;
private double totalFluidBBL, testOilBBL, testWaterBBL, testGasMCF;
private double kFactor, oilRatio, waterRatio, gasMCFRatio;
- public WellTest(Date testStart, double testHours, double totalFluidBBL, double testOilBBL, double testWaterBBL, double testGasMCF, double prevDailyTotal) {
+ public WellTest(ZonedDateTime testStart, double testHours, double totalFluidBBL, double testOilBBL, double testWaterBBL, double testGasMCF, double prevDailyTotal) {
this.testStart = testStart;
this.testHours = testHours;
this.totalFluidBBL = totalFluidBBL;
@@ -39,7 +41,7 @@ public class WellTest {
return testHours;
}
- public Date getTestStart() {
+ public ZonedDateTime getTestStart() {
return testStart;
}
@@ -75,4 +77,14 @@ public class WellTest {
return gasMCFRatio;
}
+ public void print(){
+ System.out.println("Well Test started at " + testStart.toString() + " lasting " + testHours + " hours");
+ System.out.println("Fluid BBL: " + totalFluidBBL);
+ System.out.println("Oil BBL: " + testOilBBL);
+ System.out.println("Water BBL: " + testWaterBBL);
+ System.out.println("Gas MCF: " + testGasMCF);
+ System.out.printf("New Ratio Oil/Water/Gas: %.2f/%.2f/%.2f\n", oilRatio, waterRatio, gasMCFRatio);
+ System.out.println("New Correction Factor: " + kFactor);
+ }
+
}