File size: 11,575 Bytes
b29ed17
 
 
 
 
 
 
 
5113cfc
b29ed17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d12505
b29ed17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
031d4db
 
b29ed17
5113cfc
031d4db
 
b29ed17
 
 
 
 
 
 
 
031d4db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import pandas as pd
import plotly.express as px
import streamlit as st

from process_kpi.process_wcel_capacity import (
    WcelCapacity,
    load_and_process_wcel_capacity_data,
)
from utils.convert_to_excel import convert_wcel_capacity_dfs

# Streamlit UI

st.title(" 📊 WCEL Capacity Analysis")
doc_col, image_col = st.columns(2)

with doc_col:
    st.write(
        """This app allows you to analyze the capacity of WCELS in a network. 
        It provides insights into the utilization of BB and CE resources, 
        helping you identify potential capacity issues and plan for upgrades.
        
        The report should be run with a minimum of 3 days of data.
        - Daily Aggregated
        - WCEL level
        - Exported in CSV format.
        """
    )

with image_col:
    st.image("./assets/wcel_capacity.png", width=400)

uploaded_file = st.file_uploader(
    "Upload WCEL capacity report in CSV format", type="csv"
)

param_col1, param_col2, param_col3 = st.columns(3)
param_col4, param_col5, param_col6 = st.columns(3)


if uploaded_file is not None:
    WcelCapacity.final_results = None
    with param_col1:
        num_last_days = st.number_input(
            "Number of days for analysis",
            min_value=3,
            max_value=30,
            value=7,
        )
    with param_col2:
        num_threshold_days = st.number_input(
            "Number of days for threshold",
            min_value=1,
            max_value=30,
            value=2,
        )
    with param_col3:
        availability_threshold = st.number_input(
            "Availability threshold (%)", value=99, min_value=0, max_value=100
        )
    with param_col4:
        iub_frameloss_threshold = st.number_input(
            "IUB frameloss threshold (%)",
            value=100,
            min_value=0,
            max_value=10000000,
        )
    with param_col5:
        hsdpa_congestion_rate_iub_threshold = st.number_input(
            "HSDPA Congestion Rate IUB threshold (%)",
            value=10,
            min_value=0,
            max_value=100,
        )
    with param_col6:
        fails_treshold = st.number_input(
            "Fails threshold (%)", value=10, min_value=0, max_value=10000000
        )

    if st.button("Analyze Data", type="primary"):
        with st.spinner("Processing data..."):
            results = load_and_process_wcel_capacity_data(
                uploaded_file,
                num_last_days,
                num_threshold_days,
                availability_threshold,
                iub_frameloss_threshold,
                hsdpa_congestion_rate_iub_threshold,
                fails_treshold,
            )

        if results is not None:
            wcel_analysis_df = results[0]
            kpi_df = results[1]

            WcelCapacity.final_results = convert_wcel_capacity_dfs(
                [wcel_analysis_df, kpi_df], ["wcel_analysis", "kpi"]
            )
            st.download_button(
                on_click="ignore",
                type="primary",
                label="Download the Analysis Report",
                data=WcelCapacity.final_results,
                file_name="WCEL_Capacity_Report.xlsx",
                mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            )
        st.write(wcel_analysis_df)
        # Add dataframe and Bar chart with "final_comments" distribution
        st.markdown("***")
        st.markdown(":blue[**Final comment distribution**]")
        final_comments_df = (
            wcel_analysis_df.groupby("final_comments")
            .size()
            .reset_index(name="count")
            .sort_values(by="count", ascending=False)
        )
        final_comments_col1, final_comments_col2 = st.columns((1, 3))
        with final_comments_col1:
            st.write(final_comments_df)
        with final_comments_col2:
            fig = px.bar(
                final_comments_df,
                x="final_comments",
                y="count",
                title="Final Comments Distribution",
                text="count",
            )
            fig.update_traces(textposition="outside")
            fig.update_layout(height=600)
            st.plotly_chart(fig)

        # Add dataframe and Pie chart with "operational_comments" distribution
        st.markdown("***")
        st.markdown(":blue[**Operational comment distribution**]")
        operational_comments_df = (
            wcel_analysis_df.groupby("operational_comments")
            .size()
            .reset_index(name="count")
            .sort_values(by="count", ascending=False)
        )
        operational_comments_df["percent"] = (
            operational_comments_df["count"] / operational_comments_df["count"].sum()
        ) * 100
        operational_comments_col1, operational_comments_col2 = st.columns((1, 3))
        with operational_comments_col1:
            st.write(operational_comments_df)
        with operational_comments_col2:
            fig = px.pie(
                operational_comments_df,
                names="operational_comments",
                values="count",
                hover_name="operational_comments",
                hover_data=["count", "percent"],
                title="Operational Comments Distribution",
            )
            fig.update_layout(height=600)
            fig.update_traces(
                texttemplate="<b>%{label}</b><br> %{value}  <b>(%{customdata[1]:.1f}%)</b>",
                textfont_size=15,
                textposition="outside",
            )
            st.plotly_chart(fig)

        # Add dataframe and Bar chart with "operational_comments" distribution per Region
        st.markdown("***")
        st.markdown(":blue[**Operational comment distribution per Region**]")
        operational_comments_df = (
            wcel_analysis_df.groupby(["Region", "operational_comments"])
            .size()
            .reset_index(name="count")
            .sort_values(by="count", ascending=False)
        )
        operational_comments_col1, operational_comments_col2 = st.columns((1, 3))
        with operational_comments_col1:
            st.write(operational_comments_df)
        with operational_comments_col2:
            fig = px.bar(
                operational_comments_df,
                x="Region",
                y="count",
                color="operational_comments",
                title="Operational Comments Distribution per Region",
                text="count",
            )
            fig.update_traces(textposition="outside")
            fig.update_layout(height=600)
            st.plotly_chart(fig)

        # Add dataframe and Pie chart with "fails_comments" distribution
        st.markdown("***")
        st.markdown(":blue[**Fails comment distribution**]")
        fails_comments_df = (
            wcel_analysis_df.groupby("fails_comments")
            .size()
            .reset_index(name="count")
            .sort_values(by="count", ascending=False)
        )

        # replace empty strings with "Cell OK"
        fails_comments_df["fails_comments"] = fails_comments_df[
            "fails_comments"
        ].replace("", "Cell OK")

        fails_comments_df["percent"] = (
            fails_comments_df["count"] / fails_comments_df["count"].sum()
        ) * 100
        fails_comments_col1, fails_comments_col2 = st.columns((1, 3))
        with fails_comments_col1:
            st.write(fails_comments_df)
        with fails_comments_col2:
            fig = px.pie(
                fails_comments_df,
                names="fails_comments",
                values="count",
                hover_name="fails_comments",
                hover_data=["count", "percent"],
                title="Fails Comments Distribution",
            )
            fig.update_layout(height=600)
            fig.update_traces(
                texttemplate="<b>%{label}</b><br> %{value}  <b>(%{customdata[1]:.1f}%)</b>",
                textfont_size=15,
                textposition="outside",
            )
            st.plotly_chart(fig)

        # Add dataframe and Bar chart with "fails_comments" distribution per Region
        st.markdown("***")
        st.markdown(":blue[**Fails comment distribution per Region**]")
        fails_comments_df = (
            wcel_analysis_df.groupby(["Region", "fails_comments"])
            .size()
            .reset_index(name="count")
            .sort_values(by="count", ascending=False)
        )

        # replace empty strings with "Cell OK"
        fails_comments_df["fails_comments"] = fails_comments_df[
            "fails_comments"
        ].replace("", "Cell OK")

        fails_comments_col1, fails_comments_col2 = st.columns((1, 3))
        with fails_comments_col1:
            st.write(fails_comments_df)
        with fails_comments_col2:
            fig = px.bar(
                fails_comments_df,
                x="Region",
                y="count",
                color="fails_comments",
                title="Fails Comments Distribution per Region",
                text="count",
            )
            fig.update_traces(textposition="outside", textfont_size=15)
            fig.update_layout(height=600)
            st.plotly_chart(fig)

        # create a map plot with scatter_map with code ,Longitude,Latitude,fails_comments
        st.markdown("***")
        st.markdown(":blue[**Fails comments distribution**]")
        fails_comments_map_df = wcel_analysis_df[
            ["code", "Longitude", "Latitude", "fails_comments"]
        ].dropna(subset=["code", "Longitude", "Latitude", "fails_comments"])

        # replace empty strings with "Cell OK"
        fails_comments_map_df["fails_comments"] = fails_comments_map_df[
            "fails_comments"
        ].replace("", "Cell OK")

        # add size column equalt to 20
        fails_comments_map_df["size"] = 20

        fig = px.scatter_map(
            fails_comments_map_df,
            lat="Latitude",
            lon="Longitude",
            color="fails_comments",
            size="size",
            zoom=10,
            height=600,
            title="Fails comments distribution",
            hover_data={
                "code": True,
                "fails_comments": True,
            },
            hover_name="code",
        )
        fig.update_layout(mapbox_style="open-street-map")
        st.plotly_chart(fig, use_container_width=True)

        # create a map plot with scatter_map with code ,Longitude,Latitude,operational_comments
        operational_comments_map_df = wcel_analysis_df[
            ["code", "Longitude", "Latitude", "operational_comments"]
        ].dropna(subset=["code", "Longitude", "Latitude", "operational_comments"])

        # replace empty strings with "Cell OK"
        operational_comments_map_df["operational_comments"] = (
            operational_comments_map_df["operational_comments"].replace("", "Cell OK")
        )

        # add size column equalt to 20
        operational_comments_map_df["size"] = 20

        fig = px.scatter_map(
            operational_comments_map_df,
            lat="Latitude",
            lon="Longitude",
            color="operational_comments",
            size="size",
            zoom=10,
            height=600,
            title="Operational comments distribution",
            hover_data={
                "code": True,
                "operational_comments": True,
            },
            hover_name="code",
        )
        fig.update_layout(mapbox_style="open-street-map")
        st.plotly_chart(fig, use_container_width=True)