Skip to content

Commit

Permalink
Merge pull request #94 from arielfayol37/polishing
Browse files Browse the repository at this point in the history
fixed calculator. polished navigation
  • Loading branch information
arielfayol37 authored Nov 9, 2023
2 parents 0268bd7 + 1c45ec8 commit ec00e74
Show file tree
Hide file tree
Showing 38 changed files with 457 additions and 405 deletions.
3 changes: 0 additions & 3 deletions astros/templates/astros/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
</div>
-->
<div class="welcome-section">
<h4>Welcome to <span class="brand-name">Dr. R</span>!</h4>
<p class="sub-heading">Are you a student or an instructor?</p>
<p>Login to continue or create courses.</p>
<p><a href="{% url 'astros:login' %}"><button class="btn btn-primary" id="login-button"> Login </button></a></p>
</div>

Expand Down
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified deimos/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added deimos/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file modified deimos/__pycache__/views.cpython-311.pyc
Binary file not shown.
54 changes: 1 addition & 53 deletions deimos/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from phobos.models import Course, Question, User, Assignment, VariableInstance, QuestionChoices
from django.core.validators import MaxValueValidator, MinValueValidator
import re
from .utils import *
class Student(User):
"""
Student class to handle students in the platform.
Expand Down Expand Up @@ -308,55 +308,3 @@ def __str__(self):
self.is_modified = False
return f"{self.question_student.student.username} score: {self.score} is modified? {self.is_modified}"


def transform_expression(expr):
"""Insert multiplication signs between combined characters, except within trig functions."""
expression = remove_extra_spaces_around_operators(expr)
expression = expression.replace(', ', '')
expression = expression.replace(' ', '*')
expression = re.sub(r'1e\+?(-?\d+)', r'10^\1', expression)
trig_functions = {
'asin': 'ò', 'acos': 'ë', 'atan': 'à', 'arcsin': 'ê', 'arccos': 'ä',
'arctan': 'ï', 'sinh': 'ù', 'cosh': 'ô', 'tanh': 'ü', 'sin': 'î', 'cos': 'â', 'tan': 'ö', 'log': 'ÿ', 'ln': 'è',
'cosec': 'é', 'sec': 'ç', 'cot': 'û', 'sqrt':'у́', 'pi': 'я',
}

expression = encode(expression, trig_functions)
transformed_expression = ''.join(
char if index == 0 or not needs_multiplication(expression, index, trig_functions)
else '*' + char for index, char in enumerate(expression)
)
transformed_expression = transformed_expression.replace('^', '**')
return decode(transformed_expression, trig_functions)

def remove_extra_spaces_around_operators(text):
pattern = r'(\s*([-+*/^])\s*)'
return re.sub(pattern, lambda match: match.group(2), text)

def needs_multiplication(expr, index, trig_functions):
char = expr[index]
prev_char = expr[index - 1]
return (
(char.isalpha() or char in trig_functions.values()) and prev_char.isalnum() or
char.isdigit() and prev_char.isalpha() or
char == "(" and (prev_char.isalpha() and not prev_char in trig_functions.values())
)

def encode(text, trig_functions):
"""Takes a string and replaces trig functions with their corresponding special character."""
result = text
for key, value in trig_functions.items():
result = result.replace(key, value)
return result

def decode(text, trig_functions):
"""Takes a string and replaces special character with their corresponding trig function."""
special_chars = {'e':'E', 'i':'((-1)^0.5)'}
result = text
# !Important. special_chars for loop must come before
# the trig_functions for loop!
for sc, value in special_chars.items():
result = result.replace(sc, value)
for key, value in trig_functions.items():
result = result.replace(value, key)
return result
7 changes: 7 additions & 0 deletions deimos/static/deimos/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ body.body {
}
ul.courses {
padding: 5%;
margin-top: -4%;
}
.page-title {
padding-left: 5%; /* This padding has to be the same as ul.courses */
}

.page-container {
Expand Down Expand Up @@ -350,6 +354,9 @@ div.tol {
.search-field:hover {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3) !important;
}
.search-field.w-limit-50 {
max-width: 50%;
}

h4{
margin-left: 5%;
Expand Down
4 changes: 2 additions & 2 deletions deimos/static/deimos/js/answer_question.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ document.addEventListener('DOMContentLoaded', ()=> {
if(showHintBtn.classList.contains('closed-hints')){
questionHintsDiv.style.display = 'block';
showHintBtn.classList.remove('closed-hints');
showHintBtn.name = 'caret-down-outline';
showHintBtn.textContent = 'hide';
if(questionHintsDiv.dataset.counter > questionHintsDiv.dataset.seen){
seeMoreBtn.style.display = 'block';
}else{
Expand All @@ -244,7 +244,7 @@ document.addEventListener('DOMContentLoaded', ()=> {
}else{
questionHintsDiv.style.display = 'none';
showHintBtn.classList.add('closed-hints');
showHintBtn.name = 'caret-forward-outline';
showHintBtn.textContent = 'Hints';
}
})
seeMoreBtn.addEventListener('click', (event)=>{
Expand Down
28 changes: 18 additions & 10 deletions deimos/static/deimos/js/calci.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,25 @@ document.addEventListener('DOMContentLoaded', ()=>{



/* Special BUTTONS */
specialBtns.forEach((item)=>{
item.addEventListener('click',()=>{
screen.value += `${specialBtnsTextDict[item.textContent.trim()]}()`
screen.focus();
cursorPosition = screen.value.length - 1;
screen.setSelectionRange(cursorPosition, cursorPosition);
})
}
)
/* Special BUTTONS */
specialBtns.forEach((item) => {
item.addEventListener('click', () => {
const specialText = `${specialBtnsTextDict[item.textContent.trim()]}()`;
cursorPosition = screen.selectionStart; // Get current cursor position

const textBeforeCursor = screen.value.substring(0, cursorPosition);
const textAfterCursor = screen.value.substring(cursorPosition);

// Insert special text at cursor position
screen.value = textBeforeCursor + specialText + textAfterCursor;

// Move the cursor inside the parentheses
cursorPosition = textBeforeCursor.length + specialText.length - 1;
screen.setSelectionRange(cursorPosition, cursorPosition);

screen.focus();
});
});


invBtn.addEventListener('click', ()=>{
Expand Down
40 changes: 22 additions & 18 deletions deimos/templates/deimos/answer_question.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h3 class="original-size">Question {{question_dict.question.number}}</h3>
<div class="hints-feedback">
<div class="hints-container">
{% if question_dict.question.hints.all %}
<ion-icon name="caret-forward-outline" class="show-hint-btn closed-hints" title="Hints"></ion-icon>
<button type="button" style="margin: 2px; transform: scale(0.8);" class="show-hint-btn closed-hints btn btn-outline-info" title="Hints">Hints</button>
<div class="question-hints" data-counter="{{question_dict.question.hints.all.count}}" data-seen="1" style="display:none">
{% for hint in question_dict.question.hints.all %}
{% if forloop.counter0 == 0%}
Expand All @@ -110,7 +110,7 @@ <h3 class="original-size">Question {{question_dict.question.number}}</h3>

{% endfor %}
<br/>
<button type="button" class="see-more-hint-btn btn btn-outline-info" style="display: none;"> see more </button>
<button type="button" class="see-more-hint-btn btn btn-outline-info" style="display: none; transform: scale(0.8);"> see more </button>
</div>
{% endif %}
</div>
Expand Down Expand Up @@ -396,7 +396,7 @@ <h5 class="n-title">
</div>
<div class="side">
<div class="side-info-icon" title="Info">
<ion-icon name="options-outline" size="large"></ion-icon>
<ion-icon name="options-outline"></ion-icon>
</div>
<div class="hide side-info">
<span class="side-info-x">X</span><br/>
Expand All @@ -414,7 +414,7 @@ <h4 class="suggestion original-size">Grading Scheme</h4>
{% else %}
<div class="settings-modification grading-number-{{forloop.counter0}}" style="display: none;">
{% endif %}
{% if not question_dict.questtype == 'mcq' %}
{% if question_dict.questtype == 'struct' %}
<div class="settings-item">
<div class="settings-label">Number of points:</div>
<div class="settings-input-div suggestion">
Expand All @@ -433,24 +433,28 @@ <h4 class="suggestion original-size">Grading Scheme</h4>
{{question_dict.question.struct_settings.deduct_per_attempt|multiply:"100" }}%
</div>
</div >

<div class="settings-item">
<div class="settings-label">% Margin error:</div>
<div class="settings-input-div suggestion">
{{question_dict.question.struct_settings.margin_error|multiply:"100" }}%
</div>
</div>
<div class="settings-item">
<div class="settings-label">% points for units:</div>
<div class="settings-input-div suggestion">
{{question_dict.question.struct_settings.percentage_pts_units|multiply:"100" }}%
</div>
</div>
<div class="settings-item">
<div class="settings-label">Max attempts(units):</div>
<div class="settings-input-div suggestion">
{{question_dict.question.struct_settings.units_num_attempts}}
</div>
</div>
{% if question_dict.answer.answer_unit %}
<div class="settings-item">
<div class="settings-label">Max attempts(units):</div>
<div class="settings-input-div suggestion">
{{question_dict.question.struct_settings.units_num_attempts}}
</div>
</div>
<div class="settings-item">
<div class="settings-label">% points for units:</div>
<div class="settings-input-div suggestion">
{{question_dict.question.struct_settings.percentage_pts_units|multiply:"100" }}%
</div>
</div>
{% endif %}

{% else %}
<div class="settings-item">
<div class="settings-label">Number of points:</div>
Expand All @@ -459,13 +463,13 @@ <h4 class="suggestion original-size">Grading Scheme</h4>
</div>
</div>
<div class="settings-item">
<div class="settings-label">Max attempts(mcq):</div>
<div class="settings-label">Max attempts:</div>
<div class="settings-input-div suggestion">
{{question_dict.question.mcq_settings.mcq_max_num_attempts}}
</div>
</div>
<div class="settings-item">
<div class="settings-label">% deduct per attempt(mcq):</div>
<div class="settings-label">% deduct per attempt:</div>
<div class="settings-input-div suggestion">
{{ question_dict.question.mcq_settings.mcq_deduct_per_attempt|multiply:"100" }}%
</div>
Expand Down
12 changes: 9 additions & 3 deletions deimos/templates/deimos/assignment_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
<li><a href="{% url 'deimos:search_question' %}">Search Question</a></li>
</ul>
</div>
<nav class="navbar-custom">
<a class="nav-link home-btn" href="{% url 'deimos:index' %}">Home </a>
<a class="nav-link" href="{% url 'deimos:course_management' course_id=assignment.course.id %}">Assignments</a>
<a class="nav-link view-notes-btn" href="{% url 'deimos:note_management' course_id=assignment.course.id%}">View notes</a>
<a class="nav-link gradebook-btn" href="{% url 'deimos:gradebook' course_id=assignment.course.id%}">GradeBook</a>
</nav>
<div class="sf-container">
<input type="text" name="search_question" class="page-search search-field" data-name="question-name" placeholder="search question"/>
<input type="text" name="search_question" class="page-search search-field w-limit-50" data-name="question-name" placeholder="search question"/>
</div>
<br/>
<br/>
<h4 class="suggestion" style="font-size: large;">{{assignment.course.name}} - {{assignment.name}}</h4><hr/>

<h4 class="suggestion original-size page-title">{{assignment.course.name}}: {{assignment.name}}</h4>
<hr/>
<!-- Display assignment's questions -->
<ul class="courses course-list">
{% for question in questions %}
Expand Down
2 changes: 1 addition & 1 deletion deimos/templates/deimos/calci.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<button type="button" class="btn calc-btn">e</button>
<button type="button" class="btn calc-btn special exempt">x <span style="position: relative; bottom: .4em; right: .1em;">y</span> </button>
<button type="button" class="btn calc-btn">0</button>
<button type="button" class="btn">.</button>
<button type="button" class="btn calc-btn">.</button>
<button type="button" id="eval" onclick="mathjsEval()">=</button>
<button type="button" class="btn calc-btn">+</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions deimos/templates/deimos/course_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<a class="nav-link home-btn" href="{% url 'deimos:index' %}">Home </a>
<a class="nav-link view-notes-btn" href="{% url 'deimos:note_management' course_id=course.id%}">View notes</a>
<a class="nav-link gradebook-btn" href="{% url 'deimos:gradebook' course_id=course.id%}">GradeBook</a>
</nav>
</nav>

<div class="home">
<div class="sf-container">
<input type="text" name="search" class="page-search search-field" data-name="assignment-name" placeholder="search assignment" />
<input type="text" name="search" class="page-search search-field w-limit-50" data-name="assignment-name" placeholder="search assignment" />
</div>
<br />
<h4>{{course.name}}</h4>
Expand Down
2 changes: 1 addition & 1 deletion deimos/templates/deimos/gradebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="sf-container">
<input type="text" name="search" class="search-field page-search" data-display="table-row"
<input type="text" name="search" class="search-field page-search w-limit-50" data-display="table-row"
data-parent="assignment-row" data-name="assignment-name" placeholder="search by assignment name" />
</div>
<div class="do-margin">
Expand Down
2 changes: 1 addition & 1 deletion deimos/templates/deimos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ul>
</div>
<div class="sf-container">
<input type="text" name="search" class="page-search search-field" data-name="course-name" placeholder="search course" />
<input type="text" name="search" class="page-search search-field w-limit-50" data-name="course-name" placeholder="search course" />
</div>
<h4>My courses</h4>
<!-- Display Student's courses -->
Expand Down
5 changes: 3 additions & 2 deletions deimos/templates/deimos/note_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
{% else %}
Note {{note.question_student.question.number}}
{% endif %}
</strong>
</strong>
</span>
<p class="note-description">{% if note_md|length > 147 %}
{{ note_md|safe|slice:":147" }}...
{% else %}
{{ note_md|safe|safe }}
{{ note_md|safe }}
{% endif %}</p><br>
<p class="timestamp" style="position:relative; float: right; right: 0%; font-size: 10px;"> From <b>question {{note.question_student.question.number}} </b> Last edited on <b>{{note.last_edited}} </b></p>
</div>
Expand Down
9 changes: 4 additions & 5 deletions deimos/templates/deimos/note_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
<a class="nav-link grabebook-btn" href="{% url 'deimos:gradebook' course_id=course.id %}">GradeBook</a>
</nav>
<div class="sf-container">
<input type="text" name="search" class="page-search search-field" data-name="note-name" placeholder="search note" />
<input type="text" name="search" class="page-search search-field w-limit-50" data-name="note-name" placeholder="search note" />
</div>
<br/>

<h4 class="suggestion original-size">{{course.name}} Notes</h4><hr/>

<h4 class="suggestion original-size page-title">{{course.name}}: Notes</h4><hr/>
{% for assignment, note_dict_list in assignments_dict.items %}
<h4>{{assignment.name}}</h4>
<ul class="courses course-list" style="padding:2%;">
<h4 class="suggestion original-size page-title">{{assignment.name}}</h4>
<ul class="courses course-list" style="padding-top:5%;">
{% for note_dict in note_dict_list %}
{% include 'deimos/note_display.html' with note=note_dict.Note note_md=note_dict.note_md assignment_id=assignment.pk course_id=assignment.course.id %}
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion deimos/templates/deimos/question_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<div class="c-text q-text">

<span class="c-name question-name"><strong>Question {{question.number}}</strong>
<span class="c-name question-name"><strong>Question {{question.number}}</strong><span>

<p class="c-description question-content">{% if question.text|length > 147 %}
{{ question.text|safe|slice:":147" }}...
Expand Down
Loading

0 comments on commit ec00e74

Please sign in to comment.