improve map plot
Browse files
apps/kpi_analysis/gsm_capacity.py
CHANGED
@@ -5,6 +5,7 @@ import streamlit as st
|
|
5 |
from process_kpi.process_gsm_capacity import analyze_gsm_data
|
6 |
from utils.convert_to_excel import ( # Import convert_dfs from the appropriate module
|
7 |
convert_gsm_dfs,
|
|
|
8 |
)
|
9 |
from utils.kpi_analysis_utils import GsmCapacity
|
10 |
|
@@ -242,25 +243,78 @@ if (
|
|
242 |
)
|
243 |
st.plotly_chart(fig, use_container_width=True)
|
244 |
|
245 |
-
# create a map
|
246 |
st.markdown("***")
|
247 |
st.markdown(":blue[**Max TCH Call Blocking BH distribution**]")
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
lat="Latitude",
|
253 |
lon="Longitude",
|
254 |
-
color=
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
261 |
zoom=10,
|
262 |
height=600,
|
263 |
title="Max TCH Call Blocking BH distribution",
|
264 |
)
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
st.plotly_chart(fig, use_container_width=True)
|
|
|
5 |
from process_kpi.process_gsm_capacity import analyze_gsm_data
|
6 |
from utils.convert_to_excel import ( # Import convert_dfs from the appropriate module
|
7 |
convert_gsm_dfs,
|
8 |
+
save_dataframe,
|
9 |
)
|
10 |
from utils.kpi_analysis_utils import GsmCapacity
|
11 |
|
|
|
243 |
)
|
244 |
st.plotly_chart(fig, use_container_width=True)
|
245 |
|
246 |
+
# create a map plot with scatter_map with gsm_analysis_df and max_tch_call_blocking_bh
|
247 |
st.markdown("***")
|
248 |
st.markdown(":blue[**Max TCH Call Blocking BH distribution**]")
|
249 |
+
|
250 |
+
# Select and clean the necessary columns
|
251 |
+
map_df = gsm_analysis_df[
|
252 |
+
["code", "max_tch_call_blocking_bh", "Latitude", "Longitude"]
|
253 |
+
].dropna(subset=["code", "max_tch_call_blocking_bh", "Latitude", "Longitude"])
|
254 |
+
|
255 |
+
# Group by code and max max_tch_call_blocking_bh, keep first occurrence of other columns
|
256 |
+
map_df = (
|
257 |
+
map_df.groupby("code")
|
258 |
+
.agg(
|
259 |
+
{
|
260 |
+
"max_tch_call_blocking_bh": "max",
|
261 |
+
"Latitude": "first",
|
262 |
+
"Longitude": "first",
|
263 |
+
}
|
264 |
+
)
|
265 |
+
.reset_index()
|
266 |
+
)
|
267 |
+
# save_dataframe(map_df, "max_tch_call_blocking_bh_map")
|
268 |
+
# Create a color column based on the threshold
|
269 |
+
map_df["color"] = map_df["max_tch_call_blocking_bh"].apply(
|
270 |
+
lambda x: (
|
271 |
+
"Above Threshold" if x > tch_blocking_threshold else "Below Threshold"
|
272 |
+
)
|
273 |
+
)
|
274 |
+
|
275 |
+
# Apply minimum size to make small values more visible
|
276 |
+
min_bubble_size = 5 # Minimum size for visibility
|
277 |
+
max_bubble_size = 30 # Maximum size for scaling
|
278 |
+
|
279 |
+
# Scale the size to make small values more visible while maintaining relative sizes
|
280 |
+
size_scale = max_bubble_size / map_df["max_tch_call_blocking_bh"].max()
|
281 |
+
map_df["scaled_size"] = map_df["max_tch_call_blocking_bh"].apply(
|
282 |
+
lambda x: max(x * size_scale, min_bubble_size)
|
283 |
+
)
|
284 |
+
|
285 |
+
fig = px.scatter_map(
|
286 |
+
map_df,
|
287 |
lat="Latitude",
|
288 |
lon="Longitude",
|
289 |
+
color="color",
|
290 |
+
color_discrete_map={"Above Threshold": "red", "Below Threshold": "green"},
|
291 |
+
size="scaled_size",
|
292 |
+
size_max=max_bubble_size,
|
293 |
+
hover_data={
|
294 |
+
"code": True, # Show code in hover data
|
295 |
+
"max_tch_call_blocking_bh": ":.2f",
|
296 |
+
"scaled_size": False,
|
297 |
+
},
|
298 |
+
hover_name="code", # This will show as the title of the hover box
|
299 |
zoom=10,
|
300 |
height=600,
|
301 |
title="Max TCH Call Blocking BH distribution",
|
302 |
)
|
303 |
+
|
304 |
+
# Update traces to show code on bubbles and customize hover
|
305 |
+
fig.update_traces(
|
306 |
+
text=map_df["code"], # Show code on the bubble
|
307 |
+
textposition="middle center",
|
308 |
+
textfont=dict(size=18, color="black"),
|
309 |
+
# hovertemplate="<b>%{hovertext}</b><br>"
|
310 |
+
# + "Blocking: %{customdata[1]:.2f}%<extra></extra>",
|
311 |
+
)
|
312 |
+
|
313 |
+
# Adjust layout for better text visibility
|
314 |
+
fig.update_layout(
|
315 |
+
mapbox_style="open-street-map",
|
316 |
+
showlegend=True,
|
317 |
+
margin=dict(l=10, r=10, t=40, b=10),
|
318 |
+
)
|
319 |
+
|
320 |
st.plotly_chart(fig, use_container_width=True)
|