Add the grafana query, could be cleaned up a bit but works
This commit is contained in:
parent
d83bb3b58c
commit
ae32fe61ac
1 changed files with 31 additions and 0 deletions
31
sql/condition-glucose-grafana.sql
Normal file
31
sql/condition-glucose-grafana.sql
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
WITH range_ts AS (
|
||||||
|
SELECT DATE_TRUNC('minute', ts) as ts
|
||||||
|
FROM generate_series($__timeFrom(), $__timeTo(), '1 minute'::interval) AS ts
|
||||||
|
), coallated AS
|
||||||
|
|
||||||
|
(SELECT ts,
|
||||||
|
gi_prev.time as stime,
|
||||||
|
gi_next.time as etime,
|
||||||
|
gi_prev.value as svalue,
|
||||||
|
gi_next.value as evalue,
|
||||||
|
EXTRACT(EPOCH FROM ts-gi_prev.time)/EXTRACT(EPOCH FROM gi_next.time-gi_prev.time) * gi_prev.value +
|
||||||
|
EXTRACT(EPOCH FROM gi_next.time-ts)/EXTRACT(EPOCH FROM gi_next.time-gi_prev.time) * gi_next.value AS samp_value
|
||||||
|
FROM range_ts rts
|
||||||
|
LEFT JOIN LATERAL (
|
||||||
|
SELECT *
|
||||||
|
FROM "glucose-import"
|
||||||
|
WHERE "time" <= rts.ts
|
||||||
|
ORDER BY "time" DESC
|
||||||
|
LIMIT 1
|
||||||
|
) AS gi_prev ON true
|
||||||
|
LEFT JOIN LATERAL (
|
||||||
|
SELECT *
|
||||||
|
FROM "glucose-import"
|
||||||
|
WHERE "time" >= rts.ts
|
||||||
|
ORDER BY "time" ASC
|
||||||
|
LIMIT 1
|
||||||
|
) AS gi_next ON true
|
||||||
|
WHERE gi_prev.time IS NOT NULL and gi_next.time IS NOT NULL AND gi_next.time <> gi_prev.time
|
||||||
|
)
|
||||||
|
SELECT ts as time, samp_value as value
|
||||||
|
FROM coallated;
|
Loading…
Add table
Reference in a new issue