Stores well test and gets latest kFactor

This commit is contained in:
Patrick McDonagh
2017-02-07 19:02:10 -06:00
parent 1699b82067
commit 2a13a25f06
16 changed files with 1125 additions and 355 deletions

View File

@@ -14,6 +14,7 @@ import org.bson.Document;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Arrays;
import com.mongodb.client.MongoCursor;
@@ -82,22 +83,21 @@ public class Database {
}
public long newMeasurement(Measurement inpMeasurement){
// String df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
// MongoCollection<Document> collection = database.getCollection("wellData");
// Document doc = new Document("tagname", inpMeasurement.getTagName())
//// .append("currentValue", inpMeasurement.getCurrentValue())
//// .append("maxDailyValue", inpMeasurement.getDailyMax())
//// .append("minDailyValue", inpMeasurement.getDailyMin())
//// .append("dailyAverage", inpMeasurement.getAverage())
//// .append("dailyTotal", inpMeasurement.getTotal())
// .append("timestamp", df);
// collection.insertOne(doc);
// return collection.count();
return 1;
String df = Date.from(Instant.now()).toString();
MongoCollection<Document> collection = database.getCollection("wellData");
Document doc = new Document("tagname", inpMeasurement.getTagName())
.append("currentValue", inpMeasurement.getCurrentValue())
.append("maxDailyValue", inpMeasurement.getDailyMax())
.append("minDailyValue", inpMeasurement.getDailyMin())
.append("dailyAverage", inpMeasurement.getAverage())
.append("dailyTotal", inpMeasurement.getTotal())
.append("timestamp", df);
collection.insertOne(doc);
return collection.count();
}
public long newDailyTotal(Measurement inpMeasurement){
String df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
String df = Date.from(Instant.now()).toString();
MongoCollection<Document> collection = database.getCollection("gaugeOffData");
Document doc = new Document("tagname", inpMeasurement.getTagName())
.append("currentValue", inpMeasurement.getCurrentValue())
@@ -111,4 +111,67 @@ public class Database {
}
public double getPreviousDailyTotal(Date inpDateTime){
String isoInpDateTime = inpDateTime.toString();
MongoCollection<Document> wellTestCollection = database.getCollection("gaugeOffData");
MongoCursor<Document> cursor = wellTestCollection.find(and(eq("tagname", "Fluid Produced"), lte("timestamp", isoInpDateTime)))
.sort(Sorts.descending("timestamp")).limit(1).iterator();
double lastTotal = -1.0;
try {
while (cursor.hasNext()) {
lastTotal = cursor.next().getDouble("dailyTotal");
}
} finally {
cursor.close();
}
return lastTotal;
};
public long newWellTest(WellTest inp){
String df = Date.from(Instant.now()).toString();
MongoCollection<Document> collection = database.getCollection("wellTestData");
Document doc = new Document("testStartTime", df)
.append("testHours", inp.getTestHours())
.append("testTotalBBL", inp.getTotalFluidBBL())
.append("testOilBBL", inp.getTestOilBBL())
.append("testWaterBBL", inp.getTestWaterBBL())
.append("testGasMCF", inp.getTestGasMCF())
.append("kFactor", inp.getkFactor())
.append("oilRatio", inp.getOilRatio())
.append("waterRatio", inp.getWaterRatio())
.append("gasMCFRatio", inp.getGasMCFRatio());
collection.insertOne(doc);
return collection.count();
}
public Document getPreviousWellTest(Date inpDateTime){
String isoInpDateTime = inpDateTime.toString();
MongoCollection<Document> wellTestCollection = database.getCollection("wellTestData");
MongoCursor<Document> cursor = wellTestCollection.find(lte("testStartTime", isoInpDateTime))
.sort(Sorts.descending("testStartTime")).limit(1).iterator();
Document lastTest = new Document("kFactor", (Double) 1.0);
try {
while (cursor.hasNext()) {
lastTest = cursor.next();
}
} finally {
cursor.close();
}
return lastTest;
};
public double getLatestKFactor(){
MongoCollection<Document> wellTestCollection = database.getCollection("wellTestData");
MongoCursor<Document> cursor = wellTestCollection.find().sort(Sorts.descending("testStartTime")).limit(1).iterator();
double kFactor = 1.0;
try {
while (cursor.hasNext()) {
kFactor = cursor.next().getDouble("kFactor");
}
} finally {
cursor.close();
}
return kFactor;
}
}

View File

@@ -7,6 +7,8 @@ package com.henrypump.poc;
*/
import java.awt.*;
import java.awt.event.*;
import java.time.Instant;
import java.util.Date;
public class POC implements Runnable{
protected Well thisWell;
@@ -91,8 +93,9 @@ public class POC implements Runnable{
public void run(){
int loopCounter = 0, loopLimit = simLoops, led2out, led3out, led4out,led5out;
double pos;
boolean newWellTest = true;
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
thisWell.setupFluidRatio(0.25, 0.75, 1.12);
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)) {
@@ -123,6 +126,20 @@ public class POC implements Runnable{
loopCounter++;
}
if (newWellTest){
System.out.println("Previous kFactor = " + thisWell.db.getLatestKFactor());
Date nowDate = Date.from(Instant.now());
thisWell.wellTest = new WellTest(nowDate, 24.0, .35, .20, .15, 1.25, thisWell);
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());
}
if (startBtn.read() == 1) thisWell.start("startbutton");
if (stopBtn.read() == 1) thisWell.stop("stopbutton");

View File

@@ -18,6 +18,7 @@ import static java.lang.Math.sqrt;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.time.LocalDate;
/**
* Created by patrickjmcd on 1/31/17.
@@ -26,6 +27,7 @@ public class Well {
private String wellName;
protected Simulation sim;
protected Database db;
protected WellTest wellTest;
/* IO */
AnalogIn inclinometer;
@@ -138,25 +140,35 @@ public class Well {
private double fluidWaterRatio; // BBL of water per 1 BBL fluid
private double fluidGasRatio; // MCF of gas per 1 BBL fluid
// DATE & TIME PARAMETERS
private LocalDate lastCheckedDate = null;
private boolean isNewDay(){
LocalDate today = LocalDate.now();
boolean ret = lastCheckedDate == null || today.isAfter(lastCheckedDate);
lastCheckedDate = today;
return ret;
}
// Measurements
private Measurement strokeSpeed = new Measurement("Stroke Speed", true, db, 0.5, 600);
private Measurement downholeGrossStroke = new Measurement("Downhole Gross Stroke", true, db, 0.5, 600);
private Measurement downholeNetStroke = new Measurement("Downhole Net Stroke", true, db, 0.5, 600);
private Measurement fluidLevel = new Measurement("Fluid Level", true, db, 10, 600);
private Measurement fluidLoad = new Measurement("Fluid Load", true, db, 20, 600);
private Measurement inflowRate = new Measurement("Inflow Rate", true, db, 0.5, 600);
private Measurement peakPolishedRodLoad = new Measurement("Peak PRL", true, db, 50, 600);
private Measurement minPolishedRodLoad = new Measurement("Min PRL", true, db, 50, 600);
private Measurement percentRun = new Measurement("Percent Run", true, db, 1.0, 600);
private Measurement polishedRodHP = new Measurement("Polished Rod HP", true, db, 0.25, 600);
private Measurement pumpHP = new Measurement("Pump HP", true, db, 0.25, 600);
private Measurement fluidProduced = new Measurement("Fluid Produced", true, db, 1.0, 600);
private Measurement oilProduced = new Measurement("Oil Produced", true, db, 1.0, 600);
private Measurement waterProduced = new Measurement("Water Produced", true, db, 1.0, 600);
private Measurement gasProduced = new Measurement("Gas Produced", true, db, 1.0, 600);
private Measurement pumpIntakePressure = new Measurement("Pump Intake Pressure", true, db, 5.0, 600);
private Measurement surfaceStrokeLength = new Measurement("Surface Stroke", true, db, 0.5, 1800);
private Measurement tubingMovement = new Measurement("Tubing Movement", true, db, 0.5, 600);
private Measurement strokeSpeed;
private Measurement downholeGrossStroke;
private Measurement downholeNetStroke;
private Measurement fluidLevel;
private Measurement fluidLoad;
private Measurement inflowRate;
private Measurement peakPolishedRodLoad;
private Measurement minPolishedRodLoad;
private Measurement percentRun;
private Measurement polishedRodHP;
private Measurement pumpHP;
private Measurement fluidProduced;
private Measurement oilProduced;
private Measurement waterProduced;
private Measurement gasProduced;
private Measurement pumpIntakePressure;
private Measurement surfaceStrokeLength;
private Measurement tubingMovement;
Well(String wellName, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
this.wellName = wellName;
@@ -166,6 +178,25 @@ public class Well {
inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100);
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
runCommand = new DigitalOut(runCommandChannel, 0);
strokeSpeed = new Measurement("Stroke Speed", true, db, 0.5, 600);
downholeGrossStroke = new Measurement("Downhole Gross Stroke", true, db, 0.5, 600);
downholeNetStroke = new Measurement("Downhole Net Stroke", true, db, 0.5, 600);
fluidLevel = new Measurement("Fluid Level", true, db, 10, 600);
fluidLoad = new Measurement("Fluid Load", true, db, 20, 600);
inflowRate = new Measurement("Inflow Rate", true, db, 0.5, 600);
peakPolishedRodLoad = new Measurement("Peak PRL", true, db, 50, 600);
minPolishedRodLoad = new Measurement("Min PRL", true, db, 50, 600);
percentRun = new Measurement("Percent Run", true, db, 1.0, 600);
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);
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);
pumpIntakePressure = new Measurement("Pump Intake Pressure", true, db, 5.0, 600);
surfaceStrokeLength = new Measurement("Surface Stroke", true, db, 0.5, 1800);
tubingMovement = new Measurement("Tubing Movement", true, db, 0.5, 600);
}
Well(String wellName, String simFileName, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
@@ -177,6 +208,25 @@ public class Well {
inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100);
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
runCommand = new DigitalOut(runCommandChannel, 0);
strokeSpeed = new Measurement("Stroke Speed", true, db, 0.5, 600);
downholeGrossStroke = new Measurement("Downhole Gross Stroke", true, db, 0.5, 600);
downholeNetStroke = new Measurement("Downhole Net Stroke", true, db, 0.5, 600);
fluidLevel = new Measurement("Fluid Level", true, db, 10, 600);
fluidLoad = new Measurement("Fluid Load", true, db, 20, 600);
inflowRate = new Measurement("Inflow Rate", true, db, 0.5, 600);
peakPolishedRodLoad = new Measurement("Peak PRL", true, db, 50, 600);
minPolishedRodLoad = new Measurement("Min PRL", true, db, 50, 600);
percentRun = new Measurement("Percent Run", true, db, 1.0, 600);
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);
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);
pumpIntakePressure = new Measurement("Pump Intake Pressure", true, db, 5.0, 600);
surfaceStrokeLength = new Measurement("Surface Stroke", true, db, 0.5, 1800);
tubingMovement = new Measurement("Tubing Movement", true, db, 0.5, 600);
}
public double getDt() {
@@ -370,6 +420,18 @@ public class Well {
return direction;
}
public double getFluidOilRatio() {
return fluidOilRatio;
}
public double getFluidWaterRatio() {
return fluidWaterRatio;
}
public double getFluidGasRatio() {
return fluidGasRatio;
}
public void setupFluidRatio(double oilRatio, double waterRatio, double gasRatio){
fluidOilRatio = oilRatio;
fluidWaterRatio = waterRatio;
@@ -571,6 +633,7 @@ public class Well {
taperTable.addRow("Rod Depth", rodDepth[i]);
taperTable.addRow("Rod Weight in Air", rodWeightAir[i]);
taperTable.addRow("Rod Weight in Fluid", rodWeightFluid[i]);
taperTable.addRule();
rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
rend.setWidth(new WidthAbsoluteEven(50));
rt = rend.render(taperTable);
@@ -820,6 +883,66 @@ public class Well {
return downholeValues;
};
public void endOfStroke(){
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("csv", true);
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;
}
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();
}
}
public void eval(){
checkSafeties();
currentSurfacePosition = inclinometer.readScaled();
@@ -853,6 +976,24 @@ public class Well {
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) {
@@ -862,49 +1003,29 @@ public class Well {
lastDirection = direction;
pointCounter++;
}
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();
}
}
public void endOfStroke(){
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("csv", true);
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());
printTotals();
currentCard = new Card(strokesLifetime);
pointCounter = -1;
if (strokesSinceStart > startupStrokes){
runStatus = RUNSTATUS_RUNNING;
}
}
public void eval(int simPoint){
checkSafeties();

View File

@@ -0,0 +1,78 @@
package com.henrypump.poc;
import org.bson.Document;
import java.util.Date;
/**
* Created by patrickjmcd on 2/7/17.
*/
public class WellTest {
private double testHours;
private Date 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, Well well) {
this.testStart = testStart;
this.testHours = testHours;
this.totalFluidBBL = totalFluidBBL;
this.testOilBBL = testOilBBL;
this.testWaterBBL = testWaterBBL;
this.testGasMCF = testGasMCF;
this.oilRatio = this.testOilBBL / this.totalFluidBBL;
this.waterRatio = this.testWaterBBL / this.totalFluidBBL;
this.gasMCFRatio = this.testGasMCF / this.totalFluidBBL;
this.kFactor = 1.0;
double lastProductionMeasured = well.db.getPreviousDailyTotal(this.testStart);
if(lastProductionMeasured != -1.0){;
this.kFactor = this.totalFluidBBL / lastProductionMeasured;
} else {
System.out.println("No production data in db");
}
}
public double getTestHours() {
return testHours;
}
public Date getTestStart() {
return testStart;
}
public double getTotalFluidBBL() {
return totalFluidBBL;
}
public double getTestOilBBL() {
return testOilBBL;
}
public double getTestWaterBBL() {
return testWaterBBL;
}
public double getTestGasMCF() {
return testGasMCF;
}
public double getkFactor() {
return kFactor;
}
public double getOilRatio() {
return oilRatio;
}
public double getWaterRatio() {
return waterRatio;
}
public double getGasMCFRatio() {
return gasMCFRatio;
}
}