diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 60dbcb4..89bd01e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,29 +2,18 @@ - - - - - - - - - - + + + + + - - - - - + - - @@ -45,8 +34,8 @@ - - + + @@ -83,8 +72,18 @@ - - + + + + + + + + + + + + @@ -93,8 +92,25 @@ - - + + + + + + + + + + + + + + + + + + + @@ -143,11 +159,12 @@ @@ -160,9 +177,9 @@ - @@ -262,9 +279,9 @@ - + @@ -521,7 +538,7 @@ - + @@ -599,13 +616,13 @@ - - - - - - - + + + + + + + @@ -615,7 +632,7 @@ - + @@ -783,7 +800,7 @@ - + @@ -793,7 +810,7 @@ - + @@ -836,22 +853,6 @@ - - - - - - - - - - - - - - - - @@ -860,10 +861,20 @@ + + + + + + + + + + - - + + @@ -896,29 +907,42 @@ - + - - - - - + + + - + - - + + + + + + + + + + - - - + + + + + + + + + + diff --git a/card_72553_surface.csv b/card_72553_surface.csv new file mode 100644 index 0000000..e7fa55d --- /dev/null +++ b/card_72553_surface.csv @@ -0,0 +1,93 @@ +59.63,8931.32 +58.61,8961.83 +56.97,9005.15 +55.54,9054.01 +54,9036.51 +52.16,8997.6 +50.41,8943.79 +48.92,8883.01 +47.12,8847.43 +44.93,8855.57 +42.33,8884.24 +40.1,8922.82 +37.55,8979.9 +35.41,8993.98 +33.2,8965.07 +30.77,8940.1 +28.78,8858.56 +26.49,8747.87 +23.8,8631.45 +21.31,8507.47 +18.37,8347.07 +15.84,8045.48 +13.34,7587.85 +11.65,7209.09 +9.58,6940.47 +7.92,6768.48 +6.8,6571.79 +5.44,6328.91 +4.63,6211.27 +3.71,6271.58 +2.84,6358.21 +2.13,6440.61 +2.16,6641.52 +2.08,6792.9 +2.52,6848.87 +2.77,6874.81 +3.23,6884.44 +3.8,6940.09 +4.28,7079.42 +5.25,7216.62 +6.06,7363.91 +7.07,7479.73 +8.2,7678.34 +9.65,7875.29 +11.46,8155.62 +12.57,8381.63 +14.23,8566.37 +15.64,8782.56 +17.17,9049.55 +18.72,9330.57 +20.27,9589.98 +21.61,9828.33 +23.12,9972.63 +24.8,9998.86 +26.45,9901.37 +28.02,9820.17 +29.16,9726.98 +30.77,9527.96 +32.57,9504.61 +34.59,9592.22 +36.45,9693.48 +38.28,9798.35 +39.95,9861.31 +41.56,9870.49 +43.77,9825.13 +45.12,9717.1 +46.95,9601.26 +48.91,9504.41 +50.68,9441.93 +52.1,9488.93 +53.06,9571.91 +54.78,9613.14 +55.98,9628.48 +57.32,9634.16 +58.53,9600.68 +59.5,9508.89 +60.58,9434.98 +61.08,9402.21 +61.96,9385.84 +63.05,9358.72 +63.06,9380.73 +63.47,9405.76 +63.66,9408.4 +63.75,9395.02 +63.74,9384.16 +63.67,9315.63 +63.45,9221.35 +63.15,9139.15 +62.65,9066.4 +62.06,8989.17 +61.48,8917.91 +61.33,8929.18 +59.63,8931.32 \ No newline at end of file diff --git a/card_72599_surface.csv b/card_72599_surface.csv new file mode 100644 index 0000000..210473e --- /dev/null +++ b/card_72599_surface.csv @@ -0,0 +1,91 @@ +2.27,6647.01 +2.47,6781.62 +2.57,6877.5 +3.29,6927.34 +4.13,7012.26 +5.24,7136.89 +6.38,7301.06 +7.62,7453.24 +8.85,7511.86 +10.52,7801.23 +12.09,8135.34 +13.71,8472.58 +15.38,8775.46 +17.08,9040.17 +18.7,9281.46 +20.62,9554.6 +21.79,9837.75 +23.33,10026.14 +24.88,10065.05 +26.59,10027.72 +28.45,10010.12 +30.47,9817.81 +32.15,9569.99 +34.22,9504.56 +36.15,9563.69 +37.68,9665.51 +39.27,9787.29 +41.26,9898.32 +43.19,9925.73 +45.45,9851.39 +47.18,9737.22 +48.91,9617.55 +50.65,9492.06 +51.76,9449.17 +53.91,9492.22 +55.09,9531.77 +56.62,9556.49 +57.61,9605.07 +58.73,9623.09 +59.53,9578.76 +61.03,9546.23 +61.56,9479.4 +62.23,9413.47 +62.62,9360.98 +63.22,9369.86 +63.6,9393.46 +63.66,9374.46 +63.81,9353.2 +63.94,9333.27 +64.05,9253.82 +63.36,9171.68 +62.79,9092.98 +62.3,9003.93 +61.11,8917.62 +60.59,8885.99 +59.54,8884.73 +58.04,8884.89 +59.63,8891.33 +57.03,8770.51 +55.46,8385.32 +53.82,7939.27 +51.89,7697.84 +49.97,7532.28 +47.8,7306.41 +46.86,7094.1 +43.25,6486.33 +42.18,6032.48 +40.39,5741.57 +38.34,5567.73 +36.19,5658.75 +34.07,5947.52 +31.87,6190.38 +29.77,6339.08 +27.34,6452.03 +25.24,6425.81 +23.17,6199.45 +20.99,6006.58 +19.01,5923.79 +17.26,5871.74 +14.69,5897.66 +13.47,6031.26 +11.43,6267.97 +9.58,6412.46 +7.77,6529.07 +6.48,6604.53 +5.27,6518.29 +4.24,6417.91 +3.22,6372.81 +3.03,6350.93 +2.52,6362.76 +2.5,6481.35 \ No newline at end of file diff --git a/src/main/java/com/henrypump/poc/Database.java b/src/main/java/com/henrypump/poc/Database.java index 2b7d840..8a0a91b 100644 --- a/src/main/java/com/henrypump/poc/Database.java +++ b/src/main/java/com/henrypump/poc/Database.java @@ -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 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 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(); + + } + } diff --git a/src/main/java/com/henrypump/poc/Measurement.java b/src/main/java/com/henrypump/poc/Measurement.java index 09060b6..38d7c8d 100644 --- a/src/main/java/com/henrypump/poc/Measurement.java +++ b/src/main/java/com/henrypump/poc/Measurement.java @@ -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; } diff --git a/src/main/java/com/henrypump/poc/Well.java b/src/main/java/com/henrypump/poc/Well.java index 14e5779..020a9b4 100644 --- a/src/main/java/com/henrypump/poc/Well.java +++ b/src/main/java/com/henrypump/poc/Well.java @@ -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++; diff --git a/target/classes/com/henrypump/poc/AnalogIn.class b/target/classes/com/henrypump/poc/AnalogIn.class deleted file mode 100644 index 2cd9263..0000000 Binary files a/target/classes/com/henrypump/poc/AnalogIn.class and /dev/null differ diff --git a/target/classes/com/henrypump/poc/App.class b/target/classes/com/henrypump/poc/App.class deleted file mode 100644 index 047ccd3..0000000 Binary files a/target/classes/com/henrypump/poc/App.class and /dev/null differ diff --git a/target/classes/com/henrypump/poc/Database.class b/target/classes/com/henrypump/poc/Database.class index 37bc482..08b1e70 100644 Binary files a/target/classes/com/henrypump/poc/Database.class and b/target/classes/com/henrypump/poc/Database.class differ diff --git a/target/classes/com/henrypump/poc/DigitalIn.class b/target/classes/com/henrypump/poc/DigitalIn.class deleted file mode 100644 index 4eb85bf..0000000 Binary files a/target/classes/com/henrypump/poc/DigitalIn.class and /dev/null differ diff --git a/target/classes/com/henrypump/poc/DigitalOut.class b/target/classes/com/henrypump/poc/DigitalOut.class deleted file mode 100644 index d4325e0..0000000 Binary files a/target/classes/com/henrypump/poc/DigitalOut.class and /dev/null differ diff --git a/target/classes/com/henrypump/poc/LPStatus.class b/target/classes/com/henrypump/poc/LPStatus.class deleted file mode 100644 index df6e919..0000000 Binary files a/target/classes/com/henrypump/poc/LPStatus.class and /dev/null differ diff --git a/target/classes/com/henrypump/poc/Measurement.class b/target/classes/com/henrypump/poc/Measurement.class index 798f1cb..c2bf919 100644 Binary files a/target/classes/com/henrypump/poc/Measurement.class and b/target/classes/com/henrypump/poc/Measurement.class differ diff --git a/target/classes/com/henrypump/poc/POC.class b/target/classes/com/henrypump/poc/POC.class deleted file mode 100644 index 33d1c43..0000000 Binary files a/target/classes/com/henrypump/poc/POC.class and /dev/null differ diff --git a/target/classes/com/henrypump/poc/Simulation.class b/target/classes/com/henrypump/poc/Simulation.class deleted file mode 100644 index 3bfb2c2..0000000 Binary files a/target/classes/com/henrypump/poc/Simulation.class and /dev/null differ diff --git a/target/classes/com/henrypump/poc/Well.class b/target/classes/com/henrypump/poc/Well.class deleted file mode 100644 index 8b517ff..0000000 Binary files a/target/classes/com/henrypump/poc/Well.class and /dev/null differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index 971c92a..7acbdb1 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Fri Feb 03 16:32:08 CST 2017 +#Mon Feb 06 13:36:59 CST 2017 version=1.0-SNAPSHOT groupId=com.henrypump.poc artifactId=poc-java diff --git a/target/original-poc-java-1.0-SNAPSHOT.jar b/target/original-poc-java-1.0-SNAPSHOT.jar index 3dc754b..0818c8a 100644 Binary files a/target/original-poc-java-1.0-SNAPSHOT.jar and b/target/original-poc-java-1.0-SNAPSHOT.jar differ diff --git a/target/poc-java-1.0-SNAPSHOT.jar b/target/poc-java-1.0-SNAPSHOT.jar index 3dc754b..5f90a98 100644 Binary files a/target/poc-java-1.0-SNAPSHOT.jar and b/target/poc-java-1.0-SNAPSHOT.jar differ diff --git a/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml b/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml index f97f1b7..fbeefa1 100644 --- a/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml +++ b/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml @@ -1,5 +1,5 @@ - + @@ -62,5 +62,5 @@ - + \ No newline at end of file diff --git a/target/surefire-reports/com.henrypump.poc.AppTest.txt b/target/surefire-reports/com.henrypump.poc.AppTest.txt index 889eba0..663ba20 100644 --- a/target/surefire-reports/com.henrypump.poc.AppTest.txt +++ b/target/surefire-reports/com.henrypump.poc.AppTest.txt @@ -1,4 +1,4 @@ ------------------------------------------------------------------------------- Test set: com.henrypump.poc.AppTest ------------------------------------------------------------------------------- -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec diff --git a/viceroyWell.json b/viceroyWell.json new file mode 100644 index 0000000..1fba860 --- /dev/null +++ b/viceroyWell.json @@ -0,0 +1,19 @@ +{ + "deltaT": 0.1, + "pumpDiameter": 1.5, + "fluidGradient": 0.45, + "tubingID": 1.995, + "tubingOD": 2.375, + "tubingAnchorDepth": 0.0, + "structuralRating": 320000.0, + "stuffingBoxFriction": 100.0, + "tubingHeadPressure": 40.0, + "tapers": [ + { + "length": 4180.0, + "diameter": 0.75, + "material": "steel", + "dampingFactor": 0.8 + } + ] +}