Adding site database and sheet
Browse files- queries/process_all_db.py +25 -2
- queries/process_site_db.py +168 -0
- queries/process_trx.py +31 -27
queries/process_all_db.py
CHANGED
@@ -3,6 +3,7 @@ from queries.process_gsm import combined_gsm_database, gsm_analaysis
|
|
3 |
from queries.process_invunit import process_invunit_data
|
4 |
from queries.process_lte import lte_fdd_analaysis, lte_tdd_analaysis, process_lte_data
|
5 |
from queries.process_mrbts import process_mrbts_data
|
|
|
6 |
from queries.process_wcdma import process_wcdma_data, wcdma_analaysis
|
7 |
from utils.convert_to_excel import convert_database_dfs, convert_dfs
|
8 |
from utils.utils_vars import UtilsVars
|
@@ -29,10 +30,21 @@ def all_dbs(filepath: str):
|
|
29 |
|
30 |
def process_all_tech_db(filepath: str):
|
31 |
all_dbs(filepath)
|
|
|
32 |
|
33 |
UtilsVars.final_all_database = convert_database_dfs(
|
34 |
UtilsVars.all_db_dfs,
|
35 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
)
|
37 |
|
38 |
|
@@ -41,6 +53,7 @@ def process_all_tech_db_with_stats(
|
|
41 |
# region_list: list
|
42 |
):
|
43 |
all_dbs(filepath)
|
|
|
44 |
gsm_analaysis(filepath)
|
45 |
wcdma_analaysis(
|
46 |
filepath,
|
@@ -50,7 +63,17 @@ def process_all_tech_db_with_stats(
|
|
50 |
lte_tdd_analaysis(filepath)
|
51 |
UtilsVars.final_all_database = convert_database_dfs(
|
52 |
UtilsVars.all_db_dfs,
|
53 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
)
|
55 |
|
56 |
|
|
|
3 |
from queries.process_invunit import process_invunit_data
|
4 |
from queries.process_lte import lte_fdd_analaysis, lte_tdd_analaysis, process_lte_data
|
5 |
from queries.process_mrbts import process_mrbts_data
|
6 |
+
from queries.process_site_db import site_db
|
7 |
from queries.process_wcdma import process_wcdma_data, wcdma_analaysis
|
8 |
from utils.convert_to_excel import convert_database_dfs, convert_dfs
|
9 |
from utils.utils_vars import UtilsVars
|
|
|
30 |
|
31 |
def process_all_tech_db(filepath: str):
|
32 |
all_dbs(filepath)
|
33 |
+
site_db()
|
34 |
|
35 |
UtilsVars.final_all_database = convert_database_dfs(
|
36 |
UtilsVars.all_db_dfs,
|
37 |
+
[
|
38 |
+
"GSM",
|
39 |
+
"MAL",
|
40 |
+
"TRX",
|
41 |
+
"WCDMA",
|
42 |
+
"LTE_FDD",
|
43 |
+
"LTE_TDD",
|
44 |
+
"MRBTS",
|
45 |
+
"INVUNIT",
|
46 |
+
"SITE",
|
47 |
+
],
|
48 |
)
|
49 |
|
50 |
|
|
|
53 |
# region_list: list
|
54 |
):
|
55 |
all_dbs(filepath)
|
56 |
+
site_db()
|
57 |
gsm_analaysis(filepath)
|
58 |
wcdma_analaysis(
|
59 |
filepath,
|
|
|
63 |
lte_tdd_analaysis(filepath)
|
64 |
UtilsVars.final_all_database = convert_database_dfs(
|
65 |
UtilsVars.all_db_dfs,
|
66 |
+
[
|
67 |
+
"GSM",
|
68 |
+
"MAL",
|
69 |
+
"TRX",
|
70 |
+
"WCDMA",
|
71 |
+
"LTE_FDD",
|
72 |
+
"LTE_TDD",
|
73 |
+
"MRBTS",
|
74 |
+
"INVUNIT",
|
75 |
+
"SITE",
|
76 |
+
],
|
77 |
)
|
78 |
|
79 |
|
queries/process_site_db.py
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
|
3 |
+
from utils.utils_vars import UtilsVars
|
4 |
+
|
5 |
+
GSM_COLUMNS = [
|
6 |
+
"code",
|
7 |
+
"site_name",
|
8 |
+
"site_config_band",
|
9 |
+
"number_trx_per_site",
|
10 |
+
"Longitude",
|
11 |
+
"Latitude",
|
12 |
+
"Hauteur",
|
13 |
+
]
|
14 |
+
|
15 |
+
WCDMA_COLUMNS = [
|
16 |
+
"code",
|
17 |
+
"site_name",
|
18 |
+
"site_config_band",
|
19 |
+
"Longitude",
|
20 |
+
"Latitude",
|
21 |
+
"Hauteur",
|
22 |
+
]
|
23 |
+
LTE_COLUMNS = [
|
24 |
+
"code",
|
25 |
+
"lnbts_name",
|
26 |
+
"site_config_band",
|
27 |
+
"Longitude",
|
28 |
+
"Latitude",
|
29 |
+
"Hauteur",
|
30 |
+
]
|
31 |
+
|
32 |
+
|
33 |
+
def clean_bands(bands):
|
34 |
+
if pd.isna(bands):
|
35 |
+
return None
|
36 |
+
parts = [p for p in bands.split("/") if p != "nan"]
|
37 |
+
return "/".join(parts) if parts else None
|
38 |
+
|
39 |
+
|
40 |
+
def site_db():
|
41 |
+
gsm_df: pd.DataFrame = UtilsVars.all_db_dfs[0]
|
42 |
+
wcdma_df: pd.DataFrame = UtilsVars.all_db_dfs[3]
|
43 |
+
lte_fdd_df: pd.DataFrame = UtilsVars.all_db_dfs[4]
|
44 |
+
lte_tdd_df: pd.DataFrame = UtilsVars.all_db_dfs[5]
|
45 |
+
|
46 |
+
gsm_df = gsm_df[GSM_COLUMNS]
|
47 |
+
gsm_df = gsm_df.rename(
|
48 |
+
columns={
|
49 |
+
"code": "code",
|
50 |
+
"site_name": "gsm_name",
|
51 |
+
"site_config_band": "2G_Bands",
|
52 |
+
}
|
53 |
+
)
|
54 |
+
gsm_df.drop_duplicates(subset=["code"], keep="first", inplace=True)
|
55 |
+
|
56 |
+
wcdma_df = wcdma_df[WCDMA_COLUMNS]
|
57 |
+
wcdma_df = wcdma_df.rename(
|
58 |
+
columns={
|
59 |
+
"code": "code",
|
60 |
+
"site_name": "wcdma_name",
|
61 |
+
"site_config_band": "3G_Bands",
|
62 |
+
}
|
63 |
+
)
|
64 |
+
|
65 |
+
wcdma_df.drop_duplicates(subset=["code"], keep="first", inplace=True)
|
66 |
+
|
67 |
+
lte_fdd_df = lte_fdd_df[LTE_COLUMNS]
|
68 |
+
lte_tdd_df = lte_tdd_df[LTE_COLUMNS]
|
69 |
+
lte_df: pd.DataFrame = pd.concat([lte_fdd_df, lte_tdd_df], ignore_index=False)
|
70 |
+
|
71 |
+
lte_df = lte_df.rename(
|
72 |
+
columns={
|
73 |
+
"code": "code",
|
74 |
+
"lnbts_name": "lte_name",
|
75 |
+
"site_config_band": "4G_Bands",
|
76 |
+
}
|
77 |
+
)
|
78 |
+
|
79 |
+
lte_df.drop_duplicates(subset=["code"], keep="first", inplace=True)
|
80 |
+
|
81 |
+
################################# CODE DATAFRAME#############################
|
82 |
+
|
83 |
+
gsm_code_df: pd.DataFrame = (
|
84 |
+
gsm_df[
|
85 |
+
[
|
86 |
+
"code",
|
87 |
+
"Longitude",
|
88 |
+
"Latitude",
|
89 |
+
"Hauteur",
|
90 |
+
]
|
91 |
+
].copy()
|
92 |
+
if gsm_df is not None
|
93 |
+
else pd.DataFrame()
|
94 |
+
)
|
95 |
+
wcdma_code_df: pd.DataFrame = (
|
96 |
+
wcdma_df[["code", "Longitude", "Latitude", "Hauteur"]].copy()
|
97 |
+
if wcdma_df is not None
|
98 |
+
else pd.DataFrame()
|
99 |
+
)
|
100 |
+
lte_code_df: pd.DataFrame = (
|
101 |
+
lte_df[
|
102 |
+
[
|
103 |
+
"code",
|
104 |
+
"Longitude",
|
105 |
+
"Latitude",
|
106 |
+
"Hauteur",
|
107 |
+
]
|
108 |
+
].copy()
|
109 |
+
if lte_df is not None
|
110 |
+
else pd.DataFrame()
|
111 |
+
)
|
112 |
+
|
113 |
+
code_df: pd.DataFrame = pd.concat(
|
114 |
+
[gsm_code_df, wcdma_code_df, lte_code_df], ignore_index=True
|
115 |
+
)
|
116 |
+
code_df.drop_duplicates(subset=["code"], keep="first", inplace=True)
|
117 |
+
code_df.dropna(subset=["code"], inplace=True)
|
118 |
+
# order by code
|
119 |
+
code_df.sort_values(by=["code"], inplace=True)
|
120 |
+
|
121 |
+
# print(code_df)
|
122 |
+
# ################################# SITE DATAFRAME#############################
|
123 |
+
gsm_df_final = gsm_df[
|
124 |
+
[
|
125 |
+
"code",
|
126 |
+
"gsm_name",
|
127 |
+
"2G_Bands",
|
128 |
+
"number_trx_per_site",
|
129 |
+
]
|
130 |
+
].copy()
|
131 |
+
wcdma_df_final = wcdma_df[["code", "wcdma_name", "3G_Bands"]].copy()
|
132 |
+
lte_df_final = lte_df[["code", "lte_name", "4G_Bands"]].copy()
|
133 |
+
|
134 |
+
site_df = pd.merge(code_df, gsm_df_final, how="left", on="code")
|
135 |
+
site_df = pd.merge(site_df, wcdma_df_final, how="left", on="code")
|
136 |
+
site_df = pd.merge(site_df, lte_df_final, how="left", on="code")
|
137 |
+
# order by code
|
138 |
+
site_df["site_name"] = (
|
139 |
+
site_df["gsm_name"].fillna(site_df["wcdma_name"]).fillna(site_df["lte_name"])
|
140 |
+
)
|
141 |
+
|
142 |
+
site_df["all_bands"] = (
|
143 |
+
(site_df[["2G_Bands", "3G_Bands", "4G_Bands"]])
|
144 |
+
.astype(str)
|
145 |
+
.apply("/".join, axis=1)
|
146 |
+
)
|
147 |
+
site_df["all_bands"] = site_df["all_bands"].apply(clean_bands)
|
148 |
+
|
149 |
+
site_df = site_df[
|
150 |
+
[
|
151 |
+
"code",
|
152 |
+
"site_name",
|
153 |
+
"2G_Bands",
|
154 |
+
"3G_Bands",
|
155 |
+
"4G_Bands",
|
156 |
+
"all_bands",
|
157 |
+
"number_trx_per_site",
|
158 |
+
"Longitude",
|
159 |
+
"Latitude",
|
160 |
+
"Hauteur",
|
161 |
+
]
|
162 |
+
]
|
163 |
+
|
164 |
+
site_df.sort_values(by=["code"], inplace=True)
|
165 |
+
|
166 |
+
UtilsVars.all_db_dfs.append(site_df)
|
167 |
+
|
168 |
+
print(site_df)
|
queries/process_trx.py
CHANGED
@@ -11,6 +11,7 @@ TRX_COLUMNS = [
|
|
11 |
"TRX_TCH",
|
12 |
"number_trx_per_cell",
|
13 |
"number_trx_per_bcf",
|
|
|
14 |
]
|
15 |
|
16 |
|
@@ -22,6 +23,7 @@ TRX_BTS_COLUMNS = [
|
|
22 |
"ID_BTS",
|
23 |
"number_trx_per_cell",
|
24 |
"number_trx_per_bcf",
|
|
|
25 |
"code",
|
26 |
"name",
|
27 |
"adminState",
|
@@ -101,32 +103,6 @@ def process_brute_trx_data(file_path: str):
|
|
101 |
return df_trx
|
102 |
|
103 |
|
104 |
-
def process_trx_data(file_path: str):
|
105 |
-
|
106 |
-
df_gsm_trx = process_brute_trx_data(file_path=file_path).copy()
|
107 |
-
|
108 |
-
bcch = df_gsm_trx[df_gsm_trx["channel0Type"] == 4]
|
109 |
-
tch = df_gsm_trx[df_gsm_trx["channel0Type"] != 4][["ID_BTS", "initialFrequency"]]
|
110 |
-
|
111 |
-
tch = tch.pivot_table(
|
112 |
-
index="ID_BTS",
|
113 |
-
values="initialFrequency",
|
114 |
-
aggfunc=lambda x: ",".join(map(str, x)),
|
115 |
-
)
|
116 |
-
|
117 |
-
tch = tch.reset_index()
|
118 |
-
|
119 |
-
# rename the columns
|
120 |
-
tch.columns = ["ID_BTS", "TRX_TCH"]
|
121 |
-
|
122 |
-
df_gsm_trx = pd.merge(bcch, tch, on="ID_BTS", how="left")
|
123 |
-
# rename "initialFrequency" to "BCCH"
|
124 |
-
df_gsm_trx = df_gsm_trx.rename(columns={"initialFrequency": "BCCH"})
|
125 |
-
df_gsm_trx = df_gsm_trx[TRX_COLUMNS]
|
126 |
-
|
127 |
-
return df_gsm_trx
|
128 |
-
|
129 |
-
|
130 |
def process_trx_with_bts_name(file_path: str):
|
131 |
|
132 |
df_gsm_trx = process_brute_trx_data(file_path=file_path).copy()
|
@@ -137,7 +113,9 @@ def process_trx_with_bts_name(file_path: str):
|
|
137 |
df_trx_bts_name: pd.DataFrame = pd.merge(
|
138 |
df_gsm_trx, df_bts, on="ID_BTS", how="left"
|
139 |
)
|
140 |
-
|
|
|
|
|
141 |
# Filter columns strictly by names like "channelXType"
|
142 |
channel_columns = [
|
143 |
col
|
@@ -211,6 +189,32 @@ def process_trx_with_bts_name(file_path: str):
|
|
211 |
return df_trx_bts_name
|
212 |
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
def process_trx_with_bts_name_data_to_excel(file_path: str):
|
215 |
"""
|
216 |
Process data from the specified file path and save it to a excel file.
|
|
|
11 |
"TRX_TCH",
|
12 |
"number_trx_per_cell",
|
13 |
"number_trx_per_bcf",
|
14 |
+
"number_trx_per_site",
|
15 |
]
|
16 |
|
17 |
|
|
|
23 |
"ID_BTS",
|
24 |
"number_trx_per_cell",
|
25 |
"number_trx_per_bcf",
|
26 |
+
"number_trx_per_site",
|
27 |
"code",
|
28 |
"name",
|
29 |
"adminState",
|
|
|
103 |
return df_trx
|
104 |
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
def process_trx_with_bts_name(file_path: str):
|
107 |
|
108 |
df_gsm_trx = process_brute_trx_data(file_path=file_path).copy()
|
|
|
113 |
df_trx_bts_name: pd.DataFrame = pd.merge(
|
114 |
df_gsm_trx, df_bts, on="ID_BTS", how="left"
|
115 |
)
|
116 |
+
df_trx_bts_name["number_trx_per_site"] = df_trx_bts_name.groupby("code")[
|
117 |
+
"code"
|
118 |
+
].transform("count")
|
119 |
# Filter columns strictly by names like "channelXType"
|
120 |
channel_columns = [
|
121 |
col
|
|
|
189 |
return df_trx_bts_name
|
190 |
|
191 |
|
192 |
+
def process_trx_data(file_path: str):
|
193 |
+
|
194 |
+
df_gsm_trx = process_trx_with_bts_name(file_path=file_path).copy()
|
195 |
+
|
196 |
+
bcch = df_gsm_trx[df_gsm_trx["channel0Type"] == 4]
|
197 |
+
tch = df_gsm_trx[df_gsm_trx["channel0Type"] != 4][["ID_BTS", "initialFrequency"]]
|
198 |
+
|
199 |
+
tch = tch.pivot_table(
|
200 |
+
index="ID_BTS",
|
201 |
+
values="initialFrequency",
|
202 |
+
aggfunc=lambda x: ",".join(map(str, x)),
|
203 |
+
)
|
204 |
+
|
205 |
+
tch = tch.reset_index()
|
206 |
+
|
207 |
+
# rename the columns
|
208 |
+
tch.columns = ["ID_BTS", "TRX_TCH"]
|
209 |
+
|
210 |
+
df_gsm_trx = pd.merge(bcch, tch, on="ID_BTS", how="left")
|
211 |
+
# rename "initialFrequency" to "BCCH"
|
212 |
+
df_gsm_trx = df_gsm_trx.rename(columns={"initialFrequency": "BCCH"})
|
213 |
+
df_gsm_trx = df_gsm_trx[TRX_COLUMNS]
|
214 |
+
|
215 |
+
return df_gsm_trx
|
216 |
+
|
217 |
+
|
218 |
def process_trx_with_bts_name_data_to_excel(file_path: str):
|
219 |
"""
|
220 |
Process data from the specified file path and save it to a excel file.
|