kolibri
kolibri copied to clipboard
Update score on content card for practice quizzes
Observed behavior
The content cards currently do not have the ability to show the score. We will need to connect to the backend to pull information for the most recent score for a practice quiz from the learner to populate on the cards.
Expected behavior
See the Figma here for the practice quiz cards.

User-facing consequences
Currently, users will see that a practice quiz has been completed, but will not have the ability to see their most recent score until they go into the learner report.
Hi, I would like to contribute! Could you please point me in the direction of the code that deals with displaying the quiz cards.
I would like to work on this issue.
There are two aspects to this issue - one is the frontend, which would require editing both the frontend state management for progress tracking (found here: https://github.com/learningequality/kolibri/blob/release-v0.15.x/kolibri/plugins/learn/assets/src/composables/useContentNodeProgress.js#L13), and the ProgressBar component that is used across multiple cards https://github.com/learningequality/kolibri/blob/release-v0.15.x/kolibri/plugins/learn/assets/src/views/ProgressBar.vue
On the backend, we would need to return a more complex response in the case of practice quizzes - at the moment the values returned are only content_id
and progress
, but this would require more information to be returned - i.e. number of attemptlogs for the most recent masterylog. The code for the current API endpoint is here: https://github.com/learningequality/kolibri/blob/release-v0.15.x/kolibri/core/content/api.py#L1268
For example code of how to retrieve the most recent MasteryLog, see here: https://github.com/learningequality/kolibri/pull/8634/files#diff-7b27ce42afb14b2ac585383ca91a1afca8b49bd9ea595d1923d740f6f547dfc8R457 (although this code is not currently PostgreSQL compatible).
So for the backend process here, #8634 is prerequisite?
I was thinking of starting with the backend and then linking it to cards from the frontend, was my idea right?
how should I get the number of attempting from the most recent masterylog
can you help me with it?
#8634 isn't a prerequisite - it was just an example of how to retrieve the the most recent MasteryLog, which would be required in order to calculate the score.
On a masterylog by masterylog basis, you can call masterylog.attemptlogs.all()
on the object to get the related attemptlogs. However, if we want to implement this within the ContentNodeProgressViewset here: https://github.com/learningequality/kolibri/blob/release-v0.15.x/kolibri/core/content/api.py#L1267 it would be good to be able to generate a query that returns all of these values for you at once.
For an example of how to annotate a MasteryLog queryset with the number answered and the number correct, see here: https://github.com/learningequality/kolibri/blob/8463da925e9e0cf92288be510e3f18b089de8064/kolibri/plugins/coach/class_summary_api.py#L156
@rtibbles I quite did not understand how should I start. here
logs = list(
ContentSummaryLog.objects.filter(
user=self.request.user,
content_id__in=queryset.exclude(kind=content_kinds.TOPIC).values_list(
"content_id", flat=True
),
).values("content_id", "progress")
currently we only get content_id
and progress
.
so, we also need to return a log for masterylog.attemptlogs.all()
and get the number of attemptlogs.
we can do it by
.annotate(attempts=Count("masterylogs__attemptlogs"))
right?
and if this is right we can do .values("content_id", "progress","attempts")
so now we have attempts in logs.
Is this correct? guide me if I am going wrong. also sorry for being late.
logs = list(
ContentSummaryLog.objects.filter(
user=self.request.user,
content_id__in=queryset.exclude(kind=content_kinds.TOPIC).values_list("content_id", flat=True))
.annotate(attempts=Count("masterylogs__attemptlogs"))
.values("content_id", "progress","attempts")
)
@rtibbles can you check the above (backend) solution?
Hi @akash5100 - apologies, I missed your notification in the middle of the Thanksgiving holiday here.
This is nearly there, the main issue is that you would be counting all of the attempts for every MasteryLog - when what is desired is the total number of correct questions and the total number of questions in order to be able to compute a score.
Instead of just counting the total number of attemptlogs associated with the summary log, you would need to count the total number of attemptlogs, and the total number of correct attemptlogs for the most recent masterylog. You would also need to count the number of questions associated with the content node.
There is some code in my recent PR that nearly does this: https://github.com/learningequality/kolibri/pull/8807/commits/61a49bc8b9f6269c8986faa7488294a974ea2564#diff-1a4cafebd9967f427eaca030d47aa155aced82ec4397be23a3fdcaf0c3ec3f5cR46
The main additional thing you would need to do is to first annotate onto the ContentSummaryLog the most recent MasteryLog - this is best done by doing a reverse ordering on end_timestamp
and then getting the first item. I do a similar subquery to annotate the previous masterylog here: https://github.com/learningequality/kolibri/pull/8807/commits/283e79d636a1546801dd1cf49a6245d58a78472b#diff-1a4cafebd9967f427eaca030d47aa155aced82ec4397be23a3fdcaf0c3ec3f5cR43
Once you have annotated the most recent masterylog for the content summary log, you can do a further annotation that counts the total number of attempt logs for that specific mastery log, the total number of correct attempt logs for that specific masterylog, and then you can find out the total number of questions for the ContentNode using 'assessmentmetadata__num_assessments'
.
Between these three fields, you should then have what you need in the progress data to display the two states above (number of questions left if in progress, score if completed).
I would like to be assigned to this issue.
Hi @laynestephens, thanks! You're welcome to give this a try. There are many comments by @rtibbles with useful guidance - please have a look. Do not hesitate to ask any additional questions.
Hi again! I am working with a partner on this issue, @adviti-mishra , and I was wondering if they could be assigned simultaneously.
Hi @laynestephens, yes sure. We will need @adviti-mishra to comment on this issue so I can assign them.
Hello @MisRob Thank you so much! I'm with @laynestephens and would love to be assigned as well.
Hi @adviti-mishra and @laynestephens, since we haven't seen activity here for a long time, I will assign you, If you're still interested, you're welcome to messages us and we can assign again. Be well
@MisRob I would like to work on this issue
@Wck-iipi Thanks for volunteering for this issue, I'll assign it to you. Let us know if you have any questions :)
Hi @Wck-iipi, are you still planning to work on this or would it be better to unassign?
@MisRob You can unassign this. I won't be able to find time to do this as current week is really busy.
Hi, I am picking this up. You can assign me!
Assigned!