Implement Tips Intervention

This commit is contained in:
Sebastian Serth
2021-11-14 16:57:33 +01:00
parent 18f05db138
commit 9079a0b15a
7 changed files with 47 additions and 18 deletions

View File

@ -768,8 +768,9 @@ var CodeOceanEditor = {
* interventions
* */
initializeInterventionTimer: function () {
const editor = $('#editor');
if ($('#editor').data('rfc-interventions') || $('#editor').data('break-interventions')) { // split in break or rfc intervention
if (editor.data('rfc-interventions') || editor.data('break-interventions') || editor.data('tips-interventions')) { // split in break or rfc intervention
window.onblur = function () {
window.blurred = true;
};
@ -777,30 +778,31 @@ var CodeOceanEditor = {
window.blurred = false;
};
var delta = 100; // time in ms to wait for window event before time gets stopped
var tid;
const delta = 100; // time in ms to wait for window event before time gets stopped
let tid;
$.ajax({
data: {
exercise_id: $('#editor').data('exercise-id'),
user_id: $('#editor').data('user-id')
exercise_id: editor.data('exercise-id'),
user_id: editor.data('user-id')
},
dataType: 'json',
method: 'GET',
// get working times for this exercise
url: $('#editor').data('working-times-url'),
url: editor.data('working-times-url'),
success: function (data) {
var percentile75 = data['working_time_75_percentile'];
var accumulatedWorkTimeUser = data['working_time_accumulated'];
const percentile75 = data['working_time_75_percentile'];
const accumulatedWorkTimeUser = data['working_time_accumulated'];
var minTimeIntervention = 10 * 60 * 1000;
const minTimeIntervention = 10 * 1000;
let timeUntilIntervention;
if ((accumulatedWorkTimeUser - percentile75) > 0) {
// working time is already over 75 percentile
var timeUntilIntervention = minTimeIntervention;
timeUntilIntervention = minTimeIntervention;
} else {
// working time is less than 75 percentile
// ensure we give user at least minTimeIntervention before we bother the user
var timeUntilIntervention = Math.max(percentile75 - accumulatedWorkTimeUser, minTimeIntervention);
timeUntilIntervention = Math.max(percentile75 - accumulatedWorkTimeUser, minTimeIntervention);
}
tid = setInterval(function () {
@ -809,9 +811,20 @@ var CodeOceanEditor = {
}
timeUntilIntervention -= delta;
if (timeUntilIntervention <= 0) {
const interventionSaveUrl = editor.data('intervention-save-url');
clearInterval(tid);
// timeUntilIntervention passed
if ($('#editor').data('break-interventions')) {
if (editor.data('tips-interventions')) {
$('#tips-intervention-modal').modal('show');
$.ajax({
data: {
intervention_type: 'TipIntervention'
},
dataType: 'json',
type: 'POST',
url: interventionSaveUrl
});
} else if (editor.data('break-interventions')) {
$('#break-intervention-modal').modal('show');
$.ajax({
data: {
@ -819,10 +832,10 @@ var CodeOceanEditor = {
},
dataType: 'json',
type: 'POST',
url: $('#editor').data('intervention-save-url')
url: interventionSaveUrl
});
} else if ($('#editor').data('rfc-interventions')) {
var button = $('#requestComments');
} else if (editor.data('rfc-interventions')) {
const button = $('#requestComments');
// only show intervention if user did not requested for a comment already
if (!button.prop('disabled')) {
$('#rfc_intervention_text').show();
@ -833,7 +846,7 @@ var CodeOceanEditor = {
},
dataType: 'json',
type: 'POST',
url: $('#editor').data('intervention-save-url')
url: interventionSaveUrl
});
}
}

View File

@ -3,8 +3,9 @@
- consumer_id = @current_user.respond_to?(:external_id) ? @current_user.consumer_id : '' #'tests' #(@current_user.uuid.present? ? @current_user.uuid : '')
- show_break_interventions = @show_break_interventions || "false"
- show_rfc_interventions = @show_rfc_interventions || "false"
- show_tips_interventions = @show_tips_interventions || "false"
- hide_rfc_button = @hide_rfc_button || false
#editor.row data-exercise-id=@exercise.id data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-submissions-url=submissions_path data-user-id=@current_user.id data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path(@exercise) data-intervention-save-url=intervention_exercise_path(@exercise) data-rfc-interventions=show_rfc_interventions data-break-interventions=show_break_interventions data-course_token=@course_token data-search-save-url=search_exercise_path(@exercise)
#editor.row data-exercise-id=@exercise.id data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-submissions-url=submissions_path data-user-id=@current_user.id data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path(@exercise) data-intervention-save-url=intervention_exercise_path(@exercise) data-rfc-interventions=show_rfc_interventions data-break-interventions=show_break_interventions data-tips-interventions=show_tips_interventions data-course_token=@course_token data-search-save-url=search_exercise_path(@exercise)
- unless @embed_options[:hide_sidebar]
- additional_classes = 'sidebar-col'
@ -53,3 +54,4 @@
= render('shared/modal', id: 'comment-modal', title: t('exercises.implement.comment.request'), template: 'exercises/_request_comment_dialogcontent') unless @embed_options[:disable_rfc]
= render('shared/modal', id: 'break-intervention-modal', title: t('exercises.implement.break_intervention.title'), template: 'interventions/_break_intervention_modal') unless @embed_options[:disable_interventions]
= render('shared/modal', id: 'tips-intervention-modal', title: t('exercises.implement.tips.heading'), template: 'interventions/_tips_intervention_modal') unless @embed_options[:disable_hints] or @tips.blank?

View File

@ -0,0 +1,3 @@
h5 == t('exercises.implement.tips_intervention.text')
= render(partial: 'exercises/tips_content')

View File

@ -438,6 +438,8 @@ de:
break_intervention:
title: "Pause"
text: "Uns ist aufgefallen, dass du schon lange an dieser Aufgabe arbeitest. Möchtest du vielleicht später weiter machen um erstmal auf neue Gedanken zu kommen?"
tips_intervention:
text: "Es scheint so als würden Sie Probleme mit der Aufgabe haben. </br> </br> Sind Ihnen die Tipps in der linken Seitenleiste aufgefallen? Sie könnten einige Ihrer Fragen beantworten und werden auch direkt hier angezeigt."
error_hints:
heading: "Hinweise"
tips:

View File

@ -438,6 +438,8 @@ en:
break_intervention:
title: "Break"
text: "We recognized that you are already working quite a while on this exercise. We would like to encourage you to take a break and come back later."
tips_intervention:
text: "It looks like you may struggle with this exercise. </br> </br> Did you notice the tips in the left sidebar? They might answer some of your questions and are also displayed below for your convenience."
error_hints:
heading: "Hints"
tips:

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class CreateTipsIntervention < ActiveRecord::Migration[6.1]
def change
Intervention.find_or_create_by(name: 'TipsIntervention')
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_06_02_071834) do
ActiveRecord::Schema.define(version: 2021_11_14_145024) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"