Kaynağa Gözat

Implement teacherautoeval param from iassign

Lucas de Souza 5 yıl önce
ebeveyn
işleme
f96721a39a

+ 28 - 10
js/iassign-integration-functions.js

@@ -12,6 +12,7 @@ var iLMparameters = {
     iLM_PARAM_SendAnswer: getParameterByName("iLM_PARAM_SendAnswer"),
     iLM_PARAM_AssignmentURL: getParameterByName("iLM_PARAM_AssignmentURL"),
     iLM_PARAM_Assignment: getParameterByName("iLM_PARAM_Assignment"),
+    iLM_PARAM_TeacherAutoEval: getParameterByName("iLM_PARAM_TeacherAutoEval"),
     lang: getParameterByName("lang", "pt")
 };
 
@@ -127,8 +128,13 @@ function getiLMContent () {
     // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
     // requisitado via AJAX para a captura dos dados da atividade
     $.get(iLMparameters.iLM_PARAM_Assignment, function (data) {
-        // Aluno está trabalhando em alguma atividade:
-        if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
+        //professor invocou a avaliação automática dos exercícios do bloco
+        if (iLMparameters.iLM_PARAM_TeacherAutoEval == 'true') {
+            teacherAutoEval(data);
+            //não deve exibir nenhuma interface...
+            return;
+        } else if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
+            // Aluno está trabalhando em alguma atividade:
             previousContent = data;
             prepareActivityToStudent(data);
         } else { // Professor está editando uma atividade:
@@ -254,25 +260,21 @@ $(document).ready(function() {
         $('.div_to_body').click(function(e) {
             trackingMatrix.push(adCoords(e, 1));                    
         });
-
-        
-
-    } else {
+    } else if (iLMparameters.iLM_PARAM_Assignment) {
         // Caso não esteja em modo de resolução de atividade, a visualização no momento
         // é para a elaboração de atividade:
         //$('.elaboracao').css("display","block");
 
         // Se possuir o parâmetro iLMparameters.iLM_PARAM_Assignment, o professor
         // está editando uma atividade:
-        if (iLMparameters.iLM_PARAM_Assignment) {
-            getiLMContent();
-        }
+        getiLMContent();
+    } else {
+        renderAlgorithm();
     }
     if (inIframe()) {
         orderIcons();
         orderWidth();
     }
-    // renderAlgorithm();
 
 });
 
@@ -507,4 +509,20 @@ function full_screen() {
     } else {
         $('.expand_button').addClass('disabled');
     }
+}
+
+function teacherAutoEval (data) {
+    // Ver arquivo js/util/iassignHelpers.js
+    var content = ivprogCore.prepareActivityToStudentHelper(data);
+    // Casos de testes agora são delegados ao tratamento apropriado pela função acima
+    // var testCases = content.testcases;
+    settingsDataTypes = content.settingsDataTypes;
+    settingsCommands = content.settingsCommands;
+    settingsFunctions = content.settingsFunctions;
+
+    if (content.algorithmInIlm != null) {
+        algorithm_in_ilm = content.algorithmInIlm;
+        parsePreviousAlgorithm();
+        ivprogCore.autoEval(parent.getEvaluationCallback);
+    }
 }

+ 2 - 1
js/main.js

@@ -4,7 +4,7 @@ import { initVisualUI, addFunctionChangeListener,
   removeGlobalListener, getTestCases } from './visualUI/functions';
 import * as LocalizedStringsService from './services/localizedStringsService';
 import { i18nHelper } from "./services/i18nHelper";
-import { prepareActivityToStudentHelper } from "./util/iassignHelpers";
+import { prepareActivityToStudentHelper, autoEval } from "./util/iassignHelpers";
 
 const i18n = i18nHelper.i18n
 const LocalizedStrings = LocalizedStringsService.getInstance();
@@ -17,6 +17,7 @@ export {
   removeFunctionListener,
   removeGlobalListener,
   getTestCases,
+  autoEval,
   prepareActivityToStudentHelper,
   LocalizedStrings,
   i18n

+ 14 - 1
js/util/iassignHelpers.js

@@ -1,4 +1,7 @@
-import { setTestCases } from "../visualUI/functions";
+import { setTestCases, getTestCases } from "../visualUI/functions";
+import { generate } from "../visualUI/code_generator";
+import { IVProgAssessment } from "../assessment/ivprogAssessment";
+import { TestConsole } from "./testConsole";
 
 export function prepareActivityToStudentHelper (ilm_cont) {
   const content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
@@ -17,4 +20,14 @@ export function prepareActivityToStudentHelper (ilm_cont) {
     settingsFunctions: settingsFunctions,
     algorithmInIlm: algorithm_in_ilm
   }
+}
+
+export function autoEval (callback) {
+  const code = generate();
+  if (code == null) {
+    return callback(-1);
+  } else {
+    const autoAssessment = new IVProgAssessment(code, getTestCases(), new TestConsole([]));
+    autoAssessment.runTest().then( grade => callback(grade)).catch(err => console.log(err))
+  }
 }

+ 59 - 0
js/util/testConsole.js

@@ -0,0 +1,59 @@
+import { DOMConsole } from "../io/domConsole";
+import { getInstance } from "../services/localizedStringsService";
+
+const LocalizedStrings = getInstance();
+
+export class TestConsole {
+
+
+  constructor (inputList) {
+    this.index = 0;
+    this.inputList = inputList;
+    this.list = [];
+  }
+
+  write (text) {
+    this._appendText(text, DOMConsole.USER);
+  }
+
+  info (text) {
+    this._appendText(text, DOMConsole.INFO);
+  }
+
+  err (text) {
+    this._appendText(text, DOMConsole.ERR);
+  }
+
+  _appendText (text) {
+    this.list.push(text);
+  }
+
+
+  getClassForType (type) {
+    switch (type) {
+      case DOMConsole.USER:
+        return "ivprog-term-userText";
+      case DOMConsole.INFO:
+        return "ivprog-term-info";
+      case DOMConsole.ERR:
+        return "ivprog-term-error";
+    }
+  }
+
+  requestInput (callback) {
+    if(this.index < this.inputList.length) {      
+      callback(this.inputList[this.index]);
+      this.index++;
+    } else {
+      throw new Error(LocalizedStrings.getError("exceeded_input_request"));
+    }
+  }
+
+  sendOutput (text) {
+    const output = ""+text;
+    output.split("\n").forEach(t => {
+      t = t.replace(/\t/g,'&#9;');
+      this.write(t)
+    });
+  }
+}