Обновить hardwareAvailabilityReport.sql

This commit is contained in:
2026-07-01 19:04:53 +00:00
parent 16d770ef25
commit ee501e7d03
+31 -12
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,12 +151,30 @@ 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
(
select
host_name,
visible_name,
equipment_type,
object_number,
coordinates,
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 from
( (
SELECT SELECT
@@ -166,8 +184,8 @@ daily_stats AS (
object_number, object_number,
coordinates, 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 = 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 null end) AS unavailable_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 --sum(next_check_time - check_time) AS all_hours
FROM FROM
( (
@@ -182,6 +200,7 @@ daily_stats AS (
object_number, object_number,
coordinates, coordinates,
DATE(check_time) 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,