Skip to content

Commit

Permalink
Created function to generate exercises by concept and type
Browse files Browse the repository at this point in the history
  • Loading branch information
janeq97 committed Jun 20, 2018
1 parent a2d27e5 commit 22c8dd0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
28 changes: 28 additions & 0 deletions src/backend/ExerciseGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import conceptInventory from '../data/ConceptMap';
// So, we import all of ConceptKnowledge
import {ConceptKnowledge, MasteryModel} from '../data/MasteryModel';

var exercises = require('../data/Exercises');

/**
* Generates exercises associated with concepts
* @class
Expand All @@ -20,6 +22,32 @@ class ExerciseGenerator {
this.counter = 0;
}

/**
* Returns and array of exercises for the given exercise type and concept
* @param exerciseType - String ("READ" or "WRITE")
* @param concept - String (Camel Cased)
*/
getExercisesByTypeAndConcept(exerciseType: string, concept: string) {
var exerciseInventory = [exercises.variable17061, exercises.variable18916, exercises.variable51520,
exercises.variable60932, exercises.variable88688]; // Add variable to this array as exercise inventory grows
var exerciseList = [];
for (var i = 0; i < exerciseInventory.length; i++) {
exerciseList = exerciseList.concat(exerciseInventory[i]);
}
var results = [];
var readTypes = ["highlightCode", "multipleChoice", "shortResponse"];
exerciseList.forEach((item) => {
if (item.exercise.concepts.includes(concept)) {
if ((exerciseType === "READ" && readTypes.includes(item.exercise.type)) ||
(exerciseType === "WRITE" && !readTypes.includes(item.exercise.type))) {
results.push(item);
}
}
});
return results;
}


/**
* Gives optimal index of the next concept to generate questions for.
* Index is based on a list of concepts, sorted in this order:
Expand Down
2 changes: 2 additions & 0 deletions src/data/ExercisePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ExercisePoolClass {
getAnswer(exercise: Exercise): ?string {
return this.pool.get(exercise);
}


}

let ExercisePool = new ExercisePoolClass();
Expand Down
12 changes: 6 additions & 6 deletions src/data/Exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const stubExercise: { exercise: Exercise, answer: ?string } = {
answer: 'abc',
};

let variable17061 = [
export let variable17061 = [
{
'exercise': {
'prompt': 'What does this expression simplify to?',
Expand Down Expand Up @@ -192,7 +192,7 @@ let variable17061 = [
},
'answer': 'x = x * 4',
}];
let variable60932 = [
export let variable60932 = [
{
'exercise': {
'prompt': 'Highlight the integer literal',
Expand Down Expand Up @@ -248,7 +248,7 @@ let variable60932 = [
},
'answer': 'new',
}];
let variable18916 = [
export let variable18916 = [
{
'exercise': {
'prompt': 'What is the value of x after the following code executes?',
Expand Down Expand Up @@ -337,7 +337,7 @@ let variable18916 = [
},
'answer': '\'3\'',
}];
let variable88688 = [
export let variable88688 = [
{
'exercise': {
'prompt': 'Choose the correct output of the following code',
Expand Down Expand Up @@ -437,7 +437,7 @@ let variable88688 = [
},
'answer': 'false',
}];
let variable51520 = [
export let variable51520 = [
{
'exercise': {
'prompt': 'Fill in the blank so that the method behaves as follows:\naddTen(15); //would evaluate to 25\naddTen(1); //would evaluate to 11',
Expand Down Expand Up @@ -483,7 +483,7 @@ let variable51520 = [
'answer': '7',
}];

let survey =
export let survey =
{
exercise: {
prompt: 'Take this survey before we begin. Rate how confident you are in your abilities for each concept.',
Expand Down
3 changes: 2 additions & 1 deletion src/ui/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const displayType = {
exercise: 'EXERCISE',
feedback: 'FEEDBACK',
concept: 'CONCEPT',
world: 'WORLD'
world: 'WORLD',
load: 'LOAD'
};
/**
* Renders the koconut application view.
Expand Down
2 changes: 1 addition & 1 deletion src/ui/containers/WorldView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {Component} from 'react';
import {ConceptKnowledge, MasteryModel} from '../../data/MasteryModel';
import {conceptInventory} from '../../data/ConceptMap.js';
import ConceptCard from './../components/ConceptCard';
import ExerciseGenerator from '../../backend/ExerciseGenerator';

/**
* WorldView is the world view for the app, where the user can see all the
Expand All @@ -23,7 +24,6 @@ class WorldView extends Component {
a.dependencyKnowledge / a.knowledge));
}


render() {
let conceptList = this.getOrderedConcepts();
return (
Expand Down

0 comments on commit 22c8dd0

Please sign in to comment.