Skip to content

Commit

Permalink
Merge pull request #136 from ubc/fix-60-log-responses-seen
Browse files Browse the repository at this point in the history
Log answers seen when submitting final answer
  • Loading branch information
xcompass committed Feb 6, 2018
2 parents 8857b8a + 29f7dbc commit ff69bbb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"chai": "^3.2.0",
"chai-as-promised": "^5.1.0",
"cucumber": "^0.5.2",
"d3": "~3.3",
"d3": "~3.5.17",
"jasmine-core": "^2.3.4",
"jquery": "~2.2",
"karma": "^0.13",
Expand All @@ -29,7 +29,7 @@
"phantomjs": "^1.9.17",
"protractor": "~2.5",
"request": "^2.60.0",
"uglify-js": "2.3.6"
"uglify-js": "2.6.0"
},
"scripts": {
"test": "./node_modules/karma/bin/karma start --reporters progress,coverage"
Expand Down
2 changes: 1 addition & 1 deletion ubcpi/static/html/ubcpi.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ <h3 id="pi-question-h" class="question-text" style="display:inline;">{{display_n
</div>
</div>

<input data-ng-disabled="answerForm.$invalid" type='button' class='ubcpi_submit' value="{{ 'Next Step' | translate }} &rarr;" name='ubcpi_next_step' data-ng-click="rc.clickSubmit($event); location.href='#reflecting;'" aria-describedby="button-disabled-reason ubcpi-next-inline-hints" onclick="location.href='#reflecting'"/>
<input data-ng-disabled="answerForm.$invalid" type='button' class='ubcpi_submit' value="{{ 'Next Step' | translate }} &rarr;" name='ubcpi_next_step' data-ng-click="rc.clickSubmit($event);" aria-describedby="button-disabled-reason ubcpi-next-inline-hints" onclick=""/>

</form>

Expand Down
8 changes: 6 additions & 2 deletions ubcpi/static/js/src/ubcpi.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ angular.module('UBCPI', ['ngSanitize', 'ngCookies', 'gettext'])
}
}])

.controller('ReviseController', ['$scope', 'notify', 'backendService', '$q', 'gettext',
function ($scope, notify, backendService, $q, gettext) {
.controller('ReviseController', ['$scope', 'notify', 'backendService', '$q', 'gettext', '$location', '$anchorScroll', '$timeout',
function ($scope, notify, backendService, $q, gettext, $location, $anchorScroll, $timeout) {
var self = this;
var data = $scope.config.data;

Expand Down Expand Up @@ -154,6 +154,10 @@ angular.module('UBCPI', ['ngSanitize', 'ngCookies', 'gettext'])
self.submitting = true;
return backendService.submit(self.answer, self.rationale, self.status()).then(function(data) {
assignData(self, data);
$timeout(function() {
$location.hash('others-responses');
$anchorScroll();
});
}, function(error) {
notify('error', {
'title': gettext('Error submitting answer!'),
Expand Down
12 changes: 6 additions & 6 deletions ubcpi/test/test_lms.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_submit_answer(self, xblock, data, mock):
self.assertEqual(xblock.stats['original'][data['post1']['q']], 1)

# Check the data is persisted
persisted = xblock.get_persisted_data()
persisted = xblock.get_persisted_data(data['expect1']['other_answers'])
self.assertEquals(persisted['answer_original'], 0)
self.assertFalse( 'correct_answer' in persisted )

Expand All @@ -84,7 +84,7 @@ def test_submit_answer(self, xblock, data, mock):
self.assertEqual(xblock.stats['revised'][data['post2']['q']], 1)

# Check we now have all the persisted data we should have
persisted = xblock.get_persisted_data()
persisted = xblock.get_persisted_data(data['expect1']['other_answers'])
self.assertEquals(persisted['answer_original'], 0)
self.assertTrue( 'correct_answer' in persisted )

Expand Down Expand Up @@ -198,13 +198,13 @@ def test_get_asset_url(self, xblock):

def test_truncate_rationale(self):
short_rationale = 'This is a rationale'
truncated_rationle, was_truncated = truncate_rationale(short_rationale)
self.assertEqual(truncated_rationle, short_rationale)
truncated_rationale, was_truncated = truncate_rationale(short_rationale)
self.assertEqual(truncated_rationale, short_rationale)
self.assertFalse(was_truncated)

long_rationale = "x" * 50000
truncated_rationle, was_truncated = truncate_rationale(long_rationale)
self.assertEqual(len(truncated_rationle), MAX_RATIONALE_SIZE_IN_EVENT)
truncated_rationale, was_truncated = truncate_rationale(long_rationale)
self.assertEqual(len(truncated_rationale), MAX_RATIONALE_SIZE_IN_EVENT)
self.assertTrue(was_truncated)

def check_fields(self, xblock, data):
Expand Down
30 changes: 17 additions & 13 deletions ubcpi/ubcpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
MAX_RATIONALE_SIZE = 32000
MAX_RATIONALE_SIZE_IN_EVENT = settings.TRACK_MAX_EVENT / 4


def truncate_rationale(rationale, max_length=MAX_RATIONALE_SIZE_IN_EVENT):
"""
Truncates the rationale for analytics event emission if necessary
Expand Down Expand Up @@ -247,6 +246,11 @@ class PeerInstructionXBlock(XBlock, MissingDataFetcherMixin, PublishEventMixin):
help=_("System selected answers to give to students during the revise stage."),
)

other_answers_shown = Dict(
default={}, scope=Scope.user_state,
help=_("Stores the specific answers of other students shown, for a given student."),
)

algo = Dict(
default={'name': 'simple', 'num_responses': '#'}, scope=Scope.content,
help=_("The algorithm for selecting which answers to be presented to students"),
Expand Down Expand Up @@ -479,8 +483,7 @@ def student_view(self, context=None):
'lang': translation.get_language(),
}
if answers.has_revision(0) and not answers.has_revision(1):
js_vals['other_answers'] = get_other_answers(
self.sys_selected_answers, self.seeds, self.get_student_item_dict, self.algo, self.options)
js_vals['other_answers'] = self.other_answers_shown

# reveal the correct answer in the end
if answers.has_revision(1):
Expand Down Expand Up @@ -509,7 +512,7 @@ def record_response(self, answer, rationale, status):
"""
answers = self.get_answers_for_student()
stats = self.get_current_stats()
truncated_rationle, was_truncated = truncate_rationale(rationale)
truncated_rationale, was_truncated = truncate_rationale(rationale)
corr_ans_text = ''
if self.correct_answer == len(self.options): # handle scenario with no correct answer
corr_ans_text = 'n/a'
Expand All @@ -518,7 +521,7 @@ def record_response(self, answer, rationale, status):
event_dict = {
'answer': answer,
'answer_text': self.options[answer].get('text'),
'rationale': truncated_rationle,
'rationale': truncated_rationale,
'correct_answer': self.correct_answer,
'correct_answer_text': corr_ans_text,
'correct_rationale': self.correct_rationale,
Expand All @@ -532,11 +535,14 @@ def record_response(self, answer, rationale, status):
offer_answer(
self.sys_selected_answers, answer, rationale,
student_item['student_id'], self.algo, self.options)

self.other_answers_shown = get_other_answers(
self.sys_selected_answers, self.seeds, self.get_student_item_dict, self.algo, self.options)
event_dict['other_student_responses'] = self.other_answers_shown
self.publish_event_from_dict(
self.event_namespace + '.original_submitted',
event_dict
)
return event_dict['other_student_responses']
elif answers.has_revision(0) and not answers.has_revision(1) and status == STATUS_ANSWERED:
sas_api.add_answer_for_student(self.get_student_item_dict(), answer, rationale)
num_resp = stats['revised'].setdefault(answer, 0)
Expand Down Expand Up @@ -594,12 +600,11 @@ def submit_answer(self, data, suffix=''):
Answer submission handler to process the student answers
"""
# convert key into integers as json.dump and json.load convert integer dictionary key into string
self.sys_selected_answers = {int(k): v for k, v in self.sys_selected_answers.items()}
self.record_response(data['q'], data['rationale'], data['status'])
self.sys_selected_answers = {int(k): v for k, v in self.sys_selected_answers.items()}

return self.get_persisted_data()
return self.get_persisted_data(self.record_response(data['q'], data['rationale'], data['status']))

def get_persisted_data(self):
def get_persisted_data(self, other_answers):
"""
Formats a usable dict based on what data the user has persisted
Adds the other answers and correct answer/rationale when needed
Expand All @@ -612,8 +617,7 @@ def get_persisted_data(self):
"rationale_revised": answers.get_rationale(1),
}
if answers.has_revision(0) and not answers.has_revision(1):
ret['other_answers'] = get_other_answers(
self.sys_selected_answers, self.seeds, self.get_student_item_dict, self.algo, self.options)
ret['other_answers'] = other_answers

# reveal the correct answer in the end
if answers.has_revision(1):
Expand All @@ -627,7 +631,7 @@ def get_data(self,data,suffix=''):
"""
Retrieve persisted date from backend for current user
"""
return self.get_persisted_data()
return self.get_persisted_data(self.other_answers_shown)

def get_answers_for_student(self):
"""
Expand Down

0 comments on commit ff69bbb

Please sign in to comment.