a_pm_4g_ct_share_day.sql 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. CREATE OR REPLACE FUNCTION app_screen.a_pm_4g_ct_share_day(vi_date character varying)
  2. RETURNS text
  3. LANGUAGE plpgsql
  4. AS $function$
  5. DECLARE
  6. v_date timestamp;
  7. v_next_day timestamp;
  8. v_begin_time timestamp;
  9. v_sql text;
  10. BEGIN
  11. v_date := vi_date::timestamp;
  12. v_next_day := vi_date::timestamp + '1 day'::interval;
  13. v_begin_time := clock_timestamp();
  14. --插入电信工参
  15. v_sql := 'drop table if exists a_pm_info';
  16. execute v_sql;
  17. v_sql := 'create temporary table a_pm_info
  18. (
  19. city varchar
  20. ,county varchar
  21. ,vendor varchar
  22. ,eci varchar
  23. ,cell_name varchar
  24. )';
  25. execute v_sql;
  26. v_sql := 'insert into a_pm_info
  27. (
  28. city
  29. ,county
  30. ,vendor
  31. ,eci
  32. ,cell_name
  33. )
  34. select
  35. city
  36. ,county
  37. ,vendor
  38. ,''127.''||enbid||''.''||cellid
  39. ,cell_name
  40. from pm_parse.pm_ct_cell_info_4g';
  41. execute v_sql;
  42. -- 取自忙时
  43. v_sql := 'drop table if exists a_pm_4g_ct_share_day_tmp00';
  44. execute v_sql;
  45. v_sql := 'create temporary table a_pm_4g_ct_share_day_tmp00
  46. (
  47. eci varchar
  48. ,total_tra_mb numeric
  49. )';
  50. execute v_sql;
  51. v_sql := 'insert into a_pm_4g_ct_share_day_tmp00
  52. select
  53. eci,max(total_tra_mb)
  54. from pm_parse.pm_4g_hour_'|| vi_date ||'
  55. group by eci';
  56. execute v_sql;
  57. v_sql := 'drop table if exists a_pm_4g_ct_share_day_tmp01';
  58. execute v_sql;
  59. v_sql := 'create temporary table a_pm_4g_ct_share_day_tmp01
  60. (
  61. eci varchar
  62. ,dl_prb_utilization numeric
  63. )';
  64. execute v_sql;
  65. v_sql := 'insert into a_pm_4g_ct_share_day_tmp01
  66. select
  67. a.eci,max(dl_prb_utilization)
  68. from pm_parse.pm_4g_hour_'|| vi_date ||' a
  69. join a_pm_4g_ct_share_day_tmp00 b
  70. on a.eci = b.eci and a.total_tra_mb = b.total_tra_mb
  71. where a.isp = ''电信''
  72. group by a.eci';
  73. execute v_sql;
  74. v_sql := 'drop table if exists a_pm_4g_ct_share_day_tmp02';
  75. execute v_sql;
  76. v_sql := 'create temporary table a_pm_4g_ct_share_day_tmp02
  77. (
  78. eci varchar
  79. ,total_tra_mb numeric
  80. ,rrc_max numeric
  81. ,erab_suc numeric
  82. ,erab_req numeric
  83. ,rrc_suc numeric
  84. ,rrc_req numeric
  85. ,erab_abnormal_release numeric
  86. ,lte_drop numeric
  87. ,x2_ho_out_suc numeric
  88. ,s1_ho_out_suc numeric
  89. ,x2_ho_out_req numeric
  90. ,s1_ho_out_req numeric
  91. ,dl_speed_mbps numeric
  92. ,erab_suc_qci1 numeric
  93. ,erab_req_qci1 numeric
  94. ,erab_abnormal_qci1 numeric
  95. ,erab_normal_qci1 numeric
  96. ,ul_pdcp_package_drop numeric
  97. ,ul_pdcp_package_total numeric
  98. ,dl_pdcp_package_drop numeric
  99. ,dl_pdcp_package_total numeric
  100. )';
  101. execute v_sql;
  102. v_sql := 'insert into a_pm_4g_ct_share_day_tmp02
  103. select
  104. eci
  105. ,PDCP_SDU_VOL_UL_plmn2 + PDCP_SDU_VOL_DL_plmn2 total_tra_mb
  106. ,effectiveconnmean_plmn2 rrc_max
  107. ,erab_suc
  108. ,erab_req
  109. ,rrc_suc
  110. ,rrc_req
  111. ,erab_abnormal_release
  112. ,lte_drop
  113. ,x2_ho_out_suc
  114. ,s1_ho_out_suc
  115. ,x2_ho_out_req
  116. ,s1_ho_out_req
  117. ,dl_speed_mbps
  118. ,erab_suc_qci1
  119. ,erab_req_qci1
  120. ,erab_abnormal_qci1
  121. ,erab_normal_qci1
  122. ,ul_pdcp_package_drop
  123. ,ul_pdcp_package_total
  124. ,dl_pdcp_package_drop
  125. ,dl_pdcp_package_total
  126. from pm_parse.pm_4g_day_'|| vi_date ||'
  127. where isp = ''电信'' and share = ''是''';
  128. execute v_sql;
  129. -- 删除当前时间数据
  130. v_sql := 'delete from app_screen.a_pm_4g_ct_share_day where sdate = '''|| v_date ||'''';
  131. execute v_sql;
  132. -- 插入目标数据
  133. v_sql := 'insert into app_screen.a_pm_4g_ct_share_day
  134. (
  135. sdate
  136. ,city
  137. ,county
  138. ,cell_number
  139. ,dl_prb_utilization
  140. ,busy_avg_dl_prb_utilization
  141. ,total_tra_mb
  142. ,rrc_max
  143. ,radio_conn_suc_r
  144. ,lte_drop_r
  145. ,ho_out_suc_r
  146. ,dl_speed_mbps_avg_d
  147. ,erab_suc_r_qci1
  148. ,lte_drop_r_qci1
  149. ,ul_pdcp_package_drop_ratio_qci1
  150. ,dl_pdcp_package_drop_ratio_qci1
  151. )
  152. select
  153. '''|| v_date ||'''
  154. ,COALESCE(a.city,''合计'') city
  155. ,COALESCE(a.county,''合计'') county
  156. ,count(distinct d.eci) cell_number
  157. ,avg(c.dl_prb_utilization)*100 dl_prb_utilization
  158. ,case when count(distinct d.eci) = 0 then 0 else sum(case when c.dl_prb_utilization*100 > 65 then 1 else 0 end)*1.0/count(distinct d.eci)*100 end busy_avg_dl_prb_utilization
  159. ,sum(d.total_tra_mb) total_tra_mb
  160. ,round(avg(d.rrc_max),0) rrc_max
  161. ,round((case when sum(d.erab_req)=0 then 0 else (sum(d.erab_suc)/sum(d.erab_req)) end) *100,2) radio_conn_suc_r
  162. ,round((case when sum(d.lte_drop) = 0 then 0 else sum(d.erab_abnormal_release)/sum(d.lte_drop) end) *100,2) lte_drop_r
  163. ,round((case when sum(d.x2_ho_out_req+d.s1_ho_out_req) = 0 then 0 else sum(d.x2_ho_out_suc+d.s1_ho_out_suc)/sum(d.x2_ho_out_req+d.s1_ho_out_req) end) *100,2) ho_out_suc_r
  164. ,round(avg(d.dl_speed_mbps),2) dl_speed_mbps_avg_d
  165. ,round((case when sum(d.erab_req_qci1) = 0 then 0 else sum(d.erab_suc_qci1)/sum(d.erab_req_qci1) end) *100,2) erab_suc_r_qci1
  166. ,round((case when sum(d.erab_abnormal_qci1+d.erab_normal_qci1) = 0 then 0 else sum(d.erab_abnormal_qci1)/sum(d.erab_abnormal_qci1+d.erab_normal_qci1) end) *100,2) lte_drop_r_qci1
  167. ,round((case when sum(d.ul_pdcp_package_total) = 0 then 0 else sum(d.ul_pdcp_package_drop)/sum(d.ul_pdcp_package_total) end)*100,2) ul_pdcp_package_drop_ratio_qci1
  168. ,round((case when sum(d.dl_pdcp_package_total) = 0 then 0 else sum(d.dl_pdcp_package_drop)/sum(d.dl_pdcp_package_total) end)*100,2) dl_pdcp_package_drop_ratio_qci1
  169. from a_pm_info a
  170. left join a_pm_4g_ct_share_day_tmp01 c
  171. on a.eci = c.eci
  172. left join a_pm_4g_ct_share_day_tmp02 d
  173. on a.eci = d.eci
  174. group by
  175. grouping sets((),(a.city),(a.city,a.county))';
  176. execute v_sql;
  177. -- 更新质差小区数量和占比
  178. v_sql := 'update app_screen.a_pm_4g_ct_share_day a
  179. set poor_cell_num = b.poor_cell_num,poor_cell_ratio = b.poor_cell_ratio
  180. from(
  181. select
  182. city
  183. ,county
  184. ,poor_cell_num
  185. ,poor_cell_ratio
  186. from app_screen.a_pm_4g_poor_cell_day
  187. where sdate = '''|| v_date ||'''
  188. and operators = ''电信''
  189. ) b
  190. where a.sdate = '''|| v_date ||'''
  191. and a.city = b.city
  192. and a.county = b.county';
  193. execute v_sql;
  194. -- 更新mr
  195. v_sql := 'update app_screen.a_pm_4g_ct_share_day a
  196. set poor_samples_110 = b.poor_samples_110,rsrp_samples = b.rsrp_samples,cove_rage = b.cove_rage
  197. from app_screen.a_pm_4g_mr_ct_share_day b
  198. where a.county = ''合计''
  199. and a.sdate = '''|| v_date ||'''
  200. and b.sdate = (select max(sdate) from app_screen.a_pm_4g_mr_ct_share_day)
  201. and a.city = b.city';
  202. execute v_sql;
  203. return '0';
  204. END;
  205. $function$
  206. ;