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
|
# 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>`
|
## Endpoint `/command?cmd=<command>&user=<username>`
|
||||||
|
- Attempts to give the command to the unit.
|
||||||
|
- Allowed values:
|
||||||
|
- start
|
||||||
|
- stop
|
||||||
|
- returns `{"status": <string: runStatus>}`
|
||||||
|
|
||||||
### `start`
|
## Endpoint `/update?wellconfig`
|
||||||
- returns `{"startCommand: <result>", "status": <runStatus>}`
|
- Updates the well configuration with values stored in
|
||||||
|
1. wellConfig.json
|
||||||
|
2. MongoDB database (configured via website)
|
||||||
|
- returns `{"configUpdated": <bool: updatestatus>}`
|
||||||
|
|
||||||
### `stop`
|
## Endpoint `/update?setpoint=<variable name>`
|
||||||
- returns `{"stopCommand: <result>", "status": <runStatus>}`
|
- 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.AggregateIterable;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
import com.mongodb.client.MongoCollection;
|
import com.mongodb.client.MongoCollection;
|
||||||
import com.mongodb.client.model.Accumulators;
|
import com.mongodb.client.model.*;
|
||||||
import com.mongodb.client.model.Aggregates;
|
|
||||||
|
|
||||||
import com.mongodb.client.model.Indexes;
|
import org.bson.BSON;
|
||||||
import com.mongodb.client.model.Sorts;
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -60,6 +58,7 @@ public class Database {
|
|||||||
wellConfigCollection.createIndex(Indexes.ascending("timestamp"));
|
wellConfigCollection.createIndex(Indexes.ascending("timestamp"));
|
||||||
|
|
||||||
setpointCollection = database.getCollection("setpoints");
|
setpointCollection = database.getCollection("setpoints");
|
||||||
|
setpointCollection.createIndex(Indexes.ascending("name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -306,5 +305,28 @@ public class Database {
|
|||||||
return lastConfig;
|
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();
|
new Thread(new IOControl(this)).start();
|
||||||
}
|
}
|
||||||
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
||||||
thisWell.setupFluidRatio(0.50, 0.50, 1.12);
|
|
||||||
thisWell.checkSafeties();
|
thisWell.checkSafeties();
|
||||||
while (true) {
|
while (true) {
|
||||||
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ public class WebServer{
|
|||||||
this.port = port;
|
this.port = port;
|
||||||
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
|
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||||
server.createContext("/command", new CommandHandler());
|
server.createContext("/command", new CommandHandler());
|
||||||
server.createContext("/config", new ConfigHandler());
|
server.createContext("/update", new UpdateHandler());
|
||||||
server.createContext("/shake", new HandshakeHandler());
|
server.createContext("/shake", new HandshakeHandler());
|
||||||
|
server.createContext("/mode", new ModeHandler());
|
||||||
server.setExecutor(null); // creates a default executor
|
server.setExecutor(null); // creates a default executor
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
@@ -95,89 +96,73 @@ public class WebServer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigHandler implements HttpHandler {
|
class UpdateHandler implements HttpHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpExchange t) throws IOException {
|
public void handle(HttpExchange t) throws IOException {
|
||||||
JSONObject respJSON = new JSONObject();
|
JSONObject respJSON = new JSONObject();
|
||||||
Map<String, String> params = queryToMap(t.getRequestURI().getQuery());
|
Map<String, String> params = queryToMap(t.getRequestURI().getQuery());
|
||||||
|
|
||||||
for(Map.Entry<String, String> param_map : params.entrySet()){
|
for(Map.Entry<String, String> param_map : params.entrySet()){
|
||||||
String key = param_map.getKey();
|
String key = param_map.getKey();
|
||||||
String param = param_map.getValue();
|
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){
|
switch (param) {
|
||||||
case "update":
|
case "fluidOilRatio":
|
||||||
if(param.equals("true")) {
|
attachedPOC.thisWell.setFluidOilRatio(newSP);
|
||||||
attachedPOC.thisWell.getWellSetup();
|
respJSON.put(param, attachedPOC.thisWell.getFluidOilRatio());
|
||||||
respJSON.put("configUpdated", "true");
|
break;
|
||||||
} else {
|
|
||||||
respJSON.put("configUpdated", "invalid value - " + param);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "fluidOilRatio":
|
case "fluidWaterRatio":
|
||||||
try {
|
attachedPOC.thisWell.setFluidWaterRatio(newSP);
|
||||||
double newSetpoint = Double.parseDouble(param);
|
respJSON.put(param, attachedPOC.thisWell.getFluidWaterRatio());
|
||||||
attachedPOC.thisWell.setFluidOilRatio(newSetpoint);
|
break;
|
||||||
respJSON.put("fluidOilRatio", attachedPOC.thisWell.getFluidOilRatio());
|
|
||||||
} catch (NullPointerException | NumberFormatException e) {
|
|
||||||
respJSON.put("fluidOilRatio", "invalid value - " + param);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "fluidWaterRatio":
|
case "fluidGasRatio":
|
||||||
try {
|
attachedPOC.thisWell.setFluidGasRatio(newSP);
|
||||||
double newSetpoint = Double.parseDouble(param);
|
respJSON.put(param, attachedPOC.thisWell.getFluidGasRatio());
|
||||||
attachedPOC.thisWell.setFluidWaterRatio(newSetpoint);
|
break;
|
||||||
respJSON.put("fluidWaterRatio", attachedPOC.thisWell.getFluidWaterRatio());
|
|
||||||
} catch (NullPointerException | NumberFormatException e) {
|
|
||||||
respJSON.put("fluidWaterRatio", "invalid value - " + param);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "fluidGasMCFRatio":
|
case "pumpOffFillPercentSetpoint":
|
||||||
try {
|
attachedPOC.thisWell.setPumpOffFillPercentSetpoint(newSP);
|
||||||
double newSetpoint = Double.parseDouble(param);
|
respJSON.put(param, attachedPOC.thisWell.getPumpOffFillPercentSetpoint());
|
||||||
attachedPOC.thisWell.setFluidGasRatio(newSetpoint);
|
break;
|
||||||
respJSON.put("fluidGasMCFRatio", attachedPOC.thisWell.getFluidGasRatio());
|
|
||||||
} catch (NullPointerException | NumberFormatException e) {
|
|
||||||
respJSON.put("fluidGasMCFRatio", "invalid value - " + param);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "pumpOffSetpoint":
|
case "pumpOffStrokesSetpoint":
|
||||||
try {
|
attachedPOC.thisWell.setPumpOffStrokesSetpoint((int) newSP);
|
||||||
double newSetpoint = Double.parseDouble(param);
|
respJSON.put(param, attachedPOC.thisWell.getPumpOffStrokesSetpoint());
|
||||||
attachedPOC.thisWell.setPumpOffFillPercentSetpoint(newSetpoint);
|
break;
|
||||||
respJSON.put("pumpOffSetpoint", attachedPOC.thisWell.getPumpOffFillPercentSetpoint());
|
|
||||||
} catch (NullPointerException | NumberFormatException e) {
|
|
||||||
respJSON.put("pumpOffSetpoint", "invalid value - " + param);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "pumpOffStrokes":
|
case "pumpOffDowntimeMinutesSetpoint":
|
||||||
try {
|
attachedPOC.thisWell.setPumpOffDowntimeMinutesSetpoint((long) newSP);
|
||||||
int newSetpoint = Integer.parseInt(param);
|
respJSON.put(param, attachedPOC.thisWell.getPumpOffDowntimeMinutesSetpoint());
|
||||||
attachedPOC.thisWell.setPumpOffStrokes(newSetpoint);
|
break;
|
||||||
respJSON.put("pumpOffStrokes", attachedPOC.thisWell.getPumpOffStrokes());
|
|
||||||
} catch (NullPointerException | NumberFormatException e) {
|
|
||||||
respJSON.put("pumpOffStrokes", "invalid value - " + param);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "pumpOffDowntime":
|
case "timerOffMinutesSetpoint":
|
||||||
try {
|
attachedPOC.thisWell.setTimerOffMinutesSetpoint((long) newSP);
|
||||||
long newSetpoint = Long.parseLong(param);
|
respJSON.put(param, attachedPOC.thisWell.getTimerOffMinutesSetpoint());
|
||||||
attachedPOC.thisWell.setPumpOffDowntimeMinutes(newSetpoint);
|
break;
|
||||||
respJSON.put("pumpOffDowntime", attachedPOC.thisWell.getPumpOffDowntimeMinutes());
|
|
||||||
} catch (NullPointerException | NumberFormatException e) {
|
|
||||||
respJSON.put("pumpOffDowntime", "invalid value - " + param);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
case "timerRunMinutesSetpoint":
|
||||||
respJSON.put(key, "not implemented");
|
attachedPOC.thisWell.setTimerRunMinutesSetpoint((long) newSP);
|
||||||
break;
|
respJSON.put(param, attachedPOC.thisWell.getTimerRunMinutesSetpoint());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
respJSON.put(param, "not implemented");
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -201,7 +186,54 @@ public class WebServer{
|
|||||||
os.close();
|
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.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
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.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -22,6 +20,8 @@ import java.time.ZonedDateTime;
|
|||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static java.lang.Math.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by patrickjmcd on 1/31/17.
|
* Created by patrickjmcd on 1/31/17.
|
||||||
*/
|
*/
|
||||||
@@ -174,15 +174,33 @@ public class Well {
|
|||||||
private Measurement tubingMovement;
|
private Measurement tubingMovement;
|
||||||
private Measurement pumpFillPercent;
|
private Measurement pumpFillPercent;
|
||||||
|
|
||||||
// Running Setpoints
|
private ZonedDateTime pumpStartTime;
|
||||||
private double pumpOffFillPercentSetpoint = 65;
|
|
||||||
private int pumpOffStrokes = 5;
|
// POC Mode Setpoints
|
||||||
|
private double pumpOffFillPercentSetpoint;
|
||||||
|
private int pumpOffStrokesSetpoint;
|
||||||
|
private long pumpOffDowntimeMinutesSetpoint;
|
||||||
|
|
||||||
|
// POC Mode Status
|
||||||
private int lowFillageStrokes = 0;
|
private int lowFillageStrokes = 0;
|
||||||
private ZonedDateTime pumpedOffTime;
|
private ZonedDateTime pumpedOffTime;
|
||||||
private long pumpOffDowntimeMinutes = 5;
|
|
||||||
private long minutesSincePumpOff = 0;
|
private long minutesSincePumpOff = 0;
|
||||||
private long minutesSincePumpOff_last = 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){
|
Well(String dbHostname, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
|
||||||
this.wellName = wellName;
|
this.wellName = wellName;
|
||||||
db = new Database(dbHostname);
|
db = new Database(dbHostname);
|
||||||
@@ -192,6 +210,7 @@ public class Well {
|
|||||||
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
||||||
|
|
||||||
initializeMeasurements();
|
initializeMeasurements();
|
||||||
|
initializeSetpoints();
|
||||||
db.newRunStatus("Boot", "io");
|
db.newRunStatus("Boot", "io");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,9 +224,89 @@ public class Well {
|
|||||||
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
||||||
|
|
||||||
initializeMeasurements();
|
initializeMeasurements();
|
||||||
|
initializeSetpoints();
|
||||||
db.newRunStatus("Boot", "commandline");
|
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(){
|
private void initializeMeasurements(){
|
||||||
strokeSpeed = new Measurement("Stroke Speed", db, 0.5, 600);
|
strokeSpeed = new Measurement("Stroke Speed", db, 0.5, 600);
|
||||||
downholeGrossStroke = new Measurement("Downhole Gross Stroke", 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() {
|
public double getCurrentSurfacePosition() {
|
||||||
return currentSurfacePosition;
|
return currentSurfacePosition;
|
||||||
}
|
}
|
||||||
@@ -514,20 +629,20 @@ public class Well {
|
|||||||
this.pumpOffFillPercentSetpoint = pumpOffFillPercentSetpoint;
|
this.pumpOffFillPercentSetpoint = pumpOffFillPercentSetpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPumpOffStrokes() {
|
public int getPumpOffStrokesSetpoint() {
|
||||||
return pumpOffStrokes;
|
return pumpOffStrokesSetpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPumpOffStrokes(int pumpOffStrokes) {
|
public void setPumpOffStrokesSetpoint(int pumpOffStrokesSetpoint) {
|
||||||
this.pumpOffStrokes = pumpOffStrokes;
|
this.pumpOffStrokesSetpoint = pumpOffStrokesSetpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getPumpOffDowntimeMinutes() {
|
public long getPumpOffDowntimeMinutesSetpoint() {
|
||||||
return pumpOffDowntimeMinutes;
|
return pumpOffDowntimeMinutesSetpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPumpOffDowntimeMinutes(long pumpOffDowntimeMinutes) {
|
public void setPumpOffDowntimeMinutesSetpoint(long pumpOffDowntimeMinutesSetpoint) {
|
||||||
this.pumpOffDowntimeMinutes = pumpOffDowntimeMinutes;
|
this.pumpOffDowntimeMinutesSetpoint = pumpOffDowntimeMinutesSetpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setupFluidRatio(double oilRatio, double waterRatio, double gasRatio){
|
public void setupFluidRatio(double oilRatio, double waterRatio, double gasRatio){
|
||||||
@@ -536,12 +651,29 @@ public class Well {
|
|||||||
fluidGasRatio = gasRatio;
|
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
|
// WELL COMMAND FUNCTIONS
|
||||||
public void start(String initiator){
|
public void start(String initiator){
|
||||||
if (runStatus == RUNSTATUS_STOPPED && permissiveOK){
|
if (runStatus == RUNSTATUS_STOPPED && permissiveOK){
|
||||||
System.out.println("Starting " + wellName + " from " + initiator + "...");
|
System.out.println("Starting " + wellName + " from " + initiator + "...");
|
||||||
runStatus = RUNSTATUS_STARTING;
|
runStatus = RUNSTATUS_STARTING;
|
||||||
strokesSinceStart = 0;
|
strokesSinceStart = 0;
|
||||||
|
pumpStartTime = ZonedDateTime.now();
|
||||||
db.newRunStatus(getRunStatusString(), initiator);
|
db.newRunStatus(getRunStatusString(), initiator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -566,8 +698,13 @@ public class Well {
|
|||||||
public void pumpOff(String initiator){
|
public void pumpOff(String initiator){
|
||||||
if (runStatus == RUNSTATUS_RUNNING){
|
if (runStatus == RUNSTATUS_RUNNING){
|
||||||
System.out.println("Pumping off from " + initiator + "...");
|
System.out.println("Pumping off from " + initiator + "...");
|
||||||
System.out.println("Restarting in " + pumpOffDowntimeMinutes + " minutes.");
|
if (runMode == RUNMODE_POC) {
|
||||||
pumpedOffTime = ZonedDateTime.now();
|
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;
|
runStatus = RUNSTATUS_PUMPEDOFF;
|
||||||
db.newRunStatus(getRunStatusString(), initiator);
|
db.newRunStatus(getRunStatusString(), initiator);
|
||||||
}
|
}
|
||||||
@@ -1115,14 +1252,16 @@ public class Well {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (runStatus == RUNSTATUS_RUNNING) {
|
if (runStatus == RUNSTATUS_RUNNING) {
|
||||||
if (pumpFillPercent.getCurrentValue() < pumpOffFillPercentSetpoint) {
|
if (runMode == RUNMODE_POC){
|
||||||
lowFillageStrokes++;
|
if (pumpFillPercent.getCurrentValue() < pumpOffFillPercentSetpoint) {
|
||||||
} else {
|
lowFillageStrokes++;
|
||||||
lowFillageStrokes = 0;
|
} else {
|
||||||
}
|
lowFillageStrokes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (lowFillageStrokes > pumpOffStrokes) {
|
if (lowFillageStrokes > pumpOffStrokesSetpoint) {
|
||||||
pumpOff("lowpumpfill");
|
pumpOff("lowpumpfill");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1181,20 +1320,44 @@ public class Well {
|
|||||||
pointCounter++;
|
pointCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runStatus == RUNSTATUS_PUMPEDOFF){
|
if (runMode == RUNMODE_POC) {
|
||||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpedOffTime);
|
if (runStatus == RUNSTATUS_PUMPEDOFF) {
|
||||||
if(minutesSincePumpOff_last != minutesSincePumpOff){
|
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpedOffTime);
|
||||||
System.out.println("Restarting in " + (pumpOffDowntimeMinutes - minutesSincePumpOff) + " minutes.");
|
if (minutesSincePumpOff_last != minutesSincePumpOff) {
|
||||||
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()){
|
if(isNewDay()){
|
||||||
gaugeOff();
|
gaugeOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eval(int simPoint){
|
public void eval(int simPoint){
|
||||||
@@ -1227,14 +1390,37 @@ public class Well {
|
|||||||
pointCounter++;
|
pointCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runStatus == RUNSTATUS_PUMPEDOFF){
|
if (runMode == RUNMODE_POC) {
|
||||||
minutesSincePumpOff = ChronoUnit.MINUTES.between(pumpedOffTime, ZonedDateTime.now());
|
if (runStatus == RUNSTATUS_PUMPEDOFF) {
|
||||||
if(minutesSincePumpOff_last != minutesSincePumpOff){
|
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpedOffTime);
|
||||||
System.out.println("Restarting in " + (pumpOffDowntimeMinutes - minutesSincePumpOff) + " minutes.");
|
if (minutesSincePumpOff_last != minutesSincePumpOff) {
|
||||||
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()
|
from_zone = tz.tzutc()
|
||||||
to_zone = tz.tzlocal()
|
to_zone = tz.tzlocal()
|
||||||
|
|
||||||
|
|
||||||
def format_datetime(inpDate, format='medium'):
|
def format_datetime(inpDate, format='medium'):
|
||||||
inpDate = inpDate.replace(tzinfo=from_zone)
|
inpDate = inpDate.replace(tzinfo=from_zone)
|
||||||
localDate = inpDate.astimezone(to_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.add_route("json_users", "/json/users", factory='pocwww.security.UserLoginFactory')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
config.scan()
|
config.scan()
|
||||||
return config.make_wsgi_app()
|
return config.make_wsgi_app()
|
||||||
|
|||||||
Reference in New Issue
Block a user