mirror of
https://github.com/UofCBaja/BajaCloud.git
synced 2025-06-15 13:14:17 -06:00
feat(ReadDB): Added comments and fixed logic and made it efficent
This commit is contained in:
parent
6df8f2231d
commit
fedbfff60c
44
ReadDB.py
44
ReadDB.py
@ -1,6 +1,18 @@
|
||||
import pandas as pd
|
||||
|
||||
import json
|
||||
def ReadDatabase():
|
||||
"""
|
||||
Reads the Database
|
||||
|
||||
``REQUIRES``: None
|
||||
|
||||
``PROMISES``: JSON (Interview Avaiable Slots)
|
||||
|
||||
``Develop in part by``: Ahmad
|
||||
|
||||
``Contact``: ahmad.ahmad1@ucalgary.ca
|
||||
|
||||
"""
|
||||
# Load the updated Excel file into a pandas DataFrame
|
||||
excel_file_path = "./interview_database.xlsx"
|
||||
df = pd.read_excel(excel_file_path)
|
||||
@ -10,17 +22,21 @@ def ReadDatabase():
|
||||
|
||||
# Group the DataFrame by Date, Start Time, and Slot for organization
|
||||
for _, row in df.iterrows():
|
||||
date = row['Date']
|
||||
start_time = row['Start Time']
|
||||
date = str(row['Date'])
|
||||
start_time = str(row['Start Time'])
|
||||
slot = int(row['Slot']) if not pd.isna(row['Slot']) else 0
|
||||
|
||||
# Initialize nested structure if not present
|
||||
if date not in interview_data:
|
||||
interview_data[date] = {}
|
||||
if start_time not in interview_data[date]:
|
||||
if len(str(row['Interviewee Name']).split()) != slot:
|
||||
interview_data[date][start_time] = {
|
||||
'Meeting Duration': row['Meeting Duration'],
|
||||
}
|
||||
# Print the structured dictionary in JSON format for readability
|
||||
return interview_data
|
||||
#Returns amount of interviewees in the slot and if it's empty it will return 0
|
||||
interviewee_amount = len(str(row['Interviewee Name']).split()) if str(row['Interviewee Name']) != "nan" else 0
|
||||
|
||||
# Check if the slot is available for an interviewee to attend
|
||||
avaliable_slots = interviewee_amount != slot
|
||||
if avaliable_slots:
|
||||
# Initialize nested structure if not present
|
||||
if date not in interview_data:
|
||||
interview_data[date] = {}
|
||||
#Adds the start time and duration if not present
|
||||
if start_time not in interview_data[date]:
|
||||
interview_data[date][start_time] = {
|
||||
'Meeting Duration': row['Meeting Duration'],
|
||||
}
|
||||
return interview_data
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user