File size: 6,238 Bytes
939b332 bb3e08f 939b332 bb3e08f 939b332 09bd64e 424caf8 939b332 56d8047 09bd64e 424caf8 56d8047 53fa613 46a5af8 56d8047 939b332 56d8047 939b332 09bd64e 939b332 56d8047 bb3e08f 56d8047 6618c9f 939b332 bb3e08f 56d8047 46a5af8 424caf8 53fa613 46a5af8 53fa613 56d8047 ad021df 56d8047 424caf8 56d8047 bb3e08f 56d8047 |
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 |
import pandas as pd
from queries.process_small_bts import process_small_bts_data
from utils.convert_to_excel import convert_dfs, save_dataframe
from utils.utils_vars import UtilsVars
TRX_COLUMNS = [
"ID_BTS",
"trxRfPower",
"BCCH",
"TRX_TCH",
"number_trx_per_cell",
"number_trx_per_bcf",
"number_trx_per_site",
]
TRX_BTS_COLUMNS = [
"BSC",
"BCF",
"BTS",
"TRX",
"ID_BTS",
"number_trx_per_cell",
"number_trx_per_bcf",
"number_trx_per_site",
"code",
"name",
"adminState",
"bbUnitSupportsEdge",
"channel0Maio",
"channel0Type",
"channel1Maio",
"channel1Type",
"channel2Maio",
"channel2Type",
"channel3Maio",
"channel3Type",
"channel4Maio",
"channel4Type",
"channel5Maio",
"channel5Type",
"channel6Maio",
"channel6Type",
"channel7Maio",
"channel7Type",
"initialFrequency",
"lapdLinkName",
"lapdLinkNumber",
"mcpaTrxNumber",
"mcpaTrxPortId",
"mcpaTrxPosition",
"numberOfTrxRfPowerLevels",
"optimumRxLevDL",
"optimumRxLevUL",
"preferredBcchMark",
"trxAbilities",
"trxFrequencyType",
"trxRfPower",
"tsc",
"TCHs",
"SDs",
"BCCHs",
"CCCHs",
"CBCs",
"TotalChannels",
"Signal",
"number_tch_per_cell",
"number_sd_per_cell",
"number_bcch_per_cell",
"number_ccch_per_cell",
"number_cbc_per_cell",
"number_total_channels_per_cell",
"number_signals_per_cell",
]
def process_brute_trx_data(file_path: str):
"""
Process data from the specified file path.
Args:
file_path (str): The path to the file.
"""
# Read the specific sheet into a DataFrame
dfs = pd.read_excel(
file_path,
sheet_name=["TRX"],
engine="calamine",
skiprows=[0],
)
# Process TRX data
df_trx = dfs["TRX"]
df_trx.columns = df_trx.columns.str.replace(r"[ ]", "", regex=True)
df_trx["ID_BTS"] = df_trx[["BSC", "BCF", "BTS"]].astype(str).apply("_".join, axis=1)
df_trx["ID_BCF"] = df_trx[["BSC", "BCF"]].astype(str).apply("_".join, axis=1)
df_trx["number_trx_per_cell"] = df_trx.groupby("ID_BTS")["ID_BTS"].transform(
"count"
)
df_trx["number_trx_per_bcf"] = df_trx.groupby("ID_BCF")["ID_BCF"].transform("count")
return df_trx
def process_trx_with_bts_name(file_path: str):
df_gsm_trx = process_brute_trx_data(file_path=file_path).copy()
df_gsm_trx.drop(columns=["name"], axis=1, inplace=True, errors="ignore")
df_bts = process_small_bts_data(file_path=file_path)
df_trx_bts_name: pd.DataFrame = pd.merge(
df_gsm_trx, df_bts, on="ID_BTS", how="left"
)
df_trx_bts_name["number_trx_per_site"] = df_trx_bts_name.groupby("code")[
"code"
].transform("count")
# Filter columns strictly by names like "channelXType"
channel_columns = [
col
for col in df_trx_bts_name.columns
if col.startswith("channel") and col.endswith("Type")
]
# TCHs SDs BCCH CCCH CBC Total Signal
# Calculate "count of channels per TRX" for each row
df_trx_bts_name["TCHs"] = df_trx_bts_name[channel_columns].apply(
lambda row: (row == 2).sum(), axis=1
)
df_trx_bts_name["SDs"] = df_trx_bts_name[channel_columns].apply(
lambda row: (row == 3).sum(), axis=1
)
df_trx_bts_name["BCCHs"] = df_trx_bts_name[channel_columns].apply(
lambda row: (row == 4).sum(), axis=1
)
df_trx_bts_name["CCCHs"] = df_trx_bts_name[channel_columns].apply(
lambda row: (row == 6).sum(), axis=1
)
df_trx_bts_name["CBCs"] = df_trx_bts_name[channel_columns].apply(
lambda row: (row == 8).sum(), axis=1
)
# Total Channels = TCHs + SDs + BCCHs + CCCHs + CBCs
df_trx_bts_name["TotalChannels"] = (
df_trx_bts_name["TCHs"]
+ df_trx_bts_name["SDs"]
+ df_trx_bts_name["BCCHs"]
+ df_trx_bts_name["CCCHs"]
+ df_trx_bts_name["CBCs"]
)
# Signal = BCCHs + CCCHs + CBCs
df_trx_bts_name["Signal"] = (
df_trx_bts_name["BCCHs"] + df_trx_bts_name["CCCHs"] + df_trx_bts_name["CBCs"]
)
df_trx_bts_name["number_tch_per_cell"] = df_trx_bts_name.groupby("ID_BTS")[
"TCHs"
].transform("sum")
df_trx_bts_name["number_sd_per_cell"] = df_trx_bts_name.groupby("ID_BTS")[
"SDs"
].transform("sum")
df_trx_bts_name["number_bcch_per_cell"] = df_trx_bts_name.groupby("ID_BTS")[
"BCCHs"
].transform("sum")
df_trx_bts_name["number_ccch_per_cell"] = df_trx_bts_name.groupby("ID_BTS")[
"CCCHs"
].transform("sum")
df_trx_bts_name["number_cbc_per_cell"] = df_trx_bts_name.groupby("ID_BTS")[
"CBCs"
].transform("sum")
df_trx_bts_name["number_total_channels_per_cell"] = df_trx_bts_name.groupby(
"ID_BTS"
)["TotalChannels"].transform("sum")
df_trx_bts_name["number_signals_per_cell"] = df_trx_bts_name.groupby("ID_BTS")[
"Signal"
].transform("sum")
df_trx_bts_name = df_trx_bts_name[TRX_BTS_COLUMNS]
# UtilsVars.all_db_dfs.append(df_trx_bts_name)
return df_trx_bts_name
def process_trx_data(file_path: str):
df_gsm_trx = process_trx_with_bts_name(file_path=file_path).copy()
bcch = df_gsm_trx[df_gsm_trx["channel0Type"] == 4]
tch = df_gsm_trx[df_gsm_trx["channel0Type"] != 4][["ID_BTS", "initialFrequency"]]
tch = tch.pivot_table(
index="ID_BTS",
values="initialFrequency",
aggfunc=lambda x: ",".join(map(str, x)),
)
tch = tch.reset_index()
# rename the columns
tch.columns = ["ID_BTS", "TRX_TCH"]
df_gsm_trx = pd.merge(bcch, tch, on="ID_BTS", how="left")
# rename "initialFrequency" to "BCCH"
df_gsm_trx = df_gsm_trx.rename(columns={"initialFrequency": "BCCH"})
df_gsm_trx = df_gsm_trx[TRX_COLUMNS]
return df_gsm_trx
def process_trx_with_bts_name_data_to_excel(file_path: str):
"""
Process data from the specified file path and save it to a excel file.
Args:
file_path (str): The path to the file.
"""
trx_bts_name = process_trx_with_bts_name(file_path)
UtilsVars.final_trx_database = convert_dfs([trx_bts_name], ["TRX"])
|