-- DL_PRB_ACT_USER
select yearweek
     , date
     , branch
     , cluster
     , kota_kabupaten
     , sum(num_dl_prb_utilization_percent)                                             as num_dl_prb_utilization
     , sum(denum_dl_prb_utilization_percent)                                           as denum_dl_prb_utilization
     , ndp(sum(num_dl_prb_utilization_percent), sum(denum_dl_prb_utilization_percent)) as dl_prb_utilization
     , sum(num_ul_prb_utilization_percent)                                             as num_ul_prb_utilization
     , sum(denum_ul_prb_utilization_percent)                                           as denum_ul_prb_utilization
     , ndp(sum(num_ul_prb_utilization_percent), sum(denum_ul_prb_utilization_percent)) as ul_prb_utilization
from r08.meas_4g_daily_bh_activeuser m
         join network_cell n on m.network_cell_id = n.id
         join ref_site r on n.site_id = r.site_id
where date between date_from('202352') and date_to('202352')
group by yearweek
       , date
       , branch
       , cluster
       , kota_kabupaten
order by branch, kota_kabupaten, cluster, date
;


-- DL_PRB_PAYLOAD
select yearweek
     , date
     , branch
     , cluster
     , kota_kabupaten
     , sum(num_dl_prb_utilization_percent)                                             as num_dl_prb_utilization
     , sum(denum_dl_prb_utilization_percent)                                           as denum_dl_prb_utilization
     , ndp(sum(num_dl_prb_utilization_percent), sum(denum_dl_prb_utilization_percent)) as dl_prb_utilization
     , sum(num_ul_prb_utilization_percent)                                             as num_ul_prb_utilization
     , sum(denum_ul_prb_utilization_percent)                                           as denum_ul_prb_utilization
     , ndp(sum(num_ul_prb_utilization_percent), sum(denum_ul_prb_utilization_percent)) as ul_prb_utilization
from r08.meas_4g_daily_bh_payload m
         join network_cell n on m.network_cell_id = n.id
         join ref_site r on n.site_id = r.site_id
where date between date_from('202352') and date_to('202352')
group by yearweek
       , date
       , branch
       , cluster
       , kota_kabupaten
order by branch, kota_kabupaten, cluster, date
;


-- DL_PRB
with master as (select yearweek
                     , date
                     , cluster
                     , kota_kabupaten
                     , n.site_id
                     , n.cell_name
                     , n.cell
                     , ndp(sum(num_dl_prb_utilization_percent), sum(denum_dl_prb_utilization_percent)) as dl_prb_utilization
                     , ndp(sum(num_ul_prb_utilization_percent), sum(denum_ul_prb_utilization_percent)) as ul_prb_utilization

                from r08.meas_4g_daily_bh_payload m
                         join network_cell n on m.network_cell_id = n.id
                         join ref_site r on n.site_id = r.site_id
                where date between date_from('202352') and date_to('202352')
                group by yearweek
                       , date
                       , cluster
                       , kota_kabupaten
                       , n.site_id
                       , n.cell_name
                       , n.cell)
select yearweek
     , date
     , cluster
     , kota_kabupaten
     , avg(dl_prb_utilization) as max_dl_prb_utilization
     , avg(ul_prb_utilization) as max_ul_prb_utilization
     , count(distinct site_id) as count_siteid
from master
group by yearweek
       , date
       , cluster
       , kota_kabupaten
order by kota_kabupaten, cluster, date
;
