Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Add progress tracking for scored lessons.
Browse files Browse the repository at this point in the history
	Change on 2013/06/28 by sll <sll@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=48714057
  • Loading branch information
johncox-google committed Jun 29, 2013
1 parent f0d0ba1 commit 2eccf54
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
6 changes: 6 additions & 0 deletions coursebuilder/assets/lib/activity-generic-1.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ function gcbActivityAudit(data_dict) {
}
}

function gcbLessonAudit(data_dict) {
if (gcbCanPostEvents) {
gcbAudit(data_dict, 'attempt-lesson', true);
}
}

function gcbAssessmentAudit(data_dict) {
if (gcbCanPostEvents) {
gcbAudit(data_dict, 'attempt-assessment', true);
Expand Down
39 changes: 32 additions & 7 deletions coursebuilder/controllers/lessons.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
ACTIVITY_PAGE_TYPE = 'activity'


def get_first_lesson(handler, unit_id):
"""Returns the first lesson in the unit."""
lessons = handler.get_course().get_lessons(unit_id)
return lessons[0] if lessons else None


def extract_unit_and_lesson(handler):
"""Loads unit and lesson specified in the request."""

Expand All @@ -74,20 +80,29 @@ def extract_unit_and_lesson(handler):
# Find lesson requested or a first lesson in the unit.
l = handler.request.get('lesson')
lesson = None
lessons = handler.get_course().get_lessons(unit.unit_id)
if not l:
if lessons:
lesson = lessons[0]
lesson = get_first_lesson(handler, unit.unit_id)
else:
lesson = handler.get_course().find_lesson_by_id(unit, l)
return unit, lesson


def get_unit_and_lesson_id_from_url(url):
def get_unit_and_lesson_id_from_url(handler, url):
"""Extracts unit and lesson ids from a URL."""
url_components = urlparse.urlparse(url)
query_dict = urlparse.parse_qs(url_components.query)
unit_id, lesson_id = query_dict['unit'][0], query_dict['lesson'][0]

if 'unit' not in query_dict:
return None, None

unit_id = query_dict['unit'][0]

lesson_id = None
if 'lesson' in query_dict:
lesson_id = query_dict['lesson'][0]
else:
lesson_id = get_first_lesson(handler, unit_id).lesson_id

return unit_id, lesson_id


Expand Down Expand Up @@ -236,6 +251,7 @@ def get(self):
self.student = student
self.unit_id = unit_id
self.lesson_id = lesson_id
self.lesson_is_scored = lesson.scored

index = lesson.index - 1 # indexes are 1-based

Expand Down Expand Up @@ -892,15 +908,24 @@ def process_event(self, user, source, payload_json):
source_url = payload['location']

if source == 'attempt-activity':
unit_id, lesson_id = get_unit_and_lesson_id_from_url(source_url)
unit_id, lesson_id = get_unit_and_lesson_id_from_url(
self, source_url)
if unit_id is not None and lesson_id is not None:
self.get_course().get_progress_tracker().put_block_completed(
student, unit_id, lesson_id, payload['index'])
elif source == 'tag-assessment':
unit_id, lesson_id = get_unit_and_lesson_id_from_url(source_url)
unit_id, lesson_id = get_unit_and_lesson_id_from_url(
self, source_url)
cpt_id = payload['instanceid']
if (unit_id is not None and lesson_id is not None and
cpt_id is not None):
self.get_course().get_progress_tracker(
).put_component_completed(
student, unit_id, lesson_id, cpt_id)
elif source == 'attempt-lesson':
# Records progress for scored lessons.
unit_id, lesson_id = get_unit_and_lesson_id_from_url(
self, source_url)
if unit_id is not None and lesson_id is not None:
self.get_course().get_progress_tracker().put_html_completed(
student, unit_id, lesson_id)
6 changes: 4 additions & 2 deletions coursebuilder/modules/assessment_tags/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def render(self, node, handler):
instanceid = node.attrib.get('instanceid')

progress = None
if hasattr(handler, 'student') and not handler.student.is_transient:
if (hasattr(handler, 'student') and not handler.student.is_transient
and not handler.lesson_is_scored):
progress = handler.get_course().get_progress_tracker(
).get_component_progress(
handler.student, handler.unit_id, handler.lesson_id,
Expand Down Expand Up @@ -180,7 +181,8 @@ def render(self, node, handler):
template_values['instanceid'] = group_instanceid
template_values['resources_path'] = RESOURCES_PATH

if hasattr(handler, 'student') and not handler.student.is_transient:
if (hasattr(handler, 'student') and not handler.student.is_transient
and not handler.lesson_is_scored):
progress = handler.get_course().get_progress_tracker(
).get_component_progress(
handler.student, handler.unit_id, handler.lesson_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,23 @@ QuestionGroup.prototype.makeReadOnly = function(state) {
function gradeScoredLesson(questions, messages) {
var score = 0.0;
var totalWeight = 0.0;
var answers = {'version': '1.5'};
$.each(questions, function(idx, question) {
var grade = question.grade();
score += grade.score * question.getWeight();
totalWeight += question.getWeight();
answers[question.id] = question.getStudentAnswer();
question.displayFeedback(grade.feedback);
});
$('div.qt-grade-report')
.text(messages.yourScoreIs + score.toFixed(2) +
'/' + totalWeight.toFixed(0))
.removeClass('qt-hidden');

gcbLessonAudit({
'answers': answers,
'score': score
});
}

function gradeAssessment(questions, unitId, xsrfToken) {
Expand Down

0 comments on commit 2eccf54

Please sign in to comment.