File size: 3,823 Bytes
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56d8047
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
939b332
 
 
 
 
 
 
 
 
56d8047
939b332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56d8047
 
 
 
 
 
 
 
 
939b332
 
 
 
 
 
 
 
 
 
 
 
56d8047
939b332
56d8047
 
939b332
56d8047
939b332
 
56d8047
 
 
 
939b332
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
import pandas as pd

from utils.convert_to_excel import convert_dfs, save_dataframe
from utils.utils_vars import UtilsVars

TRX_COLUMNS = [
    "ID_BTS",
    "trxRfPower",
    "BCCH",
    "TCH",
    "number_trx_per_cell",
    "number_trx_per_site",
]


TRX_BTS_COLUMNS = [
    "BSC",
    "BCF",
    "BTS",
    "TRX",
    "ID_BTS",
    "number_trx_per_cell",
    "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",
]


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_site"] = df_trx.groupby("ID_BCF")["ID_BCF"].transform(
        "count"
    )

    return df_trx


def process_trx_data(file_path: str):

    df_gsm_trx = process_brute_trx_data(file_path=file_path).copy()

    bcch = df_gsm_trx[df_gsm_trx["channel0Type"] == 4]
    tch = df_gsm_trx[df_gsm_trx["channel0Type"] == 3][["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", "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 trx_with_bts_name(file_path: str):

    df_gsm_trx = process_brute_trx_data(file_path=file_path).copy()
    df_gsm_trx.drop(["name"], axis=1, inplace=True)

    # Process TRX data
    dfs = pd.read_excel(
        file_path,
        sheet_name=["BTS"],
        engine="calamine",
        skiprows=[0],
    )
    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 = df_bts[["ID_BTS", "code", "name"]]

    df_trx_bts_name = pd.merge(df_gsm_trx, df_bts, on="ID_BTS", how="left")
    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_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 = trx_with_bts_name(file_path)
    UtilsVars.final_trx_database = convert_dfs([trx_bts_name], ["TRX"])