improve invunit
Browse files- queries/process_invunit.py +58 -14
- utils/convert_to_excel.py +69 -0
queries/process_invunit.py
CHANGED
|
@@ -1,9 +1,51 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
|
| 3 |
-
from utils.convert_to_excel import
|
| 4 |
from utils.extract_code import extract_code_from_mrbts
|
| 5 |
from utils.utils_vars import UtilsVars
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def create_invunit_summary(df: pd.DataFrame) -> pd.DataFrame:
|
| 9 |
"""
|
|
@@ -75,20 +117,22 @@ def process_invunit_data(file_path: str) -> pd.DataFrame:
|
|
| 75 |
)
|
| 76 |
df_invunit = create_invunit_summary(df_invunit)
|
| 77 |
df_invunit["code"] = df_invunit["MRBTS"].apply(extract_code_from_mrbts)
|
| 78 |
-
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
# df_invunit["MRBTS_NUM"] = df_invunit.groupby("code").cumcount() + 1
|
| 83 |
-
# df_invunit["MRBTS_NUM"] = "MRBTS_" + df_invunit["MRBTS_NUM"].astype(str)
|
| 84 |
-
|
| 85 |
-
# Move the columns to the desired position and keep all other columns
|
| 86 |
-
df_invunit = df_invunit[["MRBTS", "code", "invunit_summary"]].merge(
|
| 87 |
-
df_invunit.drop(["MRBTS", "code", "invunit_summary"], axis=1),
|
| 88 |
-
left_index=True,
|
| 89 |
-
right_index=True,
|
| 90 |
)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
UtilsVars.all_db_dfs.append(df_invunit)
|
| 93 |
UtilsVars.all_db_dfs_names.append("INVUNIT")
|
| 94 |
return df_invunit
|
|
@@ -102,4 +146,4 @@ def process_invunit_data_to_excel(file_path: str) -> None:
|
|
| 102 |
file_path (str): The path to the file.
|
| 103 |
"""
|
| 104 |
invunit_df = process_invunit_data(file_path)
|
| 105 |
-
UtilsVars.final_invunit_database =
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
|
| 3 |
+
from utils.convert_to_excel import convert_invunit_dfs, save_dataframe
|
| 4 |
from utils.extract_code import extract_code_from_mrbts
|
| 5 |
from utils.utils_vars import UtilsVars
|
| 6 |
|
| 7 |
+
RF_UNIT = [
|
| 8 |
+
"AHDA",
|
| 9 |
+
"AHEGB",
|
| 10 |
+
"AHEGC",
|
| 11 |
+
"AHEGHA",
|
| 12 |
+
"AHGA",
|
| 13 |
+
"AHMA",
|
| 14 |
+
"AHPMDA",
|
| 15 |
+
"AHPMDG",
|
| 16 |
+
"AHPMDI",
|
| 17 |
+
"ARDA",
|
| 18 |
+
"AREA",
|
| 19 |
+
"ARGA",
|
| 20 |
+
"ARMA",
|
| 21 |
+
"AZNA",
|
| 22 |
+
"FHDB",
|
| 23 |
+
"FHEB",
|
| 24 |
+
"FHEL",
|
| 25 |
+
"FRGU",
|
| 26 |
+
"FRGY",
|
| 27 |
+
"FRMB",
|
| 28 |
+
"FRMF",
|
| 29 |
+
"FXDB",
|
| 30 |
+
"FXED",
|
| 31 |
+
"FZNI",
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
BB_UNIT_LIST = [
|
| 35 |
+
"FBBA",
|
| 36 |
+
"FBBC",
|
| 37 |
+
"FSMF",
|
| 38 |
+
"ABIA",
|
| 39 |
+
"total_number_of_subunit",
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
BB_UNIT_VALUES = {
|
| 43 |
+
"FBBA": 6,
|
| 44 |
+
"FBBC": 6,
|
| 45 |
+
"FSMF": 5.5,
|
| 46 |
+
"ABIA": 8,
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
|
| 50 |
def create_invunit_summary(df: pd.DataFrame) -> pd.DataFrame:
|
| 51 |
"""
|
|
|
|
| 117 |
)
|
| 118 |
df_invunit = create_invunit_summary(df_invunit)
|
| 119 |
df_invunit["code"] = df_invunit["MRBTS"].apply(extract_code_from_mrbts)
|
| 120 |
+
|
| 121 |
+
# Compute total_number_of_subunit
|
| 122 |
+
df_invunit["total_number_of_subunit"] = sum(
|
| 123 |
+
df_invunit[col].fillna(0) * val for col, val in BB_UNIT_VALUES.items()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
)
|
| 125 |
|
| 126 |
+
# Start order with "MRBTS", "code", "invunit_summary" follow by bb_unit , rf_unit and then all other columns
|
| 127 |
+
df_invunit = df_invunit[
|
| 128 |
+
["MRBTS", "code", "invunit_summary"]
|
| 129 |
+
+ BB_UNIT_LIST
|
| 130 |
+
+ RF_UNIT
|
| 131 |
+
+ df_invunit.columns.difference(
|
| 132 |
+
["MRBTS", "code", "invunit_summary"] + BB_UNIT_LIST + RF_UNIT
|
| 133 |
+
).tolist()
|
| 134 |
+
]
|
| 135 |
+
|
| 136 |
UtilsVars.all_db_dfs.append(df_invunit)
|
| 137 |
UtilsVars.all_db_dfs_names.append("INVUNIT")
|
| 138 |
return df_invunit
|
|
|
|
| 146 |
file_path (str): The path to the file.
|
| 147 |
"""
|
| 148 |
invunit_df = process_invunit_data(file_path)
|
| 149 |
+
UtilsVars.final_invunit_database = convert_invunit_dfs([invunit_df], ["INVUNIT"])
|
utils/convert_to_excel.py
CHANGED
|
@@ -146,6 +146,36 @@ def get_format_map_by_format_type(formats: dict, format_type: str) -> dict:
|
|
| 146 |
"number_trx_per_cell": formats["blue_light"],
|
| 147 |
"number_trx_per_bcf": formats["blue_light"],
|
| 148 |
"number_trx_per_site": formats["blue_light"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
elif format_type == "LTE_Analysis":
|
| 151 |
return {
|
|
@@ -228,6 +258,40 @@ def get_format_map_by_format_type(formats: dict, format_type: str) -> dict:
|
|
| 228 |
"final_comments": formats["green"],
|
| 229 |
}
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
else:
|
| 232 |
return {} # No formatting if format_type not matched
|
| 233 |
|
|
@@ -285,6 +349,11 @@ def convert_database_dfs(dfs, sheet_names) -> bytes:
|
|
| 285 |
return _write_to_excel(dfs, sheet_names, index=True, format_type="database")
|
| 286 |
|
| 287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
def save_dataframe(df: pd.DataFrame, sheet_name: str):
|
| 289 |
"""
|
| 290 |
Save the dataframe to a csv file.
|
|
|
|
| 146 |
"number_trx_per_cell": formats["blue_light"],
|
| 147 |
"number_trx_per_bcf": formats["blue_light"],
|
| 148 |
"number_trx_per_site": formats["blue_light"],
|
| 149 |
+
# invunit part in database
|
| 150 |
+
"FBBA": formats["blue_light"],
|
| 151 |
+
"FBBC": formats["blue_light"],
|
| 152 |
+
"FSMF": formats["blue_light"],
|
| 153 |
+
"ABIA": formats["blue_light"],
|
| 154 |
+
"total_number_of_subunit": formats["blue_light"],
|
| 155 |
+
"AHDA": formats["beurre"],
|
| 156 |
+
"AHEGB": formats["beurre"],
|
| 157 |
+
"AHEGC": formats["beurre"],
|
| 158 |
+
"AHEGHA": formats["beurre"],
|
| 159 |
+
"AHGA": formats["beurre"],
|
| 160 |
+
"AHMA": formats["beurre"],
|
| 161 |
+
"AHPMDA": formats["beurre"],
|
| 162 |
+
"AHPMDG": formats["beurre"],
|
| 163 |
+
"AHPMDI": formats["beurre"],
|
| 164 |
+
"ARDA": formats["beurre"],
|
| 165 |
+
"AREA": formats["beurre"],
|
| 166 |
+
"ARGA": formats["beurre"],
|
| 167 |
+
"ARMA": formats["beurre"],
|
| 168 |
+
"AZNA": formats["beurre"],
|
| 169 |
+
"FHDB": formats["beurre"],
|
| 170 |
+
"FHEB": formats["beurre"],
|
| 171 |
+
"FHEL": formats["beurre"],
|
| 172 |
+
"FRGU": formats["beurre"],
|
| 173 |
+
"FRGY": formats["beurre"],
|
| 174 |
+
"FRMB": formats["beurre"],
|
| 175 |
+
"FRMF": formats["beurre"],
|
| 176 |
+
"FXDB": formats["beurre"],
|
| 177 |
+
"FXED": formats["beurre"],
|
| 178 |
+
"FZNI": formats["beurre"],
|
| 179 |
}
|
| 180 |
elif format_type == "LTE_Analysis":
|
| 181 |
return {
|
|
|
|
| 258 |
"final_comments": formats["green"],
|
| 259 |
}
|
| 260 |
|
| 261 |
+
elif format_type == "invunit":
|
| 262 |
+
return {
|
| 263 |
+
"code": formats["blue"],
|
| 264 |
+
"FBBA": formats["blue_light"],
|
| 265 |
+
"FBBC": formats["blue_light"],
|
| 266 |
+
"FSMF": formats["blue_light"],
|
| 267 |
+
"ABIA": formats["blue_light"],
|
| 268 |
+
"total_number_of_subunit": formats["blue_light"],
|
| 269 |
+
"AHDA": formats["beurre"],
|
| 270 |
+
"AHEGB": formats["beurre"],
|
| 271 |
+
"AHEGC": formats["beurre"],
|
| 272 |
+
"AHEGHA": formats["beurre"],
|
| 273 |
+
"AHGA": formats["beurre"],
|
| 274 |
+
"AHMA": formats["beurre"],
|
| 275 |
+
"AHPMDA": formats["beurre"],
|
| 276 |
+
"AHPMDG": formats["beurre"],
|
| 277 |
+
"AHPMDI": formats["beurre"],
|
| 278 |
+
"ARDA": formats["beurre"],
|
| 279 |
+
"AREA": formats["beurre"],
|
| 280 |
+
"ARGA": formats["beurre"],
|
| 281 |
+
"ARMA": formats["beurre"],
|
| 282 |
+
"AZNA": formats["beurre"],
|
| 283 |
+
"FHDB": formats["beurre"],
|
| 284 |
+
"FHEB": formats["beurre"],
|
| 285 |
+
"FHEL": formats["beurre"],
|
| 286 |
+
"FRGU": formats["beurre"],
|
| 287 |
+
"FRGY": formats["beurre"],
|
| 288 |
+
"FRMB": formats["beurre"],
|
| 289 |
+
"FRMF": formats["beurre"],
|
| 290 |
+
"FXDB": formats["beurre"],
|
| 291 |
+
"FXED": formats["beurre"],
|
| 292 |
+
"FZNI": formats["beurre"],
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
else:
|
| 296 |
return {} # No formatting if format_type not matched
|
| 297 |
|
|
|
|
| 349 |
return _write_to_excel(dfs, sheet_names, index=True, format_type="database")
|
| 350 |
|
| 351 |
|
| 352 |
+
@st.cache_data
|
| 353 |
+
def convert_invunit_dfs(dfs, sheet_names) -> bytes:
|
| 354 |
+
return _write_to_excel(dfs, sheet_names, index=True, format_type="invunit")
|
| 355 |
+
|
| 356 |
+
|
| 357 |
def save_dataframe(df: pd.DataFrame, sheet_name: str):
|
| 358 |
"""
|
| 359 |
Save the dataframe to a csv file.
|