Skip to content

Commit

Permalink
move selectQuestions.js into utils dir
Browse files Browse the repository at this point in the history
  • Loading branch information
nucleogenesis committed Jan 30, 2024
1 parent 210baba commit ee329f9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { get, set } from '@vueuse/core';
import { computed, ref, watch, provide, inject } from 'kolibri.lib.vueCompositionApi';
import logging from 'kolibri.lib.logging';
// TODO: Probably move this to this file's local dir
import selectQuestions from '../modules/examCreation/selectQuestions.js';
import selectQuestions from '../utils/selectQuestions.js';
import { Quiz, QuizSection, QuizQuestion, QuizExercise } from './quizCreationSpecs.js';

const logger = logging.getLogger(__filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants';
import { PageNames } from '../../constants';
import { MAX_QUESTIONS } from '../../constants/examConstants';
import { createExam } from '../examShared/exams';
import selectQuestions from './selectQuestions';

export function resetExamCreationState(store) {
store.commit('RESET_STATE');
Expand Down Expand Up @@ -216,14 +215,17 @@ export function updateSelectedQuestions(store) {
contentNodes.forEach(exercise => {
exercises[exercise.id] = exercise;
});
// TODO This file needs to be cleaned up when updates to quiz management are complete -- this
// will be removed altogether so just no-op for now is ok
const doNothing = () => null;
const availableExercises = exerciseIds.filter(id => exercises[id]);
const exerciseTitles = availableExercises.map(id => exercises[id].title);
const questionIdArrays = availableExercises.map(
id => assessmentMetaDataState(exercises[id]).assessmentIds
);
store.commit(
'SET_SELECTED_QUESTIONS',
selectQuestions(
doNothing(
store.state.numberOfQuestions,
availableExercises,
exerciseTitles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ const logging = logger.getLogger(__filename);
const getTotalOfQuestions = sumBy(qArray => qArray.length);

/**
* TODO: Move this into the composables directory, clarify typing expectations below
* Choose a an evenly-distributed random selection of questions from exercises. Note that the order
* of the arrays should correspond to each other, ie, exerciseIds[i] should correspond to
* questionIdArrays[i] should correspond to exerciseTitles[i], etc.
*
* Choose a an evenly-distributed random selection of questions from exercises.
* @param {number} numQuestions - target number of questions
* @param {array} exerciseIds - exercise IDs
* @param {array} exerciseTitle - exercise titles
* @param {array} questionIdArrays - arrays of question/assessment IDs
* corresponding to the exercise IDs
* @param {Number} numQuestions - target number of questions
* @param {String[]} exerciseIds - QuizExercise IDs
* @param {String[]} exerciseTitle - QuizExercise titles
* @param {Array[String[]]} questionIdArrays - QuizQuestion (assessment) ID arrays corresponding
* to each exercise by index (ie, questionIdArrays[i] corresponds to exerciseIds[i])
* @param {number} seed - value to seed the random shuffle with
* @return {array} - objects of the form { exercise_id, question_id, title }
*
* @return {QuizQuestion[]}
*/
export default function selectQuestions(
numQuestions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import filter from 'lodash/filter';
import selectQuestions from '../src/modules/examCreation/selectQuestions';
import selectQuestions from '../src/utils/selectQuestions';

jest.mock('kolibri.lib.logging');

Expand Down

0 comments on commit ee329f9

Please sign in to comment.