Re-worked command endpoint to be update endpoint
all values must first go through the database to be sent to the POC
This commit is contained in:
1012
.idea/workspace.xml
generated
1012
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
67
README.md
67
README.md
@@ -45,40 +45,41 @@ systemctl enable mongod.service
|
||||
|
||||
# Local Web API
|
||||
|
||||
## Endpoint `/config?`
|
||||
|
||||
### `update=<doUpdate:string>`
|
||||
- if doUpdate = `true`, the well configuration will be updated.
|
||||
- returns `{"configUpdated: <result>"}`
|
||||
|
||||
### `fluidOilRatio=<newRatio:double>`
|
||||
- sets the fluidOilRatio (BBL oil to every 1 BBL fluid producted) to `newRatio`
|
||||
- returns `{"fluidOilRatio": <fluidOilRatio>}`
|
||||
|
||||
### `fluidWaterRatio=<newRatio:double>`
|
||||
- sets the fluidWaterRatio (BBL water to every 1 BBL fluid producted) to `newRatio`
|
||||
- returns `{"fluidWaterRatio": <fluidWaterRatio>}`
|
||||
|
||||
### `fluidGasMCFRatio=<newRatio:double>`
|
||||
- sets the fluidGasMCFRatio (MCF gas to every 1 BBL fluid producted) to `newRatio`
|
||||
- returns `{"fluidGasMCFRatio": <fluidGasMCFRatio>}`
|
||||
|
||||
### `pumpOffSetpoint=<newSetpoint:double>`
|
||||
- sets the pump-off fill percent setpoint to `newSetpoint`
|
||||
- returns `{"pumpOffSetpoint": <pumpOffSetpoint>}`
|
||||
|
||||
### `pumpOffStrokes=<newSetpoint:long>`
|
||||
- sets the number of low-fillage strokes required for pump-off to `newSetpoint`
|
||||
- returns `{"pumpOffStrokes": <pumpOffStrokes>}`
|
||||
|
||||
### `pumpOffDowntime=<newSetpoint:long>`
|
||||
- sets the minutes of downtime after pumpoff to `newSetpoint`
|
||||
- returns `{"pumpOffDowntime": <pumpOffDowntime>}`
|
||||
|
||||
## Endpoint `/command?cmd=<command>&user=<username>`
|
||||
- Attempts to give the command to the unit.
|
||||
- Allowed values:
|
||||
- start
|
||||
- stop
|
||||
- returns `{"status": <string: runStatus>}`
|
||||
|
||||
### `start`
|
||||
- returns `{"startCommand: <result>", "status": <runStatus>}`
|
||||
## Endpoint `/update?wellconfig`
|
||||
- Updates the well configuration with values stored in
|
||||
1. wellConfig.json
|
||||
2. MongoDB database (configured via website)
|
||||
- returns `{"configUpdated": <bool: updatestatus>}`
|
||||
|
||||
### `stop`
|
||||
- returns `{"stopCommand: <result>", "status": <runStatus>}`
|
||||
## Endpoint `/update?setpoint=<variable name>`
|
||||
- Updates the value of the variable name supplied from values in the database.
|
||||
- Allowed values:
|
||||
- fluidOilRatio
|
||||
- fluidWaterRatio
|
||||
- fluidGasRatio
|
||||
- pumpOffFillPercentSetpoint
|
||||
- pumpOffStrokesSetpoint
|
||||
- pumpOffDowntimeMinutesSetpoint
|
||||
- timerOffMinutesSetpoint
|
||||
- timerRunMinutesSetpoint
|
||||
- returns `{<string: variable name>: <double: variable value>}`
|
||||
|
||||
## Endpoint `/mode?mode=<commanded mode>&user=<username>`
|
||||
- Attempts to change to mode of the unit to the commanded mode.
|
||||
- Allowed values:
|
||||
- manual
|
||||
- poc
|
||||
- timer
|
||||
- returns `{"runMode": <string: runMode>}`
|
||||
|
||||
## Endpoint `/shake`
|
||||
- Used to verify the POC is active
|
||||
- returns `{"shake": "shook"}`
|
||||
|
||||
@@ -9,11 +9,9 @@ import com.mongodb.*;
|
||||
import com.mongodb.client.AggregateIterable;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.model.Accumulators;
|
||||
import com.mongodb.client.model.Aggregates;
|
||||
import com.mongodb.client.model.*;
|
||||
|
||||
import com.mongodb.client.model.Indexes;
|
||||
import com.mongodb.client.model.Sorts;
|
||||
import org.bson.BSON;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -60,6 +58,7 @@ public class Database {
|
||||
wellConfigCollection.createIndex(Indexes.ascending("timestamp"));
|
||||
|
||||
setpointCollection = database.getCollection("setpoints");
|
||||
setpointCollection.createIndex(Indexes.ascending("name"));
|
||||
}
|
||||
|
||||
|
||||
@@ -306,5 +305,28 @@ public class Database {
|
||||
return lastConfig;
|
||||
}
|
||||
|
||||
public long storeSetpoint(String setpointName, double setpointValue){
|
||||
Document newSetpoint = new Document("name", setpointName)
|
||||
.append("value", setpointValue)
|
||||
.append("lastStored", Date.from(ZonedDateTime.now().toInstant()))
|
||||
.append("storedBy", "poc");
|
||||
setpointCollection.updateOne(eq("name", setpointName), new Document("$set", newSetpoint), (new UpdateOptions()).upsert(true));
|
||||
return setpointCollection.count();
|
||||
|
||||
}
|
||||
|
||||
public Double getSetpoint(String setpointName){
|
||||
Document setpointDoc = setpointCollection.find(eq("name", setpointName)).first();
|
||||
double setpoint;
|
||||
try {
|
||||
setpoint = setpointDoc.getDouble("value");
|
||||
String storedBy = setpointDoc.getString("storedBy");
|
||||
System.out.println("Setpoint retrieved from database: [" + setpointName + " = " + setpoint + " stored by " + storedBy + "]");
|
||||
} catch (NullPointerException e){
|
||||
setpoint = Double.MIN_VALUE;
|
||||
System.out.println("Could not find a value for " + setpointName + " in the database.");
|
||||
}
|
||||
return setpoint;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ public class POC implements Runnable{
|
||||
new Thread(new IOControl(this)).start();
|
||||
}
|
||||
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
||||
thisWell.setupFluidRatio(0.50, 0.50, 1.12);
|
||||
thisWell.checkSafeties();
|
||||
while (true) {
|
||||
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
||||
|
||||
@@ -25,8 +25,9 @@ public class WebServer{
|
||||
this.port = port;
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||
server.createContext("/command", new CommandHandler());
|
||||
server.createContext("/config", new ConfigHandler());
|
||||
server.createContext("/update", new UpdateHandler());
|
||||
server.createContext("/shake", new HandshakeHandler());
|
||||
server.createContext("/mode", new ModeHandler());
|
||||
server.setExecutor(null); // creates a default executor
|
||||
server.start();
|
||||
}
|
||||
@@ -95,89 +96,73 @@ public class WebServer{
|
||||
}
|
||||
|
||||
|
||||
class ConfigHandler implements HttpHandler {
|
||||
class UpdateHandler implements HttpHandler {
|
||||
@Override
|
||||
public void handle(HttpExchange t) throws IOException {
|
||||
JSONObject respJSON = new JSONObject();
|
||||
Map<String, String> params = queryToMap(t.getRequestURI().getQuery());
|
||||
|
||||
for(Map.Entry<String, String> param_map : params.entrySet()){
|
||||
String key = param_map.getKey();
|
||||
String param = param_map.getValue();
|
||||
double newSP;
|
||||
if (key.equals("wellconfig")) {
|
||||
attachedPOC.thisWell.getWellSetup();
|
||||
respJSON.put("configUpdated", "true");
|
||||
continue;
|
||||
} else if (key.equals("setpoint")) {
|
||||
newSP = attachedPOC.thisWell.db.getSetpoint(param);
|
||||
if (newSP == Double.MIN_VALUE) {
|
||||
respJSON.put("no entry", key);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (key){
|
||||
case "update":
|
||||
if(param.equals("true")) {
|
||||
attachedPOC.thisWell.getWellSetup();
|
||||
respJSON.put("configUpdated", "true");
|
||||
} else {
|
||||
respJSON.put("configUpdated", "invalid value - " + param);
|
||||
}
|
||||
break;
|
||||
switch (param) {
|
||||
case "fluidOilRatio":
|
||||
attachedPOC.thisWell.setFluidOilRatio(newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getFluidOilRatio());
|
||||
break;
|
||||
|
||||
case "fluidOilRatio":
|
||||
try {
|
||||
double newSetpoint = Double.parseDouble(param);
|
||||
attachedPOC.thisWell.setFluidOilRatio(newSetpoint);
|
||||
respJSON.put("fluidOilRatio", attachedPOC.thisWell.getFluidOilRatio());
|
||||
} catch (NullPointerException | NumberFormatException e) {
|
||||
respJSON.put("fluidOilRatio", "invalid value - " + param);
|
||||
}
|
||||
break;
|
||||
case "fluidWaterRatio":
|
||||
attachedPOC.thisWell.setFluidWaterRatio(newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getFluidWaterRatio());
|
||||
break;
|
||||
|
||||
case "fluidWaterRatio":
|
||||
try {
|
||||
double newSetpoint = Double.parseDouble(param);
|
||||
attachedPOC.thisWell.setFluidWaterRatio(newSetpoint);
|
||||
respJSON.put("fluidWaterRatio", attachedPOC.thisWell.getFluidWaterRatio());
|
||||
} catch (NullPointerException | NumberFormatException e) {
|
||||
respJSON.put("fluidWaterRatio", "invalid value - " + param);
|
||||
}
|
||||
break;
|
||||
case "fluidGasRatio":
|
||||
attachedPOC.thisWell.setFluidGasRatio(newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getFluidGasRatio());
|
||||
break;
|
||||
|
||||
case "fluidGasMCFRatio":
|
||||
try {
|
||||
double newSetpoint = Double.parseDouble(param);
|
||||
attachedPOC.thisWell.setFluidGasRatio(newSetpoint);
|
||||
respJSON.put("fluidGasMCFRatio", attachedPOC.thisWell.getFluidGasRatio());
|
||||
} catch (NullPointerException | NumberFormatException e) {
|
||||
respJSON.put("fluidGasMCFRatio", "invalid value - " + param);
|
||||
}
|
||||
break;
|
||||
case "pumpOffFillPercentSetpoint":
|
||||
attachedPOC.thisWell.setPumpOffFillPercentSetpoint(newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getPumpOffFillPercentSetpoint());
|
||||
break;
|
||||
|
||||
case "pumpOffSetpoint":
|
||||
try {
|
||||
double newSetpoint = Double.parseDouble(param);
|
||||
attachedPOC.thisWell.setPumpOffFillPercentSetpoint(newSetpoint);
|
||||
respJSON.put("pumpOffSetpoint", attachedPOC.thisWell.getPumpOffFillPercentSetpoint());
|
||||
} catch (NullPointerException | NumberFormatException e) {
|
||||
respJSON.put("pumpOffSetpoint", "invalid value - " + param);
|
||||
}
|
||||
break;
|
||||
case "pumpOffStrokesSetpoint":
|
||||
attachedPOC.thisWell.setPumpOffStrokesSetpoint((int) newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getPumpOffStrokesSetpoint());
|
||||
break;
|
||||
|
||||
case "pumpOffStrokes":
|
||||
try {
|
||||
int newSetpoint = Integer.parseInt(param);
|
||||
attachedPOC.thisWell.setPumpOffStrokes(newSetpoint);
|
||||
respJSON.put("pumpOffStrokes", attachedPOC.thisWell.getPumpOffStrokes());
|
||||
} catch (NullPointerException | NumberFormatException e) {
|
||||
respJSON.put("pumpOffStrokes", "invalid value - " + param);
|
||||
}
|
||||
break;
|
||||
case "pumpOffDowntimeMinutesSetpoint":
|
||||
attachedPOC.thisWell.setPumpOffDowntimeMinutesSetpoint((long) newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getPumpOffDowntimeMinutesSetpoint());
|
||||
break;
|
||||
|
||||
case "pumpOffDowntime":
|
||||
try {
|
||||
long newSetpoint = Long.parseLong(param);
|
||||
attachedPOC.thisWell.setPumpOffDowntimeMinutes(newSetpoint);
|
||||
respJSON.put("pumpOffDowntime", attachedPOC.thisWell.getPumpOffDowntimeMinutes());
|
||||
} catch (NullPointerException | NumberFormatException e) {
|
||||
respJSON.put("pumpOffDowntime", "invalid value - " + param);
|
||||
}
|
||||
break;
|
||||
case "timerOffMinutesSetpoint":
|
||||
attachedPOC.thisWell.setTimerOffMinutesSetpoint((long) newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getTimerOffMinutesSetpoint());
|
||||
break;
|
||||
|
||||
default:
|
||||
respJSON.put(key, "not implemented");
|
||||
break;
|
||||
case "timerRunMinutesSetpoint":
|
||||
attachedPOC.thisWell.setTimerRunMinutesSetpoint((long) newSP);
|
||||
respJSON.put(param, attachedPOC.thisWell.getTimerRunMinutesSetpoint());
|
||||
break;
|
||||
|
||||
default:
|
||||
respJSON.put(param, "not implemented");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -201,7 +186,54 @@ public class WebServer{
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
|
||||
class ModeHandler implements HttpHandler {
|
||||
@Override
|
||||
public void handle(HttpExchange t) throws IOException {
|
||||
JSONObject respJSON = new JSONObject();
|
||||
Map<String, String> params = queryToMap(t.getRequestURI().getQuery());
|
||||
String action = "";
|
||||
String user = "";
|
||||
for(Map.Entry<String, String> param_map : params.entrySet()){
|
||||
String key = param_map.getKey();
|
||||
String param = param_map.getValue();
|
||||
|
||||
switch (key) {
|
||||
case "mode":
|
||||
action = param;
|
||||
break;
|
||||
case "user":
|
||||
user = param;
|
||||
break;
|
||||
default:
|
||||
respJSON.put(key, "not implemented");
|
||||
|
||||
}
|
||||
}
|
||||
if ((user.length() > 0) && (action.length() > 0)) {
|
||||
switch (action) {
|
||||
case "manual":
|
||||
attachedPOC.thisWell.setRunMode("MANUAL");
|
||||
break;
|
||||
case "poc":
|
||||
attachedPOC.thisWell.setRunMode("POC");
|
||||
break;
|
||||
case "timer":
|
||||
attachedPOC.thisWell.setRunMode("TIMER");
|
||||
break;
|
||||
default:
|
||||
respJSON.put(action, "not implemented");
|
||||
break;
|
||||
}
|
||||
respJSON.put("runMode", attachedPOC.thisWell.getRunModeString());
|
||||
} else {
|
||||
respJSON.put("bad request", "cmd and user parameters required");
|
||||
}
|
||||
String response = respJSON.toJSONString();
|
||||
t.sendResponseHeaders(200, response.getBytes().length);
|
||||
OutputStream os = t.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import static java.lang.Math.exp;
|
||||
import static java.lang.Math.pow;
|
||||
import static java.lang.Math.sqrt;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
@@ -22,6 +20,8 @@ import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 1/31/17.
|
||||
*/
|
||||
@@ -174,15 +174,33 @@ public class Well {
|
||||
private Measurement tubingMovement;
|
||||
private Measurement pumpFillPercent;
|
||||
|
||||
// Running Setpoints
|
||||
private double pumpOffFillPercentSetpoint = 65;
|
||||
private int pumpOffStrokes = 5;
|
||||
private ZonedDateTime pumpStartTime;
|
||||
|
||||
// POC Mode Setpoints
|
||||
private double pumpOffFillPercentSetpoint;
|
||||
private int pumpOffStrokesSetpoint;
|
||||
private long pumpOffDowntimeMinutesSetpoint;
|
||||
|
||||
// POC Mode Status
|
||||
private int lowFillageStrokes = 0;
|
||||
private ZonedDateTime pumpedOffTime;
|
||||
private long pumpOffDowntimeMinutes = 5;
|
||||
private long minutesSincePumpOff = 0;
|
||||
private long minutesSincePumpOff_last = 0;
|
||||
|
||||
|
||||
// Timer Mode Setpoints
|
||||
private long timerRunMinutesSetpoint;
|
||||
private long timerOffMinutesSetpoint;
|
||||
|
||||
// Timer Mode status
|
||||
|
||||
private ZonedDateTime timerStopTime;
|
||||
private long minutesSinceTimerStop = 0;
|
||||
private long minutesSinceTimerStop_last = 0;
|
||||
private long minutesSinceTimerStart = 0;
|
||||
private long minutesSinceTimerStart_last = 0;
|
||||
|
||||
|
||||
Well(String dbHostname, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
|
||||
this.wellName = wellName;
|
||||
db = new Database(dbHostname);
|
||||
@@ -192,6 +210,7 @@ public class Well {
|
||||
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
||||
|
||||
initializeMeasurements();
|
||||
initializeSetpoints();
|
||||
db.newRunStatus("Boot", "io");
|
||||
}
|
||||
|
||||
@@ -205,9 +224,89 @@ public class Well {
|
||||
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
||||
|
||||
initializeMeasurements();
|
||||
initializeSetpoints();
|
||||
db.newRunStatus("Boot", "commandline");
|
||||
}
|
||||
|
||||
private void initializeSetpoints(){
|
||||
/**
|
||||
* intializeSetpoints
|
||||
* This function will retrieve setpoint data from the mongodb instance.
|
||||
* If there is no setpoint stored in the database, a default value will be used.
|
||||
*/
|
||||
double dbPumpOffFillPercentSetpoint = db.getSetpoint("pumpOffFillPercentSetpoint");
|
||||
if (dbPumpOffFillPercentSetpoint == Double.MIN_VALUE){
|
||||
pumpOffFillPercentSetpoint = 65.0; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + pumpOffFillPercentSetpoint + " for PumpOffFillPercentSetpoint.");
|
||||
db.storeSetpoint("pumpOffFillPercentSetpoint", pumpOffFillPercentSetpoint);
|
||||
} else {
|
||||
pumpOffFillPercentSetpoint = dbPumpOffFillPercentSetpoint;
|
||||
}
|
||||
|
||||
double dbPumpOffStrokes = db.getSetpoint("pumpOffStrokesSetpoint");
|
||||
if (dbPumpOffStrokes == Double.MIN_VALUE){
|
||||
pumpOffStrokesSetpoint = 5; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + pumpOffStrokesSetpoint + " for pumpOffStrokesSetpoint.");
|
||||
db.storeSetpoint("pumpOffStrokesSetpoint", (double) pumpOffStrokesSetpoint);
|
||||
} else {
|
||||
pumpOffStrokesSetpoint = (int) dbPumpOffStrokes;
|
||||
}
|
||||
|
||||
double dbPumpOffDowntimeMinutesSetpoint = db.getSetpoint("pumpOffDowntimeMinutesSetpoint");
|
||||
if (dbPumpOffDowntimeMinutesSetpoint == Double.MIN_VALUE){
|
||||
pumpOffDowntimeMinutesSetpoint = 30; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + pumpOffDowntimeMinutesSetpoint + " for pumpOffDowntimeMinutesSetpoint.");
|
||||
db.storeSetpoint("pumpOffDowntimeMinutesSetpoint", (double) pumpOffDowntimeMinutesSetpoint);
|
||||
} else {
|
||||
pumpOffDowntimeMinutesSetpoint = (long) dbPumpOffDowntimeMinutesSetpoint;
|
||||
}
|
||||
|
||||
double dbTimerRunMinutesSetpoint = db.getSetpoint("timerRunMinutesSetpoint");
|
||||
if (dbTimerRunMinutesSetpoint == Double.MIN_VALUE){
|
||||
timerRunMinutesSetpoint = 45; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + timerRunMinutesSetpoint + " for timerRunMinutesSetpoint.");
|
||||
db.storeSetpoint("timerRunMinutesSetpoint", (double) timerRunMinutesSetpoint);
|
||||
} else {
|
||||
timerRunMinutesSetpoint = (long) dbTimerRunMinutesSetpoint;
|
||||
}
|
||||
|
||||
double dbTimerOffMinutesSetpoint = db.getSetpoint("timerOffMinutesSetpoint");
|
||||
if (dbTimerOffMinutesSetpoint == Double.MIN_VALUE){
|
||||
timerOffMinutesSetpoint = 15; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + timerOffMinutesSetpoint + " for timerOffMinutesSetpoint.");
|
||||
db.storeSetpoint("timerOffMinutesSetpoint", (double) timerOffMinutesSetpoint);
|
||||
} else {
|
||||
timerOffMinutesSetpoint = (long) dbTimerOffMinutesSetpoint;
|
||||
}
|
||||
|
||||
double dbFluidOilRatio = db.getSetpoint("fluidOilRatio");
|
||||
if (dbFluidOilRatio == Double.MIN_VALUE){
|
||||
fluidOilRatio = 0.5; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + fluidOilRatio + " for fluidOilRatio.");
|
||||
db.storeSetpoint("fluidOilRatio", (double) fluidOilRatio);
|
||||
} else {
|
||||
fluidOilRatio = dbFluidOilRatio;
|
||||
}
|
||||
|
||||
double dbFluidWaterRatio = db.getSetpoint("fluidWaterRatio");
|
||||
if (dbFluidWaterRatio == Double.MIN_VALUE){
|
||||
fluidWaterRatio = 0.5; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + fluidWaterRatio + " for fluidWaterRatio.");
|
||||
db.storeSetpoint("fluidWaterRatio", (double) fluidWaterRatio);
|
||||
} else {
|
||||
fluidWaterRatio = dbFluidWaterRatio;
|
||||
}
|
||||
|
||||
double dbFluidGasRatio = db.getSetpoint("fluidGasRatio");
|
||||
if (dbFluidGasRatio == Double.MIN_VALUE){
|
||||
fluidGasRatio = 2; // DEFAULT VALUE
|
||||
System.out.println("Using default value of " + fluidGasRatio + " for fluidGasRatio.");
|
||||
db.storeSetpoint("fluidGasRatio", (double) fluidGasRatio);
|
||||
} else {
|
||||
fluidGasRatio = dbFluidGasRatio;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeMeasurements(){
|
||||
strokeSpeed = new Measurement("Stroke Speed", db, 0.5, 600);
|
||||
downholeGrossStroke = new Measurement("Downhole Gross Stroke", db, 0.5, 600);
|
||||
@@ -422,6 +521,22 @@ public class Well {
|
||||
}
|
||||
}
|
||||
|
||||
public void setRunMode(String runModeString){
|
||||
switch (runModeString){
|
||||
case "POC":
|
||||
runMode = RUNMODE_POC;
|
||||
break;
|
||||
case "MANUAL":
|
||||
runMode = RUNMODE_MANUAL;
|
||||
break;
|
||||
case "TIMER":
|
||||
runMode = RUNMODE_TIMER;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public double getCurrentSurfacePosition() {
|
||||
return currentSurfacePosition;
|
||||
}
|
||||
@@ -514,20 +629,20 @@ public class Well {
|
||||
this.pumpOffFillPercentSetpoint = pumpOffFillPercentSetpoint;
|
||||
}
|
||||
|
||||
public int getPumpOffStrokes() {
|
||||
return pumpOffStrokes;
|
||||
public int getPumpOffStrokesSetpoint() {
|
||||
return pumpOffStrokesSetpoint;
|
||||
}
|
||||
|
||||
public void setPumpOffStrokes(int pumpOffStrokes) {
|
||||
this.pumpOffStrokes = pumpOffStrokes;
|
||||
public void setPumpOffStrokesSetpoint(int pumpOffStrokesSetpoint) {
|
||||
this.pumpOffStrokesSetpoint = pumpOffStrokesSetpoint;
|
||||
}
|
||||
|
||||
public long getPumpOffDowntimeMinutes() {
|
||||
return pumpOffDowntimeMinutes;
|
||||
public long getPumpOffDowntimeMinutesSetpoint() {
|
||||
return pumpOffDowntimeMinutesSetpoint;
|
||||
}
|
||||
|
||||
public void setPumpOffDowntimeMinutes(long pumpOffDowntimeMinutes) {
|
||||
this.pumpOffDowntimeMinutes = pumpOffDowntimeMinutes;
|
||||
public void setPumpOffDowntimeMinutesSetpoint(long pumpOffDowntimeMinutesSetpoint) {
|
||||
this.pumpOffDowntimeMinutesSetpoint = pumpOffDowntimeMinutesSetpoint;
|
||||
}
|
||||
|
||||
public void setupFluidRatio(double oilRatio, double waterRatio, double gasRatio){
|
||||
@@ -536,12 +651,29 @@ public class Well {
|
||||
fluidGasRatio = gasRatio;
|
||||
}
|
||||
|
||||
public long getTimerRunMinutesSetpoint() {
|
||||
return timerRunMinutesSetpoint;
|
||||
}
|
||||
|
||||
public void setTimerRunMinutesSetpoint(long timerRunMinutesSetpoint) {
|
||||
this.timerRunMinutesSetpoint = timerRunMinutesSetpoint;
|
||||
}
|
||||
|
||||
public long getTimerOffMinutesSetpoint() {
|
||||
return timerOffMinutesSetpoint;
|
||||
}
|
||||
|
||||
public void setTimerOffMinutesSetpoint(long timerOffMinutesSetpoint) {
|
||||
this.timerOffMinutesSetpoint = timerOffMinutesSetpoint;
|
||||
}
|
||||
|
||||
// WELL COMMAND FUNCTIONS
|
||||
public void start(String initiator){
|
||||
if (runStatus == RUNSTATUS_STOPPED && permissiveOK){
|
||||
System.out.println("Starting " + wellName + " from " + initiator + "...");
|
||||
runStatus = RUNSTATUS_STARTING;
|
||||
strokesSinceStart = 0;
|
||||
pumpStartTime = ZonedDateTime.now();
|
||||
db.newRunStatus(getRunStatusString(), initiator);
|
||||
}
|
||||
}
|
||||
@@ -566,8 +698,13 @@ public class Well {
|
||||
public void pumpOff(String initiator){
|
||||
if (runStatus == RUNSTATUS_RUNNING){
|
||||
System.out.println("Pumping off from " + initiator + "...");
|
||||
System.out.println("Restarting in " + pumpOffDowntimeMinutes + " minutes.");
|
||||
pumpedOffTime = ZonedDateTime.now();
|
||||
if (runMode == RUNMODE_POC) {
|
||||
System.out.println("Restarting in " + pumpOffDowntimeMinutesSetpoint + " minutes.");
|
||||
pumpedOffTime = ZonedDateTime.now();
|
||||
} else if (runMode == RUNMODE_TIMER){
|
||||
System.out.println("Restarting in " + timerOffMinutesSetpoint + " minutes.");
|
||||
timerStopTime = ZonedDateTime.now();
|
||||
}
|
||||
runStatus = RUNSTATUS_PUMPEDOFF;
|
||||
db.newRunStatus(getRunStatusString(), initiator);
|
||||
}
|
||||
@@ -1115,14 +1252,16 @@ public class Well {
|
||||
}
|
||||
|
||||
if (runStatus == RUNSTATUS_RUNNING) {
|
||||
if (pumpFillPercent.getCurrentValue() < pumpOffFillPercentSetpoint) {
|
||||
lowFillageStrokes++;
|
||||
} else {
|
||||
lowFillageStrokes = 0;
|
||||
}
|
||||
if (runMode == RUNMODE_POC){
|
||||
if (pumpFillPercent.getCurrentValue() < pumpOffFillPercentSetpoint) {
|
||||
lowFillageStrokes++;
|
||||
} else {
|
||||
lowFillageStrokes = 0;
|
||||
}
|
||||
|
||||
if (lowFillageStrokes > pumpOffStrokes) {
|
||||
pumpOff("lowpumpfill");
|
||||
if (lowFillageStrokes > pumpOffStrokesSetpoint) {
|
||||
pumpOff("lowpumpfill");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1181,20 +1320,44 @@ public class Well {
|
||||
pointCounter++;
|
||||
}
|
||||
|
||||
if (runStatus == RUNSTATUS_PUMPEDOFF){
|
||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpedOffTime);
|
||||
if(minutesSincePumpOff_last != minutesSincePumpOff){
|
||||
System.out.println("Restarting in " + (pumpOffDowntimeMinutes - minutesSincePumpOff) + " minutes.");
|
||||
minutesSincePumpOff_last = minutesSincePumpOff;
|
||||
if (runMode == RUNMODE_POC) {
|
||||
if (runStatus == RUNSTATUS_PUMPEDOFF) {
|
||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpedOffTime);
|
||||
if (minutesSincePumpOff_last != minutesSincePumpOff) {
|
||||
System.out.println("Restarting in " + (pumpOffDowntimeMinutesSetpoint - minutesSincePumpOff) + " minutes.");
|
||||
minutesSincePumpOff_last = minutesSincePumpOff;
|
||||
}
|
||||
if (minutesSincePumpOff > pumpOffDowntimeMinutesSetpoint) {
|
||||
restart("pumpoffdowntime");
|
||||
}
|
||||
}
|
||||
if (minutesSincePumpOff > pumpOffDowntimeMinutes){
|
||||
restart("pumpoffdowntime");
|
||||
}
|
||||
else if (runMode == RUNMODE_TIMER) {
|
||||
if(runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING) {
|
||||
minutesSinceTimerStart = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpStartTime);
|
||||
if (minutesSinceTimerStart_last != minutesSinceTimerStart) {
|
||||
System.out.println("Timer stopping in " + (timerRunMinutesSetpoint - minutesSinceTimerStart) + " minutes.");
|
||||
minutesSinceTimerStart_last = minutesSinceTimerStart;
|
||||
}
|
||||
if (minutesSinceTimerStart > timerRunMinutesSetpoint) {
|
||||
pumpOff("timer");
|
||||
}
|
||||
} else if(runStatus == RUNSTATUS_PUMPEDOFF) {
|
||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), timerStopTime);
|
||||
if (minutesSincePumpOff_last != minutesSincePumpOff) {
|
||||
System.out.println("Timer stopping in " + (timerOffMinutesSetpoint - minutesSinceTimerStop) + " minutes.");
|
||||
minutesSinceTimerStop_last = minutesSinceTimerStop;
|
||||
}
|
||||
if (minutesSinceTimerStop > timerOffMinutesSetpoint) {
|
||||
restart("timer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isNewDay()){
|
||||
gaugeOff();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void eval(int simPoint){
|
||||
@@ -1227,14 +1390,37 @@ public class Well {
|
||||
pointCounter++;
|
||||
}
|
||||
|
||||
if (runStatus == RUNSTATUS_PUMPEDOFF){
|
||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(pumpedOffTime, ZonedDateTime.now());
|
||||
if(minutesSincePumpOff_last != minutesSincePumpOff){
|
||||
System.out.println("Restarting in " + (pumpOffDowntimeMinutes - minutesSincePumpOff) + " minutes.");
|
||||
minutesSincePumpOff_last = minutesSincePumpOff;
|
||||
if (runMode == RUNMODE_POC) {
|
||||
if (runStatus == RUNSTATUS_PUMPEDOFF) {
|
||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpedOffTime);
|
||||
if (minutesSincePumpOff_last != minutesSincePumpOff) {
|
||||
System.out.println("Restarting in " + (pumpOffDowntimeMinutesSetpoint - minutesSincePumpOff) + " minutes.");
|
||||
minutesSincePumpOff_last = minutesSincePumpOff;
|
||||
}
|
||||
if (minutesSincePumpOff > pumpOffDowntimeMinutesSetpoint) {
|
||||
restart("pumpoffdowntime");
|
||||
}
|
||||
}
|
||||
if (minutesSincePumpOff > pumpOffDowntimeMinutes){
|
||||
restart("pumpoffdowntime");
|
||||
}
|
||||
else if (runMode == RUNMODE_TIMER) {
|
||||
if(runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING) {
|
||||
minutesSinceTimerStart = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpStartTime);
|
||||
if (minutesSinceTimerStart_last != minutesSinceTimerStart) {
|
||||
System.out.println("Timer stopping in " + (timerRunMinutesSetpoint - minutesSinceTimerStart) + " minutes.");
|
||||
minutesSinceTimerStart_last = minutesSinceTimerStart;
|
||||
}
|
||||
if (minutesSinceTimerStart > timerRunMinutesSetpoint) {
|
||||
pumpOff("timer");
|
||||
}
|
||||
} else if(runStatus == RUNSTATUS_PUMPEDOFF) {
|
||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), timerStopTime);
|
||||
if (minutesSincePumpOff_last != minutesSincePumpOff) {
|
||||
System.out.println("Timer stopping in " + (timerOffMinutesSetpoint - minutesSinceTimerStop) + " minutes.");
|
||||
minutesSinceTimerStop_last = minutesSinceTimerStop;
|
||||
}
|
||||
if (minutesSinceTimerStop > timerOffMinutesSetpoint) {
|
||||
restart("timer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ from pymongo import MongoClient
|
||||
from_zone = tz.tzutc()
|
||||
to_zone = tz.tzlocal()
|
||||
|
||||
|
||||
def format_datetime(inpDate, format='medium'):
|
||||
inpDate = inpDate.replace(tzinfo=from_zone)
|
||||
localDate = inpDate.astimezone(to_zone)
|
||||
@@ -186,7 +187,5 @@ def main(global_config, **settings):
|
||||
|
||||
config.add_route("json_users", "/json/users", factory='pocwww.security.UserLoginFactory')
|
||||
|
||||
|
||||
|
||||
config.scan()
|
||||
return config.make_wsgi_app()
|
||||
|
||||
Reference in New Issue
Block a user