File size: 9,628 Bytes
939b332 bcc0fd9 939b332 bcc0fd9 939b332 bcc0fd9 b89c5d7 bcc0fd9 b89c5d7 bcc0fd9 81c766f bcc0fd9 b89c5d7 bcc0fd9 b89c5d7 bcc0fd9 b89c5d7 81c766f b89c5d7 bcc0fd9 b290f2d bcc0fd9 027f03b bcc0fd9 939b332 bcc0fd9 939b332 bcc0fd9 939b332 bcc0fd9 939b332 bcc0fd9 027f03b bcc0fd9 939b332 50b11f5 |
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
import io
import time
import pandas as pd
import streamlit as st
# @st.cache_data
# def convert_dfs(dfs: list[pd.DataFrame], sheet_names: list[str]) -> bytes:
# # IMPORTANT: Cache the conversion to prevent computation on every rerun
# # Create a BytesIO object
# bytes_io = io.BytesIO()
# # Write the dataframes to the BytesIO object
# with pd.ExcelWriter(bytes_io, engine="xlsxwriter") as writer:
# for df, sheet_name in zip(dfs, sheet_names):
# df.to_excel(writer, sheet_name=sheet_name, index=True)
# # Get the bytes data
# bytes_data = bytes_io.getvalue()
# # Close the BytesIO object
# bytes_io.close()
# return bytes_data
def get_formats(workbook):
return {
"green": workbook.add_format(
{"bg_color": "#37CC73", "bold": True, "border": 1}
),
"green_light": workbook.add_format(
{"bg_color": "#87E0AB", "bold": True, "border": 1}
),
"blue": workbook.add_format({"bg_color": "#1A64FF", "bold": True, "border": 1}),
"blue_light": workbook.add_format(
{"bg_color": "#00B0F0", "bold": True, "border": 1}
),
"beurre": workbook.add_format(
{"bg_color": "#FFE699", "bold": True, "border": 1}
),
"orange": workbook.add_format(
{"bg_color": "#F47F31", "bold": True, "border": 1}
),
"purple5": workbook.add_format(
{"bg_color": "#E03DCD", "bold": True, "border": 1}
),
"purple6": workbook.add_format(
{"bg_color": "#AE83F8", "bold": True, "border": 1}
),
"gray": workbook.add_format({"bg_color": "#D9D9D9", "bold": True, "border": 1}),
"red": workbook.add_format({"bg_color": "#FF0000", "bold": True, "border": 1}),
"yellow": workbook.add_format(
{"bg_color": "#FFFF00", "bold": True, "border": 1}
),
}
def get_format_map_by_format_type(formats: dict, format_type: str) -> dict:
if format_type == "GSM_Analysis":
return {
# "name": formats["blue"],
"amrSegLoadDepTchRateLower": formats["beurre"],
"amrSegLoadDepTchRateUpper": formats["beurre"],
"btsSpLoadDepTchRateLower": formats["beurre"],
"btsSpLoadDepTchRateUpper": formats["beurre"],
"amrWbFrCodecModeSet": formats["beurre"],
"dedicatedGPRScapacity": formats["beurre"],
"defaultGPRScapacity": formats["beurre"],
"number_trx_per_cell": formats["blue"],
"number_trx_per_bcf": formats["blue"],
"number_tch_per_cell": formats["blue"],
"number_sd_per_cell": formats["blue"],
"number_bcch_per_cell": formats["blue"],
"number_ccch_per_cell": formats["blue"],
"number_cbc_per_cell": formats["blue"],
"number_total_channels_per_cell": formats["blue"],
"number_signals_per_cell": formats["blue"],
"hf_rate_coef": formats["purple5"],
"GPRS": formats["purple5"],
"TCH Actual HR%": formats["green"],
"Offered Traffic BH": formats["green"],
"Max_Traffic BH": formats["green"],
"Avg_Traffic BH": formats["green"],
"TCH UTILIZATION (@Max Traffic)": formats["red"],
"Tch utilization comments": formats["orange"],
"ErlabngB_value": formats["purple6"],
"Target FR CHs": formats["purple6"],
"Target HR CHs": formats["purple6"],
"Target TCHs": formats["purple6"],
"Target TRXs": formats["purple6"],
"Number of required TRXs": formats["purple6"],
"max_tch_call_blocking_bh": formats["yellow"],
"avg_tch_call_blocking_bh": formats["yellow"],
"number_of_days_with_tch_blocking_exceeded_bh": formats["yellow"],
"tch_call_blocking_bh_comment": formats["orange"],
"max_sdcch_real_blocking_bh": formats["yellow"],
"avg_sdcch_real_blocking_bh": formats["yellow"],
"number_of_days_with_sdcch_blocking_exceeded_bh": formats["yellow"],
"sdcch_real_blocking_bh_comment": formats["orange"],
"Average_cell_availability_bh": formats["yellow"],
"number_of_days_exceeding_availability_threshold_bh": formats["yellow"],
"availability_comment_bh": formats["orange"],
"max_tch_abis_fail_bh": formats["yellow"],
"avg_tch_abis_fail_bh": formats["yellow"],
"number_of_days_with_tch_abis_fail_exceeded_bh": formats["yellow"],
"tch_abis_fail_bh_comment": formats["orange"],
"Average_cell_availability_daily": formats["green_light"],
"number_of_days_exceeding_availability_threshold_daily": formats[
"green_light"
],
"availability_comment_daily": formats["orange"],
"max_tch_abis_fail_daily": formats["green_light"],
"avg_tch_abis_fail_daily": formats["green_light"],
"number_of_days_with_tch_abis_fail_exceeded_daily": formats["green_light"],
"tch_abis_fail_daily_comment": formats["orange"],
"BH Congestion status": formats["gray"],
"operational_comment": formats["gray"],
"Final comment": formats["gray"],
"Final comment summary": formats["gray"],
# Operational Neighbours Distance Sheet
"Source_ID_BTS": formats["blue"],
"Source_name": formats["blue"],
"Source_BH Congestion status": formats["blue"],
"Source_Longitude": formats["blue"],
"Source_Latitude": formats["blue"],
"Neighbour_ID_BTS": formats["green_light"],
"Neighbour_name": formats["green_light"],
"Neighbour_operational_comment": formats["green_light"],
"Neighbour_Longitude": formats["green_light"],
"Neighbour_Latitude": formats["green_light"],
"Distance_km": formats["beurre"],
}
elif format_type == "database":
return {
"code": formats["blue"],
"Azimut": formats["green"],
"Longitude": formats["green"],
"Latitude": formats["green"],
"Hauteur": formats["green"],
"number_trx_per_cell": formats["blue_light"],
"number_trx_per_bcf": formats["blue_light"],
"number_trx_per_site": formats["blue_light"],
}
elif format_type == "LTE_Analysis":
return {
"code": formats["blue"],
"code_sector": formats["blue"],
"Region": formats["blue"],
"site_config_band": formats["blue"],
"LNCEL_name_l800": formats["beurre"],
"LNCEL_name_l1800": formats["purple5"],
"LNCEL_name_l2300": formats["purple6"],
"LNCEL_name_l2600": formats["blue_light"],
"LNCEL_name_l1800s": formats["gray"],
"avg_prb_usage_bh_l800": formats["beurre"],
"avg_prb_usage_bh_l1800": formats["purple5"],
"avg_prb_usage_bh_l2300": formats["purple6"],
"avg_prb_usage_bh_l2600": formats["blue_light"],
"avg_prb_usage_bh_l1800s": formats["gray"],
"num_congested_cells": formats["orange"],
"num_cells": formats["orange"],
"num_cell_with_kpi": formats["orange"],
"num_down_or_no_kpi_cells": formats["orange"],
"prb_diff_between_cells": formats["orange"],
"load_balance_required": formats["orange"],
"congestion_comment": formats["orange"],
"final_comments": formats["green"],
}
else:
return {} # No formatting if format_type not matched
def _apply_custom_formatting(
writer, df: pd.DataFrame, sheet_name: str, format_type: str
):
workbook = writer.book
worksheet = writer.sheets[sheet_name]
formats = get_formats(workbook)
format_map = get_format_map_by_format_type(formats, format_type)
for col_idx, col_name in enumerate(df.columns):
fmt = format_map.get(col_name)
if fmt:
worksheet.write(0, col_idx + 1, col_name, fmt)
def _write_to_excel(
dfs: list[pd.DataFrame], sheet_names: list[str], index=True, format_type: str = None
) -> bytes:
bytes_io = io.BytesIO()
with pd.ExcelWriter(bytes_io, engine="xlsxwriter") as writer:
for df, name in zip(dfs, sheet_names):
# df.index.name = "index"
df.to_excel(writer, sheet_name=name, index=index)
if format_type:
_apply_custom_formatting(writer, df, name, format_type)
return bytes_io.getvalue()
@st.cache_data
def convert_dfs(dfs: list[pd.DataFrame], sheet_names: list[str]) -> bytes:
return _write_to_excel(dfs, sheet_names, index=True)
@st.cache_data
def convert_gsm_dfs(dfs, sheet_names) -> bytes:
return _write_to_excel(dfs, sheet_names, index=True, format_type="GSM_Analysis")
@st.cache_data
def convert_lte_analysis_dfs(dfs, sheet_names) -> bytes:
return _write_to_excel(dfs, sheet_names, index=True, format_type="LTE_Analysis")
@st.cache_data
def convert_database_dfs(dfs, sheet_names) -> bytes:
return _write_to_excel(dfs, sheet_names, index=True, format_type="database")
def save_dataframe(df: pd.DataFrame, sheet_name: str):
"""
Save the dataframe to a csv file.
Args:
df (pd.DataFrame): The dataframe to save.
sheet_name (str): The name of the sheet.
"""
df.to_csv(f"data2/{sheet_name}_{time.time()}.csv", index=False, encoding="latin1")
|