File size: 3,703 Bytes
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86110dd
 
 
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86110dd
 
 
 
 
 
 
 
 
 
 
 
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a209e6
939b332
 
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
import pandas as pd

from queries.process_trx import process_trx_data
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",
]

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", "TRX"],
        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.band_frequence).fillna("not found")
    )
    df_bts["type_cellule"] = (
        df_bts["frequencyBandInUse"].map(UtilsVars.type_cellule).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]

    df_trx = process_trx_data(file_path)

    # 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_physical_db = UtilsVars.physisal_db
    df_2g = pd.merge(df_2g, df_physical_db, on="Code_Sector", how="left")

    # Save dataframes
    # save_dataframe(df_bts, "bts")
    # 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):
    gsm_dfs = process_gsm_data(file_path)
    UtilsVars.final_gsm_database = convert_dfs([gsm_dfs], ["GSM"])