diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e26b4a2..5d76b79 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,10 @@ - - - - + + + + @@ -128,50 +128,52 @@ - - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -296,7 +298,7 @@ - + @@ -748,9 +750,9 @@ @@ -765,8 +767,9 @@ + @@ -1116,7 +1119,7 @@ - + @@ -1133,7 +1136,7 @@ - + @@ -1357,6 +1360,12 @@ + + + + + + @@ -1599,16 +1608,6 @@ - - - - - - - - - - @@ -1850,14 +1849,6 @@ - - - - - - - - @@ -1874,26 +1865,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -1910,12 +1881,58 @@ + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 22dee7d..7fe4890 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,45 @@ Enable the systemd script with: ``` systemctl enable mongod.service ``` + +# Local Web API + +## Endpoint `/config?` + +### `update=` +- if doUpdate = `true`, the well configuration will be updated. +- returns `{"configUpdated: "}` + +### `fluidOilRatio=` +- sets the fluidOilRatio (BBL oil to every 1 BBL fluid producted) to `newRatio` +- returns `{"fluidOilRatio": }` + +### `fluidWaterRatio=` +- sets the fluidWaterRatio (BBL water to every 1 BBL fluid producted) to `newRatio` +- returns `{"fluidWaterRatio": }` + +### `fluidGasMCFRatio=` +- sets the fluidGasMCFRatio (MCF gas to every 1 BBL fluid producted) to `newRatio` +- returns `{"fluidGasMCFRatio": }` + +### `pumpOffSetpoint=` +- sets the pump-off fill percent setpoint to `newSetpoint` +- returns `{"pumpOffSetpoint": }` + +### `pumpOffStrokes=` +- sets the number of low-fillage strokes required for pump-off to `newSetpoint` +- returns `{"pumpOffStrokes": }` + +### `pumpOffDowntime=` +- sets the minutes of downtime after pumpoff to `newSetpoint` +- returns `{"pumpOffDowntime": }` + +## Endpoint `/command?` + +### `start=` +- if startCommand = `true`, the well will attempt to start. +- returns `{"startCommand: ", "status": }` + +### `stop=` +- if stopCommand = `true`, the well will attempt to stop. +- returns `{"stopCommand: ", "status": }` diff --git a/mallet.csv b/mallet.csv new file mode 100644 index 0000000..eacde97 --- /dev/null +++ b/mallet.csv @@ -0,0 +1,673 @@ +0,8484.74 +0.066215,8615.27 +0.171112,8951.1 +0.316819,9280.12 +0.498586,9613.75 +0.715024,10084.6 +0.97621,10624.4 +1.2883,10886 +1.63867,10787.3 +2.02093,10515.7 +2.43243,10317 +2.87705,10188.2 +3.36461,10107.5 +3.8875,10058.3 +4.44299,10128.3 +5.03967,10279.2 +5.67946,10368 +6.35611,10397.3 +7.05754,10422.5 +7.7809,10496.4 +8.53069,10721.6 +9.32235,11145.6 +10.1506,11569.2 +11.013,12015.8 +11.9097,12514.9 +12.842,12892 +13.8065,12964.3 +14.7986,12892.5 +15.8226,12869.7 +16.8842,12904.7 +17.9785,12974.2 +19.1005,13055.2 +20.2442,13145.5 +21.4129,13406.1 +22.6127,13789.8 +23.8375,13974.4 +25.0839,14102 +26.3506,14397.5 +27.6347,14832.5 +28.936,15269.6 +30.2719,15730.9 +31.6607,16128.3 +33.0885,16138.4 +34.5314,15870.9 +35.9861,15687 +37.4602,15666 +38.9614,15642.7 +40.4966,15570.9 +42.0607,15503.3 +43.6394,15452.3 +45.2335,15386.8 +46.8483,15105.5 +48.4878,14678 +50.152,14434.2 +51.8308,14364.4 +53.5259,14356.1 +55.2375,14236.2 +56.9713,14093.1 +58.7226,13891.4 +60.4832,13598.9 +62.2413,13513.1 +64.007,13694.1 +65.7803,13886.4 +67.5656,13987.5 +69.3593,14073.4 +71.1599,14208.2 +72.9585,14286.5 +74.7583,14322 +76.556,14312 +78.3522,14427.3 +80.1504,14687.4 +81.9521,14818.9 +83.7547,14816.3 +85.5546,14750.8 +87.3472,14682.4 +89.1313,14642.8 +90.9046,14661.6 +92.6711,14728.2 +94.4368,14709.3 +96.2018,14537.4 +97.9579,14323.4 +99.6993,14149.4 +101.428,13975.5 +103.143,13769.3 +104.844,13652.9 +106.527,13573.9 +108.191,13526.9 +109.842,13466.2 +111.478,13316.7 +113.09,13212.9 +114.669,13210.8 +116.219,13258 +117.74,13319.1 +119.238,13443.1 +120.709,13533.1 +122.148,13525.3 +123.547,13536 +124.909,13699.2 +126.234,14000.9 +127.523,14235.3 +128.772,14383.4 +129.979,14674.1 +131.149,14953.1 +132.282,14981 +133.374,14929.8 +134.416,14898.1 +135.41,14954.7 +136.359,14988.7 +137.266,14932.4 +138.126,14798 +138.939,14617.8 +139.7,14300.7 +140.403,13873.7 +141.05,13581.8 +141.639,13342 +142.175,13062.5 +142.646,12627.3 +143.058,12231.8 +143.405,11767.8 +143.683,11330.1 +143.878,10991 +143.996,10990.7 +144,11457.4 +143.95,13420 +143.839,14602.7 +143.662,15329.3 +143.407,15622.4 +143.091,15098.6 +142.687,14170.6 +142.183,13026.4 +141.6,12231.2 +140.93,11669.8 +140.172,11416.2 +139.341,11030.2 +138.434,10372.5 +137.43,9651.43 +136.346,9073.28 +135.19,8552.75 +133.945,7961.3 +132.611,7503.35 +131.196,7265.97 +129.659,7476.43 +128.044,8425.79 +126.37,8998.29 +124.599,9058.83 +122.758,8750.14 +120.876,7922.02 +119.005,6829.66 +117.1,5739.27 +115.16,4938.02 +113.195,4556.92 +111.124,4009.97 +108.956,3076.65 +106.734,2809.43 +104.501,3435.44 +102.236,4114.62 +99.8892,4774.08 +97.4932,5494.42 +95.0781,6051.92 +92.6506,6267.32 +90.2226,6215.52 +87.773,6104.6 +85.3137,6203.32 +82.8008,6609.69 +80.2456,7243.11 +77.6691,7868.18 +75.059,8409.37 +72.4444,8770.91 +69.889,9123 +67.3891,9726.37 +64.9092,10533.1 +62.449,10876.2 +60.006,10686.3 +57.606,10357 +55.2767,9938.64 +53.0145,9433.22 +50.7868,8896.33 +48.581,8634.28 +46.4189,8698.11 +44.3031,8840.73 +42.2375,8833.26 +40.2273,8726.52 +38.2721,8607.14 +36.3855,8449.8 +34.5648,8343.22 +32.8088,8334.71 +31.0978,8226.37 +29.4095,7798.63 +27.7617,7187.13 +26.1538,6973.54 +24.6108,7240.64 +23.1211,7661.24 +21.6577,8004.98 +20.237,8433.32 +18.8709,9012.46 +17.57,9429.65 +16.3306,9509.81 +15.1428,9421.25 +13.9942,9405.43 +12.8928,9478.66 +11.837,9530.74 +10.8323,9548.98 +9.88763,9552.49 +8.99399,9483.55 +8.1242,9405.81 +7.2898,9492.06 +6.51456,9765.15 +5.80287,9996.22 +5.14662,9887.11 +4.5243,9551.61 +3.93801,9254.68 +3.40371,8961.15 +2.91193,8378.6 +2.4483,7819.07 +2.01826,7649.43 +1.63363,7745.02 +1.29812,7860 +1.00485,7939.93 +0.741844,8024.7 +0.515951,8110.57 +0.329747,8151.66 +0.179453,8272.08 +0.073617,8535.67 +0.018252,8665.32 +0,8484.74 +0.066215,8615.27 +0.171112,8951.1 +0.316819,9280.12 +0.498586,9613.75 +0.715024,10084.6 +0.97621,10624.4 +1.2883,10886 +1.63867,10787.3 +2.02093,10515.7 +2.43243,10317 +2.87705,10188.2 +3.36461,10107.5 +3.8875,10058.3 +4.44299,10128.3 +5.03967,10279.2 +5.67946,10368 +6.35611,10397.3 +7.05754,10422.5 +7.7809,10496.4 +8.53069,10721.6 +9.32235,11145.6 +10.1506,11569.2 +11.013,12015.8 +11.9097,12514.9 +12.842,12892 +13.8065,12964.3 +14.7986,12892.5 +15.8226,12869.7 +16.8842,12904.7 +17.9785,12974.2 +19.1005,13055.2 +20.2442,13145.5 +21.4129,13406.1 +22.6127,13789.8 +23.8375,13974.4 +25.0839,14102 +26.3506,14397.5 +27.6347,14832.5 +28.936,15269.6 +30.2719,15730.9 +31.6607,16128.3 +33.0885,16138.4 +34.5314,15870.9 +35.9861,15687 +37.4602,15666 +38.9614,15642.7 +40.4966,15570.9 +42.0607,15503.3 +43.6394,15452.3 +45.2335,15386.8 +46.8483,15105.5 +48.4878,14678 +50.152,14434.2 +51.8308,14364.4 +53.5259,14356.1 +55.2375,14236.2 +56.9713,14093.1 +58.7226,13891.4 +60.4832,13598.9 +62.2413,13513.1 +64.007,13694.1 +65.7803,13886.4 +67.5656,13987.5 +69.3593,14073.4 +71.1599,14208.2 +72.9585,14286.5 +74.7583,14322 +76.556,14312 +78.3522,14427.3 +80.1504,14687.4 +81.9521,14818.9 +83.7547,14816.3 +85.5546,14750.8 +87.3472,14682.4 +89.1313,14642.8 +90.9046,14661.6 +92.6711,14728.2 +94.4368,14709.3 +96.2018,14537.4 +97.9579,14323.4 +99.6993,14149.4 +101.428,13975.5 +103.143,13769.3 +104.844,13652.9 +106.527,13573.9 +108.191,13526.9 +109.842,13466.2 +111.478,13316.7 +113.09,13212.9 +114.669,13210.8 +116.219,13258 +117.74,13319.1 +119.238,13443.1 +120.709,13533.1 +122.148,13525.3 +123.547,13536 +124.909,13699.2 +126.234,14000.9 +127.523,14235.3 +128.772,14383.4 +129.979,14674.1 +131.149,14953.1 +132.282,14981 +133.374,14929.8 +134.416,14898.1 +135.41,14954.7 +136.359,14988.7 +137.266,14932.4 +138.126,14798 +138.939,14617.8 +139.7,14300.7 +140.403,13873.7 +141.05,13581.8 +141.639,13342 +142.175,13062.5 +142.646,12627.3 +143.058,12231.8 +143.405,11767.8 +143.683,11330.1 +143.878,10991 +143.996,10990.7 +144,11457.4 +143.95,13420 +143.839,14602.7 +143.662,15329.3 +143.407,15622.4 +143.091,15098.6 +142.687,14170.6 +142.183,13026.4 +141.6,12231.2 +140.93,11669.8 +140.172,11416.2 +139.341,11030.2 +138.434,10372.5 +137.43,9651.43 +136.346,9073.28 +135.19,8552.75 +133.945,7961.3 +132.611,7503.35 +131.196,7265.97 +129.659,7476.43 +128.044,8425.79 +126.37,8998.29 +124.599,9058.83 +122.758,8750.14 +120.876,7922.02 +119.005,6829.66 +117.1,5739.27 +115.16,4938.02 +113.195,4556.92 +111.124,4009.97 +108.956,3076.65 +106.734,2809.43 +104.501,3435.44 +102.236,4114.62 +99.8892,4774.08 +97.4932,5494.42 +95.0781,6051.92 +92.6506,6267.32 +90.2226,6215.52 +87.773,6104.6 +85.3137,6203.32 +82.8008,6609.69 +80.2456,7243.11 +77.6691,7868.18 +75.059,8409.37 +72.4444,8770.91 +69.889,9123 +67.3891,9726.37 +64.9092,10533.1 +62.449,10876.2 +60.006,10686.3 +57.606,10357 +55.2767,9938.64 +53.0145,9433.22 +50.7868,8896.33 +48.581,8634.28 +46.4189,8698.11 +44.3031,8840.73 +42.2375,8833.26 +40.2273,8726.52 +38.2721,8607.14 +36.3855,8449.8 +34.5648,8343.22 +32.8088,8334.71 +31.0978,8226.37 +29.4095,7798.63 +27.7617,7187.13 +26.1538,6973.54 +24.6108,7240.64 +23.1211,7661.24 +21.6577,8004.98 +20.237,8433.32 +18.8709,9012.46 +17.57,9429.65 +16.3306,9509.81 +15.1428,9421.25 +13.9942,9405.43 +12.8928,9478.66 +11.837,9530.74 +10.8323,9548.98 +9.88763,9552.49 +8.99399,9483.55 +8.1242,9405.81 +7.2898,9492.06 +6.51456,9765.15 +5.80287,9996.22 +5.14662,9887.11 +4.5243,9551.61 +3.93801,9254.68 +3.40371,8961.15 +2.91193,8378.6 +2.4483,7819.07 +2.01826,7649.43 +1.63363,7745.02 +1.29812,7860 +1.00485,7939.93 +0.741844,8024.7 +0.515951,8110.57 +0.329747,8151.66 +0.179453,8272.08 +0.073617,8535.67 +0.018252,8665.32 +0,8566.76 +0.066215,8484.74 +0.171112,8615.27 +0.316819,8951.1 +0.498586,9280.12 +0.715024,9613.75 +0.97621,10084.6 +1.2883,10624.4 +1.63867,10886 +2.02093,10787.3 +2.43243,10515.7 +2.87705,10317 +3.36461,10188.2 +3.8875,10107.5 +4.44299,10058.3 +5.03967,10128.3 +5.67946,10279.2 +6.35611,10368 +7.05754,10397.3 +7.7809,10422.5 +8.53069,10496.4 +9.32235,10721.6 +10.1506,11145.6 +11.013,11569.2 +11.9097,12015.8 +12.842,12514.9 +13.8065,12892 +14.7986,12964.3 +15.8226,12892.5 +16.8842,12869.7 +17.9785,12904.7 +19.1005,12974.2 +20.2442,13055.2 +21.4129,13145.5 +22.6127,13406.1 +23.8375,13789.8 +25.0839,13974.4 +26.3506,14102 +27.6347,14397.5 +28.936,14832.5 +30.2719,15269.6 +31.6607,15730.9 +33.0885,16128.3 +34.5314,16138.4 +35.9861,15870.9 +37.4602,15687 +38.9614,15666 +40.4966,15642.7 +42.0607,15570.9 +43.6394,15503.3 +45.2335,15452.3 +46.8483,15386.8 +48.4878,15105.5 +50.152,14678 +51.8308,14434.2 +53.5259,14364.4 +55.2375,14356.1 +56.9713,14236.2 +58.7226,14093.1 +60.4832,13891.4 +62.2413,13598.9 +64.007,13513.1 +65.7803,13694.1 +67.5656,13886.4 +69.3593,13987.5 +71.1599,14073.4 +72.9585,14208.2 +74.7583,14286.5 +76.556,14322 +78.3522,14312 +80.1504,14427.3 +81.9521,14687.4 +83.7547,14818.9 +85.5546,14816.3 +87.3472,14750.8 +89.1313,14682.4 +90.9046,14642.8 +92.6711,14661.6 +94.4368,14728.2 +96.2018,14709.3 +97.9579,14537.4 +99.6993,14323.4 +101.428,14149.4 +103.143,13975.5 +104.844,13769.3 +106.527,13652.9 +108.191,13573.9 +109.842,13526.9 +111.478,13466.2 +113.09,13316.7 +114.669,13212.9 +116.219,13210.8 +117.74,13258 +119.238,13319.1 +120.709,13443.1 +122.148,13533.1 +123.547,13525.3 +124.909,13536 +126.234,13699.2 +127.523,14000.9 +128.772,14235.3 +129.979,14383.4 +131.149,14674.1 +132.282,14953.1 +133.374,14981 +134.416,14929.8 +135.41,14898.1 +136.359,14954.7 +137.266,14988.7 +138.126,14932.4 +138.939,14798 +139.7,14617.8 +140.403,14300.7 +141.05,13873.7 +141.639,13581.8 +142.175,13342 +142.646,13062.5 +143.058,12627.3 +143.405,12231.8 +143.683,11767.8 +143.878,11330.1 +143.996,10991 +144,10990.7 +143.95,11457.4 +143.839,13420 +143.662,14602.7 +143.407,15329.3 +143.091,15622.4 +142.687,15098.6 +142.183,14170.6 +141.6,13026.4 +140.93,12231.2 +140.172,11669.8 +139.341,11416.2 +138.434,11030.2 +137.43,10372.5 +136.346,9651.43 +135.19,9073.28 +133.945,8552.75 +132.611,7961.3 +131.196,7503.35 +129.659,7265.97 +128.044,7476.43 +126.37,8425.79 +124.599,8998.29 +122.758,9058.83 +120.876,8750.14 +119.005,7922.02 +117.1,6829.66 +115.16,5739.27 +113.195,4938.02 +111.124,4556.92 +108.956,4009.97 +106.734,3076.65 +104.501,2809.43 +102.236,3435.44 +99.8892,4114.62 +97.4932,4774.08 +95.0781,5494.42 +92.6506,6051.92 +90.2226,6267.32 +87.773,6215.52 +85.3137,6104.6 +82.8008,6203.32 +80.2456,6609.69 +77.6691,7243.11 +75.059,7868.18 +72.4444,8409.37 +69.889,8770.91 +67.3891,9123 +64.9092,9726.37 +62.449,10533.1 +60.006,10876.2 +57.606,10686.3 +55.2767,10357 +53.0145,9938.64 +50.7868,9433.22 +48.581,8896.33 +46.4189,8634.28 +44.3031,8698.11 +42.2375,8840.73 +40.2273,8833.26 +38.2721,8726.52 +36.3855,8607.14 +34.5648,8449.8 +32.8088,8343.22 +31.0978,8334.71 +29.4095,8226.37 +27.7617,7798.63 +26.1538,7187.13 +24.6108,6973.54 +23.1211,7240.64 +21.6577,7661.24 +20.237,8004.98 +18.8709,8433.32 +17.57,9012.46 +16.3306,9429.65 +15.1428,9509.81 +13.9942,9421.25 +12.8928,9405.43 +11.837,9478.66 +10.8323,9530.74 +9.88763,9548.98 +8.99399,9552.49 +8.1242,9483.55 +7.2898,9405.81 +6.51456,9492.06 +5.80287,9765.15 +5.14662,9996.22 +4.5243,9887.11 +3.93801,9551.61 +3.40371,9254.68 +2.91193,8961.15 +2.4483,8378.6 +2.01826,7819.07 +1.63363,7649.43 +1.29812,7745.02 +1.00485,7860 +0.741844,7939.93 +0.515951,8024.7 +0.329747,8110.57 +0.179453,8151.66 +0.073617,8272.08 +0.018252,8535.67 +0,8665.32 \ No newline at end of file diff --git a/mallet.json b/mallet.json new file mode 100644 index 0000000..f7c917b --- /dev/null +++ b/mallet.json @@ -0,0 +1,32 @@ +{ + "wellName": "Mallet", + "deltaT": 0.033333333333, + "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": 1475.0, + "diameter": 1.0, + "material": "steel", + "dampingFactor": 0.8 + }, + { + "length": 1525.0, + "diameter": 0.875, + "material": "steel", + "dampingFactor": 0.8 + }, + { + "length": 2000.0, + "diameter": 0.750, + "material": "steel", + "dampingFactor": 0.8 + } + ] +} diff --git a/src/main/java/com/henrypump/poc/WebServer.java b/src/main/java/com/henrypump/poc/WebServer.java index 436bafd..8713cc4 100644 --- a/src/main/java/com/henrypump/poc/WebServer.java +++ b/src/main/java/com/henrypump/poc/WebServer.java @@ -2,6 +2,8 @@ package com.henrypump.poc; import java.io.*; import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.Map; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; @@ -22,55 +24,62 @@ public class WebServer{ this.attachedPOC = attachedPOC; this.port = port; HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); - server.createContext("/cmd/start", new StartHandler()); - server.createContext("/cmd/stop", new StopHandler()); - server.createContext("/sts", new StatusHandler()); - server.createContext("/cmd/updateconfig", new UpdateConfigHandler()); + server.createContext("/command", new CommandHandler()); + server.createContext("/config", new ConfigHandler()); server.setExecutor(null); // creates a default executor server.start(); } - class StartHandler implements HttpHandler { - @Override - public void handle(HttpExchange t) throws IOException { - attachedPOC.thisWell.start("webserver"); - String response = attachedPOC.thisWell.getRunStatusString(); - t.sendResponseHeaders(200, response.getBytes().length); - OutputStream os = t.getResponseBody(); - os.write(response.getBytes()); - os.close(); + public static Map queryToMap(String query){ + Map result = new HashMap(); + for (String param : query.split("&")) { + String pair[] = param.split("="); + if (pair.length>1) { + result.put(pair[0], pair[1]); + }else{ + result.put(pair[0], ""); + } } + return result; } - class StopHandler implements HttpHandler { + class CommandHandler implements HttpHandler { @Override public void handle(HttpExchange t) throws IOException { - attachedPOC.thisWell.stop("webserver"); - String response = attachedPOC.thisWell.getRunStatusString(); - t.sendResponseHeaders(200, response.getBytes().length); - OutputStream os = t.getResponseBody(); - os.write(response.getBytes()); - os.close(); - } - } - - class StatusHandler implements HttpHandler { - @Override - public void handle(HttpExchange t) throws IOException { - String response = attachedPOC.thisWell.getRunStatusString(); - t.sendResponseHeaders(200, response.getBytes().length); - OutputStream os = t.getResponseBody(); - os.write(response.getBytes()); - os.close(); - } - } - - class UpdateConfigHandler implements HttpHandler { - @Override - public void handle(HttpExchange t) throws IOException { - attachedPOC.thisWell.getWellSetup(); JSONObject respJSON = new JSONObject(); - respJSON.put("status", "OK"); + Map params = queryToMap(t.getRequestURI().getQuery()); + for(Map.Entry param_map : params.entrySet()){ + String key = param_map.getKey(); + String param = param_map.getValue(); + + switch (key){ + case "start": + if(param.equals("true")) { + attachedPOC.thisWell.start("web"); + respJSON.put("startCommand", "true"); + respJSON.put("status", attachedPOC.thisWell.getRunStatusString()); + } else { + respJSON.put("startCommand", "invalid value - " + param); + } + break; + + case "stop": + if(param.equals("true")) { + attachedPOC.thisWell.stop("web"); + respJSON.put("stopCommand", "true"); + respJSON.put("status", attachedPOC.thisWell.getRunStatusString()); + } else { + respJSON.put("stopCommand", "invalid value - " + param); + } + break; + + + default: + respJSON.put(key, "not implemented"); + + } + + } String response = respJSON.toJSONString(); t.sendResponseHeaders(200, response.getBytes().length); OutputStream os = t.getResponseBody(); @@ -80,6 +89,100 @@ public class WebServer{ } + class ConfigHandler implements HttpHandler { + @Override + public void handle(HttpExchange t) throws IOException { + JSONObject respJSON = new JSONObject(); + Map params = queryToMap(t.getRequestURI().getQuery()); + for(Map.Entry param_map : params.entrySet()){ + String key = param_map.getKey(); + String param = param_map.getValue(); + + switch (key){ + case "update": + if(param.equals("true")) { + attachedPOC.thisWell.getWellSetup(); + respJSON.put("configUpdated", "true"); + } else { + respJSON.put("configUpdated", "invalid value - " + param); + } + 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": + 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 "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 "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 "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 "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; + + default: + respJSON.put(key, "not implemented"); + break; + + } + + } + String response = respJSON.toJSONString(); + t.sendResponseHeaders(200, response.getBytes().length); + OutputStream os = t.getResponseBody(); + os.write(response.getBytes()); + os.close(); + } + } } + diff --git a/src/main/java/com/henrypump/poc/Well.java b/src/main/java/com/henrypump/poc/Well.java index 453ba9c..487f64f 100644 --- a/src/main/java/com/henrypump/poc/Well.java +++ b/src/main/java/com/henrypump/poc/Well.java @@ -450,6 +450,18 @@ public class Well { return direction; } + public void setFluidOilRatio(double fluidOilRatio) { + this.fluidOilRatio = fluidOilRatio; + } + + public void setFluidWaterRatio(double fluidWaterRatio) { + this.fluidWaterRatio = fluidWaterRatio; + } + + public void setFluidGasRatio(double fluidGasRatio) { + this.fluidGasRatio = fluidGasRatio; + } + public double getFluidOilRatio() { return fluidOilRatio; } @@ -609,7 +621,7 @@ public class Well { try { Object obj = parser.parse(new FileReader(jsonFilename)); - System.out.println("Reading well configuration from JSON file 'wellSetup.json"); + System.out.println("Reading well configuration from JSON file 'wellSetup.json'"); JSONObject well = (JSONObject) obj; Object newWellName = well.get("wellName"); @@ -663,7 +675,12 @@ public class Well { Path fromFile = Paths.get(jsonFilename); Path toFile = Paths.get(jsonFilename + ".bak"); - Files.move(fromFile, toFile); + try { + Files.move(fromFile, toFile); + } catch (FileAlreadyExistsException e) { + Files.delete(toFile); + Files.move(fromFile, toFile); + } } catch (FileNotFoundException e) { System.out.println("No configuration file found. Pulling latest value from database."); diff --git a/www/pocwww/pocwww/json.py b/www/pocwww/pocwww/json.py index b288f1f..6ef50f1 100644 --- a/www/pocwww/pocwww/json.py +++ b/www/pocwww/pocwww/json.py @@ -117,4 +117,34 @@ def json_runstatusnow(request): @view_config(route_name="json_updateconfig", renderer="prettyjson", request_method='POST') def json_updateconfig(request): - return {'POST': request.json_body} + conv_to_float = [ + 'deltaT', + 'pumpDiameter', + 'fluidGradient', + 'tubingID', + 'tubingOD', + 'tubingAnchorDepth', + 'structuralRating', + 'stuffingBoxFriction', + 'tubingHeadPressure' + ] + t_conv_to_float = ['length', 'diameter', 'dampingFactor'] + jsb = request.json_body + new_config = {} + new_config['timestamp'] = datetime.now() + new_config['storedBy'] = "web" + new_config['wellName'] = jsb['wellName'] + new_config['tapers'] = [] + for p in conv_to_float: + new_config[p] = float(jsb[p]) + + for t_i in range(0, len(jsb['tapers'])): + t = {} + for p in t_conv_to_float: + t[p] = float(jsb['tapers'][t_i][p]) + t['material'] = jsb['tapers'][t_i]['material'] + new_config['tapers'].append(t) + + result = request.db['wellConfiguration'].insert(new_config) + + return {'new_config': request.json_body, 'stored_result': result}