CourseDB

Documentation for CourseDB.

CourseDB.CourseType
Course

A structure representing a course, with multiple constructors for creating Course objects in various formats.

Fields

  • id::Union{String, Int}: A unique identifier for the course, which can either be a string (default is "new") or an integer (after the course is created in the database).
  • term::String: The academic term in which the course is offered, represented as a string (e.g., "241").
  • code::String: The course code (e.g., "MATH371") with spaces removed and converted to uppercase.
  • name::String: The full name of the course (e.g., "Introduction to Numerical Computing").
  • section::String: The section number of the course, represented as a string.
  • students::Vector{Student}: A list (vector) of students enrolled in the course.

Constructors

  • Course(term::String, code::String, name::String, section::String): Creates a new Course with the term, code, name, and section as strings, initializing id to "new" and students to an empty array.
  • Course(term::Integer, code::String, name::String, section::Integer): Creates a new Course with an integer term and section, with the code converted to uppercase and spaces removed.
  • Course(term::Integer, code::String, name::String, section::String): Creates a new Course with an integer term, string section, and processes the course code similarly.
  • Course(term::String, code::String, name::String, section::Integer): Creates a Course with a string term and an integer section.
  • Course(c::Course, id::Int): Creates a new Course with an updated ID while retaining all other attributes of the existing Course object.
  • Course(c::Course, students::Vector{Student}): Creates a new Course by updating the list of students, while keeping all other course information the same.

Example

course = Course(241, "MATH 371", "Introduction to Numerical Computing", 1)
println(course.code)  # Prints "MATH371"
println(course.id)    # Prints "new"
source
CourseDB.FileDataType
FileData(path::String, fields::Dict{String, String}, data::DataFrame)

A structure representing data loaded from a file, along with metadata about its fields.

Fields

  • path::String: The file path from which the data was read.
  • fields::Dict{String, String}: A dictionary mapping column names to their data types. The keys are the column names (as strings), and the values are either "number" or "string", indicating the type of data in each column.
  • data::DataFrame: The actual data loaded from the file, stored as a DataFrame.

Example

file_data = FileData("students.csv", Dict("id" => "number", "name" => "string"), DataFrame())
println(file_data.path)    # Prints the file path
println(file_data.fields)  # Prints the fields dictionary
println(file_data.data)    # Prints the DataFrame
source
CourseDB.GradeType
Grade

A structure representing a detailed record of a student's grade for a specific assessment in a course.

Fields

  • student_id::Int: The unique identifier of the student.
  • student_name::String: The full name of the student.
  • student_email::String: The email address of the student.
  • course_id::Int: The unique identifier of the course.
  • course_code::String: The code of the course (e.g., "MATH371").
  • course_name::String: The full name of the course (e.g., "Introduction to Numerical Computing").
  • name::String: The name of the assessment or assignment (e.g., "Midterm Exam").
  • value::Float64: The grade received by the student for the assessment.
  • max_value::Float64: The maximum possible grade for the assessment.

Example

grade = Grade(12345, "John Doe", "johndoe@example.com", 1, "MATH371", "Introduction to Numerical Computing", "Final Exam", 90.0, 100.0)
println(grade.student_name)  # Prints "John Doe"
println(grade.value)         # Prints 90.0
source
CourseDB.ResultType
Result

A structure used to represent the outcome of an operation, which can include data and a corresponding message.

Fields

  • data::Union{Nothing, Vector{Student}, Vector{Grade}, DataFrame}: The result of an operation. This field can contain:
    • Nothing: If no data is available or the operation failed.
    • Vector{Student}: A list of Student objects, typically representing enrolled students.
    • Vector{Grade}: A list of Grade objects, typically representing grades assigned to students.
    • DataFrame: A DataFrame containing tabular data, such as a dataset from an external source (e.g., a file).
  • message::String: A descriptive message accompanying the result, which may provide feedback on the operation (e.g., success or error messages).

Example

result = Result(Vector{Student}(), "Operation successful")
println(result.message)  # Prints "Operation successful"
println(result.data)     # Prints an empty vector of students
source
CourseDB.StudentType
Student(id::Int, name::String, email::String)

A structure representing a student with their basic details.

Fields

  • id::Int: The student's unique identifier, typically a numeric value.
  • name::String: The student's full name.
  • email::String: The student's email address.

Example

student = Student(12345, "John Doe", "johndoe@example.com")
println(student.id)    # Prints the student ID
println(student.name)  # Prints the student name
println(student.email) # Prints the student email
source
Base.namesMethod
names(c::Course)::Vector{String}

Retrieves the names of students enrolled in a given Course.

Arguments

  • c::Course: A Course object containing student data.

Returns

  • A Vector{String} of student names. If the course has no students, returns an empty array.

Example

course = createCourse(241, "MATH 371", "Introduction to Numerical Computing", 1)
student_names = names(course)
println(student_names)  # Prints a vector of student names
source
CourseDB.addGradesMethod
addGrades(c::Course, file_path::String, args...;
    fields::Union{Dict{Symbol, String}, Dict{Symbol, Any}}=Dict(:sid => "sid", :name => "name", :value => "value", :max_value => "max_value"), kwargs...)

Adds student grades to a Course object by reading grade data from a file and creating Grade objects.

Arguments

  • c::Course: The Course object to which grades will be added.
  • file_path::String: The path to the file containing grade data. Supported file types are csv, txt, and xlsx.
  • args...: Additional positional arguments passed to the file reading function (readdata).
  • fields::Union{Dict{Symbol, String}, Dict{Symbol, Any}}: A dictionary mapping the grade data fields (student ID, name, value, max value) to their corresponding column names in the file. Default mapping is :sid => "sid", :name => "name", :value => "value", and :max_value => "max_value". Each field can also be a tuple where the first value is the column name, and the second value is a transformation function.
  • kwargs...: Additional keyword arguments passed to the file reading function.

Returns

  • A Course object with the added grades.

Workflow

  1. Reads the grade data from the specified file using readdata.
  2. Extracts student IDs, names, grade values, and maximum possible values based on the provided or default fields mapping.
  3. Creates Grade objects for each student in the course.
  4. Filters out any grades that do not match the existing student IDs in the course.
  5. Adds the valid grades to the course using the add_student_grades function.
  6. If some grades cannot be matched to students, a warning is issued.

Example

course = createCourse(241, "MATH 371", "Introduction to Numerical Computing", 1)
updated_course = addGrades(course, "grades.csv", delim=',', header=true)
println(updated_course.students)  # Prints the course with students and their grades
source
CourseDB.addStudentsMethod
addStudents(c::Course, file_path::String, args...; fields::Union{Dict{Symbol, String}, Dict{Symbol, Any}}=Dict(:id => "id", :name => "name", :email => "email"), kwargs...)

Adds students to a Course object by reading data from a file and creating Student objects based on the file content.

Arguments

  • c::Course: The Course object to which students will be added.
  • file_path::String: The path to the file containing student data. Supported file types are csv, txt, and xlsx.
  • args...: Additional positional arguments passed to the file reading function (readdata).
  • fields::Union{Dict{Symbol, String}, Dict{Symbol, Any}}: A dictionary mapping the student data fields (ID, name, and email) to their corresponding column names in the file. By default, it assumes :id => "id", :name => "name", and :email => "email". If any field is a tuple, the first value is the column name, and the second value is a transformation function.
  • kwargs...: Additional keyword arguments passed to the file reading function.

Returns

  • A new Course object containing the students loaded from the file, with student data saved to the database.

Workflow

  1. Reads the student data from the specified file using the readdata function.
  2. Extracts student IDs, names, and emails based on the provided or default fields mapping.
  3. Converts the extracted data to create Student objects.
  4. Associates the students with the provided course and saves the student data to the database.

Example

course = Course("241", "MATH 371", "Introduction to Numerical Computing", 1)
updated_course = addStudents(course, "students.csv", delim=',', header=true)
println(updated_course.students)  # Prints the list of added students
source
CourseDB.coursesMethod
courses(term::Union{Int,String}) -> Vector{Course}
courses() -> Vector{Course}

Retrieves a list of courses. The function can either return courses for a specific term or return all courses.

Methods

  • courses(term::Union{Int,String}): Returns courses for a specific term.
  • courses(): Returns all courses, regardless of the term.

Arguments

  • term::Union{Int,String}: The term for which courses should be retrieved. If an Int is provided, it is converted to a string (e.g., 241 becomes "241"). A String term can also be passed directly.

Returns

  • Vector{Course}: A vector containing Course objects. Each object represents a course in the system.

Example

courses_for_term = courses(241)  # Retrieves courses for the term "241"
all_courses = courses()  # Retrieves all courses
source
CourseDB.createCourseMethod
createCourse(term::Union{Integer, String}, code::String, name::String, section::Union{Integer, String})::Course

Creates a Course object and populates it with students by fetching data from a database.

Arguments

  • term::Union{Integer, String}: The term in which the course is offered. This can be an integer (e.g., 241) or a string (e.g., "241").
  • code::String: The course code (e.g., "MATH 371").
  • name::String: The name of the course (e.g., "Introduction to Numerical Computing").
  • section::Union{Integer, String}: The section number of the course, either as an integer or string.

Returns

  • A Course object that contains:
    • course_with_id: The course details (term, code, name, section) with an assigned unique ID from the database.
    • students: A list or collection of students enrolled in the course, fetched from the database.

Example

course = createCourse("241", "MATH 371", "Introduction to Numerical Computing", 1)
println(course.students)  # Prints the list of students enrolled
source
CourseDB.emailsMethod
emails(c::Course)::Vector{String}

Retrieves the email addresses of students enrolled in a given Course.

Arguments

  • c::Course: A Course object containing student data.

Returns

  • A Vector{String} of student email addresses. If the course has no students, returns an empty array.

Example

course = createCourse(241, "MATH 371", "Introduction to Numerical Computing", 1)
student_emails = emails(course)
println(student_emails)  # Prints a vector of student email addresses
source
CourseDB.getGradesMethod
getGrades(c::Course)::Union{Nothing, Vector{Grade}}

Retrieves the grades of students enrolled in a given Course.

Arguments

  • c::Course: A Course object for which to retrieve the grades.

Returns

  • A Vector{Grade} containing the grades of the students if the course has an existing ID.
  • If the course is marked as "new" (i.e., c.id == "new"), returns nothing because no grades are associated with a new course.

Example

course = createCourse(241, "MATH 371", "Introduction to Numerical Computing", 1)
grades = getGrades(course)
if grades !== nothing
    println(grades)  # Prints the grades of the students
else
    println("No grades available for a new course.")
end
source
CourseDB.gradesnamesMethod
gradesnames(c::Course) -> Vector{String}

Retrieves a unique list of grade names (e.g., assignment or exam names) for a given course.

Arguments

  • c::Course: The course for which the grade names are to be retrieved.

Returns

  • Vector{String}: A vector containing the unique names of the assessments or assignments (e.g.,"Quiz1", "MidtermExam", "FinalProject") for the course.

Example

course = createCourse(241, "MATH 371", "Introduction to Numerical Computing", 1)
grade_names = gradsnames(course)
println(grade_names)  # Example output: ["Quiz1", "Midterm", "FinalExam"]
source
CourseDB.readdataMethod
readdata(filepath::String, args...; kwargs...)::FileData

Reads data from a file and returns a FileData object, which includes the file path, a dictionary of field types, and the data as a DataFrame.

Arguments

  • filepath::String: The path to the file to be read. Supported file formats are .csv, .txt, and .xlsx.
  • args...: Positional arguments passed to the file reading functions (XLSX.readtable for .xlsx files).
  • kwargs...: Keyword arguments passed to the file reading functions (CSV.File for .csv and .txt files, XLSX.readtable for .xlsx).

Returns

  • A FileData object containing:
    • filepath: The path of the file.
    • fields: A dictionary where the keys are the column names and the values indicate the data type ("number" for numeric fields and "string" for other types).
    • data: The content of the file as a DataFrame.

Errors

  • Throws an AssertionError if the file does not exist or if the file extension is not supported (csv, txt, xlsx).

Example

file_data = readdata("data.csv", delim=',', header=true)
println(file_data.fields)  # Dict with column names and their types
println(file_data.data)    # DataFrame with the file content
source
CourseDB.writedataMethod
writedata(filepath::String, students::Vector{Student}, args...; kwargs...) -> Result
writedata(filepath::String, grades::Vector{Grade}, args...; kwargs...) -> Result

Writes data to a specified file in tabular format using either XLSX.writetable for .xlsx files or CSV.write for .csv files. The input data can either be a vector of Student objects or a vector of Grade objects.

Arguments

  • filepath::String: The path of the file where the data will be written. The file extension determines whether the data is written in CSV or XLSX format:
    • .csv files are written using CSV.write.
    • .xlsx files are written using XLSX.writetable.
  • students::Vector{Student}: A vector of Student objects to be written to the file (used in the first method).
  • grades::Vector{Grade}: A vector of Grade objects to be written to the file (used in the second method).
  • args...: Additional positional arguments passed to the underlying write operation.
  • kwargs...: Optional keyword arguments passed to the underlying write operation.

Returns

  • Result: A Result object containing the data that was written (Vector{Student} or Vector{Grade}) and a message describing the outcome.

Methods

  • writedata(filepath::String, students::Vector{Student}, args...; kwargs...): Converts the student data to a DataFrame with columns id, name, and email, and writes it to a .csv or .xlsx file using CSV.write or XLSX.writetable, respectively.
  • writedata(filepath::String, grades::Vector{Grade}, args...; kwargs...): Converts the grade data to a DataFrame with columns student_id, student_name, student_email, course_code, course_name, grade, value, and max_value, and writes it to a .csv or .xlsx file using CSV.write or XLSX.writetable, respectively.

Example

students = [Student(123, "John Doe", "john@example.com"), Student(456, "Jane Doe", "jane@example.com")]
res = writedata("students.csv", students)
println(res.message)  # Prints the result message after writing the data using CSV.write

grades = [Grade(123, "John Doe", "john@example.com", 1, "MATH371", "Numerical Computing", "Midterm", 85.0, 100.0)]
res = writedata("grades.xlsx", grades)
println(res.message)  # Prints the result message after writing the data using XLSX.writetable
source