From 3f9d03a9b65a4afed9e493d3edfd0183c6817b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=A5=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=D1=86=D0=BA=D0=B8=D0=B9?= Date: Sun, 28 Jun 2026 21:41:13 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20hardwareAvailabilityReport.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardwareAvailabilityReport.sql | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/hardwareAvailabilityReport.sql b/hardwareAvailabilityReport.sql index b19b209..25c1bd6 100644 --- a/hardwareAvailabilityReport.sql +++ b/hardwareAvailabilityReport.sql @@ -39,8 +39,8 @@ checks AS ( -- Исключаем оборудование, начинающееся на IRZ (любой регистр) --AND UPPER(h.host) NOT LIKE 'IRZ%' -- Период: май 2026 года (измените под свои даты) - --and hinv.notes = 'ОБЪЕКТ № 12' - --and hinv."name" = 'Видеокамера Trassir TR-D6254IR15' + --and hinv.notes = 'ОБЪЕКТ № 5' + --and hinv."name" = 'Метеостанция Кондор' and CAST(nullif(regexp_replace(hinv.notes, 'ОБЪЕКТ №\s*', '', 'g'),'') as INTEGER) between 1 and 85 --in (44,77,43,54,27,48,12,49,65,9,60,35,38,1,51,41,53,84,8) AND TO_TIMESTAMP(hx.clock) >= to_date(${start_dt}, 'yyyymmdd') - interval '1 day' @@ -111,8 +111,8 @@ grouped_intervals AS ( equipment_type, object_number, coordinates, - MIN(date_trunc('second', check_time)) AS check_time, - MAX(date_trunc('second', next_check_time)) AS next_check_time, + MIN(check_time) AS check_time, + MAX(next_check_time) AS next_check_time, MAX(status) AS status FROM intervals GROUP BY @@ -126,12 +126,12 @@ grouped_intervals AS ( daily_stats AS ( select *, - extract('hour' from available_hours)::int AS a_h, - extract('minute' from available_hours)::int AS a_m, - extract('second' from available_hours)::int AS a_s, - extract('hour' from unavailable_hours)::int AS u_h, - extract('minute' from unavailable_hours)::int AS u_m, - extract('second' from unavailable_hours)::int AS u_s + case when unavailable_hours is not null then coalesce(extract('hour' from available_hours)::int,0) else 24 end AS a_h, + coalesce(extract('minute' from available_hours)::int,0) AS a_m, + coalesce(extract('second' from available_hours)::int,0) AS a_s, + case when available_hours is not null then coalesce(extract('hour' from unavailable_hours)::int,0) else 24 end AS u_h, + coalesce(extract('minute' from unavailable_hours)::int,0) AS u_m, + coalesce(extract('second' from unavailable_hours)::int,0) AS u_s from ( SELECT @@ -140,10 +140,10 @@ daily_stats AS ( equipment_type, object_number, coordinates, - DATE(check_time) AS check_date, + DATE(check_time) AS check_date, sum(case when status = 1 then next_check_time - check_time else null end) AS available_hours, - sum(case when status = 0 then next_check_time - check_time else null end) AS unavailable_hours, - sum(next_check_time - check_time) AS all_hours + sum(case when status = 0 then next_check_time - check_time else null end) AS unavailable_hours + --sum(next_check_time - check_time) AS all_hours FROM grouped_intervals GROUP BY host_name,