Reorder traffic analysis pivot columns to display voice before data and pre before post periods
Browse files
apps/kpi_analysis/trafic_analysis.py
CHANGED
|
@@ -183,6 +183,24 @@ def merge_and_compare(df_2g, df_3g, df_lte, pre_range, post_range, last_period_r
|
|
| 183 |
/ sum_pivot.get(f"{metric}_pre", 1)
|
| 184 |
) * 100
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
avg_pivot = (
|
| 187 |
comparison.groupby(["code", "period"])[
|
| 188 |
["total_voice_trafic", "total_data_trafic"]
|
|
@@ -221,6 +239,24 @@ def merge_and_compare(df_2g, df_3g, df_lte, pre_range, post_range, last_period_r
|
|
| 221 |
}
|
| 222 |
)
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
return df, last_period, sum_pivot.round(2), avg_pivot.round(2)
|
| 225 |
|
| 226 |
|
|
|
|
| 183 |
/ sum_pivot.get(f"{metric}_pre", 1)
|
| 184 |
) * 100
|
| 185 |
|
| 186 |
+
# Reorder sum_pivot columns: voice before data, pre before post
|
| 187 |
+
sum_order = [
|
| 188 |
+
"code",
|
| 189 |
+
"total_voice_trafic_pre",
|
| 190 |
+
"total_voice_trafic_post",
|
| 191 |
+
"total_voice_trafic_diff",
|
| 192 |
+
"total_voice_trafic_diff_pct",
|
| 193 |
+
"total_data_trafic_pre",
|
| 194 |
+
"total_data_trafic_post",
|
| 195 |
+
"total_data_trafic_diff",
|
| 196 |
+
"total_data_trafic_diff_pct",
|
| 197 |
+
]
|
| 198 |
+
sum_existing_cols = [col for col in sum_order if col in sum_pivot.columns]
|
| 199 |
+
sum_remaining_cols = [
|
| 200 |
+
col for col in sum_pivot.columns if col not in sum_existing_cols
|
| 201 |
+
]
|
| 202 |
+
sum_pivot = sum_pivot[sum_existing_cols + sum_remaining_cols]
|
| 203 |
+
|
| 204 |
avg_pivot = (
|
| 205 |
comparison.groupby(["code", "period"])[
|
| 206 |
["total_voice_trafic", "total_data_trafic"]
|
|
|
|
| 239 |
}
|
| 240 |
)
|
| 241 |
|
| 242 |
+
# Reorder avg_pivot columns: voice before data, pre before post
|
| 243 |
+
avg_order = [
|
| 244 |
+
"code",
|
| 245 |
+
"avg_voice_trafic_pre",
|
| 246 |
+
"avg_voice_trafic_post",
|
| 247 |
+
"avg_voice_trafic_diff",
|
| 248 |
+
"avg_voice_trafic_diff_pct",
|
| 249 |
+
"avg_data_trafic_pre",
|
| 250 |
+
"avg_data_trafic_post",
|
| 251 |
+
"avg_data_trafic_diff",
|
| 252 |
+
"avg_data_trafic_diff_pct",
|
| 253 |
+
]
|
| 254 |
+
avg_existing_cols = [col for col in avg_order if col in avg_pivot.columns]
|
| 255 |
+
avg_remaining_cols = [
|
| 256 |
+
col for col in avg_pivot.columns if col not in avg_existing_cols
|
| 257 |
+
]
|
| 258 |
+
avg_pivot = avg_pivot[avg_existing_cols + avg_remaining_cols]
|
| 259 |
+
|
| 260 |
return df, last_period, sum_pivot.round(2), avg_pivot.round(2)
|
| 261 |
|
| 262 |
|