File size: 11,809 Bytes
123d5ff
06c863c
123d5ff
 
ccb28f5
123d5ff
fbf7879
50b11f5
 
 
 
9a4ad92
50b11f5
cbbcd31
a9f4212
cbbcd31
ad021df
 
bb3e08f
 
ad021df
 
cbbcd31
fbf7879
 
123d5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cae6a38
123d5ff
 
 
06c863c
123d5ff
 
06c863c
123d5ff
 
06c863c
123d5ff
 
cabf258
123d5ff
 
cabf258
bb3e08f
 
 
a9f4212
 
 
50b11f5
 
 
9a4ad92
 
 
123d5ff
 
 
 
 
 
 
 
 
cbbcd31
 
 
 
 
 
270acdd
cbbcd31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123d5ff
 
 
 
 
 
 
 
 
 
 
50b11f5
 
 
 
 
 
 
 
 
 
 
9a4ad92
 
 
 
 
 
 
 
 
 
 
cae6a38
 
 
fbf7879
 
cae6a38
 
 
 
fbf7879
 
 
 
 
 
 
50b11f5
 
123d5ff
 
ccb28f5
123d5ff
ccb28f5
123d5ff
 
 
 
 
56d8047
 
bb3e08f
a9f4212
123d5ff
 
 
ccb28f5
bb3e08f
123d5ff
 
 
56d8047
bb3e08f
a9f4212
123d5ff
 
 
ae5e7a8
 
 
 
 
 
a9f4212
ae5e7a8
fbf7879
123d5ff
ae5e7a8
 
 
 
 
 
123d5ff
 
 
 
 
ae5e7a8
123d5ff
 
 
 
 
 
 
ae5e7a8
123d5ff
 
 
 
bb3e08f
ad021df
bb3e08f
 
 
 
 
 
a9f4212
 
 
 
 
 
 
 
123d5ff
ae5e7a8
a9f4212
ae5e7a8
 
 
 
 
 
cbbcd31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50b11f5
 
 
 
 
 
9a4ad92
 
 
 
 
 
123d5ff
 
fbf7879
 
 
ccb28f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbf7879
 
 
cae6a38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbf7879
cae6a38
 
 
 
 
ccb28f5
 
 
 
 
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import time
from datetime import datetime

import streamlit as st
from st_aggrid import AgGrid, ColumnsAutoSizeMode

from apps.dump_analysis import dump_analysis_space
from queries.process_all_db import (
    process_all_tech_db,
    process_all_tech_db_with_stats,
    process_atoll_db,
    process_nice_db,
)
from queries.process_gsm import process_gsm_data_to_excel, process_gsm_data_to_kml
from queries.process_invunit import process_invunit_data_to_excel
from queries.process_lte import process_lte_data_to_excel, process_lte_data_to_kml

# from queries.process_mal import process_mal_data_to_excel
from queries.process_mrbts import process_mrbts_data_to_excel
from queries.process_neighbors import process_neighbors_data_to_excel

# from queries.process_trx import process_trx_with_bts_name_data_to_excel
from queries.process_wcdma import process_wcdma_data_to_excel, process_wcdma_data_to_kml
from utils.check_sheet_exist import DumpType, Technology, execute_checks_sheets_exist
from utils.utils_vars import GsmAnalysisData, UtilsVars, WcdmaAnalysisData

st.title("Database processing")

uploaded_file = st.file_uploader("Upload updated dump file", type="xlsb")


def process_database(process_func, database_type):
    if uploaded_file is not None:
        start_time = time.time()
        process_func(uploaded_file)
        execution_time = time.time() - start_time
        st.write(
            f"{database_type} database is generated. Execution time: {execution_time:.2f} seconds"
        )
        download_button(database_type)


@st.fragment()
def download_button(database_type):
    if database_type == "2G":
        data = UtilsVars.final_gsm_database
        file_name = f"2G database_{datetime.now()}.xlsx"
    elif database_type == "3G":
        data = UtilsVars.final_wcdma_database
        file_name = f"3G database_{datetime.now()}.xlsx"
    elif database_type == "LTE":
        data = UtilsVars.final_lte_database
        file_name = f"LTE database_{datetime.now()}.xlsx"
    elif database_type == "All":
        data = UtilsVars.final_all_database
        file_name = f"All databases_{datetime.now()}.xlsx"
    elif database_type == "NEI":
        data = UtilsVars.neighbors_database
        file_name = f"Neighbors databases_{datetime.now()}.xlsx"
    elif database_type == "MRBTS":
        data = UtilsVars.final_mrbts_database
        file_name = f"MRBTS database_{datetime.now()}.xlsx"
    elif database_type == "INVUNIT":
        data = UtilsVars.final_invunit_database
        file_name = f"INVUNIT database_{datetime.now()}.xlsx"
    elif database_type == "Custom":
        data = UtilsVars.final_atoll_database
        file_name = f"Custom database_{datetime.now()}.xlsx"
    elif database_type == "Nice":
        data = UtilsVars.final_nice_database
        file_name = f"Nice database_{datetime.now()}.xlsx"
    st.download_button(
        type="primary",
        label=f"Download {database_type} Database File",
        data=data,
        file_name=file_name,
        mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    )


def process_kml_database(process_func, database_type):
    if uploaded_file is not None:
        start_time = time.time()
        process_func(uploaded_file)
        execution_time = time.time() - start_time
        st.write(
            f"{database_type} KML is generated. Execution time: {execution_time:.2f} seconds"
        )
        kml_download_button(database_type)


@st.fragment()
def kml_download_button(database_type):
    if database_type == "2G":
        data = UtilsVars.gsm_kml_file
        file_name = f"2G kml_{datetime.now()}.kml"
    elif database_type == "3G":
        data = UtilsVars.wcdma_kml_file
        file_name = f"3G kml_{datetime.now()}.kml"
    elif database_type == "LTE":
        data = UtilsVars.lte_kml_file
        file_name = f"LTE kml_{datetime.now()}.kml"
    st.download_button(
        type="primary",
        label=f"Download {database_type} KML File",
        data=data,
        file_name=file_name,
        mime="application/vnd.google-earth.kml+xml",
    )


def execute_process_all_tech_db(uploaded_file):
    if uploaded_file is not None:
        start_time = time.time()
        process_all_tech_db(uploaded_file)
        execution_time = time.time() - start_time
        st.write(
            f"All databases are generated. Execution time: {execution_time:.2f} seconds"
        )
        download_button("All")


def execute_process_custom_db(uploaded_file):
    if uploaded_file is not None:
        start_time = time.time()
        process_atoll_db(uploaded_file)
        execution_time = time.time() - start_time
        st.write(
            f"ATL databases are generated. Execution time: {execution_time:.2f} seconds"
        )
        download_button("Custom")


def execute_process_nice_db(uploaded_file):
    if uploaded_file is not None:
        start_time = time.time()
        process_nice_db(uploaded_file)
        execution_time = time.time() - start_time
        st.write(
            f"Nice databases are generated. Execution time: {execution_time:.2f} seconds"
        )
        download_button("Nice")


# def execute_process_all_tech_db_with_stats(uploaded_file: str, region_list: list):
def execute_process_all_tech_db_with_stats(uploaded_file: str):

    if uploaded_file is not None:
        start_time = time.time()
        process_all_tech_db_with_stats(
            uploaded_file,
            #    region_list
        )
        execution_time = time.time() - start_time
        st.write(
            f"All databases are generated. Execution time: {execution_time:.2f} seconds"
        )
        download_button("All")


col1, col2, col3, col4, col5, col6 = st.columns(6)
col7, col8, col9, col10, col11, col12 = st.columns(6)
if uploaded_file is not None:
    # UtilsVars.file_path = uploaded_file

    try:

        execute_checks_sheets_exist(uploaded_file)
        if (
            Technology.gsm == False
            and Technology.wcdma == False
            and Technology.lte == False
            and Technology.neighbors == False
            and Technology.trx == False
            and Technology.mrbts == False
            and Technology.invunit == False
        ):
            st.error(
                """
                    Uploaded file does not contain required sheets for any technology.
                    "gsm": ["BTS", "BCF", "TRX","MAL"],
                    "wcdma": ["WCEL", "WBTS", "WNCEL"],
                    "lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
                    "neighbors": ["ADCE", "ADJS", "ADJI", "ADJG", "ADJW", "BTS", "WCEL"],
                    "trx": ["TRX", "BTS"],
                    "mrbts": ["MRBTS"],
                    "invunit": ["INVUNIT"]
                """
            )

        if (
            Technology.gsm == True
            and Technology.wcdma == True
            and Technology.lte == True
            and Technology.trx == True
            and Technology.mrbts == True
            and Technology.invunit == True
        ):
            DumpType.full_dump = True
            with col1:
                st.button(
                    "Generate All DBs",
                    on_click=lambda: execute_process_all_tech_db(uploaded_file),
                )
        if Technology.gsm == True:
            with col2:
                st.button(
                    "Generate 2G DB",
                    on_click=lambda: process_database(process_gsm_data_to_excel, "2G"),
                )
        if Technology.wcdma == True:
            with col3:
                st.button(
                    "Generate 3G DB",
                    on_click=lambda: process_database(
                        process_wcdma_data_to_excel, "3G"
                    ),
                )
        if Technology.lte == True:
            with col4:
                st.button(
                    "Generate LTE DB",
                    on_click=lambda: process_database(process_lte_data_to_excel, "LTE"),
                )
        if Technology.mrbts == True:
            with col5:
                st.button(
                    "Generate MRBTS",
                    on_click=lambda: process_database(
                        process_mrbts_data_to_excel, "MRBTS"
                    ),
                )
        if Technology.invunit == True:
            with col6:
                st.button(
                    "Generate INVUNIT",
                    on_click=lambda: process_database(
                        process_invunit_data_to_excel, "INVUNIT"
                    ),
                )

        if Technology.neighbors == True:
            with col7:
                st.button(
                    "Generate NEI DB",
                    on_click=lambda: process_database(
                        process_neighbors_data_to_excel, "NEI"
                    ),
                )
        if Technology.gsm == True:
            with col8:
                st.button(
                    "Generate 2G KML",
                    on_click=lambda: process_kml_database(
                        process_gsm_data_to_kml, "2G"
                    ),
                )

        if Technology.wcdma == True:
            with col9:
                st.button(
                    "Generate 3G KML",
                    on_click=lambda: process_kml_database(
                        process_wcdma_data_to_kml, "3G"
                    ),
                )

        if Technology.lte == True:
            with col10:
                st.button(
                    "Generate LTE KML",
                    on_click=lambda: process_kml_database(
                        process_lte_data_to_kml, "LTE"
                    ),
                )
        if DumpType.full_dump == True:
            with col11:
                st.button(
                    "Generate ATL DB",
                    on_click=lambda: execute_process_custom_db(uploaded_file),
                )
        if DumpType.full_dump == True:
            with col12:
                st.button(
                    "Generate Nice DB",
                    on_click=lambda: execute_process_nice_db(uploaded_file),
                )
    except Exception as e:
        st.error(f"Error: {e}")


######################## ANALYTICS AND STATS ####################################
@st.fragment
def table_data():
    if UtilsVars.all_db_dfs_names != []:
        selected_table = st.selectbox("Choose Data", UtilsVars.all_db_dfs_names)
        table_df = UtilsVars.all_db_dfs[
            UtilsVars.all_db_dfs_names.index(selected_table)
        ]
        st.write(f"### {selected_table} Data")
        AgGrid(
            table_df,
            fit_columns_on_grid_load=True,
            theme="streamlit",
            enable_enterprise_modules=True,
            filter=True,
            # columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
        )


if uploaded_file is not None:
    if DumpType.full_dump == True:
        # regions = st.multiselect(
        #     "Select the region(s) you want to analyze",
        #     ["Test BTS", "SKS", "SEG", "TBC", "KDL", "KKO", "GAO", "MPT", "KYS"],
        #     default=[
        #         "Test BTS",
        #         "SKS",
        #         "SEG",
        #         "TBC",
        #         "KDL",
        #         "KKO",
        #         "GAO",
        #         "MPT",
        #         "KYS",
        #     ],
        # )
        if st.button("Generate All DBs and Show Stats"):
            # if regions:
            execute_process_all_tech_db_with_stats(
                uploaded_file,
                #    regions
            )
            tab1, tab2 = st.tabs(["πŸ—ƒ Data", "πŸ“ˆ Chart"])
            with tab1:
                table_data()
            with tab2:
                dump_analysis_space()