Обновить 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 (любой регистр)
--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;
ORDER BY 1;