Created
March 22, 2019 23:38
-
-
Save hbs/0c175c5b05dc023395e7badec3de307d to your computer and use it in GitHub Desktop.
WarpScript™ equivalent of https://www.influxdata.com/blog/practical-uses-of-cross-measurement-math-in-flux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Tmeas, Pmeas, CO2meas | |
// Assuming read token is in $RTOKEN | |
// Measurments span $duration time units | |
// Store the current time | |
NOW 'now' STORE | |
[ $RTOKEN 'Tmeas' {} $now $duration ] FETCH 'Tmeas' STORE | |
[ $RTOKEN 'Pmeas' {} $now $duration ] FETCH 'Pmeas' STORE | |
[ $RTOKEN 'CO2meas' {} $now $duration ] FETCH 'CO2meas' STORE | |
// Now bucketize the series, using 30s buckets and applying a mean | |
[ $Tmeas bucketizer.mean $now 30 s 0 ] BUCKETIZE 'Tmeas' STORE | |
[ $Pmeas bucketizer.mean $now 30 s 0 ] BUCKETIZE 'Pmeas' STORE | |
[ $CO2meas bucketizer.mean $now 30 s 0 ] BUCKETIZE 'CO2meas' STORE | |
// We now fill the gaps | |
$Tmeas FILLPREVIOUS [ NaN NaN NaN 20.0 ] FILLVALUE 0 GET 'Tmeas' STORE | |
$Pmeas FILLPREVIOUS [ NaN NaN NaN 1013.25 ] FILLVALUE 0 GET 'Pmeas' STORE | |
$CO2meas FILLPREVIOUS [ NaN NaN NaN 400.0 ] FILLVALUE 0 GET 'CO2meas' STORE | |
// Now compute the final result | |
298.15 1013.25 [ 'Tref' 'Pref' ] STORE | |
$Tmeas 273.15 + $Pref * $Pmeas $Tref * / $CO2meas + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment