12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import { setTestCases, getTestCases } from "../visualUI/functions";
- import { generate } from "../visualUI/code_generator";
- import { IVProgAssessment } from "../assessment/ivprogAssessment";
- import { TestConsole } from "./testConsole";
- import { parseLogs } from "./../services/userLog";
- import { LocalizedStrings } from './../services/localizedStringsService';
- function parseActivityData (data) {
- let algorithm_in_ilm = null;
- if (data.split('\n::algorithm::')[1]) {
- algorithm_in_ilm = data.split('\n::algorithm::')[1].split('\n::logs::')[0];
- const logs = data.split('\n::algorithm::')[1].split('\n::logs::')[1];
- if (logs != null) {
- parseLogs(logs);
- }
- }
- let content;
- try {
- content = JSON.parse(data.split('\n::algorithm::')[0]);
- content['algorithm_in_ilm'] = algorithm_in_ilm;
- } catch (e) {
- $('.ui.height_100.add_accordion').dimmer({
- closable: false
- });
- $('.dimmer_content_message h3').html(LocalizedStrings.getUI('text_message_error_activity_file'));
- $('.dimmer_content_message button').text(LocalizedStrings.getUI('text_message_error_activity_reload'));
- $('.dimmer_content_message').css('display', 'block');
- $('.ui.height_100.add_accordion').dimmer('add content', '.dimmer_content_message');
- $('.ui.height_100.add_accordion').dimmer('show');
- console.error(e);
- }
- return content;
- }
- export function prepareActivityToStudentHelper (ilm_cont) {
- const content = parseActivityData(ilm_cont);
- const testCases = content.testcases;
- setTestCases(testCases);
- let prog_type = null;
- if (content.settings_programming_type) {
- prog_type = content.settings_programming_type[0].value;
- } else {
- prog_type = "visual";
- }
- return {
- settingsProgrammingType: prog_type,
- settingsDataTypes: content.settings_data_types,
- settingsCommands: content.settings_commands,
- settingsFunctions: content.settings_functions,
- algorithmInIlm: content.algorithm_in_ilm
- }
- }
- export function autoEval (originalData, callback) {
- const code = generate();
- const original = parseActivityData(originalData);
- if (code == null) {
- return callback(-1);
- } else {
- if (!compareTestcases(original.testcases, getTestCases())) {
- return callback(-2);
- }
- const autoAssessment = new IVProgAssessment(code, getTestCases(), new TestConsole([]));
- autoAssessment.runTest().then( grade => callback(grade)).catch(err => {
- console.log(err);
- callback(0);
- });
- }
- }
- function compareTestcases (original, student) {
- if (original.length != student.length) {
- return false;
- }
- for (let i = 0; i < original.length; ++i) {
- const elementO = original[i];
- const elementS = student[i];
- if(!compareArray(elementO.input, elementS.input)) {
- return false;
- }
- if(!compareArray(elementO.output, elementS.output)) {
- return false;
- }
- }
- }
- function compareArray (a, b) {
- for (let i = 0; i < a.length; ++i) {
- const elementA = a[i];
- const elementB = b[i];
- if (elementA != elementB) {
- return false;
- }
- }
- }
|