File size: 4,179 Bytes
939b332
 
 
01dd930
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86110dd
 
 
01dd930
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56d8047
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86110dd
01dd930
 
 
86110dd
 
 
 
01dd930
 
 
86110dd
 
 
 
 
 
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
56d8047
939b332
 
01dd930
 
 
939b332
 
 
01dd930
939b332
 
 
 
 
01dd930
939b332
1a209e6
939b332
 
57fe85f
 
 
 
 
 
 
01dd930
 
 
 
 
 
57fe85f
 
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
import pandas as pd

from queries.process_trx import process_trx_data
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",
    "BSC",
    "BCF",
    "BTS",
    "code",
    "plmnPermitted",
    "frequencyBandInUse",
    "name",
    "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 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["ID_BTS"] = df_bts[["BSC", "BCF", "BTS"]].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)

    # create band dataframe
    df_band = config_band(df_bts)

    # Merge dataframes
    df_bts_bcf = pd.merge(df_bts, df_bcf, 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_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 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 = process_gsm_data(file_path)
    UtilsVars.final_gsm_database = convert_dfs([gsm_dfs], ["GSM"])