db_query / utils /check_sheet_exist.py
DavMelchi's picture
Adding inventory units
a9f4212
import pandas as pd
class DumpType:
full_dump = False
class Technology:
gsm = False
wcdma = False
lte = False
neighbors = False
trx = False
mrbts = False
mal = False
invunit = False
# Dictionary of sheet groups to check
sheets_to_check = {
"gsm": ["BTS", "BCF", "TRX", "MAL"],
"neighbors": ["ADCE", "ADJS", "ADJI", "ADJG", "ADJW", "BTS", "WCEL"],
"wcdma": ["WCEL", "WBTS", "WNCEL"],
"lte": ["LNBTS", "LNCEL", "LNCEL_FDD", "LNCEL_TDD"],
"trx": ["TRX", "BTS"],
"mrbts": ["MRBTS"],
"mal": ["MAL", "BTS"],
"invunit": ["INVUNIT"],
}
def load(file_path):
# Load the Excel file
xlsb_file = pd.ExcelFile(file_path, engine="calamine")
# Get all sheet names in the file
available_sheets = xlsb_file.sheet_names
return available_sheets
def check_sheets(technology_attr, sheet_list, file_path):
"""
Check if all sheets in the given sheet_list exist in the Excel file.
Parameters
----------
technology_attr : str
The attribute of the Technology class to set.
sheet_list : list[str]
The list of sheet names to check.
Returns
-------
None
"""
available_sheets = load(file_path)
missing_sheets = [sheet for sheet in sheet_list if sheet not in available_sheets]
available_sheets_in_list = [
sheet for sheet in sheet_list if sheet in available_sheets
]
if not missing_sheets:
setattr(Technology, technology_attr, True)
# print(getattr(Technology, technology_attr))
# print(f"available:", available_sheets_in_list)
# print("All sheets exist")
# else:
# print(f"Missing sheets: {missing_sheets}")
# print(f"available:", available_sheets_in_list)
# print(getattr(Technology, technology_attr))
# Check each technology's sheets
def execute_checks_sheets_exist(file_path):
Technology.gsm = False
Technology.wcdma = False
Technology.lte = False
Technology.neighbors = False
Technology.trx = False
Technology.mrbts = False
Technology.invunit = False
Technology.mal = False
DumpType.full_dump = False
for tech_attr, sheets in sheets_to_check.items():
check_sheets(tech_attr, sheets, file_path)
# execute_checks_sheets_exist(
# r"C:\Users\David\Documents\PROJECTS\2023\PROJET 2023\DUMP\DUMP\2142\DUMP 2142.xlsb"
# )