@sunzhongmou/math
Version:
Mathematical knowledge context
56 lines • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mathematics = void 0;
const exercise_1 = require("./exercise");
const expression_1 = require("./expression");
const permutation_1 = require("./permutation");
const sourceInput_1 = require("./rule/sourceInput");
class Mathematics {
constructor(sequence) {
this.sequence = sequence;
this.exercise = new exercise_1.Exercise([], []);
this.addExpressions = [];
this.subExpressions = [];
}
generateAddQuestions(velocity, rules) {
const per = permutation_1.shuffle(permutation_1.getFullPermutation(this.sequence).filter(ele => rules.isSatisfied(new sourceInput_1.SourceInput(ele[0], ele[1]))));
const randomElements = permutation_1.randomPickElements(per, velocity);
for (const ele of randomElements) {
this.addExpressions.push(new expression_1.Expression(ele[0], expression_1.Operations.ADD, ele[1]));
}
}
generateLoopAddQuestions(velocity, rules, secondRules) {
const per = permutation_1.getFullPermutation(this.sequence);
const iPer = permutation_1.getIteratedPermutation(this.sequence, per);
const permutation = permutation_1.shuffle(iPer.filter(ele => rules.isSatisfied(new sourceInput_1.SourceInput(ele[0], ele[1])) &&
secondRules.isSatisfied(new sourceInput_1.SourceInput(new expression_1.Expression(ele[0], expression_1.Operations.ADD, ele[1]).execute(), ele[2]))));
const randomElements = permutation_1.randomPickElements(permutation, velocity);
for (const ele of randomElements) {
const exp = new expression_1.Expression(ele[0], expression_1.Operations.ADD, ele[1]);
exp.addOperationSet(expression_1.Operations.ADD, ele[2]);
this.addExpressions.push(exp);
}
}
generateSubQuestions(velocity, rules) {
const per = permutation_1.shuffle(permutation_1.getDescendingPermutation(this.sequence.reverse()).filter(ele => rules.isSatisfied(new sourceInput_1.SourceInput(ele[0], ele[1]))));
const randomElements = permutation_1.randomPickElements(per, velocity);
for (const ele of randomElements) {
this.subExpressions.push(new expression_1.Expression(ele[0], expression_1.Operations.SUB, ele[1]));
}
}
generateQuestions(rawVelocity, fillVelocity) {
let expressions = [];
expressions = permutation_1.shuffle(expressions.concat(this.addExpressions).concat(this.subExpressions));
for (let i = 0; i < rawVelocity; i++) {
this.exercise.addQuestion(expressions[i], exercise_1.QuestionType.RAW);
}
for (let j = rawVelocity; j < rawVelocity + fillVelocity; j++) {
this.exercise.addQuestion(expressions[j], exercise_1.QuestionType.FILL);
}
}
generate() {
return this.exercise.generate();
}
}
exports.Mathematics = Mathematics;
//# sourceMappingURL=mathematics.js.map