a_pm_4g_cuct_all_day.sql 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. CREATE OR REPLACE FUNCTION app_screen.a_pm_4g_cuct_all_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. select
  28. a.city
  29. ,a.county
  30. ,b.vendor
  31. ,b.eci
  32. ,b.cellname
  33. from app_screen.county a
  34. left join pm_parse.per_cfg_cell b
  35. on a.city = replace(b.city,''市'','''') and a.county = b.quxian';
  36. execute v_sql;
  37. --插入电信工参
  38. v_sql := 'insert into a_pm_info
  39. (
  40. city
  41. ,county
  42. ,vendor
  43. ,eci
  44. ,cell_name
  45. )
  46. select
  47. city
  48. ,county
  49. ,vendor
  50. ,''127.''||enbid||''.''||cellid
  51. ,cell_name
  52. from pm_parse.pm_ct_cell_info_4g';
  53. execute v_sql;
  54. -- 取自忙时
  55. v_sql := 'drop table if exists a_pm_4g_cuct_all_day_tmp00';
  56. execute v_sql;
  57. v_sql := 'create temporary table a_pm_4g_cuct_all_day_tmp00
  58. (
  59. eci varchar
  60. ,total_tra_mb numeric
  61. )';
  62. execute v_sql;
  63. v_sql := 'insert into a_pm_4g_cuct_all_day_tmp00
  64. select
  65. eci,max(total_tra_mb)
  66. from pm_parse.pm_4g_hour_'|| vi_date ||'
  67. group by eci';
  68. execute v_sql;
  69. v_sql := 'drop table if exists a_pm_4g_cuct_all_day_tmp01';
  70. execute v_sql;
  71. v_sql := 'create temporary table a_pm_4g_cuct_all_day_tmp01
  72. (
  73. eci varchar
  74. ,dl_prb_utilization numeric
  75. )';
  76. execute v_sql;
  77. v_sql := 'insert into a_pm_4g_cuct_all_day_tmp01
  78. select
  79. coalesce(c.end_eci,a.eci),max(dl_prb_utilization)
  80. from pm_parse.pm_4g_hour_'|| vi_date ||' a
  81. join a_pm_4g_cuct_all_day_tmp00 b
  82. on a.eci = b.eci and a.total_tra_mb = b.total_tra_mb
  83. left join app_screen.nokia_eci_conf c --添加诺基亚eci映射关系表
  84. on a.eci = c.eci
  85. group by coalesce(c.end_eci,a.eci)';
  86. execute v_sql;
  87. v_sql := 'drop table if exists a_pm_4g_cuct_all_day_tmp02';
  88. execute v_sql;
  89. v_sql := 'create temporary table a_pm_4g_cuct_all_day_tmp02
  90. (
  91. eci varchar
  92. ,total_tra_mb numeric
  93. ,rrc_max numeric
  94. ,erab_suc numeric
  95. ,erab_req numeric
  96. ,rrc_suc numeric
  97. ,rrc_req numeric
  98. ,erab_abnormal_release numeric
  99. ,lte_drop numeric
  100. ,x2_ho_out_suc numeric
  101. ,s1_ho_out_suc numeric
  102. ,x2_ho_out_req numeric
  103. ,s1_ho_out_req numeric
  104. ,dl_speed_mbps numeric
  105. ,erab_suc_qci1 numeric
  106. ,erab_req_qci1 numeric
  107. ,erab_abnormal_qci1 numeric
  108. ,erab_normal_qci1 numeric
  109. ,ul_pdcp_package_drop numeric
  110. ,ul_pdcp_package_total numeric
  111. ,dl_pdcp_package_drop numeric
  112. ,dl_pdcp_package_total numeric
  113. )';
  114. execute v_sql;
  115. v_sql := 'insert into a_pm_4g_cuct_all_day_tmp02
  116. select
  117. coalesce(c.end_eci,a.eci)
  118. ,sum(total_tra_mb)
  119. ,sum(rrc_max)
  120. ,sum(erab_suc)
  121. ,sum(erab_req)
  122. ,sum(rrc_suc)
  123. ,sum(rrc_req)
  124. ,sum(erab_abnormal_release)
  125. ,sum(lte_drop)
  126. ,sum(x2_ho_out_suc)
  127. ,sum(s1_ho_out_suc)
  128. ,sum(x2_ho_out_req)
  129. ,sum(s1_ho_out_req)
  130. ,sum(dl_speed_mbps)
  131. ,sum(erab_suc_qci1)
  132. ,sum(erab_req_qci1)
  133. ,sum(erab_abnormal_qci1)
  134. ,sum(erab_normal_qci1)
  135. ,sum(ul_pdcp_package_drop)
  136. ,sum(ul_pdcp_package_total)
  137. ,sum(dl_pdcp_package_drop)
  138. ,sum(dl_pdcp_package_total)
  139. from pm_parse.pm_4g_day_'|| vi_date ||' a
  140. left join app_screen.nokia_eci_conf c --添加诺基亚eci映射关系表
  141. on a.eci = c.eci
  142. group by coalesce(c.end_eci,a.eci)';
  143. execute v_sql;
  144. -- 删除当前时间数据
  145. v_sql := 'delete from app_screen.a_pm_4g_cuct_all_day where sdate = '''|| v_date ||'''';
  146. execute v_sql;
  147. -- 插入目标数据
  148. v_sql := 'insert into app_screen.a_pm_4g_cuct_all_day
  149. (
  150. sdate
  151. ,city
  152. ,county
  153. ,cell_number
  154. ,dl_prb_utilization
  155. ,busy_avg_dl_prb_utilization
  156. ,total_tra_mb
  157. ,rrc_max
  158. ,radio_conn_suc_r
  159. ,lte_drop_r
  160. ,ho_out_suc_r
  161. ,dl_speed_mbps_avg_d
  162. ,erab_suc_r_qci1
  163. ,lte_drop_r_qci1
  164. ,ul_pdcp_package_drop_ratio_qci1
  165. ,dl_pdcp_package_drop_ratio_qci1
  166. )
  167. select
  168. '''|| v_date ||'''
  169. ,COALESCE(a.city,''合计'') city
  170. ,COALESCE(a.county,''合计'') county
  171. ,count(distinct d.eci) cell_number
  172. ,avg(c.dl_prb_utilization)*100 dl_prb_utilization
  173. ,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
  174. ,sum(d.total_tra_mb) total_tra_mb
  175. ,round(avg(d.rrc_max),0) rrc_max
  176. ,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
  177. ,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
  178. ,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
  179. ,round(avg(d.dl_speed_mbps),2) dl_speed_mbps_avg_d
  180. ,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
  181. ,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
  182. ,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
  183. ,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
  184. from a_pm_info a
  185. left join a_pm_4g_cuct_all_day_tmp01 c
  186. on a.eci = c.eci
  187. left join a_pm_4g_cuct_all_day_tmp02 d
  188. on a.eci = d.eci
  189. group by
  190. grouping sets((),(a.city),(a.city,a.county))';
  191. execute v_sql;
  192. -- 更新质差小区数量和占比
  193. v_sql := 'update app_screen.a_pm_4g_cuct_all_day a
  194. set poor_cell_num = COALESCE(b.poor_cell_num,0),poor_cell_ratio = COALESCE(b.poor_cell_ratio,0)
  195. from(
  196. select
  197. city
  198. ,county
  199. ,poor_cell_num
  200. ,poor_cell_ratio
  201. from app_screen.a_pm_4g_poor_cell_day
  202. where sdate = '''|| v_date ||'''
  203. and operators = ''联通''
  204. ) b
  205. where a.sdate = '''|| v_date ||'''
  206. and a.city = b.city
  207. and a.county = b.county';
  208. execute v_sql;
  209. --更新mr数据
  210. v_sql := 'update app_screen.a_pm_4g_cuct_all_day a
  211. set poor_samples_110 = b.poor_samples_110,rsrp_samples = b.rsrp_samples,cove_rage = b.cove_rage
  212. from app_screen.a_pm_4g_mr_cuct_all_day b
  213. where a.county = ''合计''
  214. and a.sdate = '''|| v_date ||'''
  215. and b.sdate = (select max(sdate) from app_screen.a_pm_4g_mr_cuct_all_day)
  216. and a.city = b.city';
  217. execute v_sql;
  218. return '0';
  219. END;
  220. $function$
  221. ;