Skip to content

Commit

Permalink
fixed(maybe) answer validation for units and sheer answer independence
Browse files Browse the repository at this point in the history
  • Loading branch information
arielfayol37 committed Nov 13, 2023
1 parent 9f88f57 commit 824846a
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 86 deletions.
Binary file modified Dr_R/__pycache__/settings.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Dr_R/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'no.reply.dr.r.valpo@gmail.com' # Your Gmail address
EMAIL_HOST_PASSWORD = 'jxey ewuu mrsq fvnb' # Your Gmail password
EMAIL_HOST_PASSWORD = 'azuv oucz hahf sfqp' # Your Gmail password


Binary file modified db.sqlite3
Binary file not shown.
Binary file modified deimos/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified deimos/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file modified deimos/__pycache__/views.cpython-311.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions deimos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def get_potential(self, no_unit = False):
return potential * overall_percentage

def __str__(self):
return f"Question-Student:{self.question} {self.student.username}"
return f"{self.question} {self.student.username}"

class Note(models.Model):
"""
Expand Down Expand Up @@ -342,7 +342,7 @@ class QuestionAttempt(models.Model):
# while the actual submission will be stored in submitted_answer.
submitted_answer =models.CharField(max_length=3000, blank=True, null=True)
def __str__(self):
return f"{self.question_student.student.username} attempt for {self.question_student.question}"
return f"{self.question_student.student.username} for {self.question_student.question}"

class QASuccessPairs(models.Model):
"""
Expand Down
15 changes: 8 additions & 7 deletions deimos/static/deimos/js/answer_question.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ document.addEventListener('DOMContentLoaded', ()=> {
return;
}

} else if (questionType.value ==='mcq' && inputedMcqAnswersDiv.trueCounter===0){
alert('Must select at least on MCQ answer as true');
} else if (questionType.value =='mcq' && inputedMcqAnswersDiv.dataset.trueCounter== 0){
alert('Must select at least one MCQ answer as true');
return;
} else if (questionType.value == 'mp'){
// check whether all the parts have been selected.
Expand Down Expand Up @@ -854,23 +854,24 @@ document.addEventListener('DOMContentLoaded', ()=> {
potential: '.status-potential',
unitsNumAttempts:'.status-units-num-attempts'
};

const qb = form.closest('.question-block');
if (result.complete){
qb.querySelector('.status-potential').style.display = 'none';
}
// Loop through each key in the statusMappings object
for (const key in statusMappings) {
if (statusMappings.hasOwnProperty(key)) {
// Construct the selector using the mapping
const selector = statusMappings[key] + ' .status-value';
const qb = form.closest('.question-block');

// Update the innerHTML of the element matching the selector
const element = qb.querySelector(selector);
if(element != null){
element.innerHTML = result[key];
}
if(result.success){
qb.querySelector('.status-potential').style.display = 'none';
}
}
}


}

Expand Down
10 changes: 5 additions & 5 deletions deimos/templates/deimos/answer_question.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h3 class="original-size">Question {{question_dict.question.number}}</h3>
</div>

<div class="status-potential">
{% if not question_dict.question_student.success %}
{% if not question_dict.question_student.is_complete %}
Potential: <span class="status-value">{{question_dict.potential}}</span>%
{% endif %}
</div>
Expand Down Expand Up @@ -67,7 +67,7 @@ <h3 class="original-size">Question {{question_dict.question.number}}</h3>
</div>

<div class="status-potential">
{% if not question_dict.question_student.success %}
{% if not question_dict.question_student.is_complete %}
Potential: <span class="status-value">{{question_dict.potential}}</span>%
{% endif %}
</div>
Expand Down Expand Up @@ -213,7 +213,7 @@ <h3 class="original-size">Question {{question_dict.question.number}}</h3>
<br/>
{% endfor %}
</div>
{% if question_dict.question_student.success %}
{% if question_dict.question_student.is_complete %}
<input type="submit" class="btn btn-success exempt submit-btn" value="Submit Answer" style="display: none;">
{% else %}
<input type="submit" class="btn btn-success exempt submit-btn" value="Submit Answer">
Expand Down Expand Up @@ -263,7 +263,7 @@ <h3 class="original-size">Question {{question_dict.question.number}}</h3>
</div>
</div>
<br/>
{% if question_dict.question_student.success or question_dict.too_many_attempts %}
{% if question_dict.question_student.is_complete %}
<input type="submit" class="btn btn-success exempt submit-btn" value="Submit Answer" style="display: none;">
{% else %}
<input type="submit" class="btn btn-success exempt submit-btn" value="Submit Answer">
Expand All @@ -289,7 +289,7 @@ <h3 class="original-size">Question {{question_dict.question.number}}</h3>
</div>
</div>
</div>
{% if not question_dict.question_student.success %}
{% if not question_dict.question_student.is_complete %}
<input type="hidden" value="structural_{{question_dict.answer.get_answer_code}}" class="question-type"/>
<!--TODO: !Important. I don't think we will ever use the pk of the answer for structural questions.-->
<input type="hidden" value="{{question_dict.answer.pk}}" name="structural_answer_id_0"/>
Expand Down
12 changes: 6 additions & 6 deletions deimos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ def compare_units(units_1, units_2):
"""

# custom_base_units = ['m', 's', 'cd', 'K', 'mol', 'g', 'A']
scales = {'k':'10^3', 'u':'10^-6', 'm_':'10^-3', 'p':'10^-12', 'M':'10^6', 'n':'10^-9','µ':'10^-6'}
scales = {'k':'(10^3)', 'u':'(10^-6)', 'm_':'(10^-3)', 'p':'(10^-12)', 'M':'(10^6)', 'n':'(10^-9)','µ':'(10^-6)'}
# Important! Hz must come before H, as well as Sv before S, Wb before W etc
correspondances = {
'C': 'A*s', 'V': 'k*g*m^2*s^-3*A^-1','Ω': 'k*g m^2*s^-3*A^-2',
'T': 'k*g*s^-2*A^-1','Hz': 's^-1','Pa': 'k*g*m^-1*s^-2','N': 'k*g*m*s^-2','J': 'k*g*m^2*s^-2',
'Wb':'k*g*m^2*A*s^-2','W': 'k*g*m^2*s^-3', 'F':'k*g*A^2*s^4*m^-2', 'H':'k*g*m^2*A^2*s^-2',
'Sv':'m^2*s^-2','S':'k*g*s^3*A^2*m^-2', 'lx':'cd*m^-2', 'Bq':'s^-1', 'Gy':'m^2*s^-2', 'kat':'mol*s^-1',
'atm':'101325*k*g*m^-1*s^-2'
'C': '(A*s)', 'V': '(k*g*m^2*s^-3*A^-1)','Ω': '(k*g m^2*s^-3*A^-2)',
'T': '(k*g*s^-2*A^-1)','Hz': '(s^-1)','Pa': '(k*g*m^-1*s^-2)','N': '(k*g*m*s^-2)','J': '(k*g*m^2*s^-2)',
'Wb':'(k*g*m^2*A*s^-2)','W': '(k*g*m^2*s^-3)', 'F':'(k*g*A^2*s^4*m^-2)', 'H':'(k*g*m^2*A^2*s^-2)',
'Sv':'(m^2*s^-2)','S':'(k*g*s^3*A^2*m^-2)', 'lx':'(cd*m^-2)', 'Bq':'(s^-1)', 'Gy':'(m^2*s^-2)', 'kat':'(mol*s^-1)',
'atm':'(101325*k*g*m^-1*s^-2)'
}
# transform_units_expression() must be done before to replacing the correspondances
# and scales to reduce runtime.
Expand Down
Loading

0 comments on commit 824846a

Please sign in to comment.