File size: 5,355 Bytes
939b332 ad021df 01dd930 939b332 bb3e08f 939b332 8ccf333 939b332 3615d9c 939b332 86110dd 01dd930 939b332 bb3e08f 939b332 56d8047 939b332 3615d9c 939b332 8ccf333 939b332 86110dd 01dd930 86110dd 01dd930 86110dd 939b332 56d8047 939b332 bb3e08f 01dd930 939b332 bb3e08f 939b332 01dd930 bb3e08f 939b332 01dd930 939b332 1a209e6 939b332 ad021df 57fe85f ad021df 57fe85f 01dd930 ad021df |
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 |
import pandas as pd
from queries.process_mal import process_mal_data, process_mal_with_bts_name
from queries.process_trx import process_trx_data, process_trx_with_bts_name
from utils.config_band import config_band
from utils.convert_to_excel import convert_dfs, save_dataframe
from utils.utils_vars import UtilsVars
BTS_COLUMNS = [
"ID_BCF",
"ID_BTS",
"ID_MAL",
"BSC",
"BCF",
"BTS",
"usedMobileAllocation",
"code",
"plmnPermitted",
"frequencyBandInUse",
"name",
"Region",
"adminState",
"allowIMSIAttachDetach",
"amrSegLoadDepTchRateLower",
"amrSegLoadDepTchRateUpper",
"antennaHopping",
"bcchTrxPower",
"bsIdentityCodeBCC",
"bsIdentityCodeNCC",
"BSIC",
"cellId",
"dedicatedGPRScapacity",
"defaultGPRScapacity",
"fddQMin",
"fddQOffset",
"fddRscpMin",
"gprsEnabled",
"locationAreaIdLAC",
"rac",
"rachDropRxLevelThreshold",
"sectorId",
"SectorId2",
"segmentId",
"fastReturnToLTE",
"gsmPriority",
"segmentName",
"Code_Sector",
"band_frequence",
"type_cellule",
"configuration_schema",
"band",
]
BCF_COLUMNS = [
"ID_BCF",
"site_name",
]
def compare_trx_tch_versus_mal(tch1, tch2):
# Split the strings by commas, convert to sets, and compare
set1 = set(str(tch1).split(",")) if isinstance(tch1, str) else set()
set2 = set(str(tch2).split(",")) if isinstance(tch2, str) else set()
return set1 == set2
def process_gsm_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=["BTS", "BCF"],
engine="calamine",
skiprows=[0],
)
# Process BTS data
df_bts = dfs["BTS"]
df_bts.columns = df_bts.columns.str.replace(r"[ ]", "", regex=True)
df_bts["code"] = df_bts["name"].str.split("_").str[0].astype(int)
df_bts["Region"] = df_bts["name"].str.split("_").str[1]
df_bts["ID_BTS"] = df_bts[["BSC", "BCF", "BTS"]].astype(str).apply("_".join, axis=1)
df_bts["ID_MAL"] = (
df_bts[["BSC", "usedMobileAllocation"]].astype(str).apply("_".join, axis=1)
)
df_bts["BSIC"] = (
df_bts[["bsIdentityCodeNCC", "bsIdentityCodeBCC"]]
.astype(str)
.apply("".join, axis=1)
)
df_bts["SectorId2"] = (
df_bts["sectorId"].map(UtilsVars.sector_mapping).fillna(df_bts["sectorId"])
)
df_bts["band_frequence"] = (
df_bts["frequencyBandInUse"]
.map(UtilsVars.oml_band_frequence)
.fillna("not found")
)
df_bts["type_cellule"] = (
df_bts["frequencyBandInUse"].map(UtilsVars.type_cellule).fillna("not found")
)
df_bts["band"] = (
df_bts["frequencyBandInUse"].map(UtilsVars.gsm_band).fillna("not found")
)
df_bts["configuration_schema"] = (
df_bts["frequencyBandInUse"]
.map(UtilsVars.configuration_schema)
.fillna("not found")
)
df_bts["ID_BCF"] = df_bts[["BSC", "BCF"]].astype(str).apply("_".join, axis=1)
df_bts["Code_Sector"] = (
df_bts[["code", "SectorId2"]].astype(str).apply("_".join, axis=1)
)
df_bts["Code_Sector"] = df_bts["Code_Sector"].str.replace(".0", "")
df_bts = df_bts[BTS_COLUMNS]
# Process BCF data
df_bcf = dfs["BCF"]
df_bcf.columns = df_bcf.columns.str.replace(r"[ ]", "", regex=True)
df_bcf["ID_BCF"] = df_bcf[["BSC", "BCF"]].astype(str).apply("_".join, axis=1)
df_bcf.rename(columns={"name": "site_name"}, inplace=True)
df_bcf = df_bcf[BCF_COLUMNS]
# Process TRX data
df_trx = process_trx_data(file_path)
# Process MAL data
df_mal = process_mal_data(file_path)
# create band dataframe
df_band = config_band(df_bts)
# Merge dataframes
df_bts_bcf = pd.merge(df_bcf, df_bts, on="ID_BCF", how="left")
df_2g = pd.merge(df_bts_bcf, df_trx, on="ID_BTS", how="left")
df_2g = pd.merge(df_2g, df_band, on="code", how="left")
df_2g = pd.merge(df_2g, df_mal, on="ID_MAL", how="left")
df_2g["TRX_TCH_VS_MAL"] = df_2g.apply(
lambda row: compare_trx_tch_versus_mal(row["TRX_TCH"], row["MAL_TCH"]), axis=1
)
df_physical_db = UtilsVars.physisal_db
df_2g = pd.merge(df_2g, df_physical_db, on="Code_Sector", how="left")
# Save dataframes
# save_dataframe(df_band, "BAND")
# save_dataframe(df_bcf, "bcf")
# save_dataframe(df_trx, "trx")
# df_2g2 = save_dataframe(df_2g, "2g")
# UtilsVars.all_db_dfs.append(df_2g)
# UtilsVars.final_gsm_database = convert_dfs([df_2g], ["GSM"])
# UtilsVars.final_gsm_database = [df_2g]
return df_2g
def combined_gsm_database(file_path: str):
gsm_df = process_gsm_data(file_path)
mal_df = process_mal_with_bts_name(file_path)
trx_df = process_trx_with_bts_name(file_path)
UtilsVars.all_db_dfs.extend([gsm_df, mal_df, trx_df])
return [gsm_df, mal_df, trx_df]
def process_gsm_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.
"""
gsm_dfs = combined_gsm_database(file_path)
UtilsVars.final_gsm_database = convert_dfs(gsm_dfs, ["GSM", "MAL", "TRX"])
|