DavMelchi commited on
Commit
57fe85f
·
1 Parent(s): 1a209e6

check existing sheet if dump and DL for all BD

Browse files
.gitignore CHANGED
@@ -1,5 +1,4 @@
1
  /.history
2
  /.venv
3
  /__pycache__
4
- /.github
5
  __pycache__
 
1
  /.history
2
  /.venv
3
  /__pycache__
 
4
  __pycache__
README.md CHANGED
@@ -7,4 +7,36 @@ sdk: streamlit
7
  sdk_version: 1.37.1
8
  app_file: app.py
9
  pinned: false
10
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  sdk_version: 1.37.1
8
  app_file: app.py
9
  pinned: false
10
+ ---
11
+
12
+ ## Db Query
13
+
14
+ This is a Streamlit app for generating 2G, 3G, and LTE databases from an Excel dump file. The app reads the dump file and processes the data. The data is then saved to an Excel file. The Excel file is then downloaded.
15
+
16
+ ## How to use
17
+
18
+ 1. Run the app by executing `streamlit run app.py` in the terminal.
19
+ 2. Upload the dump file to the app.
20
+ 3. Click the buttons to generate the databases.
21
+ 4. Download the databases.
22
+
23
+ ## How it works
24
+
25
+ The app reads the dump file and processes the data. The data is then saved to an excel file. The excel file is then downloaded.
26
+
27
+ ## Why
28
+
29
+ The app is a simple way to generate the databases from the dump file. It saves time and effort.
30
+
31
+ ## Hosted Version
32
+
33
+ You can access the hosted version of the app at [https://davmelchi-db-query.hf.space/](https://davmelchi-db-query.hf.space/).
34
+
35
+ ## TODO
36
+
37
+ - [*] check if required sheets exist in the dump file
38
+ - [*] Add a download button for all databases
39
+ - [ ] Add option to download Neighbors database
40
+ - [ ] Add dashboards for each database (Count of NE)
41
+ - [ ] Add the ability to select columns
42
+ - [ ] Error handling
app.py CHANGED
@@ -2,9 +2,11 @@ import time
2
 
3
  import streamlit as st
4
 
5
- from queries.process_gsm import process_gsm_data
6
- from queries.process_lte import process_lte_data
7
- from queries.process_wcdma import process_wcdma_data
 
 
8
  from utils.utils_vars import UtilsVars
9
 
10
  st.title("Database processing")
@@ -31,9 +33,14 @@ def download_button(database_type):
31
  data = UtilsVars.final_wcdma_database
32
  file_name = f"3G database_{time.time()}.xlsx"
33
  elif database_type == "LTE":
 
34
  data = UtilsVars.final_lte_database
35
  file_name = f"LTE database_{time.time()}.xlsx"
 
 
 
36
  st.download_button(
 
37
  label=f"Download {database_type} Database File",
38
  data=data,
39
  file_name=file_name,
@@ -41,20 +48,62 @@ def download_button(database_type):
41
  )
42
 
43
 
44
- col1, col2, col3 = st.columns(3)
45
- if uploaded_file is not None:
46
- with col1:
47
- st.button(
48
- "Generate 2G Database",
49
- on_click=lambda: process_database(process_gsm_data, "2G"),
50
- )
51
- with col2:
52
- st.button(
53
- "Generate 3G Database",
54
- on_click=lambda: process_database(process_wcdma_data, "3G"),
55
- )
56
- with col3:
57
- st.button(
58
- "Generate LTE Database",
59
- on_click=lambda: process_database(process_lte_data, "LTE"),
60
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import streamlit as st
4
 
5
+ from queries.process_all_db import process_all_tech_db
6
+ from queries.process_gsm import process_gsm_data_to_excel
7
+ from queries.process_lte import process_lte_data_to_excel
8
+ from queries.process_wcdma import process_wcdma_data_to_excel
9
+ from utils.check_sheet_exist import Technology, execute_checks_sheets_exist
10
  from utils.utils_vars import UtilsVars
11
 
12
  st.title("Database processing")
 
33
  data = UtilsVars.final_wcdma_database
34
  file_name = f"3G database_{time.time()}.xlsx"
35
  elif database_type == "LTE":
36
+ # data = UtilsVars.final_lte_database
37
  data = UtilsVars.final_lte_database
38
  file_name = f"LTE database_{time.time()}.xlsx"
39
+ elif database_type == "All":
40
+ data = UtilsVars.final_all_database
41
+ file_name = f"All database_{time.time()}.xlsx"
42
  st.download_button(
43
+ type="primary",
44
  label=f"Download {database_type} Database File",
45
  data=data,
46
  file_name=file_name,
 
48
  )
49
 
50
 
51
+ def execute_process_all_tech_db(uploaded_file):
52
+ if uploaded_file is not None:
53
+ start_time = time.time()
54
+ process_all_tech_db(uploaded_file)
55
+ execution_time = time.time() - start_time
56
+ st.write(
57
+ f"All databases are generated. Execution time: {execution_time:.2f} seconds"
 
 
 
 
 
 
 
 
 
58
  )
59
+ download_button("All")
60
+
61
+
62
+ col1, col2, col3, col4 = st.columns(4)
63
+ if uploaded_file is not None:
64
+ # UtilsVars.file_path = uploaded_file
65
+ try:
66
+ execute_checks_sheets_exist(uploaded_file)
67
+ if (
68
+ Technology.gsm == False
69
+ and Technology.wcdma == False
70
+ and Technology.lte == False
71
+ ):
72
+ st.error(
73
+ """
74
+ Uploaded file does not contain required sheets for any technology.
75
+ "gsm": ["BTS", "BCF", "TRX"],
76
+ "wcdma": ["WCEL", "WBTS", "WNCEL"],
77
+ "lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
78
+ """
79
+ )
80
+
81
+ if Technology.gsm == True:
82
+ with col1:
83
+ st.button(
84
+ "Generate 2G DB",
85
+ on_click=lambda: process_database(process_gsm_data_to_excel, "2G"),
86
+ )
87
+ if Technology.wcdma == True:
88
+ with col2:
89
+ st.button(
90
+ "Generate 3G DB",
91
+ on_click=lambda: process_database(
92
+ process_wcdma_data_to_excel, "3G"
93
+ ),
94
+ )
95
+ if Technology.lte == True:
96
+ with col3:
97
+ st.button(
98
+ "Generate LTE DB",
99
+ on_click=lambda: process_database(process_lte_data_to_excel, "LTE"),
100
+ )
101
+ if Technology.gsm == True or Technology.wcdma == True or Technology.lte == True:
102
+ with col4:
103
+ st.button(
104
+ "Generate All DBs",
105
+ on_click=lambda: execute_process_all_tech_db(uploaded_file),
106
+ )
107
+
108
+ except Exception as e:
109
+ st.error(f"Error: {e}")
queries/process_all_db.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from queries.process_gsm import process_gsm_data
2
+ from queries.process_lte import process_lte_data
3
+ from queries.process_wcdma import process_wcdma_data
4
+ from utils.convert_to_excel import convert_dfs
5
+ from utils.utils_vars import UtilsVars
6
+
7
+
8
+ def process_all_tech_db(filepath: str):
9
+ UtilsVars.all_db_dfs.clear()
10
+ process_gsm_data(filepath)
11
+ process_wcdma_data(filepath)
12
+ process_lte_data(filepath)
13
+
14
+ UtilsVars.final_all_database = convert_dfs(
15
+ UtilsVars.all_db_dfs, ["GSM", "WCDMA", "LTE_FDD", "LTE_TDD"]
16
+ )
queries/process_gsm.py CHANGED
@@ -107,4 +107,12 @@ def process_gsm_data(file_path: str):
107
  # save_dataframe(df_trx, "trx")
108
  # df_2g2 = save_dataframe(df_2g, "2g")
109
 
110
- UtilsVars.final_gsm_database = convert_dfs([df_2g], ["GSM"])
 
 
 
 
 
 
 
 
 
107
  # save_dataframe(df_trx, "trx")
108
  # df_2g2 = save_dataframe(df_2g, "2g")
109
 
110
+ UtilsVars.all_db_dfs.append(df_2g)
111
+ # UtilsVars.final_gsm_database = convert_dfs([df_2g], ["GSM"])
112
+ # UtilsVars.final_gsm_database = [df_2g]
113
+ return df_2g
114
+
115
+
116
+ def process_gsm_data_to_excel(file_path: str):
117
+ gsm_dfs = process_gsm_data(file_path)
118
+ UtilsVars.final_gsm_database = convert_dfs([gsm_dfs], ["GSM"])
queries/process_lte.py CHANGED
@@ -139,10 +139,17 @@ def process_lte_data(file_path: str):
139
  # Save dataframes
140
  # save_dataframe(df_fdd_final, "fdd")
141
  # save_dataframe(df_tdd_final, "tdd")
 
142
 
143
- UtilsVars.final_lte_database = convert_dfs(
144
- [df_fdd_final, df_tdd_final], ["lte_fdd", "lte_tdd"]
145
- )
 
 
 
 
 
 
146
 
147
 
148
  # process_lte_data(r"data2\20240805_5810_05082024_Dump.xml.gz.xlsb")
 
139
  # Save dataframes
140
  # save_dataframe(df_fdd_final, "fdd")
141
  # save_dataframe(df_tdd_final, "tdd")
142
+ UtilsVars.all_db_dfs.extend([df_fdd_final, df_tdd_final])
143
 
144
+ return [df_fdd_final, df_tdd_final]
145
+ # add the fdd and tdd to the list
146
+
147
+ # UtilsVars.final_lte_database = [df_fdd_final, df_tdd_final]
148
+
149
+
150
+ def process_lte_data_to_excel(file_path: str):
151
+ lte_dfs = process_lte_data(file_path)
152
+ UtilsVars.final_lte_database = convert_dfs(lte_dfs, ["LTE_FDD", "LTE_TDD"])
153
 
154
 
155
  # process_lte_data(r"data2\20240805_5810_05082024_Dump.xml.gz.xlsb")
queries/process_wcdma.py CHANGED
@@ -122,7 +122,15 @@ def process_wcdma_data(file_path: str):
122
  # save_dataframe(df_wcel_bcf, "wbts")
123
  # save_dataframe(df_wncel, "wncel")
124
  # df_3g = save_dataframe(df_3g, "3G")
 
125
 
126
- UtilsVars.final_wcdma_database = convert_dfs([df_3g], ["WCDMA"])
 
 
127
 
128
  # BTS.process_ok = "Done"
 
 
 
 
 
 
122
  # save_dataframe(df_wcel_bcf, "wbts")
123
  # save_dataframe(df_wncel, "wncel")
124
  # df_3g = save_dataframe(df_3g, "3G")
125
+ UtilsVars.all_db_dfs.append(df_3g)
126
 
127
+ # UtilsVars.final_wcdma_database = convert_dfs([df_3g], ["WCDMA"])
128
+ return df_3g
129
+ # UtilsVars.final_wcdma_database = [df_3g]
130
 
131
  # BTS.process_ok = "Done"
132
+
133
+
134
+ def process_wcdma_data_to_excel(file_path: str):
135
+ wcdma_dfs = process_wcdma_data(file_path)
136
+ UtilsVars.final_wcdma_database = convert_dfs([wcdma_dfs], ["WCDMA"])
utils/check_sheet_exist.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+
4
+ class Technology:
5
+ gsm = False
6
+ wcdma = False
7
+ lte = False
8
+
9
+
10
+ # Dictionary of sheet groups to check
11
+ sheets_to_check = {
12
+ "gsm": ["BTS", "BCF", "TRX"],
13
+ "wcdma": ["WCEL", "WBTS", "WNCEL"],
14
+ "lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
15
+ }
16
+
17
+
18
+ def load(file_path):
19
+ # Load the Excel file
20
+ xlsb_file = pd.ExcelFile(file_path, engine="calamine")
21
+
22
+ # Get all sheet names in the file
23
+ available_sheets = xlsb_file.sheet_names
24
+ return available_sheets
25
+
26
+
27
+ def check_sheets(technology_attr, sheet_list, file_path):
28
+ """
29
+ Check if all sheets in the given sheet_list exist in the Excel file.
30
+
31
+ Parameters
32
+ ----------
33
+ technology_attr : str
34
+ The attribute of the Technology class to set.
35
+ sheet_list : list[str]
36
+ The list of sheet names to check.
37
+
38
+ Returns
39
+ -------
40
+ None
41
+ """
42
+ available_sheets = load(file_path)
43
+ missing_sheets = [sheet for sheet in sheet_list if sheet not in available_sheets]
44
+ if not missing_sheets:
45
+ setattr(Technology, technology_attr, True)
46
+ print(getattr(Technology, technology_attr))
47
+ print("All sheets exist")
48
+ else:
49
+ print(f"Missing sheets: {missing_sheets}")
50
+ print(getattr(Technology, technology_attr))
51
+
52
+
53
+ # Check each technology's sheets
54
+ def execute_checks_sheets_exist(file_path):
55
+ for tech_attr, sheets in sheets_to_check.items():
56
+ check_sheets(tech_attr, sheets, file_path)
57
+
58
+
59
+ # execute_checks(
60
+ # r"C:\Users\HP\Desktop\LTE\PROJET 2023\DUMP\2024\AOUT\20240822_7837_22082024_Dump.xml.gz.xlsb"
61
+ # )
utils/convert_to_excel.py CHANGED
@@ -26,23 +26,6 @@ def convert_dfs(dfs: list[pd.DataFrame], sheet_names: list[str]) -> bytes:
26
  return bytes_data
27
 
28
 
29
- # def save_dataframes(dfs: list[pd.DataFrame], sheet_names: list[str], folder_path: str):
30
- # """
31
- # Save the dataframes to an excel file. The excel file will be saved in the
32
- # folder_path directory.
33
-
34
- # Args:
35
- # dfs (list[pd.DataFrame]): The list of dataframes to save.
36
- # sheet_names (list[str]): The list of names for each sheet.
37
- # folder_path (str): The path to the folder where the excel file will be saved.
38
- # """
39
- # bytes_data = convert_dfs(dfs, sheet_names)
40
- # timestamp = int(time.time())
41
- # file_name = f"{folder_path}/data_{timestamp}.xlsx"
42
- # with open(file_name, "wb") as f:
43
- # f.write(bytes_data)
44
-
45
-
46
  def save_dataframe(df: pd.DataFrame, sheet_name: str):
47
  """
48
  Save the dataframe to a csv file.
 
26
  return bytes_data
27
 
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def save_dataframe(df: pd.DataFrame, sheet_name: str):
30
  """
31
  Save the dataframe to a csv file.
utils/utils_vars.py CHANGED
@@ -22,6 +22,9 @@ class UtilsVars:
22
  final_lte_database = ""
23
  final_gsm_database = ""
24
  final_wcdma_database = ""
 
 
 
25
  physisal_db = get_physical_db()
26
 
27
 
 
22
  final_lte_database = ""
23
  final_gsm_database = ""
24
  final_wcdma_database = ""
25
+ all_db_dfs = []
26
+ final_all_database = ""
27
+ file_path = ""
28
  physisal_db = get_physical_db()
29
 
30