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

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