DavMelchi commited on
Commit
263b2ce
·
1 Parent(s): 86110dd

addind NEI database

Browse files
.gitignore CHANGED
@@ -1,4 +1,5 @@
1
  /.history
2
  /.venv
3
  /__pycache__
4
- __pycache__
 
 
1
  /.history
2
  /.venv
3
  /__pycache__
4
+ __pycache__
5
+ /data2
README.md CHANGED
@@ -36,7 +36,8 @@ You can access the hosted version of the app at [https://davmelchi-db-query.hf.s
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
 
 
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
43
+ - [ ] Add option to update physical db
app.py CHANGED
@@ -5,6 +5,10 @@ import streamlit as st
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
@@ -39,6 +43,9 @@ def download_button(database_type):
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",
@@ -60,6 +67,7 @@ def execute_process_all_tech_db(uploaded_file):
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:
@@ -75,6 +83,7 @@ if uploaded_file is not None:
75
  "gsm": ["BTS", "BCF", "TRX"],
76
  "wcdma": ["WCEL", "WBTS", "WNCEL"],
77
  "lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
 
78
  """
79
  )
80
 
@@ -104,6 +113,15 @@ if uploaded_file is not None:
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}")
 
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_neighbors import (
9
+ process_neighbors_data,
10
+ process_neighbors_data_to_excel,
11
+ )
12
  from queries.process_wcdma import process_wcdma_data_to_excel
13
  from utils.check_sheet_exist import Technology, execute_checks_sheets_exist
14
  from utils.utils_vars import UtilsVars
 
43
  elif database_type == "All":
44
  data = UtilsVars.final_all_database
45
  file_name = f"All database_{time.time()}.xlsx"
46
+ elif database_type == "NEI":
47
+ data = UtilsVars.neighbors_database
48
+ file_name = f"Neighbors database_{time.time()}.xlsx"
49
  st.download_button(
50
  type="primary",
51
  label=f"Download {database_type} Database File",
 
67
 
68
 
69
  col1, col2, col3, col4 = st.columns(4)
70
+ col5, col6, col7, col8 = st.columns(4)
71
  if uploaded_file is not None:
72
  # UtilsVars.file_path = uploaded_file
73
  try:
 
83
  "gsm": ["BTS", "BCF", "TRX"],
84
  "wcdma": ["WCEL", "WBTS", "WNCEL"],
85
  "lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
86
+ "neighbors": ["ADCE", "ADJS", "ADJI", "ADJG", "ADJW", "BTS", "WCEL"],
87
  """
88
  )
89
 
 
113
  "Generate All DBs",
114
  on_click=lambda: execute_process_all_tech_db(uploaded_file),
115
  )
116
+ if Technology.neighbors == True:
117
+ with col5:
118
+ st.button(
119
+ "Generate NEI DB",
120
+ on_click=lambda: process_database(
121
+ process_neighbors_data_to_excel, "NEI"
122
+ ),
123
+ # on_click=lambda: process_neighbors_data(uploaded_file),
124
+ )
125
 
126
  except Exception as e:
127
  st.error(f"Error: {e}")
queries/process_neighbors.py ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ from utils.convert_to_excel import convert_dfs, save_dataframe
4
+ from utils.utils_vars import UtilsVars
5
+
6
+ ADCE_INITIAL_COLUMNS = [
7
+ "ID_BTS",
8
+ "lac_id",
9
+ ]
10
+
11
+ ADJS_INITIAL_COLUMNS = [
12
+ "ID_WCEL",
13
+ "lac_id",
14
+ ]
15
+
16
+ BTS_SOURCE = [
17
+ "ID_BTS",
18
+ "name",
19
+ ]
20
+ BTS_TARGET = [
21
+ "lac_id",
22
+ "name",
23
+ ]
24
+
25
+ WCEL_SOURCE = [
26
+ "ID_WCEL",
27
+ "name",
28
+ ]
29
+
30
+ WCEL_TARGET = [
31
+ "lac_id",
32
+ "name",
33
+ ]
34
+
35
+
36
+ def process_neighbors_data(file_path: str):
37
+ """
38
+ Process data from the specified file path.
39
+
40
+ Args:
41
+ file_path (str): The path to the file.
42
+ """
43
+ # Read the specific sheet into a DataFrame
44
+ dfs = pd.read_excel(
45
+ file_path,
46
+ sheet_name=["ADCE", "ADJS", "ADJI", "ADJG", "ADJW", "BTS", "WCEL"],
47
+ engine="calamine",
48
+ skiprows=[0],
49
+ )
50
+
51
+ # # Process ADCE data
52
+ df_adce = dfs["ADCE"]
53
+ df_adce.columns = df_adce.columns.str.replace(r"[ ]", "", regex=True)
54
+ df_adce["ID_BTS"] = (
55
+ df_adce[["BSC", "BCF", "BTS"]].astype(str).apply("_".join, axis=1)
56
+ )
57
+ df_adce["lac_id"] = (
58
+ df_adce[["adjacentCellIdLac", "adjacentCellIdCI"]]
59
+ .astype(str)
60
+ .apply("_".join, axis=1)
61
+ )
62
+ df_adce["lac_id"] = df_adce["lac_id"].str.replace(".0", "")
63
+ df_adce = df_adce[ADCE_INITIAL_COLUMNS]
64
+
65
+ # Process BTS data
66
+ df_bts = dfs["BTS"]
67
+ df_bts.columns = df_bts.columns.str.replace(r"[ ]", "", regex=True)
68
+ df_bts["ID_BTS"] = df_bts[["BSC", "BCF", "BTS"]].astype(str).apply("_".join, axis=1)
69
+ df_bts["lac_id"] = (
70
+ df_bts[["locationAreaIdLAC", "cellId"]].astype(str).apply("_".join, axis=1)
71
+ )
72
+
73
+ df_bts_source = df_bts[BTS_SOURCE]
74
+ df_bts_source.rename(columns={"name": "SOURCE_NAME"}, inplace=True)
75
+
76
+ df_bts_target = df_bts[BTS_TARGET]
77
+ df_bts_target.rename(columns={"name": "TARGET_NAME"}, inplace=True)
78
+
79
+ # #create final adce
80
+ df_adce_final = pd.merge(df_adce, df_bts_source, on="ID_BTS", how="left")
81
+ df_adce_final = pd.merge(
82
+ df_adce_final, df_bts_target, on="lac_id", how="left"
83
+ ).dropna()
84
+ df_adce_final.rename(
85
+ columns={"ID_BTS": "SOURCE_ID", "lac_id": "TARGET_LAC_ID"}, inplace=True
86
+ )
87
+
88
+ # process ADJS data
89
+ df_adjs = dfs["ADJS"]
90
+ df_adjs.columns = df_adjs.columns.str.replace(r"[ ]", "", regex=True)
91
+
92
+ df_adjs["ID_WCEL"] = (
93
+ df_adjs[["RNC", "WBTS", "WCEL"]].astype(str).apply("_".join, axis=1)
94
+ )
95
+ df_adjs["lac_id"] = (
96
+ df_adjs[["AdjsLAC", "AdjsCI"]].astype(str).apply("_".join, axis=1)
97
+ )
98
+ df_adjs = df_adjs[ADJS_INITIAL_COLUMNS]
99
+
100
+ # process WCEL DATA
101
+ df_wcel = dfs["WCEL"]
102
+ df_wcel.columns = df_wcel.columns.str.replace(r"[ ]", "", regex=True)
103
+ df_wcel["ID_WCEL"] = (
104
+ df_wcel[["RNC", "WBTS", "WCEL"]].astype(str).apply("_".join, axis=1)
105
+ )
106
+ df_wcel["lac_id"] = df_wcel[["LAC", "CId"]].astype(str).apply("_".join, axis=1)
107
+ df_wcel = df_wcel[["ID_WCEL", "lac_id", "name"]]
108
+
109
+ df_wcel_source = df_wcel[WCEL_SOURCE]
110
+ df_wcel_source.rename(columns={"name": "SOURCE_NAME"}, inplace=True)
111
+
112
+ df_wcel_target = df_wcel[WCEL_TARGET]
113
+ df_wcel_target.rename(columns={"name": "TARGET_NAME"}, inplace=True)
114
+
115
+ # create final adjs
116
+ df_adjs_final = pd.merge(df_adjs, df_wcel_source, on="ID_WCEL", how="left")
117
+ df_adjs_final = pd.merge(
118
+ df_adjs_final, df_wcel_target, on="lac_id", how="left"
119
+ ).dropna()
120
+ df_adjs_final.rename(
121
+ columns={"ID_WCEL": "SOURCE_ID", "lac_id": "TARGET_LAC_ID"}, inplace=True
122
+ )
123
+
124
+ # process ADJI DATA
125
+ df_adji = dfs["ADJI"]
126
+ df_adji.columns = df_adji.columns.str.replace(r"[ ]", "", regex=True)
127
+
128
+ df_adji["ID_WCEL"] = (
129
+ df_adji[["RNC", "WBTS", "WCEL"]].astype(str).apply("_".join, axis=1)
130
+ )
131
+ df_adji["lac_id"] = (
132
+ df_adji[["AdjiLAC", "AdjiCI"]].astype(str).apply("_".join, axis=1)
133
+ )
134
+ df_adji = df_adji[["ID_WCEL", "lac_id"]]
135
+
136
+ df_adji_final = pd.merge(df_adji, df_wcel_source, on="ID_WCEL", how="left")
137
+ df_adji_final = pd.merge(
138
+ df_adji_final, df_wcel_target, on="lac_id", how="left"
139
+ ).dropna()
140
+ df_adji_final.rename(
141
+ columns={"ID_WCEL": "SOURCE_ID", "lac_id": "TARGET_LAC_ID"}, inplace=True
142
+ )
143
+
144
+ # process ADJG DATA
145
+ df_adjg = dfs["ADJG"]
146
+ df_adjg.columns = df_adjg.columns.str.replace(r"[ ]", "", regex=True)
147
+
148
+ df_adjg["ID_WCEL"] = (
149
+ df_adjg[["RNC", "WBTS", "WCEL"]].astype(str).apply("_".join, axis=1)
150
+ )
151
+ df_adjg["lac_id"] = (
152
+ df_adjg[["AdjgLAC", "AdjgCI"]].astype(str).apply("_".join, axis=1)
153
+ )
154
+ df_adjg = df_adjg[["ID_WCEL", "lac_id"]]
155
+
156
+ df_adjg_final = pd.merge(df_adjg, df_wcel_source, on="ID_WCEL", how="left")
157
+ df_adjg_final = pd.merge(
158
+ df_adjg_final, df_bts_target, on="lac_id", how="left"
159
+ ).dropna()
160
+ df_adjg_final.rename(
161
+ columns={"ID_WCEL": "SOURCE_ID", "lac_id": "TARGET_LAC_ID"}, inplace=True
162
+ )
163
+
164
+ # process ADJW DATA
165
+ df_adjw = dfs["ADJW"]
166
+ df_adjw.columns = df_adjw.columns.str.replace(r"[ ]", "", regex=True)
167
+
168
+ df_adjw["ID_BTS"] = (
169
+ df_adjw[["BSC", "BCF", "BTS"]].astype(str).apply("_".join, axis=1)
170
+ )
171
+ df_adjw["lac_id"] = df_adjw[["lac", "AdjwCId"]].astype(str).apply("_".join, axis=1)
172
+ df_adjw = df_adjw[["ID_BTS", "lac_id"]]
173
+
174
+ df_adjw_final = pd.merge(df_adjw, df_bts_source, on="ID_BTS", how="left")
175
+ df_adjw_final = pd.merge(
176
+ df_adjw_final, df_wcel_target, on="lac_id", how="left"
177
+ ).dropna()
178
+ df_adjw_final.rename(
179
+ columns={"ID_BTS": "SOURCE_ID", "lac_id": "TARGET_LAC_ID"}, inplace=True
180
+ )
181
+
182
+ # save_dataframe(df_adjw_final, "ADJW")
183
+
184
+ return [df_adjw_final, df_adjg_final, df_adji_final, df_adjs_final, df_adce_final]
185
+
186
+
187
+ def process_neighbors_data_to_excel(file_path: str):
188
+ neighbors_dfs = process_neighbors_data(file_path)
189
+ UtilsVars.neighbors_database = convert_dfs(
190
+ neighbors_dfs, ["ADJW", "ADJG", "ADJI", "ADJS", "ADCE"]
191
+ )
utils/check_sheet_exist.py CHANGED
@@ -5,11 +5,13 @@ 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
  }
 
5
  gsm = False
6
  wcdma = False
7
  lte = False
8
+ neighbors = False
9
 
10
 
11
  # Dictionary of sheet groups to check
12
  sheets_to_check = {
13
  "gsm": ["BTS", "BCF", "TRX"],
14
+ "neighbors": ["ADCE", "ADJS", "ADJI", "ADJG", "ADJW", "BTS", "WCEL"],
15
  "wcdma": ["WCEL", "WBTS", "WNCEL"],
16
  "lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
17
  }
utils/utils_vars.py CHANGED
@@ -34,6 +34,7 @@ class UtilsVars:
34
  final_wcdma_database = ""
35
  all_db_dfs = []
36
  final_all_database = ""
 
37
  file_path = ""
38
  physisal_db = get_physical_db()
39
 
 
34
  final_wcdma_database = ""
35
  all_db_dfs = []
36
  final_all_database = ""
37
+ neighbors_database = ""
38
  file_path = ""
39
  physisal_db = get_physical_db()
40