Fixed SQL query to get tag values at time

This commit is contained in:
Patrick McDonagh
2016-04-21 15:13:12 -05:00
parent 45d99d1465
commit 1ca2291f31
2 changed files with 6 additions and 7 deletions

View File

@@ -28,9 +28,8 @@
<div class="row">
<pre>{{tagData}}</pre>
<div class="col-sm-4">
<div id="Status" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Status:</h4><h5>{{cardData.Card_Type}}</h5><h6>at {{tagData.fillage_percent.dtime * 1000 | date: "medium"}}</h6></div>
<div id="Status" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Status:</h4><h5>{{cardData.Card_Type}}</h5><h6>at {{cardData.Stroke_Time | date: "medium"}}</h6></div>
</div>
<div class="col-sm-4">
<div id="FillageGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Pump Fillage:</h4><h5>{{tagData.fillage_percent.val | number:3}} %</h5><h6>at {{tagData.fillage_percent.dtime * 1000 | date: "medium"}}</h6></div>
@@ -39,16 +38,16 @@
<div id="FAPGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Fluid Above Pump:</h4><h5>{{tagData.fluid_level.val | number:3}} ft.</h5><h6>at {{tagData.fluid_level.dtime * 1000 | date: "medium"}}</h6></div>
</div>
<div class="col-sm-4">
<div id="PRHPGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Polished Rod HP:</h4><h5>{{tagData.polished_rod_hp.val | number:3}} HP</h5></div>
<div id="PRHPGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Polished Rod HP:</h4><h5>{{tagData.polished_rod_hp.val | number:3}} HP</h5><h6>at {{tagData.polished_rod_hp.dtime * 1000 | date: "medium"}}</h6></div>
</div>
<div class="col-sm-4">
<div id="PMPHPGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Pump HP:</h4><h5>{{tagData.pump_hp.val | number:3}} HP</h5></div>
<div id="PMPHPGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Pump HP:</h4><h5>{{tagData.pump_hp.val | number:3}} HP</h5><h6>at {{tagData.pump_hp.dtime * 1000 | date: "medium"}}</h6></div>
</div>
<div class="col-sm-4">
<div id="SpeedGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Speed:</h4><h5>{{tagData.spm.val | number:3}} SPM</h5></div>
<div id="SpeedGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Speed:</h4><h5>{{tagData.spm.val | number:3}} SPM</h5><h6>at {{tagData.spm.dtime * 1000 | date: "medium"}}</h6></div>
</div>
<div class="col-sm-4">
<div id="FluidLoadGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Fluid Load:</h4><h5>{{tagData.downhole_fluid_load.val | number:3}} lbs.</h5></div>
<div id="FluidLoadGauge" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Fluid Load:</h4><h5>{{tagData.downhole_fluid_load.val | number:3}} lbs.</h5><h6>at {{tagData.downhole_fluid_load.dtime * 1000 | date: "medium"}}</h6></div>
</div>
<div class="col-sm-4">
<div id="LastUpdated" class="gauge well" style="width:95%; text-align:center; margin:10px;"><h4>Current Stroke:</h4><h5>{{cardData.Stroke_Time | date: "medium"}}</h5></div>

View File

@@ -1349,7 +1349,7 @@ exports.getValuesClosestTo = (req, res) ->
sqlite3 = require('sqlite3').verbose()
db = new sqlite3.Database(dbFile)
db.serialize ()->
query = 'SELECT v1.id, v1.tagID, v1.dtime, v1.val, t.name, t.class, t.units FROM tag_vals v1 LEFT JOIN tags t ON t.id = v1.tagID WHERE v1.id = (SELECT v2.id FROM tag_vals v2 WHERE v2.tagID = v1.tagID ORDER BY ABS(v2.dtime - ?) ASC LIMIT 1);'
query = 'SELECT v.id, v.val, v.dtime, t.name, t.maxExpected, t.minExpected, t.units FROM (SELECT tagID, MAX(dtime) dtime FROM tag_vals WHERE dtime <= ? GROUP BY tagID) v0 JOIN tag_vals v ON v0.tagID = v.tagID AND v0.dtime = v.dtime JOIN tags t ON t.id = v.tagID'
prepQuery = db.prepare query
prepQuery.all req.params.unixTS, (err, rows)->
prepQuery.finalize()