Обновить hardwareAvailabilityReport.sql

This commit is contained in:
2026-07-01 19:04:53 +00:00
parent 16d770ef25
commit ee501e7d03
+49 -30
View File
@@ -40,8 +40,8 @@ checks AS (
-- Исключаем оборудование, начинающееся на IRZ (любой регистр) -- Исключаем оборудование, начинающееся на IRZ (любой регистр)
--AND UPPER(h.host) NOT LIKE 'IRZ%' --AND UPPER(h.host) NOT LIKE 'IRZ%'
-- Период: май 2026 года (измените под свои даты) -- Период: май 2026 года (измените под свои даты)
--and hinv.notes = 'ОБЪЕКТ № 5' --and hinv.notes = 'ОБЪЕКТ № 8'
--and hinv."name" = 'Метеостанция Кондор' --and hinv."name" = 'Видеокамера Trassir TR-D6254IR15'
and CAST(nullif(regexp_replace(hinv.notes, 'ОБЪЕКТ №\s*', '', 'g'),'') as INTEGER) 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) 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' AND TO_TIMESTAMP(hx.clock) >= to_date(${start_dt}, 'yyyymmdd') - interval '1 day'
@@ -151,37 +151,56 @@ router as
daily_stats AS ( daily_stats AS (
select *, select *,
case when unavailable_hours is not null then coalesce(extract('hour' from available_hours)::int,0) else 24 end AS a_h, extract('hour' from available_hours)::int as a_h,
coalesce(extract('minute' from available_hours)::int,0) AS a_m, extract('minute' from available_hours)::int as a_m,
coalesce(extract('second' from available_hours)::int,0) AS a_s, extract('second' from available_hours)::int 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, extract('hour' from unavailable_hours)::int as u_h,
coalesce(extract('minute' from unavailable_hours)::int,0) AS u_m, extract('minute' from unavailable_hours)::int as u_m,
coalesce(extract('second' from unavailable_hours)::int,0) AS u_s extract('second' from unavailable_hours)::int as u_s
from from
( (
SELECT select
host_name, host_name,
visible_name, visible_name,
equipment_type, equipment_type,
object_number, object_number,
coordinates, coordinates,
DATE(check_time) AS check_date, check_date,
sum(case when status = 1 then next_check_time - check_time else null end) AS available_hours, case
sum(case when status = 0 then next_check_time - check_time else null end) AS unavailable_hours when available_hours = '1 day' then '24:00:00'::interval
--sum(next_check_time - check_time) AS all_hours else available_hours
FROM end as available_hours,
( case
select * from grouped_intervals where equipment_type not like 'Маршрутизатор%' when unavailable_hours = '1 day' then '24:00:00'::interval
union all when available_hours + unavailable_hours != '24:00:00'::interval then '24:00:00'::interval - available_hours
select * from router else unavailable_hours
) g end as unavailable_hours
GROUP BY from
host_name, (
visible_name, SELECT
equipment_type, host_name,
object_number, visible_name,
coordinates, equipment_type,
DATE(check_time) 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 ) f
), ),
@@ -212,8 +231,8 @@ device_summary AS (
equipment_type, equipment_type,
object_number, object_number,
coordinates, 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/3600) > 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_unavailable_ge_12h
FROM daily_stats FROM daily_stats
GROUP BY GROUP BY
visible_name, visible_name,
@@ -233,4 +252,4 @@ SELECT
FROM daily_graph dg FROM daily_graph dg
INNER JOIN device_summary ds INNER JOIN device_summary ds
ON ds.visible_name = dg.visible_name ON ds.visible_name = dg.visible_name
ORDER BY 1; ORDER BY 1;