File size: 4,549 Bytes
939b332
 
 
 
57fe85f
 
 
263b2ce
 
 
 
57fe85f
 
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57fe85f
939b332
 
57fe85f
 
 
263b2ce
 
 
939b332
57fe85f
939b332
 
 
 
 
 
 
57fe85f
 
 
 
 
 
 
939b332
57fe85f
 
 
 
263b2ce
57fe85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263b2ce
57fe85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263b2ce
 
 
 
 
 
 
 
 
57fe85f
 
 
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
import time

import streamlit as st

from queries.process_all_db import process_all_tech_db
from queries.process_gsm import process_gsm_data_to_excel
from queries.process_lte import process_lte_data_to_excel
from queries.process_neighbors import (
    process_neighbors_data,
    process_neighbors_data_to_excel,
)
from queries.process_wcdma import process_wcdma_data_to_excel
from utils.check_sheet_exist import Technology, execute_checks_sheets_exist
from utils.utils_vars import UtilsVars

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)


def download_button(database_type):
    if database_type == "2G":
        data = UtilsVars.final_gsm_database
        file_name = f"2G database_{time.time()}.xlsx"
    elif database_type == "3G":
        data = UtilsVars.final_wcdma_database
        file_name = f"3G database_{time.time()}.xlsx"
    elif database_type == "LTE":
        # data = UtilsVars.final_lte_database
        data = UtilsVars.final_lte_database
        file_name = f"LTE database_{time.time()}.xlsx"
    elif database_type == "All":
        data = UtilsVars.final_all_database
        file_name = f"All database_{time.time()}.xlsx"
    elif database_type == "NEI":
        data = UtilsVars.neighbors_database
        file_name = f"Neighbors database_{time.time()}.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 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")


col1, col2, col3, col4 = st.columns(4)
col5, col6, col7, col8 = st.columns(4)
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
        ):
            st.error(
                """
                     Uploaded file does not contain required sheets for any technology.
                    "gsm": ["BTS", "BCF", "TRX"],
                    "wcdma": ["WCEL", "WBTS", "WNCEL"],
                    "lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
                    "neighbors": ["ADCE", "ADJS", "ADJI", "ADJG", "ADJW", "BTS", "WCEL"],
                """
            )

        if Technology.gsm == True:
            with col1:
                st.button(
                    "Generate 2G DB",
                    on_click=lambda: process_database(process_gsm_data_to_excel, "2G"),
                )
        if Technology.wcdma == True:
            with col2:
                st.button(
                    "Generate 3G DB",
                    on_click=lambda: process_database(
                        process_wcdma_data_to_excel, "3G"
                    ),
                )
        if Technology.lte == True:
            with col3:
                st.button(
                    "Generate LTE DB",
                    on_click=lambda: process_database(process_lte_data_to_excel, "LTE"),
                )
        if Technology.gsm == True or Technology.wcdma == True or Technology.lte == True:
            with col4:
                st.button(
                    "Generate All DBs",
                    on_click=lambda: execute_process_all_tech_db(uploaded_file),
                )
        if Technology.neighbors == True:
            with col5:
                st.button(
                    "Generate NEI DB",
                    on_click=lambda: process_database(
                        process_neighbors_data_to_excel, "NEI"
                    ),
                    # on_click=lambda: process_neighbors_data(uploaded_file),
                )

    except Exception as e:
        st.error(f"Error: {e}")