File size: 5,877 Bytes
939b332 01dd930 939b332 fbf7879 939b332 3615d9c 939b332 7209b6d 939b332 86110dd 01dd930 939b332 fbf7879 3615d9c 939b332 86110dd 01dd930 939b332 01dd930 939b332 57fe85f 939b332 57fe85f 939b332 57fe85f 01dd930 57fe85f fbf7879 4662aef |
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 |
import pandas as pd
from utils.config_band import config_band
from utils.convert_to_excel import convert_dfs, save_dataframe
from utils.extract_code import extract_code_from_mrbts
from utils.utils_vars import UtilsVars, WcdmaAnalysisData
WCEL_COLUMNS = [
"ID_WBTS",
"ID_WCEL",
"RNC",
"WBTS",
"WCEL",
"site_name",
"name",
"code",
"Region",
"AdminCellState",
"CId",
"LAC",
"RAC",
"UARFCN",
"PriScrCode",
"SAC",
"maxCarrierPower",
"PtxPrimaryCPICH",
"CellRange",
"CodeTreeOptTimer",
"CodeTreeOptimisation",
"CodeTreeUsage",
"PRACHDelayRange",
"PrxOffset",
"PrxTarget",
"PrxTargetMax",
"PrxTargetPSMax",
"PrxTargetPSMaxtHSRACH",
"PtxCellMax",
"PtxOffset",
"PtxTarget",
"SmartLTELayeringEnabled",
"SectorID",
"Code_Sector",
"code_wcel",
"porteuse",
"band",
]
WBTS_COLUMNS = [
"ID_WBTS",
"site_name",
]
WNCEL_COLUMNS = [
"code_wcel",
"maxCarrierPower",
]
def process_wcdma_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
# df_wcel = pd.read_excel(
# file_path, sheet_name="WCEL", engine="calamine", skiprows=[0]
# )
# df_wbts = pd.read_excel(
# file_path, sheet_name="WBTS", engine="calamine", skiprows=[0]
# )
# df_wncel = pd.read_excel(
# file_path, sheet_name="WNCEL", engine="calamine", skiprows=[0]
# )
dfs = pd.read_excel(
file_path,
sheet_name=["WCEL", "WBTS", "WNCEL"],
engine="calamine",
skiprows=[0],
)
# Process BTS data
df_wcel = dfs["WCEL"]
df_wcel.columns = df_wcel.columns.str.replace(r"[ ]", "", regex=True)
df_wcel["code"] = df_wcel["name"].str.split("_").str[0]
df_wcel["code"] = (
pd.to_numeric(df_wcel["code"], errors="coerce").fillna(0).astype(int)
)
df_wcel["Region"] = df_wcel["name"].str.split("_").str[1]
df_wcel["ID_WCEL"] = (
df_wcel[["RNC", "WBTS", "WCEL"]].astype(str).apply("_".join, axis=1)
)
df_wcel["ID_WBTS"] = df_wcel[["RNC", "WBTS"]].astype(str).apply("_".join, axis=1)
df_wcel["Code_Sector"] = (
df_wcel[["code", "SectorID"]].astype(str).apply("_".join, axis=1)
)
df_wcel["code_wcel"] = df_wcel[["code", "WCEL"]].astype(str).apply("_".join, axis=1)
df_wcel["Code_Sector"] = df_wcel["Code_Sector"].str.replace(".0", "")
df_wcel["porteuse"] = (
df_wcel["UARFCN"].map(UtilsVars.porteuse_mapping).fillna("not found")
)
df_wcel["band"] = df_wcel["UARFCN"].map(UtilsVars.wcdma_band).fillna("not found")
# create config_band dataframe
df_band = config_band(df_wcel)
# Process WBTS data
df_wbts = dfs["WBTS"]
df_wbts.columns = df_wbts.columns.str.replace(r"[ ]", "", regex=True)
df_wbts["ID_WBTS"] = df_wbts[["RNC", "WBTS"]].astype(str).apply("_".join, axis=1)
df_wbts.rename(columns={"name": "site_name"}, inplace=True)
df_wbts = df_wbts[WBTS_COLUMNS]
# Process WNCEL data
df_wncel = dfs["WNCEL"]
df_wncel.columns = df_wncel.columns.str.replace(r"[ ]", "", regex=True)
df_wncel["CODE"] = df_wncel["MRBTS"].apply(extract_code_from_mrbts)
df_wncel["code_wcel"] = (
df_wncel[["CODE", "WNCEL"]].astype(str).apply("_".join, axis=1)
)
df_wncel = df_wncel[WNCEL_COLUMNS]
# Merge dataframes
df_wcel_bcf = pd.merge(df_wcel, df_wbts, on="ID_WBTS", how="left")
df_3g = pd.merge(df_wcel_bcf, df_wncel, on="code_wcel", how="left")
df_3g = df_3g[WCEL_COLUMNS]
df_physical_db = UtilsVars.physisal_db
df_3g = pd.merge(df_3g, df_band, on="code", how="left")
df_3g = pd.merge(df_3g, df_physical_db, on="Code_Sector", how="left")
# Save dataframes
# save_dataframe(df_wcel, "wcel")
# save_dataframe(df_wcel_bcf, "wbts")
# save_dataframe(df_wncel, "wncel")
# df_3g = save_dataframe(df_3g, "3G")
UtilsVars.all_db_dfs.append(df_3g)
# UtilsVars.final_wcdma_database = convert_dfs([df_3g], ["WCDMA"])
return df_3g
# UtilsVars.final_wcdma_database = [df_3g]
# BTS.process_ok = "Done"
def process_wcdma_data_to_excel(file_path: str):
"""
Process WCDMA data from the specified file path and convert it to Excel format
Args:
file_path (str): The path to the file.
"""
wcdma_dfs = process_wcdma_data(file_path)
UtilsVars.final_wcdma_database = convert_dfs([wcdma_dfs], ["WCDMA"])
############################ANALYTICSS AND STATISTICS############################
def wcdma_analaysis(filepath: str):
"""
Process WCDMA data from the specified file path and convert it to Excel format
Args:
filepath (str): The path to the file.
"""
wcdma_df = process_wcdma_data(filepath)
# df to count number of site per rnc
df_site_per_rnc = wcdma_df[["RNC", "code"]]
df_site_per_rnc = df_site_per_rnc.drop_duplicates(subset=["code"], keep="first")
WcdmaAnalysisData.total_number_of_rnc = wcdma_df["RNC"].nunique()
WcdmaAnalysisData.total_number_of_wcel = wcdma_df["ID_WCEL"].nunique()
WcdmaAnalysisData.number_of_site = len(wcdma_df["site_name"].unique())
WcdmaAnalysisData.number_of_site_per_rnc = df_site_per_rnc["RNC"].value_counts()
WcdmaAnalysisData.number_of_cell_per_rnc = wcdma_df["RNC"].value_counts()
WcdmaAnalysisData.number_of_empty_wbts_name = wcdma_df["site_name"].isnull().sum()
WcdmaAnalysisData.number_of_empty_wcel_name = wcdma_df["name"].isnull().sum()
WcdmaAnalysisData.wcel_administate_distribution = wcdma_df[
"AdminCellState"
].value_counts()
WcdmaAnalysisData.number_of_cell_per_lac = wcdma_df["LAC"].value_counts()
WcdmaAnalysisData.psc_distribution = wcdma_df["PriScrCode"].value_counts()
|