-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added more DynamoDB course functions
- Loading branch information
Nicholas Couillard
authored and
Nicholas Couillard
committed
Oct 11, 2023
1 parent
14d965b
commit 66ae00d
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from boto3 import resource | ||
from boto3.dynamodb.conditions import Attr, Key | ||
import math | ||
|
||
course_table = resource('dynamodb').Table('Courses') | ||
# 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, courseStartTime=0, courseEndTime=0, courseScheduledDays='None', courseLocation='None'): | ||
courseInsertion = course_table.put_item( | ||
Item = { | ||
'CourseId' : courseId, # partition key | ||
'Section' : courseSection, # sort key? | ||
'Level' : courseLevel, # useful attribute for searching | ||
'Department' : courseDepartment, # useful attribute for searching | ||
'Professor' : courseProfessor, # TODO: support multiple instructors | ||
'StudentsEnrolled' : courseEnrolledStudents, # useful attribute for professor | ||
'MaxStudents' : courseMaxStudents, # can calculate OpenStatus using some logic | ||
'StartTime' : courseStartTime, # is storing times in the form of 24-hour time easier? it's simple to convert when necessary | ||
'EndTime' : courseEndTime, | ||
'OpenStatus' : courseIsOpen, # this attribute could be useful for hiding unavailable courses | ||
'CourseFormat' : courseFormat, | ||
'CourseScheduledDays' : courseScheduledDays, # this will likely be a list, but im lazy so for now it's a string | ||
'PreRequisites' : prerequisites, # this will be a list of courses | ||
'CourseLocation' : courseLocation # could increase functionality by separating into building and room number, to allow searching by building | ||
} | ||
) | ||
|
||
print(f"Insert response: {courseInsertion}") | ||
|
||
def courseRemove(courseId, courseSection): | ||
courseRemoval = course_table.delete_item( | ||
Key={ | ||
'CourseId' : courseId, # partition key | ||
'Section' : courseSection # sort key | ||
} | ||
) | ||
|
||
print(f"Removal response: {courseRemoval}") | ||
|
||
def enrollStudent(courseId, courseSection): | ||
studentEnroller = course_table.get_item( | ||
Key={ | ||
'CourseId' : courseId, | ||
'Section' : courseSection | ||
}, | ||
AttributesToGet = ['OpenStatus', 'StudentsEnrolled', 'MaxStudents'] | ||
) | ||
|
||
isOpen = (studentEnroller.get('Item')).get('OpenStatus') | ||
numStudents = (studentEnroller.get('Item')).get('StudentsEnrolled') | ||
maxStudents = (studentEnroller.get('Item')).get('MaxStudents') | ||
if maxStudents - (numStudents + 1) > 0: | ||
newOpenStatus = True | ||
else: | ||
newOpenStatus = False | ||
|
||
if isOpen == True: | ||
numStudents += 1 | ||
student_enrolled = course_table.update_item( | ||
Key={ | ||
'CourseId' : courseId, | ||
'Section' : courseSection | ||
}, | ||
UpdateExpression='SET StudentsEnrolled = :val1, OpenStatus = :val2', | ||
ExpressionAttributeValues={ | ||
':val1': numStudents, | ||
':val2': newOpenStatus | ||
} | ||
) | ||
|
||
print(f"{student_enrolled}") | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
# NOTE: NONE OF THE INFO COLLECTING WILL LIKELY BE DONE IN PYTHON, THIS IS PROBABLY VUE STUFF. JUST FOR DEMO | ||
# courseDepartment = input("Enter department: ").upper() | ||
# courseNumber = int(input("\nEnter course number: ")) # NOTE: In vue, make text box that only accepts integers to avoid errors | ||
# courseSection = input("\nEnter course section: ") | ||
# if len(courseSection) == 1: | ||
# courseSection = '00' + courseSection | ||
# elif len(courseSection) == 2: | ||
# courseSection = '0' + 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 = input("\nEnter professor: ") # TODO: support multiple instructors | ||
# courseMaxStudents = int(input("\nEnrollment slots: ")) | ||
# courseFormat = input("\nIs the course online asynchronous, online synchronous, or in-person?: ") # this will be easier to integrate with a few select vue options | ||
# if courseFormat == "In-person" or courseFormat == "Online synchronous": | ||
# courseScheduledDays = input("\nDays the course will meet: ") | ||
# courseStartTime = input("\nStart time: ") # TODO: Turn 12-hour time into 24-hour time integer. Will be easy with vue | ||
# courseEndTime = input("\nEnd time: ") # TODO: Turn 12-hour time into 24-hour time integer. Will be easy with vue | ||
# courseEnrolledStudents = 0 | ||
# courseIsOpen = bool(courseMaxStudents - courseEnrolledStudents) | ||
# if courseFormat == "In-person": | ||
# courseLocation = input("Where will the course be held?: ") | ||
|
||
# courseInsert(courseId, courseSection, courseLevel, courseDepartment, courseProfessor, courseEnrolledStudents, courseMaxStudents, courseStartTime, courseEndTime, courseIsOpen, courseFormat, courseScheduledDays, courseLocation) | ||
|
||
#courseRemove('COMM1000', '001D') | ||
enrollStudent('CSE1010', '001L') |