control the well from a text-based cli

This commit is contained in:
Patrick McDonagh
2017-02-08 17:15:04 -06:00
parent a65597d3e1
commit 419f42cf17
33 changed files with 1176 additions and 359 deletions

3
.idea/compiler.xml generated
View File

@@ -6,11 +6,12 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="poc-java" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="poc-java" target="1.5" />
<module name="poc-java_main" target="1.8" />
<module name="poc-java_test" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

18
.idea/gradle.xml generated Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: com.googlecode.json-simple:json-simple:1.1.1">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1.1/c9ad4a0850ab676c5c64461a05ca524cdfff59f1/json-simple-1.1.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1.1/15bba08e3a239d54b68209c001f9c911559d2fed/json-simple-1.1.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: de.vandermeer:asciilist:0.0.3">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/de.vandermeer/asciilist/0.0.3/376c4dd76ad61d9a071e12563d40bf170c64a59c/asciilist-0.0.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/de.vandermeer/asciilist/0.0.3/c7804c3b0cd4e0530cca6dd72c34393ff56dda09/asciilist-0.0.3-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: de.vandermeer:asciitable:0.2.5">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/de.vandermeer/asciitable/0.2.5/459c280c4e464aff06116809c399923dfdde9193/asciitable-0.2.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/de.vandermeer/asciitable/0.2.5/5cf6cbd82c2ff3750089d79826f8df2e440bcd74/asciitable-0.2.5-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: io.mraa:mraa:1.5.1">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/io.mraa/mraa/1.5.1/13a16af744c18366b502bfa8a2e99a492d9af3c2/mraa-1.5.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/io.mraa/mraa/1.5.1/5a03f09c477e6fa9e16a38bcac4752da36e0d2a7/mraa-1.5.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: junit:junit:4.10">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.10/e4f1766ce7404a08f45d859fb9c226fc9e41a861/junit-4.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.10/6c98d6766e72d5575f96c9479d1c1d3b865c6e25/junit-4.10-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: org.apache.commons:commons-lang3:3.4">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.4/5fe28b9518e58819180a43a850fbc0dd24b7c050/commons-lang3-3.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.4/b49dafc9cfef24c356827f322e773e7c26725dd2/commons-lang3-3.4-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: org.hamcrest:hamcrest-core:1.1">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.1/860340562250678d1a344907ac75754e259cdb14/hamcrest-core-1.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.1/2ccf1154d1a8936042a8a742dc3e611d02ac7213/hamcrest-core-1.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: org.mongodb:bson:3.4.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mongodb/bson/3.4.2/8455e0c6926ff2bf444325ea46fd8b74adaf0362/bson-3.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mongodb/bson/3.4.2/45d50be5acaa04e372d1f9621b5f53abde8d4267/bson-3.4.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: org.mongodb:mongodb-driver:3.4.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver/3.4.2/d565cc4db7fd756973b1500424577a503d17f48a/mongodb-driver-3.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver/3.4.2/c9ed6ee227ea070e1568ad5276e7b8891abd8ebf/mongodb-driver-3.4.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="Gradle: org.mongodb:mongodb-driver-core:3.4.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver-core/3.4.2/d0a18b4e46fe79467a71d7f9f1bc5932de670829/mongodb-driver-core-3.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver-core/3.4.2/1676e26aa86a3c8af0fb1a9eda4b00000062d649/mongodb-driver-core-3.4.2-sources.jar!/" />
</SOURCES>
</library>
</component>

4
.idea/modules.xml generated
View File

@@ -2,7 +2,9 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/poc-java.iml" filepath="$PROJECT_DIR$/poc-java.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/poc-java.iml" filepath="$PROJECT_DIR$/.idea/modules/poc-java.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/poc-java_main.iml" filepath="$PROJECT_DIR$/.idea/modules/poc-java_main.iml" group="poc-java" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/poc-java_test.iml" filepath="$PROJECT_DIR$/.idea/modules/poc-java_test.iml" group="poc-java" />
</modules>
</component>
</project>

12
.idea/modules/poc-java.iml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="poc-java" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="com.henrypump.poc" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/../..">
<excludeFolder url="file://$MODULE_DIR$/../../.gradle" />
<excludeFolder url="file://$MODULE_DIR$/../../build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

23
.idea/modules/poc-java_main.iml generated Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="poc-java:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="com.henrypump.poc" external.system.module.type="sourceSet" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../../build/classes/main" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../src/main">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: io.mraa:mraa:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Gradle: org.mongodb:mongodb-driver:3.4.2" level="project" />
<orderEntry type="library" name="Gradle: de.vandermeer:asciitable:0.2.5" level="project" />
<orderEntry type="library" name="Gradle: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Gradle: org.mongodb:bson:3.4.2" level="project" />
<orderEntry type="library" name="Gradle: org.mongodb:mongodb-driver-core:3.4.2" level="project" />
<orderEntry type="library" name="Gradle: de.vandermeer:asciilist:0.0.3" level="project" />
<orderEntry type="library" name="Gradle: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Gradle: org.hamcrest:hamcrest-core:1.1" level="project" />
</component>
</module>

25
.idea/modules/poc-java_test.iml generated Normal file
View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="poc-java:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="com.henrypump.poc" external.system.module.type="sourceSet" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output-test url="file://$MODULE_DIR$/../../build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../src/test">
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="poc-java_main" />
<orderEntry type="library" name="Gradle: io.mraa:mraa:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Gradle: org.mongodb:mongodb-driver:3.4.2" level="project" />
<orderEntry type="library" name="Gradle: de.vandermeer:asciitable:0.2.5" level="project" />
<orderEntry type="library" name="Gradle: org.mongodb:bson:3.4.2" level="project" />
<orderEntry type="library" name="Gradle: org.mongodb:mongodb-driver-core:3.4.2" level="project" />
<orderEntry type="library" name="Gradle: de.vandermeer:asciilist:0.0.3" level="project" />
<orderEntry type="library" name="Gradle: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Gradle: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Gradle: org.hamcrest:hamcrest-core:1.1" level="project" />
</component>
<component name="TestModuleProperties" production-module="poc-java_main" />
</module>

1
.idea/vcs.xml generated
View File

@@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

904
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@@ -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'
}

View File

@@ -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

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" name="Maven: io.mraa:mraa:1.5.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver:3.4.2" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:bson:3.4.2" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.4.2" level="project" />
<orderEntry type="library" name="Maven: de.vandermeer:asciitable:0.2.5" level="project" />
<orderEntry type="library" name="Maven: de.vandermeer:asciilist:0.0.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
</component>
</module>

View File

@@ -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();
}
}
}
}
}

View File

@@ -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;

View File

@@ -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<Document> 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<Document> collection = database.getCollection("wellData");
MongoCursor<Document> 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<Document> 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<Document> wellTestCollection = database.getCollection("gaugeOffData");
MongoCursor<Document> 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<Document> 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<Document> wellTestCollection = database.getCollection("wellTestData");
MongoCursor<Document> cursor = wellTestCollection.find(lte("testStartTime", isoInpDateTime))

View File

@@ -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);

View File

@@ -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;
}
}
}

View File

@@ -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();
}
}

View File

@@ -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(){

View File

@@ -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);
}
}