automatic-assessments
Version:
Automatic assessment of Marty and Scratch 3.0 projects
60 lines (59 loc) • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LIST_OPCODE_STRING = exports.LIST_OPCODE_PREFIX = exports.SET_VARIABLE_OPCODE = exports.CHANGE_VARIABLE_OPCODE = exports.MOTION_OPCODE_PREFIX = void 0;
const Analyzer_1 = require("../Analyzer");
exports.MOTION_OPCODE_PREFIX = 'motion_';
exports.CHANGE_VARIABLE_OPCODE = 'data_changevariableby';
exports.SET_VARIABLE_OPCODE = 'data_setvariableto';
exports.LIST_OPCODE_PREFIX = 'data_';
exports.LIST_OPCODE_STRING = 'list';
class DataRepresentation extends Analyzer_1.default {
constructor(targets) {
super();
this.score = 0;
this.targets = targets;
}
execute() {
this.firstPointMotion();
this.twoPointsVariableOperations();
this.threePointsListsOperations();
return this.score;
}
firstPointMotion() {
// one point when at least a motion block is used
for (const target of this.targets) {
for (const _blockKey of Object.keys(target.blocks._blocks)) {
const _block = target.blocks._blocks[_blockKey];
if (_block.opcode.includes(exports.MOTION_OPCODE_PREFIX)) {
this.score = 1;
break;
}
}
}
}
twoPointsVariableOperations() {
// two points when the program contains variable operations
for (const target of this.targets) {
for (const _blockKey of Object.keys(target.blocks._blocks)) {
const _block = target.blocks._blocks[_blockKey];
if (_block.opcode === exports.CHANGE_VARIABLE_OPCODE || _block.opcode === exports.SET_VARIABLE_OPCODE) {
this.score = 2;
break;
}
}
}
}
threePointsListsOperations() {
// three points when the program contains list operations
for (const target of this.targets) {
for (const _blockKey of Object.keys(target.blocks._blocks)) {
const _block = target.blocks._blocks[_blockKey];
if (_block.opcode.includes(exports.LIST_OPCODE_PREFIX) && _block.opcode.includes(exports.LIST_OPCODE_STRING)) {
this.score = 3;
break;
}
}
}
}
}
exports.default = DataRepresentation;