-
Models 1.1 General 1.2 Difficulty and Subject Choices 1.3 Course 1.4 Professor 1.5 Topic and SubTopic 1.6 Assignment 1.7 Question 1.8 QuestionImage 1.9 Hint 1.10 FloatAnswer 1.11 VariableFloatAnswer 1.12 ExpressionAnswer 1.13 LatexAnswer 1.14 TextAnswer 1.15 MCQFloatAnswer 1.16 MCQVariableFloatAnswer 1.17 MCQExpressionAnswer 1.18 MCQLatexAnswer 1.19 MCQTextAnswer 1.20 MCQImageAnswer 1.21 Variable 1.22 VariableInstance 1.23 VariableInterval 1.24 VectorAnswer
-
JavaScript Documentation for Question Creation (answer_input.js)
-
JavaScript Documentation for CALCI (the High Precision Calculator)
models.py
is part of the Django application for the Phobos platform and contains Django models for various aspects of the platform, such as courses, assignments, questions, and more.
Phobos uses the following choices for difficulty and subject:
-
Difficulty:
- Easy
- Medium
- Difficult
-
Subject:
- Computer Science
- Maths
- Physics
The Course
model represents a course on the Phobos platform, with attributes such as name, description, subject, number of students, difficulty level, professors, topics, timestamp, and an optional image.
The Professor
model represents professors on the platform and extends the built-in Django User
model with a department field.
The Topic
model represents course topics, while the SubTopic
model represents subtopics associated with topics.
The Assignment
model represents assignments, including quizzes, homework, and practice tests, with attributes such as name, course, timestamp, due date, assigned date, difficulty level, and category.
The Question
model represents questions, which can be standalone or part of an assignment. It includes attributes such as number, text, assignment, category, topic, sub-topic, number of points, parent question, timestamp, difficulty level, answer type, maximum number of attempts, answer, deduction per attempt, margin of error, and due date.
The QuestionImage
model represents images associated with questions, allowing for additional context.
The Hint
model represents hints for questions, providing additional guidance for solving questions.
The FloatAnswer
model represents float-type answers for structural questions, such as algebraic expressions or numerical values.
The VariableFloatAnswer
model represents variable float answers for structural questions, allowing variables with different values for different users.
The ExpressionAnswer
model represents expression answers for structural questions, which are compared to teacher-provided expressions.
The LatexAnswer
model represents Latex answers for multiple-choice questions (MCQs).
The TextAnswer
model represents text answers for questions, which may include semantic validation using transformers.
The MCQFloatAnswer
model represents float-type answers for MCQs, including correct and incorrect options.
The MCQVariableFloatAnswer
model represents variable float answers for MCQs, allowing different variable values for different users.
The MCQExpressionAnswer
model represents expression answers for MCQs, with both correct and incorrect options.
The MCQLatexAnswer
model represents Latex answers for MCQs, with both correct and incorrect options.
The MCQTextAnswer
model represents text answers for MCQs, with both correct and incorrect options.
The MCQImageAnswer
model represents image answers for MCQs, including correct and incorrect options.
The Variable
model represents variables associated with questions, allowing different instances of variables to be assigned to different users.
The VariableInstance
model represents instances of variables associated with questions.
The VariableInterval
model represents intervals for variables, defining the range of values for variables.
The VectorAnswer
model (deprecated) represented vector-type answers for structural questions. It was stored as a float array.
This documentation provides an overview of the Django models used in the Phobos platform for course management, assignments, and questions. For detailed information on each model and its attributes, please refer to the code in models.py
.
The search_question
view is responsible for enabling users to search for questions that are similar based on a search input. This view utilizes BERT embeddings to compute the cosine similarity between the input text and the text of stored questions. It then presents the top similar questions to the user.
Users initiate a POST request to the view, including the search_question
parameter with the input text they wish to search for.
The view performs the following steps:
- Tokenizes and encodes the input text using a BERT tokenizer.
- Processes the encoded input text through a BERT model to obtain the hidden states of the input.
- Computes the cosine similarity between the encoded input text and the encoded text of each stored question using the
cosine_similarity
function. - Sorts the questions based on their similarity scores and returns the top N (e.g., 5) most similar questions.
The associated template (phobos/search_question.html
) displays the list of top similar questions along with the search input.
The create_question
view is used to allow professors to create new questions and associate them with assignments. It supports various types of question answers, including Multiple Choice Questions (MCQs), expression answers, and text answers.
Professors can access the create_question
view either through a link or by submitting a form.
If accessed via a form submission, the view expects POST data containing different parameters such as question text, answer type, options, etc.
The view carries out the following actions:
- Creates a new
Question
object and associated answer objects based on the submitted data and answer type. - Handles various MCQ answer types (expression, text, float, image, latex) and generates the corresponding answer objects.
- Manages image creation linked to the question using image labels and URLs.
- After question and answer creation, redirects the user to an appropriate page, such as the assignment management page.
The associated template (phobos/create_question.html
) provides a form for entering question details, answer choices, and options for attaching images.
The following explains the functionality and structure of the JavaScript for create question. The general idea is that creating a question is very dynamic and as such we have to track 1) The type of the answer 2) variables 3) Images. Given that certain answers may be algebraic equations and MCQ answers may be entered in latex format, we make use of MathJs to simplify the expressions entered and convert them into readable format using MathJax.
For variables, each time one is created, hidden input fields associated with the variable which is going to processed in the backend when the form is submitted. For images, each time one is uploaded (not submitted), we render the uploaded images and create input fields with information depending on whether is an image for an mcq or just part of the question body.
- Listens for the DOM to be fully loaded before executing the code.
- Initializes various variables and sets up event listeners.
- Listens for a click on the "Survey Question" button.
- Sets the mode to 's-answer' (survey answer), but the functionality is marked as not a high priority and to be implemented later.
- Listens for changes in the file input for image uploads.
- Reads and displays the uploaded image on the page.
- Listens for a click on the "MCQ Question" button.
- Sets the mode to 'm-answer' (multiple-choice answer).
- Displays relevant input fields and options for creating MCQ questions.
- Updates the form's action attribute.
- Listens for clicks on different MCQ modes (expression, float, text, latex, image).
- Configures the input field and placeholders based on the selected mode.
- Listens for a click on the "Add MCQ Option" button.
- Adds a new MCQ option to the list of inputed MCQ answers.
- Validates the input and handles errors.
- Listens for clicks on MCQ options.
- Allows changing the status of an MCQ option (true/false) and deleting options.
- Listens for a click on the "Free Response" button.
- Sets the mode to 'fr-answer' (free response answer).
- Displays relevant input fields and options for creating free response questions.
- Updates the form's action attribute.
- Listens for a click on the "Expression" button.
- Sets the mode to 'e-answer' (expression answer).
- Displays relevant input fields and options for creating expression-based questions.
- Updates the form's action attribute.
- Listens for a click on the "Float" button.
- Sets the mode to 'f-answer' (float answer).
- Displays relevant input fields and options for creating float-based questions.
- Updates the form's action attribute.
- Listens for a click on the "LaTeX" button.
- Sets the mode to 'l-answer' (LaTeX answer), although this functionality is not fully used.
- Displays relevant input fields and options for creating LaTeX-based questions.
- Updates the form's action attribute.
- Listens for changes in the input field used for expression, float, and LaTeX questions.
- Uses MathJax to display the updated content as formatted mathematical expressions.
- Listens for the form submission event.
- Performs validation and processing based on the selected mode before allowing the form to submit.
- Creates and returns an HTML div element for an inputed MCQ option.
- Accepts an input field and the answer type as arguments.
- Converts the input value based on the answer type (expression, float, text, LaTeX, image).
- Handles display and encoding of MCQ options.
- Used within the code to add MCQ options.
- Creates and returns an HTML div element for an uploaded image.
- Accepts an image input field and an image label as arguments.
- Handles display and encoding of uploaded images.
- Used within the code to add uploaded images.
- Utility function to replace a character at a specific index in a string.
- Used within the code for string manipulation.
- Utility function to set a character at a specific index in a string.
- Used within the code for string manipulation.
- Allows users to upload images for the main question.
- Provides options to add and delete uploaded images.
- Supports image labels and display previews.
screen
: Holds a reference to an HTML element with the IDscreen
, presumably an input field for mathematical expressions.btn
: Stores references to all HTML elements with the classbtn
.previousActiveElement
: Keeps track of the previously active element to handle focus.trigMode
: Stores the current trigonometric mode ('deg' or 'rad'), with 'deg' as the default.degModeBtn
: References the HTML element with the IDdeg-mode
.radModeBtn
: References the HTML element with the IDrad-mode
.cursorPosition
: Tracks the cursor position within thescreen
input field.invBtn
: References the HTML element with the IDinv-mode
.trigBtns
: Stores references to all HTML elements with the classtrig
.specialBtns
: Stores references to all HTML elements with the classspecial
.replacementDict
: A dictionary that maps special characters (e.g., 'π' and '√') to their corresponding replacements (e.g., 'pi' and 'sqrt').specialBtnsTextDict
: A dictionary that maps special button text (e.g., 'x y', '√', 'log', etc.) to their corresponding mathematical representations.
-
The
DOMContentLoaded
event listener initializes various elements and sets up additional event listeners when the DOM is fully loaded. -
A loop iterates over each
btn
element (excluding those with the 'exempt' class) and sets up a click event listener. These buttons represent mathematical operations and functions. When clicked, the respective text is inserted into thescreen
input field, updating the cursor position accordingly. -
degModeBtn
andradModeBtn
event listeners handle the switch between degree and radian trigonometric modes. The active button is highlighted. -
The
screen
input field's focus event listener updatespreviousActiveElement
when it receives focus. -
Special buttons (e.g., trigonometric and mathematical functions) have event listeners that insert their corresponding representations into the
screen
input field when clicked. -
invBtn
toggles the inverse mode for trigonometric functions by prefixing 'a' to the button text or removing it.
-
backspc()
: Removes the last character from thescreen
input field. -
mathjsEval()
: Evaluates the mathematical expression entered in thescreen
input field using the Math.js library and updates the input field with the result. -
replaceChars(str, charA, charB)
: Replaces all occurrences ofcharA
withcharB
in the given stringstr
. -
processString(str)
: Processes the input string by replacing characters defined in thereplacementDict
dictionary with their corresponding replacements.
- Jump to Phobos (Instructor App)
- Models
- Views 2.1 Index View 2.2 Course Management View 2.3 Assignment Management View 2.4 Course Enrollment View 2.5 Answer Question View 2.6 Validate Answer View (API Endpoint) 2.7 Authentication Views
- Helper Functions 3.1 is_student_enrolled(student_id, course_id) 3.3 extract_numbers(text) 3.4 compare_expressions(expression1, expression2) 3.5 compare_floats(f1, f2, margin_error=0.0) 3.6 replace_links_with_html(text) 3.7 replace_vars_with_values(text, variable_dict) 3.8 replace_image_labels_with_links(text, labels_url_pairs)
The Student
class is used to represent students on the platform. It extends the User
class.
courses
: A many-to-many relationship withCourse
through theEnrollment
model.assignments
: A many-to-many relationship withAssignment
through theAssignmentStudent
model.questions
: A many-to-many relationship withQuestion
through theQuestionStudent
model.
- Profile pictures can be added if needed.
- School name may be added if the platform scales.
The Note
class is used to allow students to write notes for questions.
student
: A foreign key to theStudent
model.question
: A foreign key to theQuestion
model.content
: Text content of the note.
The NoteImage
class is used to store images in a student's notes for a particular question.
note
: A foreign key to theNote
model.image
: An image field for uploading images related to the note.
The Resource
class is used to store resources suggested by students.
url
: A URL field for the suggested resource.description
: A text field for the description of the resource.student
: A foreign key to theStudent
model.question
: A foreign key to theQuestion
model.is_approved
: A boolean field indicating whether the resource is approved.
The BonusPoint
class represents bonus points gained by students.
points
: An integer representing the number of bonus points.resource
: A one-to-one relationship with theResource
model.student
: A foreign key to theStudent
model.
The Enrollment
class is used to handle a student's enrollment in a particular course.
student
: A foreign key to theStudent
model.course
: A foreign key to theCourse
model.grade
: A float representing the student's grade in the course.registration_date
: A date and time field indicating the date of enrollment.
The AssignmentStudent
class manages the relationship between assignments and students.
student
: A foreign key to theStudent
model.assignment
: A foreign key to theAssignment
model.grade
: A float representing the student's grade for the assignment.
get_grade()
: Computes and returns the grade of a student on an assignment.
The QuestionStudent
class manages the relationship between questions and students.
student
: A foreign key to theStudent
model.question
: A foreign key to theQuestion
model.num_points
: A float representing the number of points earned by the student.success
: A boolean indicating if the question was successfully answered.var_instances
: A many-to-many relationship withVariableInstance
.instances_created
: A boolean indicating if variable instances have been created.
create_instances()
: Creates variable instances for the question.compute_structural_answer()
: Computes the answer to the question if it has variable answers.get_var_value_dict()
: Returns a dictionary of variable symbols and values.evaluate_var_expressions_in_text(text, add_html_style)
: Evaluates expressions containing variables in text.compute_mcq_answers()
: Computes the float answers to an MCQ question if they are variables.get_num_points()
: Calculates and returns the number of points earned by a student.get_num_attempts()
: Returns the number of attempts on a question by a student.
The QuestionAttempt
class is used to manage student attempts on questions.
content
: Text content of the attempt.question_student
: A foreign key to theQuestionStudent
model.success
: A boolean indicating if the attempt was successful.num_points
: A float representing the number of points earned.timestamp
: A date and time field indicating the timestamp of the attempt.
__str__()
: Returns a string representation of the attempt.
The transform_expression
function is a utility function that inserts multiplication signs between combined characters in a mathematical expression.
- URL Route:
/deimos/index
- Description: Displays the main dashboard for students.
- User Access: Requires user authentication. Redirects to the login page if not authenticated.
- Functionality:
- Retrieves courses associated with the authenticated student.
- Displays a list of courses.
- Template:
deimos/index.html
- URL Route:
/deimos/course_management/<course_id>
- Description: Manages a specific course, displaying assignments and related information.
- User Access: Requires user authentication. Redirects to the login page if not authenticated.
- Functionality:
- Checks if the authenticated student is enrolled in the specified course.
- Retrieves assignments associated with the course.
- Template:
deimos/course_management.html
- URL Route:
/deimos/assignment_management/<assignment_id>
- Description: Manages a specific assignment, displaying questions and related information.
- User Access: Requires user authentication. Redirects to the login page if not authenticated.
- Functionality:
- Validates if the authenticated student is assigned to the specified assignment.
- Retrieves questions associated with the assignment.
- Template:
deimos/assignment_management.html
- URL Route:
/deimos/course_enroll/<course_id>
- Description: Allows students to enroll in a specific course.
- User Access: Requires user authentication. Redirects to the login page if not authenticated.
- Functionality:
- Checks if the authenticated student is already enrolled in the course.
- Creates a new enrollment instance if not enrolled.
- Template: N/A
- URL Route:
/deimos/answer_question/<question_id>
- Description: Allows students to answer a specific question within an assignment.
- User Access: Requires user authentication. Redirects to the login page if not authenticated.
- Functionality:
- Retrieves the question and associated answers.
- Handles different types of questions, including MCQ and structural questions.
- Template:
deimos/answer_question.html
- URL Route:
/deimos/validate_answer/<question_id>
- Description: Validates a student's answer to a specific question.
- User Access: Requires user authentication. Redirects to the login page if not authenticated.
- Functionality:
- Validates submitted answers, considering question types and attempts.
- Returns a JSON response indicating correctness.
- Template: N/A
- URL Route:
/deimos/login
- Description: Handles user authentication and login.
- User Access: Available for all users, including guests and authenticated users.
- Functionality:
- Validates email and password.
- Logs in the user if credentials are correct.
- Template:
astros/login.html
- URL Route:
/deimos/logout
- Description: Logs out the currently authenticated user.
- User Access: Available for authenticated users.
- Functionality:
- Logs out the user and redirects to the homepage.
- Template: N/A
- URL Route:
/deimos/register
- Description: Handles user registration.
- User Access: Available for all users, including guests and authenticated users.
- Functionality:
- Validates and registers new students.
- Performs password confirmation.
- Template:
astros/register.html
- Description: Checks if a student is enrolled in a specific course.
- Parameters:
student_id
: The ID of the student to check enrollment for.course_id
: The ID of the course to check enrollment in.
- Returns:
is_enrolled
: Boolean value indicating enrollment status.
- Description: Extracts numbers and subscripted characters from a string.
- Parameters:
text
: The input text to extract numbers and characters from.
- Returns:
matches
: A list of extracted numbers and characters.
- Description: Compares two algebraic expressions for equivalence.
- Parameters:
expression1
: The first algebraic expression.expression2
: The second algebraic expression.
- Returns:
True
: If the expressions are algebraically equivalent.False
: Otherwise.
- Description: Compares two floating-point numbers for equality with a specified margin of error.
- Parameters:
f1
: The first floating-point number.f2
: The second floating-point number.margin_error
: Margin of error for the comparison (default is 0.0).
- Returns:
True
: If the numbers are equal or close within the margin of error.False
: Otherwise.
- Description: Finds links in text and replaces them with HTML
a
tags. - Parameters:
text
: The input text containing links.
- Returns:
text
: The text with links replaced by HTMLa
tags.
- Description: Replaces variables in text with colored values.
- Parameters:
text
: The input text containing variables.variable_dict
: A dictionary of variables and their values.
- Returns:
text
: The text with variables replaced by colored values.
- Description: Replaces labels in text with HTML links.
- Parameters:
text
: The input text containing labels.labels_url_pairs
: A list of label-url pairs.
- Returns:
text
: The text with labels replaced by HTML links.