Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨(projet) get user completionrecover the student's progress #9

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Arame22
Copy link
Collaborator

@Arame22 Arame22 commented Sep 20, 2024

use moodle's completion tracker to track student progress

Purpose

Proposal

@SergioSim SergioSim added the enhancement New feature or request label Sep 20, 2024
@SergioSim SergioSim self-requested a review September 20, 2024 08:24
block_iagora.php Outdated
@@ -55,9 +55,49 @@ public function get_content() {
} else {
$this->content->text = $this->generate_chat_content($copilotendpointurl);
}

// Marquer l'activité comme vue pour la complétion si le suivi est activé
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Marquer l'activité comme vue pour la complétion si le suivi est activé
// Mark activity as viewed if tracking is enabled.

As most of our comments are in English, could we keep it that way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite right

block_iagora.php Outdated
// Generate a unique identifier for the chat container.
$chatid = uniqid('iagora_chat_');

// Si la complétion est activée et que l'utilisateur visualise l'activité
if ($completion->is_enabled($cm) && $completion->is_tracked_user($USER->id)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is $completion defined? (I got an exception here saying that it's null)

block_iagora.php Outdated
$completion = new completion_info($COURSE);
if ($completion->is_enabled($this->context) && $completion->is_tracked_user($USER->id)) {
// Marquer l'activité comme vue dans le système de complétion
$completion->set_module_viewed($this->context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we set the module as viewed? Isn't this managed by the completion plugin?
Maybe we could retrieve all completed activities and pass this information the the copilot? For example:

        global $COURSE, $USER;

        $completed_activities = array();
        $completion = new completion_info($COURSE);
        $modinfo = get_fast_modinfo($COURSE, $USER->id);
        $cms = $modinfo->get_cms();

        foreach ($cms as $cm) {
            if ($cm->completion == COMPLETION_TRACKING_NONE) {
                continue;
            }
            if (!$cm->uservisible) {
                continue;
            }
            $completiondata = $completion->get_data($cm, true, $USER->id);
            if ($completiondata->completionstate == COMPLETION_COMPLETE ||
                $completiondata->completionstate == COMPLETION_COMPLETE_PASS) {
                $completed_activities[] = $cm->name;
            }
        }

Maybe passing a list of incomplete activities might be useful, too? What do you think?

block_iagora.php Outdated
Comment on lines 80 to 84
// Appeler l'API Moodle
$completionstatus = call_external_api('core_completion_get_activities_completion_status', [
'courseid' => $courseid,
'userid' => $userid
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin runs inside Moodle; thus, I guess we should avoid calling the external API.
We could check out the source code of the get_activities_completion_status function, which gives an excellent example of how to use the completion_info class to retrieve information about course completion.
The Moodle block_selfcompletion plugin might serve as a great example too)

block_iagora.php Outdated
$context = [
'chatId' => $chatid,
'tokenEndpointURL' => $copilotendpointurl,
'progress' => $progressPercentage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'progress' => $progressPercentage
'progressPercentage' => $progressPercentage

The key should match the one used in the Mustache template.

@Arame22 Arame22 force-pushed the track-user-completion branch 6 times, most recently from 5aacf45 to 9e3f576 Compare September 25, 2024 20:39
@Arame22 Arame22 force-pushed the track-user-completion branch 6 times, most recently from dfcae7f to 6b5b399 Compare October 8, 2024 10:47
use moodle's completion tracker to track student progress
Copy link
Contributor

@SergioSim SergioSim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better 👍

Maybe we could also add a second variable to provide a list of incomplete activities? What do you think?

block_iagora.php Outdated
// Generate a unique identifier for the chat container.
$chatid = uniqid('iagora_chat_');
$context = [
'chatId' => $chatid,
'tokenEndpointURL' => $copilotendpointurl,
'completedactivities' => json_encode($this->get_student_progress()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'completedactivities' => json_encode($this->get_student_progress()),
'completedActivities' => json_encode($this->get_student_progress()),

Aren't JavaScript variables using camelCase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but moodle has not accepted this naming.Here's the error he made Variable "completedActivities" must be all lower-case

block_iagora.php Outdated
@@ -66,12 +100,13 @@ public function get_content() {
* @return string The generated HTML content for the chat.
*/
private function generate_chat_content($copilotendpointurl) {
global $OUTPUT;
global $OUTPUT, $USER, $COURSE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
global $OUTPUT, $USER, $COURSE;
global $OUTPUT;

Where are $USER and $COURSE used?

Copy link
Collaborator Author

@Arame22 Arame22 Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In get_student_progress() I used $COURSE and $USER to retrieve the user's activity progress information get_fast_modinfo($COURSE, $USER->id) and also in $completion->get_data($cm, true, $USER->id) to retrieve whether or not the user has completed the activity.

@@ -45,8 +45,21 @@
/* eslint-disable promise/no-native */
(async function() {
const styleOptions = {
hideUploadButton: true
hideUploadButton: true,
botAvatarImage: "/image/iagora.jpg",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a 404 - image not found. Where is this image defined?
Setting a fixed image for the bot should be fine in the first iteration; however, we should probably make this configurable in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, the method I had originally used required providing a link to the image, which had to be available online. I now wanted to try and create a sub-folder in the IAgora folder to store the image in, and then provide the local path to that image.

Comment on lines 50 to 62
botAvatarInitials: 'BF',
userAvatarImage: 'https://github.com/compulim.png?size=64',
userAvatarInitials: 'WC'
};
const styleSet = window.WebChat.createStyleSet({
bubbleBackground: 'rgba(0, 0, 255, .1)',
bubbleFromUserBackground: 'rgba(0, 255, 0, .1)'
});

styleSet.textContent = Object.assign({}, styleSet.textContent, {
fontFamily: "'Comic Sans MS', 'Arial', sans-serif",
fontWeight: 'bold'
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thoughts here; these values should be configurable.
For the userAvatarImage, we could use the Moodle user profile image, and for the userAvatarInitials - the first letter of the Moodle user's first name and last name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's a good idea, I'm going to follow this approach.

type: 'event'
type: 'event',
value: {
completedactivities: completedactivities
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
completedactivities: completedactivities
completedActivities: '{{completedActivities}}'

@@ -69,7 +82,7 @@
})
.then(({token}) => token)
]);

const completedactivities = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const completedactivities = [];

Isn't the completedActivities variable already defined in the Mustache template?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completedactivities is defined in the mustache template, but as an empty array. I'll fix that using the data passed from the block. I'll fix that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing doc string for the completedActivities context variable (line 29)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll add it

@Arame22 Arame22 force-pushed the track-user-completion branch 3 times, most recently from 8b5b855 to e5495b9 Compare October 10, 2024 14:58
block_iagora.php Outdated Show resolved Hide resolved
block_iagora.php Outdated
$uncompletedactivities[] = $cm->name;
}
}
// Return the array of completed activities and uncompleted activities .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Return the array of completed activities and uncompleted activities .

Isn't this information is already present in the function docstring?

block_iagora.php Outdated Show resolved Hide resolved
@@ -28,11 +28,14 @@
Context variables required for this template:
* chatId: The ID of the chat div element where to render the chat block.
* tokenEndpointURL: The Copilot Token Endpoint URL for native apps.
* completedActivities: A JSON string containing the list of activities the user has already completed.
* uncompletedActivities: A JSON string containing the list of activities the user has not yet completed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstrings for userAvatarImage and userAvatarInitials


Example context (json):
{
"chatId": "iagora_chat_55a6cad25a0f6",
"tokenEndpointURL": "https://insert/your/copilot/endpoint/url"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing example values for completedActivities, uncompletedActivities, userAvatarImage and userAvatarInitials

block_iagora.php Outdated Show resolved Hide resolved
block_iagora.php Outdated Show resolved Hide resolved
block_iagora.php Outdated Show resolved Hide resolved
block_iagora.php Outdated Show resolved Hide resolved
templates/chat.mustache Outdated Show resolved Hide resolved
@Arame22 Arame22 force-pushed the track-user-completion branch 6 times, most recently from c479f42 to cdaaa50 Compare October 11, 2024 17:50
@Arame22 Arame22 force-pushed the track-user-completion branch 3 times, most recently from 7f59af2 to 517e618 Compare October 11, 2024 18:33
Update the block_iagora to include customisable avatar initials and
profil image.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants