From ee501e7d030beff1f476a17a7b812bd73e31c648 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: Wed, 1 Jul 2026 19:04:53 +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 | 79 +++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/hardwareAvailabilityReport.sql b/hardwareAvailabilityReport.sql index 631a798..4f9ebc7 100644 --- a/hardwareAvailabilityReport.sql +++ b/hardwareAvailabilityReport.sql @@ -40,8 +40,8 @@ checks AS ( -- Исключаем оборудование, начинающееся на IRZ (любой регистр) --AND UPPER(h.host) NOT LIKE 'IRZ%' -- Период: май 2026 года (измените под свои даты) - --and hinv.notes = 'ОБЪЕКТ № 5' - --and hinv."name" = 'Метеостанция Кондор' + --and hinv.notes = 'ОБЪЕКТ № 8' + --and hinv."name" = 'Видеокамера Trassir TR-D6254IR15' 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' @@ -151,37 +151,56 @@ router as daily_stats AS ( select *, - 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 + 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 from ( - SELECT - host_name, + select + host_name, visible_name, equipment_type, object_number, coordinates, - 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 - FROM - ( - select * from grouped_intervals where equipment_type not like 'Маршрутизатор%' - union all - select * from router - ) g - GROUP BY - host_name, - visible_name, - equipment_type, - object_number, - coordinates, - DATE(check_time) + check_date, + case + when available_hours = '1 day' then '24:00:00'::interval + else available_hours + end as available_hours, + case + when unavailable_hours = '1 day' then '24:00:00'::interval + when available_hours + unavailable_hours != '24:00:00'::interval then '24:00:00'::interval - available_hours + else unavailable_hours + end as unavailable_hours + from + ( + SELECT + host_name, + visible_name, + equipment_type, + object_number, + coordinates, + DATE(check_time) AS check_date, + sum(case when status = 1 then next_check_time - check_time else '00:00:00'::interval end) AS available_hours, + sum(case when status = 0 then next_check_time - check_time else '00:00:00'::interval end) AS unavailable_hours + --sum(next_check_time - check_time) AS all_hours + FROM + ( + select * from grouped_intervals where equipment_type not like 'Маршрутизатор%' + union all + select * from router + ) g + GROUP BY + host_name, + visible_name, + equipment_type, + object_number, + coordinates, + DATE(check_time) + ) s ) f ), @@ -212,8 +231,8 @@ device_summary AS ( equipment_type, object_number, coordinates, - SUM(CASE WHEN (a_h + a_m/60 + a_s/360) > 12 THEN 1 ELSE 0 END) AS days_available_gt_12h, - SUM(CASE WHEN (a_h + a_m/60 + a_s/360) <= 12 THEN 1 ELSE 0 END) AS days_unavailable_ge_12h + SUM(CASE WHEN (a_h + a_m/60 + a_s/3600) > 12 THEN 1 ELSE 0 END) AS days_available_gt_12h, + SUM(CASE WHEN (a_h + a_m/60 + a_s/3600) <= 12 THEN 1 ELSE 0 END) AS days_unavailable_ge_12h FROM daily_stats GROUP BY visible_name, @@ -233,4 +252,4 @@ SELECT FROM daily_graph dg INNER JOIN device_summary ds ON ds.visible_name = dg.visible_name -ORDER BY 1; \ No newline at end of file +ORDER BY 1;