Well measurements now can be stored in database
also added some more sample data
This commit is contained in:
@@ -11,6 +11,9 @@ import com.mongodb.client.MongoCollection;
|
||||
|
||||
import com.mongodb.client.model.Sorts;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.mongodb.client.MongoCursor;
|
||||
@@ -21,6 +24,7 @@ import com.mongodb.client.result.DeleteResult;
|
||||
import static com.mongodb.client.model.Updates.*;
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
public class Database {
|
||||
private String pocDatabase = "poc";
|
||||
@@ -76,4 +80,35 @@ public class Database {
|
||||
public void close(){
|
||||
mongoClient.close();
|
||||
}
|
||||
|
||||
public long newMeasurement(Measurement inpMeasurement){
|
||||
String df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
|
||||
MongoCollection<Document> collection = database.getCollection("wellData");
|
||||
Document doc = new Document("tagname", inpMeasurement.getTagName())
|
||||
.append("currentValue", inpMeasurement.getCurrentValue())
|
||||
.append("maxDailyValue", inpMeasurement.getDailyMax())
|
||||
.append("minDailyValue", inpMeasurement.getDailyMin())
|
||||
.append("dailyAverage", inpMeasurement.getAverage())
|
||||
.append("dailyTotal", inpMeasurement.getTotal())
|
||||
.append("timestamp", df);
|
||||
collection.insertOne(doc);
|
||||
return collection.count();
|
||||
|
||||
}
|
||||
|
||||
public long newDailyTotal(Measurement inpMeasurement){
|
||||
String df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
|
||||
MongoCollection<Document> collection = database.getCollection("gaugeOffData");
|
||||
Document doc = new Document("tagname", inpMeasurement.getTagName())
|
||||
.append("currentValue", inpMeasurement.getCurrentValue())
|
||||
.append("maxDailyValue", inpMeasurement.getDailyMax())
|
||||
.append("minDailyValue", inpMeasurement.getDailyMin())
|
||||
.append("dailyAverage", inpMeasurement.getAverage())
|
||||
.append("dailyTotal", inpMeasurement.getTotal())
|
||||
.append("timestamp", df);
|
||||
collection.insertOne(doc);
|
||||
return collection.count();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,54 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 2/3/17.
|
||||
*/
|
||||
public class Measurement {
|
||||
private String tagName;
|
||||
private double currentValue;
|
||||
private double lastValue;
|
||||
private double average;
|
||||
private double total;
|
||||
private double max;
|
||||
private double min;
|
||||
private double dailyMax;
|
||||
private double dailyMin;
|
||||
private double[] totalHistory = new double[30];
|
||||
private double[] averageHistory = new double[30];
|
||||
private long numMeasurements;
|
||||
private boolean storeInDatabase;
|
||||
private double lastSentValue;
|
||||
private double sendDelta;
|
||||
private Database db;
|
||||
private long lastSentTimestamp;
|
||||
private long sendTimeDelta;
|
||||
|
||||
Measurement(){
|
||||
Measurement(String tagName, boolean storeInDatabase, Database db, double sendDelta, long sendTimeDelta){
|
||||
this.tagName = tagName;
|
||||
average = 0;
|
||||
total = 0;
|
||||
numMeasurements = 0;
|
||||
max = Double.MIN_VALUE;
|
||||
min = Double.MAX_VALUE;
|
||||
dailyMax = Double.MIN_VALUE;
|
||||
dailyMin = Double.MAX_VALUE;
|
||||
|
||||
// Database code
|
||||
this.storeInDatabase = storeInDatabase;
|
||||
this.db = db;
|
||||
this.sendDelta = sendDelta;
|
||||
this.lastSentValue = 0.0;
|
||||
this.sendTimeDelta = sendTimeDelta;
|
||||
}
|
||||
|
||||
Measurement(String tagName, boolean storeInDatabase){
|
||||
this.tagName = tagName;
|
||||
average = 0;
|
||||
total = 0;
|
||||
numMeasurements = 0;
|
||||
dailyMax = Double.MIN_VALUE;
|
||||
dailyMin = Double.MAX_VALUE;
|
||||
|
||||
// Database code
|
||||
this.storeInDatabase = storeInDatabase;
|
||||
}
|
||||
|
||||
public double getCurrentValue() {
|
||||
@@ -42,8 +71,21 @@ public class Measurement {
|
||||
return numMeasurements;
|
||||
}
|
||||
|
||||
public String getTagName() {
|
||||
return tagName;
|
||||
}
|
||||
|
||||
public double getDailyMax() {
|
||||
return dailyMax;
|
||||
}
|
||||
|
||||
public double getDailyMin() {
|
||||
return dailyMin;
|
||||
}
|
||||
|
||||
public void update(double value)
|
||||
{
|
||||
long currentTimestamp = System.currentTimeMillis();
|
||||
lastValue = currentValue;
|
||||
currentValue = value;
|
||||
|
||||
@@ -51,11 +93,22 @@ public class Measurement {
|
||||
average = average * (((float)numMeasurements - 1)/(float)numMeasurements) + (currentValue / (float)numMeasurements);
|
||||
total = total + value;
|
||||
|
||||
max = Math.max(max, currentValue);
|
||||
min = Math.min(min, currentValue);
|
||||
};
|
||||
dailyMax = Math.max(dailyMax, currentValue);
|
||||
dailyMin = Math.min(dailyMin, currentValue);
|
||||
|
||||
if(storeInDatabase){
|
||||
if(abs(currentValue - lastSentValue) > sendDelta ||
|
||||
currentTimestamp - lastSentTimestamp > (sendTimeDelta * 1000)){
|
||||
db.newMeasurement(this);
|
||||
lastSentValue = currentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void endOfDay(){
|
||||
if (storeInDatabase){
|
||||
db.newDailyTotal(this);
|
||||
}
|
||||
for(int i = 28; i >= 0; i--){
|
||||
totalHistory[i] = totalHistory[i+1];
|
||||
averageHistory[i] = averageHistory[i+1];
|
||||
@@ -66,8 +119,8 @@ public class Measurement {
|
||||
|
||||
total = 0;
|
||||
average = 0;
|
||||
max = Double.MIN_VALUE;
|
||||
min = Double.MAX_VALUE;
|
||||
dailyMax = Double.MIN_VALUE;
|
||||
dailyMin = Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Well {
|
||||
protected Simulation sim;
|
||||
protected Database db;
|
||||
|
||||
// IO
|
||||
/* IO */
|
||||
AnalogIn inclinometer;
|
||||
AnalogIn loadCell;
|
||||
DigitalOut runCommand;
|
||||
@@ -36,7 +36,7 @@ public class Well {
|
||||
private double currentDownholePosition;
|
||||
private double currentDownholeLoad;
|
||||
|
||||
// CARDS
|
||||
/* CARDS */
|
||||
private Card currentCard;
|
||||
private Card[] cardStorage = new Card[100];
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Well {
|
||||
public static final int BAD_STATUS = 0;
|
||||
public static final int GOOD_STATUS = 1;
|
||||
|
||||
// USER INPUTS
|
||||
/* USER INPUTS */
|
||||
private double dt;
|
||||
private double tubingHeadPressure;
|
||||
private double fluidGradient;
|
||||
@@ -139,24 +139,24 @@ public class Well {
|
||||
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();
|
||||
private Measurement strokeSpeed = new Measurement("Stroke Speed", true, db, 0.5, 600);
|
||||
private Measurement downholeGrossStroke = new Measurement("Downhole Gross Stroke", true, db, 0.5, 600);
|
||||
private Measurement downholeNetStroke = new Measurement("Downhole Net Stroke", true, db, 0.5, 600);
|
||||
private Measurement fluidLevel = new Measurement("Fluid Level", true, db, 10, 600);
|
||||
private Measurement fluidLoad = new Measurement("Fluid Load", true, db, 20, 600);
|
||||
private Measurement inflowRate = new Measurement("Inflow Rate", true, db, 0.5, 600);
|
||||
private Measurement peakPolishedRodLoad = new Measurement("Peak PRL", true, db, 50, 600);
|
||||
private Measurement minPolishedRodLoad = new Measurement("Min PRL", true, db, 50, 600);
|
||||
private Measurement percentRun = new Measurement("Percent Run", true, db, 1.0, 600);
|
||||
private Measurement polishedRodHP = new Measurement("Polished Rod HP", true, db, 0.25, 600);
|
||||
private Measurement pumpHP = new Measurement("Pump HP", true, db, 0.25, 600);
|
||||
private Measurement fluidProduced = new Measurement("Fluid Produced", true, db, 1.0, 600);
|
||||
private Measurement oilProduced = new Measurement("Oil Produced", true, db, 1.0, 600);
|
||||
private Measurement waterProduced = new Measurement("Water Produced", true, db, 1.0, 600);
|
||||
private Measurement gasProduced = new Measurement("Gas Produced", true, db, 1.0, 600);
|
||||
private Measurement pumpIntakePressure = new Measurement("Pump Intake Pressure", true, db, 5.0, 600);
|
||||
private Measurement surfaceStrokeLength = new Measurement("Surface Stroke", true, db, 0.5, 1800);
|
||||
private Measurement tubingMovement = new Measurement("Tubing Movement", true, db, 0.5, 600);
|
||||
|
||||
Well(String wellName, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
|
||||
this.wellName = wellName;
|
||||
@@ -529,6 +529,13 @@ public class Well {
|
||||
inputTable.addRule();
|
||||
inputTable.addRow("Number of Tapers", getNumTapers());
|
||||
inputTable.addRule();
|
||||
inputTable.addRow("Buoyant Force Total", buoyantForceTotal);
|
||||
inputTable.addRow("Weight Data Total", weightDataTotal);
|
||||
inputTable.addRow("Annular Force Data Total", annularForceDataTotal);
|
||||
inputTable.addRow("Rod Depth Total", rodDepthTotal);
|
||||
inputTable.addRow("Rod Weight Air Total", rodWeightAirTotal);
|
||||
inputTable.addRow("Rod Weight Fluid Total", rodWeightFluidTotal);
|
||||
inputTable.addRule();
|
||||
V2_AsciiTableRenderer rend = new V2_AsciiTableRenderer();
|
||||
rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
|
||||
rend.setWidth(new WidthAbsoluteEven(50));
|
||||
@@ -547,6 +554,23 @@ public class Well {
|
||||
taperTable.addRow("Rod Material", getRodMaterial(i));
|
||||
taperTable.addRow("Rod Young's Modulus", getRodYM(i));
|
||||
taperTable.addRule();
|
||||
taperTable.addRow("a", a[i]);
|
||||
taperTable.addRow("Area", area[i]);
|
||||
taperTable.addRow("Pressure", pressure[i]);
|
||||
taperTable.addRow("Buoyant Force", buoyantForce[i]);
|
||||
taperTable.addRow("Stretch", stretch[i]);
|
||||
taperTable.addRow("WeightData", weightData[i]);
|
||||
taperTable.addRow("Annular Force Data", annularForceData[i]);
|
||||
taperTable.addRow("force", force[i]);
|
||||
taperTable.addRow("Alpha", alpha[i]);
|
||||
taperTable.addRow("xOverA", xOverA[i]);
|
||||
taperTable.addRow("Factor", factor[i]);
|
||||
taperTable.addRow("Lag Index", lagIndex[i]);
|
||||
taperTable.addRow("Length Required", lengthRequired[i]);
|
||||
taperTable.addRow("Center Point", centerPoint[i]);
|
||||
taperTable.addRow("Rod Depth", rodDepth[i]);
|
||||
taperTable.addRow("Rod Weight in Air", rodWeightAir[i]);
|
||||
taperTable.addRow("Rod Weight in Fluid", rodWeightFluid[i]);
|
||||
rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
|
||||
rend.setWidth(new WidthAbsoluteEven(50));
|
||||
rt = rend.render(taperTable);
|
||||
@@ -554,7 +578,6 @@ public class Well {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
public void updateTapers(){
|
||||
@@ -851,7 +874,7 @@ public class Well {
|
||||
cardStorage[j + 1] = cardStorage[j];
|
||||
}
|
||||
cardStorage[0] = currentCard;
|
||||
currentCard.printCard("none", true);
|
||||
currentCard.printCard("csv", true);
|
||||
strokesSinceStart++;
|
||||
strokesToday++;
|
||||
strokesLifetime++;
|
||||
|
||||
Reference in New Issue
Block a user