Daily Totals storing, with max min average total

This commit is contained in:
Patrick McDonagh
2017-02-03 16:41:42 -06:00
parent 2730d2ee0f
commit 73d376038c
27 changed files with 960 additions and 410 deletions

View File

@@ -28,11 +28,13 @@ public class Well {
protected Database db;
// IO
AnalogIn inclinometer = new AnalogIn(99, 0, 100, 0, 100);
AnalogIn loadCell = new AnalogIn(99, 0, 50000, 0, 50000);
DigitalOut runCommand = new DigitalOut(7, 0);
private double currentPosition;
private double currentLoad;
AnalogIn inclinometer;
AnalogIn loadCell;
DigitalOut runCommand;
private double currentSurfacePosition;
private double currentSurfaceLoad;
private double currentDownholePosition;
private double currentDownholeLoad;
// CARDS
private Card currentCard;
@@ -131,19 +133,50 @@ public class Well {
private int[] count = new int[11];
private double sPositionPrevious;
Well(String wellName){
// Fluid Makeup
private double fluidOilRatio; // BBL of oil per 1 BBL fluid
private double fluidWaterRatio; // BBL of water per 1 BBL fluid
private double fluidGasRatio; // MCF of gas per 1 BBL fluid
// Measurements
private Measurement strokeSpeed = new Measurement();
private Measurement downholeGrossStroke = new Measurement();
private Measurement downholeNetStroke = new Measurement();
private Measurement fluidLevel = new Measurement();
private Measurement fluidLoad = new Measurement();
private Measurement inflowRate = new Measurement();
private Measurement peakPolishedRodLoad = new Measurement();
private Measurement minPolishedRodLoad = new Measurement();
private Measurement percentRun = new Measurement();
private Measurement polishedRodHP = new Measurement();
private Measurement pumpHP = new Measurement();
private Measurement fluidProduced = new Measurement();
private Measurement oilProduced = new Measurement();
private Measurement waterProduced = new Measurement();
private Measurement gasProduced = new Measurement();
private Measurement pumpIntakePressure = new Measurement();
private Measurement surfaceStrokeLength = new Measurement();
private Measurement tubingMovement = new Measurement();
Well(String wellName, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
this.wellName = wellName;
db = new Database();
strokesLifetime = db.getLastStrokeNum() + 1;
currentCard = new Card(strokesLifetime);
inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100);
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
runCommand = new DigitalOut(runCommandChannel, 0);
}
Well(String wellName, String simFileName){
Well(String wellName, String simFileName, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
this.wellName = wellName;
sim = new Simulation(simFileName);
db = new Database();
strokesLifetime = db.getLastStrokeNum() + 1;
currentCard = new Card(strokesLifetime);
inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100);
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
runCommand = new DigitalOut(runCommandChannel, 0);
}
public double getDt() {
@@ -297,12 +330,20 @@ public class Well {
return runMode;
}
public double getCurrentPosition() {
return currentPosition;
public double getCurrentSurfacePosition() {
return currentSurfacePosition;
}
public double getCurrentLoad() {
return currentLoad;
public double getCurrentSurfaceLoad() {
return currentSurfaceLoad;
}
public double getCurrentDownholePosition() {
return currentDownholePosition;
}
public double getCurrentDownholeLoad() {
return currentDownholeLoad;
}
public long getStartupStrokes() {
@@ -329,6 +370,12 @@ public class Well {
return direction;
}
public void setupFluidRatio(double oilRatio, double waterRatio, double gasRatio){
fluidOilRatio = oilRatio;
fluidWaterRatio = waterRatio;
fluidGasRatio = gasRatio;
}
// WELL COMMAND FUNCTIONS
public void start(String initiator){
if (runStatus == RUNSTATUS_STOPPED && permissiveOK){
@@ -707,7 +754,7 @@ public class Well {
{
topLoadArray[1][lengthRequired[1]] = loadMult * (sLoad - rodWeightFluidTotal) + sbfriction;
}
sPositionPrevious = sPosition;
int j = 1;
while (j <= tapersAllowed)
{
@@ -752,13 +799,13 @@ public class Well {
public void eval(){
checkSafeties();
currentPosition = inclinometer.readScaled();
currentLoad = loadCell.readScaled();
LPStatus lastPoint = calc(currentPosition, currentLoad);
currentSurfacePosition = inclinometer.readScaled();
currentSurfaceLoad = loadCell.readScaled();
LPStatus lastPoint = calc(currentSurfacePosition, currentSurfaceLoad);
if(runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING) {
if (lastPoint.getStatus() == GOOD_STATUS) {
currentCard.setSurfacePosition(pointCounter, currentPosition);
currentCard.setSurfaceLoad(pointCounter, currentLoad);
currentCard.setSurfacePosition(pointCounter, currentSurfacePosition);
currentCard.setSurfaceLoad(pointCounter, currentSurfaceLoad);
currentCard.setDownholePosition(pointCounter, lastPoint.getPosition());
currentCard.setDownholeLoad(pointCounter, lastPoint.getLoad());
}
@@ -773,7 +820,7 @@ public class Well {
currentCard.calcStrokeData(150, fluidGradient,
rodDepthTotal, tubingAnchorDepth,
tubingCrossSectionalArea, pumpArea,
frictionEstimate, structuralRating);
frictionEstimate, structuralRating, fluidWaterRatio, fluidOilRatio, fluidGasRatio);
for (int j = 98; j >= 0; j--) {
cardStorage[j + 1] = cardStorage[j];
}
@@ -794,17 +841,64 @@ public class Well {
}
}
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("none", 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();
currentPosition = inclinometer.readScaledSim(sim.getPositionAtIndex(simPoint));
currentLoad = loadCell.readScaledSim(sim.getLoadAtIndex(simPoint));
LPStatus lastPoint = calc(currentPosition, currentLoad);
currentSurfacePosition = inclinometer.readScaledSim(sim.getPositionAtIndex(simPoint));
currentSurfaceLoad = loadCell.readScaledSim(sim.getLoadAtIndex(simPoint));
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, currentPosition);
currentCard.setSurfaceLoad(pointCounter, currentLoad);
currentCard.setDownholePosition(pointCounter, lastPoint.getPosition());
currentCard.setDownholeLoad(pointCounter, lastPoint.getLoad());
currentCard.setSurfacePosition(pointCounter, currentSurfacePosition);
currentCard.setSurfaceLoad(pointCounter, currentSurfaceLoad);
currentCard.setDownholePosition(pointCounter, currentDownholePosition);
currentCard.setDownholeLoad(pointCounter, currentDownholeLoad);
}
if (inclinometer.getHistory(0) > inclinometer.getHistory(1))
@@ -813,25 +907,7 @@ 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);
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++;
currentCard = new Card(strokesLifetime);
pointCounter = -1;
if (strokesSinceStart > startupStrokes){
runStatus = RUNSTATUS_RUNNING;
}
endOfStroke();
}
lastDirection = direction;
pointCounter++;
@@ -843,15 +919,44 @@ public class Well {
runCommand.write(0);
}
}
public void printTotals(){
V2_AsciiTable taperTable = new V2_AsciiTable();
taperTable.addRule();
taperTable.addRow("Measuremnt", "Average", "Total");
taperTable.addStrongRule();
taperTable.addRow("Stroke Speed", strokeSpeed.getAverage(), strokeSpeed.getTotal());
taperTable.addRow("DH Gross Stroke", downholeGrossStroke.getAverage(), downholeGrossStroke.getTotal());
taperTable.addRow("DH Net Stroke", downholeNetStroke.getAverage(), downholeNetStroke.getTotal());
taperTable.addRow("Fluid Level", fluidLevel.getAverage(), fluidLevel.getTotal());
taperTable.addRow("Fluid Load", fluidLoad.getAverage(), fluidLoad.getTotal());
taperTable.addRow("Peak PR Load", peakPolishedRodLoad.getAverage(), peakPolishedRodLoad.getTotal());
taperTable.addRow("Min PR Load", minPolishedRodLoad.getAverage(), minPolishedRodLoad.getTotal());
taperTable.addRow("PR HP", polishedRodHP.getAverage(), polishedRodHP.getTotal());
taperTable.addRow("Pump HP", pumpHP.getAverage(), pumpHP.getTotal());
taperTable.addRow("Fluid Produced", fluidProduced.getAverage(), fluidProduced.getTotal());
taperTable.addRow("Oil Produced", oilProduced.getAverage(), oilProduced.getTotal());
taperTable.addRow("Water Produced", waterProduced.getAverage(), waterProduced.getTotal());
taperTable.addRow("Gas Produced", gasProduced.getAverage(), gasProduced.getTotal());
taperTable.addRow("Pump Intake Pressure", pumpIntakePressure.getAverage(), pumpIntakePressure.getTotal());
taperTable.addRow("Surf Stroke Length", surfaceStrokeLength.getAverage(), surfaceStrokeLength.getTotal());
taperTable.addRow("Tubing Movement", tubingMovement.getAverage(), tubingMovement.getTotal());
taperTable.addRule();
V2_AsciiTableRenderer rend = new V2_AsciiTableRenderer();
rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
rend.setWidth(new WidthAbsoluteEven(100));
RenderedTable rt = rend.render(taperTable);
System.out.println(rt);
System.out.println();
}
public void allOutputsOff(){
runCommand.write(0, true);
}
public static void main( String[] args ){
Well thisWell = new Well("Barney");
Well thisWell = new Well("Barney", args[1], 99, 99, 99);
thisWell.parseJSONFile(args[0]);
// thisWell.parseJSONFile("/Users/patrickjmcd/Henry_Pump/poc-java/wellSetup.json");
thisWell.printTapers();
}