You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
, datediff(hour, last_read::date, '{max_date.isoformat()}') as last_read_hours
423
+
--
424
+
, count(interval_value) as observations
425
+
, datediff(hour, '{min_date.isoformat()}', '{max_date.isoformat()}') + 24 as hours_in_period
426
+
, observations / hours_in_period as read_freq
427
+
, 1 - read_freq as unread_freq
428
+
--
429
+
, count(distinct case when duration_hours > duration_hours_thr and coalesce(interval_value, 0) = 0 then grp end) stuck_events
430
+
, sum(case when duration_hours > duration_hours_thr and coalesce(interval_value, 0) = 0 then flowinterval else 0 end)/3600 stuck_hours
431
+
, duration_hours_thr
432
+
--
433
+
,sum(case when coalesce(interval_value,0) > 0 then interval_value end) as total_usage
434
+
,sum(case when coalesce(interval_value,0) > 0 then flowinterval end)/3600 as used_hours
435
+
,sum(case when coalesce(interval_value,0) = 0 then flowinterval end)/3600 as idle_hours
436
+
,total_usage / used_hours as avg_hourly_usage
437
+
,avg_hourly_usage * stuck_hours as unaccounted
438
+
from failing_meters_0 a
439
+
join failing_meters_thresholds b on a.org_id = b.org_id and a.class_full_name = b.class_full_name
440
+
group by all
441
+
)
442
+
, z_scores as
443
+
(
444
+
select *
445
+
, (last_read_hours - avg(last_read_hours) over(partition by org_id, class_full_name)) / nullif(stddev(last_read_hours) over(partition by org_id, class_full_name), 0) as z_last_read
446
+
, (unread_freq - avg(unread_freq ) over(partition by org_id, class_full_name)) / nullif(stddev(unread_freq ) over(partition by org_id, class_full_name), 0) as z_unread_freq
447
+
, (stuck_hours - avg(stuck_hours ) over(partition by org_id, class_full_name)) / nullif(stddev(stuck_hours ) over(partition by org_id, class_full_name), 0) as z_stuck_hours
448
+
, (stuck_events - avg(stuck_events ) over(partition by org_id, class_full_name)) / nullif(stddev(stuck_events ) over(partition by org_id, class_full_name), 0) as z_stuck_events
449
+
, (unaccounted - avg(unaccounted ) over(partition by org_id, class_full_name)) / nullif(stddev(unaccounted ) over(partition by org_id, class_full_name), 0) as z_unaccounted
450
+
from failing_meters_score_0
451
+
)
452
+
select *
453
+
,1+4*((z_last_read -min(z_last_read) over(partition by org_id, class_full_name))/nullif((max(z_last_read) over(partition by org_id, class_full_name)-min(z_last_read) over(partition by org_id, class_full_name)),0)) as score_last_read
454
+
,1+4*((z_unread_freq -min(z_unread_freq) over(partition by org_id, class_full_name))/nullif((max(z_unread_freq) over(partition by org_id, class_full_name)-min(z_unread_freq) over(partition by org_id, class_full_name)),0)) as score_unread_freq
455
+
,1+4*((z_stuck_hours -min(z_stuck_hours) over(partition by org_id, class_full_name))/nullif((max(z_stuck_hours) over(partition by org_id, class_full_name)-min(z_stuck_hours) over(partition by org_id, class_full_name)),0)) as score_stuck_hours
456
+
,1+4*((z_stuck_events-min(z_stuck_events) over(partition by org_id, class_full_name))/nullif((max(z_stuck_events) over(partition by org_id, class_full_name)-min(z_stuck_events) over(partition by org_id, class_full_name)),0)) as score_stuck_events
457
+
,1+4*((z_unaccounted -min(z_unaccounted) over(partition by org_id, class_full_name))/nullif((max(z_unaccounted) over(partition by org_id, class_full_name)-min(z_unaccounted) over(partition by org_id, class_full_name)),0)) as score_unaccounted
0 commit comments