-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoolkit.sql
More file actions
35 lines (29 loc) · 1.27 KB
/
toolkit.sql
File metadata and controls
35 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
DROP TABLE if exists measurements cascade;
CREATE TABLE "measurements" ("device_id" integer not null, "val" decimal not null, "ts" timestamp not null);
SELECT create_hypertable('measurements', 'ts', chunk_time_interval => INTERVAL '1 day');
INSERT INTO measurements (ts, device_id, val)
SELECT ts, device_id, random()*80
FROM generate_series(TIMESTAMP '2022-01-01 00:00:00',
TIMESTAMP '2022-02-01 00:00:00',
INTERVAL '5 minutes') AS g1(ts),
generate_series(0, 5) AS g2(device_id);
set search_path to toolkit_experimental, public;
-- Validating if timevector is generating a null value
WITH a as (
SELECT device_id, (timevector(ts, val) -> unnest()).*
FROM "measurements"
GROUP BY device_id)
select a.* FROM a WHERE a.time is null or a.value is null;
-- Validating if sort is generating some null value
WITH a as (
SELECT device_id, (timevector(ts, val) -> sort() -> unnest()).*
FROM "measurements"
GROUP BY device_id)
select a.* FROM a WHERE a.time is null or a.value is null;
-- Trying only to compute delta
--SELECT device_id, timevector(ts, val) -> sort() -> delta()
--FROM "measurements"
--GROUP BY device_id ;
SELECT device_id, timevector(ts, val) -> sort() -> delta() -> abs() -> sum() as volatility
FROM "measurements"
GROUP BY device_id;