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 pandas as pd
|
||||||
|
import json
|
||||||
def ReadDatabase():
|
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
|
# Load the updated Excel file into a pandas DataFrame
|
||||||
excel_file_path = "./interview_database.xlsx"
|
excel_file_path = "./interview_database.xlsx"
|
||||||
df = pd.read_excel(excel_file_path)
|
df = pd.read_excel(excel_file_path)
|
||||||
@ -10,17 +22,21 @@ def ReadDatabase():
|
|||||||
|
|
||||||
# Group the DataFrame by Date, Start Time, and Slot for organization
|
# Group the DataFrame by Date, Start Time, and Slot for organization
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
date = row['Date']
|
date = str(row['Date'])
|
||||||
start_time = row['Start Time']
|
start_time = str(row['Start Time'])
|
||||||
slot = int(row['Slot']) if not pd.isna(row['Slot']) else 0
|
slot = int(row['Slot']) if not pd.isna(row['Slot']) else 0
|
||||||
|
#Returns amount of interviewees in the slot and if it's empty it will return 0
|
||||||
# Initialize nested structure if not present
|
interviewee_amount = len(str(row['Interviewee Name']).split()) if str(row['Interviewee Name']) != "nan" else 0
|
||||||
if date not in interview_data:
|
|
||||||
interview_data[date] = {}
|
# Check if the slot is available for an interviewee to attend
|
||||||
if start_time not in interview_data[date]:
|
avaliable_slots = interviewee_amount != slot
|
||||||
if len(str(row['Interviewee Name']).split()) != slot:
|
if avaliable_slots:
|
||||||
interview_data[date][start_time] = {
|
# Initialize nested structure if not present
|
||||||
'Meeting Duration': row['Meeting Duration'],
|
if date not in interview_data:
|
||||||
}
|
interview_data[date] = {}
|
||||||
# Print the structured dictionary in JSON format for readability
|
#Adds the start time and duration if not present
|
||||||
return interview_data
|
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