lte drop trafic app
Browse files- app.py +4 -0
- apps/kpi_analysis/lte_drop_trafic.py +161 -0
- assets/traffic_drop.png +0 -0
app.py
CHANGED
|
@@ -158,6 +158,10 @@ if check_password():
|
|
| 158 |
"apps/kpi_analysis/lte_capacity.py",
|
| 159 |
title=" π LTE Capacity Analysis",
|
| 160 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
],
|
| 162 |
"Paging Analysis": [
|
| 163 |
st.Page(
|
|
|
|
| 158 |
"apps/kpi_analysis/lte_capacity.py",
|
| 159 |
title=" π LTE Capacity Analysis",
|
| 160 |
),
|
| 161 |
+
st.Page(
|
| 162 |
+
"apps/kpi_analysis/lte_drop_trafic.py",
|
| 163 |
+
title=" π LTE Drop Traffic Analysis",
|
| 164 |
+
),
|
| 165 |
],
|
| 166 |
"Paging Analysis": [
|
| 167 |
st.Page(
|
apps/kpi_analysis/lte_drop_trafic.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from io import BytesIO
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
import streamlit as st
|
| 6 |
+
|
| 7 |
+
from utils.utils_vars import get_physical_db
|
| 8 |
+
|
| 9 |
+
st.title("LTE Cell Traffic Drop Detection")
|
| 10 |
+
doc_col, image_col = st.columns(2)
|
| 11 |
+
|
| 12 |
+
with doc_col:
|
| 13 |
+
st.write(
|
| 14 |
+
"""
|
| 15 |
+
This App allow you to detect cells with significant traffic drop in LTE Network.
|
| 16 |
+
- Upload traffic CSV file
|
| 17 |
+
- Select number of last days for drop analysis
|
| 18 |
+
- Select loss percentage threshold
|
| 19 |
+
"""
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
with image_col:
|
| 23 |
+
st.image("./assets/traffic_drop.png", width=250)
|
| 24 |
+
|
| 25 |
+
uploaded_file = st.file_uploader("Upload traffic CSV file", type=["csv"])
|
| 26 |
+
|
| 27 |
+
if uploaded_file:
|
| 28 |
+
df = pd.read_csv(uploaded_file, sep=";")
|
| 29 |
+
|
| 30 |
+
df["PERIOD_START_TIME"] = pd.to_datetime(df["PERIOD_START_TIME"], format="%m.%d.%Y")
|
| 31 |
+
df.sort_values("PERIOD_START_TIME", inplace=True)
|
| 32 |
+
|
| 33 |
+
df["Total_Traffic"] = (
|
| 34 |
+
df["4G/LTE DL Traffic Volume (GBytes)"]
|
| 35 |
+
+ df["4G/LTE UL Traffic Volume (GBytes)"]
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
unique_dates = sorted(df["PERIOD_START_TIME"].unique())
|
| 39 |
+
last_n_days = st.slider(
|
| 40 |
+
"Select number of last days for drop analysis",
|
| 41 |
+
1,
|
| 42 |
+
min(10, len(unique_dates) - 1),
|
| 43 |
+
2,
|
| 44 |
+
)
|
| 45 |
+
treshold_percent = st.slider("Loss percentage threshold", 10, 100, 50)
|
| 46 |
+
|
| 47 |
+
last_days = unique_dates[-last_n_days:]
|
| 48 |
+
long_term_days = unique_dates[:-last_n_days]
|
| 49 |
+
|
| 50 |
+
last_df = df[df["PERIOD_START_TIME"].isin(last_days)]
|
| 51 |
+
long_term_df = df[df["PERIOD_START_TIME"].isin(long_term_days)]
|
| 52 |
+
|
| 53 |
+
avg_last = last_df.groupby("LNCEL name")["Total_Traffic"].mean()
|
| 54 |
+
avg_long = long_term_df.groupby("LNCEL name")["Total_Traffic"].mean()
|
| 55 |
+
|
| 56 |
+
result = pd.DataFrame(
|
| 57 |
+
{"avg_long_term": avg_long, "avg_last_days": avg_last}
|
| 58 |
+
).dropna()
|
| 59 |
+
|
| 60 |
+
result["drop_%"] = (
|
| 61 |
+
(result["avg_long_term"] - result["avg_last_days"])
|
| 62 |
+
/ result["avg_long_term"]
|
| 63 |
+
* 100
|
| 64 |
+
)
|
| 65 |
+
result = result[result["drop_%"] >= treshold_percent]
|
| 66 |
+
result = result.reset_index()
|
| 67 |
+
|
| 68 |
+
st.subheader("Cells with Significant Traffic Drop")
|
| 69 |
+
st.dataframe(result)
|
| 70 |
+
|
| 71 |
+
def convert_df(df: pd.DataFrame) -> bytes:
|
| 72 |
+
output = BytesIO()
|
| 73 |
+
df.to_excel(output, index=False)
|
| 74 |
+
processed_data = output.getvalue()
|
| 75 |
+
return processed_data
|
| 76 |
+
|
| 77 |
+
if not result.empty:
|
| 78 |
+
st.download_button(
|
| 79 |
+
label="π₯ Download affected cells",
|
| 80 |
+
data=convert_df(result),
|
| 81 |
+
file_name="traffic_drop_cells.xlsx",
|
| 82 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 83 |
+
type="primary",
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
@st.fragment
|
| 87 |
+
def trend_plot():
|
| 88 |
+
st.subheader("Traffic Trend Plot")
|
| 89 |
+
default_cell = result["LNCEL name"].iloc[0]
|
| 90 |
+
selected_cell = st.selectbox(
|
| 91 |
+
"Select cell to plot",
|
| 92 |
+
result["LNCEL name"].unique(),
|
| 93 |
+
index=result["LNCEL name"].unique().tolist().index(default_cell),
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
if selected_cell:
|
| 97 |
+
trend_df = df[df["LNCEL name"].eq(selected_cell)]
|
| 98 |
+
fig = px.line(
|
| 99 |
+
trend_df,
|
| 100 |
+
x="PERIOD_START_TIME",
|
| 101 |
+
y="Total_Traffic",
|
| 102 |
+
title="Traffic Trends",
|
| 103 |
+
markers=True,
|
| 104 |
+
height=700,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
if selected_cell in avg_long:
|
| 108 |
+
fig.add_shape(
|
| 109 |
+
type="line",
|
| 110 |
+
x0=trend_df["PERIOD_START_TIME"].min(),
|
| 111 |
+
x1=trend_df["PERIOD_START_TIME"].max(),
|
| 112 |
+
y0=avg_long[selected_cell],
|
| 113 |
+
y1=avg_long[selected_cell],
|
| 114 |
+
line=dict(color="blue", dash="dot"),
|
| 115 |
+
name=f"{selected_cell} Long Term Avg",
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
if last_days:
|
| 119 |
+
start_date = pd.to_datetime(str(last_days[0]))
|
| 120 |
+
fig.add_shape(
|
| 121 |
+
type="line",
|
| 122 |
+
x0=start_date,
|
| 123 |
+
x1=start_date,
|
| 124 |
+
y0=0,
|
| 125 |
+
y1=trend_df["Total_Traffic"].max(),
|
| 126 |
+
line=dict(color="red", dash="dash"),
|
| 127 |
+
name="Start of Last Days",
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 131 |
+
|
| 132 |
+
trend_plot()
|
| 133 |
+
|
| 134 |
+
st.subheader("Map of Affected Cells (Bubble Size = Drop %)")
|
| 135 |
+
result_map = result.copy()
|
| 136 |
+
physical_db = get_physical_db()
|
| 137 |
+
|
| 138 |
+
# Add code column to physical_db element before _
|
| 139 |
+
physical_db["code"] = physical_db["Code_Sector"].str.split("_").str[0]
|
| 140 |
+
# add code column to result_map
|
| 141 |
+
result_map["code"] = result_map["LNCEL name"].str.split("_").str[0]
|
| 142 |
+
|
| 143 |
+
result_map = pd.merge(result_map, physical_db, on="code", how="left")
|
| 144 |
+
|
| 145 |
+
result_map["Latitude"] = result_map["Latitude"]
|
| 146 |
+
result_map["Longitude"] = result_map["Longitude"]
|
| 147 |
+
fig_map = px.scatter_map(
|
| 148 |
+
result_map,
|
| 149 |
+
lat="Latitude",
|
| 150 |
+
lon="Longitude",
|
| 151 |
+
size="drop_%",
|
| 152 |
+
color=result_map["drop_%"],
|
| 153 |
+
color_continuous_scale="reds",
|
| 154 |
+
hover_name="LNCEL name",
|
| 155 |
+
zoom=6,
|
| 156 |
+
height=600,
|
| 157 |
+
title="Dropped Cells Map",
|
| 158 |
+
map_style="satellite-streets",
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
st.plotly_chart(fig_map, use_container_width=True)
|
assets/traffic_drop.png
ADDED
|