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

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