analyzer_init.sql 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. \connect senslog1
  2. create schema if not exists statistics;
  3. alter schema statistics OWNER TO senslog;
  4. /* table with calculated values */
  5. create table statistics.records (
  6. id SERIAL PRIMARY KEY NOT NULL,
  7. group_id bigint not null,
  8. value_attribute text not null, -- [MIN, MAX, SUM, COUNT]
  9. record_value double precision not null,
  10. time_interval integer not null, -- interval in seconds
  11. time_stamp timestamptz not null,
  12. created timestamptz DEFAULT CURRENT_TIMESTAMP,
  13. UNIQUE (group_id, value_attribute, time_stamp)
  14. );
  15. alter table statistics.records OWNER TO senslog;
  16. /* time interval to analyse sensor groups */
  17. create table statistics.groups_interval (
  18. id SERIAL PRIMARY KEY NOT NULL,
  19. time_interval integer not null, -- interval in seconds
  20. persistence boolean not null,
  21. aggregation_type text not null -- ['DOUBLE']
  22. );
  23. alter table statistics.groups_interval OWNER TO senslog;
  24. /* list of unit-sensor pair to run analyses */
  25. create table statistics.sensors (
  26. id SERIAL PRIMARY KEY NOT NULL,
  27. unit_id bigint not null,
  28. sensor_id bigint not null,
  29. CONSTRAINT fk_unit_sensor FOREIGN KEY (unit_id, sensor_id) REFERENCES public.units_to_sensors(unit_id, sensor_id)
  30. );
  31. alter table statistics.sensors OWNER TO senslog;
  32. /* thresholds to be checked */
  33. create table statistics.thresholds (
  34. id SERIAL PRIMARY KEY NOT NULL,
  35. group_id integer not null,
  36. mode varchar(10) not null, -- [le, lt, ge, gt, ne, eq]
  37. property varchar(10) not null, -- [MIN, MAX, AVG, VAL]
  38. threshold_value double precision not null
  39. );
  40. alter table statistics.thresholds OWNER TO senslog;
  41. create table statistics.sensor_to_group (
  42. id SERIAL PRIMARY KEY NOT NULL,
  43. sensor_id integer REFERENCES statistics.sensors(id),
  44. group_id integer REFERENCES statistics.groups_interval(id),
  45. created timestamptz DEFAULT CURRENT_TIMESTAMP
  46. );
  47. alter table statistics.sensor_to_group OWNER TO senslog;