Skip to content

Commit

Permalink
added second table, now they communicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Couillard authored and Nicholas Couillard committed Oct 16, 2023
1 parent 87b9037 commit bae8b39
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 59 deletions.
145 changes: 86 additions & 59 deletions CourseFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import random

course_table = resource('dynamodb').Table('Courses')
student_table = resource('dynamodb').Table('Students')
# NOTE: another table for users and professors may be necessary. In order to do this we might need functionality to introduce salt and hashing for security

def courseInsert(courseId, courseSection, courseLevel, courseDepartment, courseProfessor, courseEnrolledStudents, courseMaxStudents, courseIsOpen, courseFormat, prerequisites='None', courseStartTime=0, courseEndTime=0, courseScheduledDays='None', courseLocation='None'):
def courseInsert(courseId, courseSection, courseLevel, courseDepartment, courseProfessor, courseEnrolledStudents, courseMaxStudents, courseIsOpen, courseFormat, prerequisites='None', courseStartTime=0, courseEndTime=0, courseScheduledDays='None', courseLocation='None', enrolledStudentList = []):
courseInsertion = course_table.put_item(
Item = {
'CourseId' : courseId, # partition key
Expand All @@ -22,7 +23,8 @@ def courseInsert(courseId, courseSection, courseLevel, courseDepartment, courseP
'StartTime' : courseStartTime, # is storing times in the form of 24-hour time easier? it's simple to convert when necessary
'EndTime' : courseEndTime,
'CourseScheduledDays' : courseScheduledDays, # this will likely be a list, but im lazy so for now it's a string
'CourseLocation' : courseLocation # could increase functionality by separating into building and room number, to allow searching by building
'CourseLocation' : courseLocation, # could increase functionality by separating into building and room number, to allow searching by building
'ListEnrolledStudents' : enrolledStudentList
}
)

Expand All @@ -38,91 +40,116 @@ def courseRemove(courseId, courseSection):

print(f"Removal response: {courseRemoval}")

def enrollStudent(courseId, courseSection):
def enrollStudent(courseId, courseSection, studentID):
studentEnroller = course_table.get_item(
Key={
'CourseId' : courseId,
'Section' : courseSection
'Section' : courseSection,
},
AttributesToGet = ['OpenStatus', 'StudentsEnrolled', 'MaxStudents']
AttributesToGet = ['OpenStatus', 'StudentsEnrolled', 'MaxStudents', 'ListEnrolledStudents']
)

isOpen = (studentEnroller.get('Item')).get('OpenStatus')
numStudents = (studentEnroller.get('Item')).get('StudentsEnrolled')
maxStudents = (studentEnroller.get('Item')).get('MaxStudents')
listEnrolledStudents = (studentEnroller.get('Item')).get('ListEnrolledStudents')


if maxStudents - (numStudents + 1) > 0:
newOpenStatus = True
else:
newOpenStatus = False

if isOpen == True:
numStudents += 1
listEnrolledStudents.append(studentID)
student_enrolled = course_table.update_item(
Key={
'CourseId' : courseId,
'Section' : courseSection
},
UpdateExpression='SET StudentsEnrolled = :val1, OpenStatus = :val2',
UpdateExpression='SET StudentsEnrolled = :val1, OpenStatus = :val2, ListEnrolledStudents = :val3',
ExpressionAttributeValues={
':val1': numStudents,
':val2': newOpenStatus
':val2': newOpenStatus,
':val3': listEnrolledStudents
}
)

print(f"{student_enrolled}")

studentCourseUpdater = student_table.get_item(
Key={
'StudentId' : studentID
},
AttributesToGet = ['EnrolledCourses']
)

studentEnrolledCourses = (studentCourseUpdater.get('Item')).get('EnrolledCourses')
studentEnrolledCourses.append(courseId)

update_courses = student_table.update_item(
Key = {
'StudentId' : studentID
},
UpdateExpression = 'SET EnrolledCourses = :val1',
ExpressionAttributeValues = {
':val1': studentEnrolledCourses
}
)

if __name__ == '__main__':

#NOTE: NONE OF THE INFO COLLECTING WILL LIKELY BE DONE IN PYTHON, THIS IS PROBABLY VUE STUFF. JUST FOR DEMO
for i in range(1000):
courseDepartment = random.choice(['CSE', 'COMM', 'ANTH', 'STAT', 'SPAN', 'GERM', 'ERTH'])
courseNumber = random.randint(1000,5000)
courseSection = 1
if len(str(courseSection)) == 1:
courseSection = '00' + str(courseSection)
elif len(str(courseSection)) == 2:
courseSection = '0' + str(courseSection)
# courseType = input("\nSelect the type of course if needed: Laboratory, Discussion: ")
# if courseType == "Laboratory":
# courseSection += 'L'
# elif courseType == "Discussion":
# courseSection += 'D'
courseLevel = math.floor(courseNumber / 1000) * 1000
courseId = courseDepartment + str(courseNumber)
courseProfessor = random.choice(['Ariana Grande', 'Jeff Bezos', 'Samuel Alito', 'Greg Jackson', 'Nicholas Couillard', 'Miley Cirus', 'Joe Biden', 'Barack Obama', 'Gabe Vincent', 'Stephen Curry', 'Kamala Harris', '6ix9ine', 'Ghandi'])
courseMaxStudents = random.randint(0,200)
courseFormat = random.choice(["In-person", "Online asynchronous", "Online synchronous"])
if courseFormat == "In-person" or courseFormat == "Online synchronous":
numDaysTest = random.randint(0,3)
counter = 0
courseScheduledDays = []
weekDays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
while counter < numDaysTest:
counter += 1
choice = random.choice(weekDays)
courseScheduledDays.append(choice)
weekDays.remove(choice)
times = [["9:05AM","9:55AM"], ["10:10AM","11:00AM"], ["11:15AM","12:05PM"], ["12:20PM","1:10PM"], ["1:25PM","2:15PM"], ["2:30PM","3:20PM"], ["3:35PM","4:25PM"]]
option = random.randint(0,6)
timeSelected = times[option]
courseStartTime = timeSelected[0]
courseEndTime = timeSelected[1]

else:
courseScheduledDays = "None"
courseStartTime = "None"
courseEndTime = "None"
courseEnrolledStudents = random.randint(0,courseMaxStudents)
courseIsOpen = bool(courseMaxStudents - courseEnrolledStudents)
if courseFormat == "In-person":
courseLocation = random.choice(["MCHU 101", "E2 306", "ITE 114", "MONT 319", "GANT 109", "ARJ 114", "ROWE 307", "ITE 332"])
else:
courseLocation = "Online"

coursePrereqs = "None"

courseInsert(courseId, courseSection, courseLevel, courseDepartment, courseProfessor, courseEnrolledStudents, courseMaxStudents, courseIsOpen, courseFormat, coursePrereqs, courseStartTime, courseEndTime, courseScheduledDays, courseLocation)

#courseRemove('CSE2102', '001')
#enrollStudent('CSE1010', '001L')
# for i in range(1000):
# courseDepartment = random.choice(['CSE', 'COMM', 'ANTH', 'STAT', 'SPAN', 'GERM', 'ERTH'])
# courseNumber = random.randint(1000,5000)
# courseSection = 1
# if len(str(courseSection)) == 1:
# courseSection = '00' + str(courseSection)
# elif len(str(courseSection)) == 2:
# courseSection = '0' + str(courseSection)
# # courseType = input("\nSelect the type of course if needed: Laboratory, Discussion: ")
# # if courseType == "Laboratory":
# # courseSection += 'L'
# # elif courseType == "Discussion":
# # courseSection += 'D'
# courseLevel = math.floor(courseNumber / 1000) * 1000
# courseId = courseDepartment + str(courseNumber)
# courseProfessor = random.choice(['Ariana Grande', 'Jeff Bezos', 'Samuel Alito', 'Greg Jackson', 'Nicholas Couillard', 'Miley Cirus', 'Joe Biden', 'Barack Obama', 'Gabe Vincent', 'Stephen Curry', 'Kamala Harris', '6ix9ine', 'Ghandi'])
# courseMaxStudents = random.randint(0,200)
# courseFormat = random.choice(["In-person", "Online asynchronous", "Online synchronous"])
# if courseFormat == "In-person" or courseFormat == "Online synchronous":
# numDaysTest = random.randint(0,3)
# counter = 0
# courseScheduledDays = []
# weekDays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
# while counter < numDaysTest:
# counter += 1
# choice = random.choice(weekDays)
# courseScheduledDays.append(choice)
# weekDays.remove(choice)
# times = [["9:05AM","9:55AM"], ["10:10AM","11:00AM"], ["11:15AM","12:05PM"], ["12:20PM","1:10PM"], ["1:25PM","2:15PM"], ["2:30PM","3:20PM"], ["3:35PM","4:25PM"]]
# option = random.randint(0,6)
# timeSelected = times[option]
# courseStartTime = timeSelected[0]
# courseEndTime = timeSelected[1]

# else:
# courseScheduledDays = "None"
# courseStartTime = "None"
# courseEndTime = "None"
# courseEnrolledStudents = random.randint(0,courseMaxStudents)
# courseIsOpen = bool(courseMaxStudents - courseEnrolledStudents)
# if courseFormat == "In-person":
# courseLocation = random.choice(["MCHU 101", "E2 306", "ITE 114", "MONT 319", "GANT 109", "ARJ 114", "ROWE 307", "ITE 332"])
# else:
# courseLocation = "Online"

# coursePrereqs = "None"

# enrolledStudentList = []

# courseInsert(courseId, courseSection, courseLevel, courseDepartment, courseProfessor, courseEnrolledStudents, courseMaxStudents, courseIsOpen, courseFormat, coursePrereqs, courseStartTime, courseEndTime, courseScheduledDays, courseLocation, enrolledStudentList)


enrollStudent('SPAN4173', '001', 'nic21003')
22 changes: 22 additions & 0 deletions StudentFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from boto3 import resource
from boto3.dynamodb.conditions import Attr, Key
import math
import random

student_table = resource('dynamodb').Table('Students')

def createStudent(studentID, studentPWD, enrolledCourses = []):
studentCreation = student_table.put_item(
Item = {
'StudentId' : studentID,
'StudentPWD' : studentPWD,
'EnrolledCourses' : enrolledCourses
}
)

print(f"Student creation output: {studentCreation}")



if __name__ == "__main__":
createStudent("nic21003", "coolTest420")

0 comments on commit bae8b39

Please sign in to comment.