|
| 1 | +import { ScheduledCard } from '../types/user'; |
| 2 | +import { CourseDBInterface } from '../interfaces/courseDB'; |
| 3 | +import { UserDBInterface } from '../interfaces/userDB'; |
| 4 | +import { ContentNavigator } from './index'; |
| 5 | +import { CourseElo } from '@vue-skuilder/common'; |
| 6 | +import { StudySessionReviewItem, StudySessionNewItem } from '..'; |
| 7 | + |
| 8 | +export default class ELONavigator extends ContentNavigator { |
| 9 | + user: UserDBInterface; |
| 10 | + course: CourseDBInterface; |
| 11 | + |
| 12 | + constructor( |
| 13 | + user: UserDBInterface, |
| 14 | + course: CourseDBInterface |
| 15 | + // The ELO strategy is non-parameterized. |
| 16 | + // |
| 17 | + // It instead relies on existing meta data from the course and user with respect to |
| 18 | + // |
| 19 | + // |
| 20 | + // strategy?: ContentNavigationStrategyData |
| 21 | + ) { |
| 22 | + super(); |
| 23 | + this.user = user; |
| 24 | + this.course = course; |
| 25 | + } |
| 26 | + |
| 27 | + async getPendingReviews(): Promise<(StudySessionReviewItem & ScheduledCard)[]> { |
| 28 | + type ratedReview = ScheduledCard & CourseElo; |
| 29 | + |
| 30 | + const reviews = await this.user.getPendingReviews(this.course.getCourseID()); // todo: this adds a db round trip - should be server side |
| 31 | + const elo = await this.course.getCardEloData(reviews.map((r) => r.cardId)); |
| 32 | + |
| 33 | + const ratedReviews = reviews.map((r, i) => { |
| 34 | + const ratedR: ratedReview = { |
| 35 | + ...r, |
| 36 | + ...elo[i], |
| 37 | + }; |
| 38 | + return ratedR; |
| 39 | + }); |
| 40 | + |
| 41 | + ratedReviews.sort((a, b) => { |
| 42 | + return a.global.score - b.global.score; |
| 43 | + }); |
| 44 | + |
| 45 | + return ratedReviews.map((r) => { |
| 46 | + return { |
| 47 | + ...r, |
| 48 | + contentSourceType: 'course', |
| 49 | + contentSourceID: this.course.getCourseID(), |
| 50 | + cardID: r.cardId, |
| 51 | + courseID: r.courseId, |
| 52 | + qualifiedID: `${r.courseId}-${r.cardId}`, |
| 53 | + reviewID: r._id, |
| 54 | + status: 'review', |
| 55 | + }; |
| 56 | + }); |
| 57 | + } |
| 58 | + |
| 59 | + async getNewCards(limit: number = 99): Promise<StudySessionNewItem[]> { |
| 60 | + const activeCards = await this.user.getActiveCards(); |
| 61 | + return ( |
| 62 | + await this.course.getCardsCenteredAtELO({ limit: limit, elo: 'user' }, (c: string) => { |
| 63 | + if (activeCards.some((ac) => c.includes(ac))) { |
| 64 | + return false; |
| 65 | + } else { |
| 66 | + return true; |
| 67 | + } |
| 68 | + }) |
| 69 | + ).map((c) => { |
| 70 | + return { |
| 71 | + ...c, |
| 72 | + status: 'new', |
| 73 | + }; |
| 74 | + }); |
| 75 | + } |
| 76 | +} |
0 commit comments