db_query / utils /config_band.py
DavMelchi's picture
Process ADJL - 2G part 1st
f135ea9
import pandas as pd
def config_band(df: pd.DataFrame) -> pd.DataFrame:
"""
Create a dataframe that contains the site configuration band for each site code.
Parameters
----------
df : pd.DataFrame
The dataframe containing the site information, with columns "code" and "band"
Returns
-------
pd.DataFrame
The dataframe containing the site configuration band for each site code, with columns "code" and "site_config_band"
"""
df_band = df[["code", "band"]].copy()
df_band["ID"] = df_band[["code", "band"]].astype(str).apply("_".join, axis=1)
# remove duplicates ID
df_band = df_band.drop_duplicates(subset=["ID"])
df_band = df_band[["code", "band"]]
df_band["band"] = df_band["band"].fillna("empty")
df_band = (
df_band.groupby("code")["band"]
.apply(lambda x: "/".join(sorted(x)))
.reset_index()
)
# rename band to config
df_band.rename(columns={"band": "site_config_band"}, inplace=True)
return df_band
def bcf_band(df: pd.DataFrame) -> pd.DataFrame:
"""
Create a dataframe that contains the bcf configuration band for each bcf ID.
Parameters
----------
df : pd.DataFrame
The dataframe containing the bcf information, with columns "ID" and "band"
Returns
-------
pd.DataFrame
The dataframe containing the bcf configuration band for each bcf ID, with columns "ID" and "bcf_config_band"
"""
df_band = df[["ID_BCF", "band"]].copy()
df_band["ID"] = df_band[["ID_BCF", "band"]].astype(str).apply("_".join, axis=1)
# remove duplicates ID
df_band = df_band.drop_duplicates(subset=["ID"])
df_band = df_band[["ID_BCF", "band"]]
df_band["band"] = df_band["band"].fillna("empty")
df_band = (
df_band.groupby("ID_BCF")["band"]
.apply(lambda x: "/".join(sorted(x)))
.reset_index()
)
# rename band to config
df_band.rename(columns={"band": "bcf_config_band"}, inplace=True)
return df_band
def wbts_band(df: pd.DataFrame) -> pd.DataFrame:
"""
Create a dataframe that contains the wbts configuration band for each wbts ID.
Parameters
----------
df : pd.DataFrame
The dataframe containing the wbts information, with columns "ID" and "band"
Returns
-------
pd.DataFrame
The dataframe containing the wbts configuration band for each wbts ID, with columns "ID" and "wbts_config_band"
"""
df_band = df[["WBTS", "band"]].copy()
df_band["ID"] = df_band[["WBTS", "band"]].astype(str).apply("_".join, axis=1)
# remove duplicates ID
df_band = df_band.drop_duplicates(subset=["ID"])
df_band = df_band[["WBTS", "band"]]
df_band["band"] = df_band["band"].fillna("empty")
df_band = (
df_band.groupby("WBTS")["band"]
.apply(lambda x: "/".join(sorted(x)))
.reset_index()
)
# rename band to config
df_band.rename(columns={"band": "wbts_config_band"}, inplace=True)
return df_band
def lte_mrbts_band(df: pd.DataFrame) -> pd.DataFrame:
"""
Create a dataframe that contains the mrbts configuration band for each mrbts ID.
Parameters
----------
df : pd.DataFrame
The dataframe containing the mrbts information, with columns "ID" and "band"
Returns
-------
pd.DataFrame
The dataframe containing the mrbts configuration band for each mrbts ID, with columns "ID" and "mrbts_config_band"
"""
df_band = df[["MRBTS", "band"]].copy()
df_band["ID"] = df_band[["MRBTS", "band"]].astype(str).apply("_".join, axis=1)
# remove duplicates ID
df_band = df_band.drop_duplicates(subset=["ID"])
df_band = df_band[["MRBTS", "band"]]
df_band["band"] = df_band["band"].fillna("empty")
df_band = (
df_band.groupby("MRBTS")["band"]
.apply(lambda x: "/".join(sorted(x)))
.reset_index()
)
# rename band to config
df_band.rename(columns={"band": "lte_config_band"}, inplace=True)
return df_band
def adjl_band(df: pd.DataFrame, id_col: str, band_col: str) -> pd.DataFrame:
"""
Create a dataframe that contains the adjl configuration band for each adjl ID.
Parameters
----------
df : pd.DataFrame
The dataframe containing the adjl information, with columns "ID" and "band"
Returns
-------
pd.DataFrame
The dataframe containing the adjl configuration band for each adjl ID, with columns "ID" and "adjl_config_band"
"""
df_band = df[[id_col, band_col]].copy()
df_band["ID"] = df_band[[id_col, band_col]].astype(str).apply("_".join, axis=1)
# remove duplicates ID
df_band = df_band.drop_duplicates(subset=["ID"])
df_band = df_band[[id_col, band_col]]
df_band[band_col] = df_band[band_col].fillna("empty")
df_band = (
df_band.groupby(id_col)[band_col]
.apply(lambda x: "/".join(sorted(x)))
.reset_index()
)
# rename band to config
df_band.rename(columns={band_col: "adjl_created_band"}, inplace=True)
return df_band