瀏覽代碼

Update 'js/util/iassignHelpers.js'

Changes to allow to load 3 different formats (old, template and Portugol).
In function setPreviousAlgorithm(code), changed "parserCodeVisual(code_obj)" by
 var result = parserCodeVisual(code_obj); // in js/util/codeParser.js
 if (result == null) { return null; } // force exception to "iassign-integration-functions.js" identify error in the current format try
 return result;
leo 2 月之前
父節點
當前提交
244b70e372
共有 1 個文件被更改,包括 40 次插入52 次删除
  1. 40 52
      js/util/iassignHelpers.js

+ 40 - 52
js/util/iassignHelpers.js

@@ -1,3 +1,6 @@
+// iVProg - www.usp.br/line/ivprog
+// LInE - Free Education, Private Data
+
 import { setTestCases, getTestCases } from "../visualUI/functions";
 import { generate } from "../visualUI/code_generator";
 import { IVProgAssessment } from "../assessment/ivprogAssessment";
@@ -15,10 +18,9 @@ function parseActivityData (data, ignore_logs=false) {
     if (logs != null && ignore_logs == false) {
       try {
         parseLogs(logs);
+      } catch (e) {}
+        }
       }
-      catch (e) {}
-    }
-  }
   let content;
   try {
     content = JSON.parse(data.split("\n::algorithm::")[0]);
@@ -26,58 +28,51 @@ function parseActivityData (data, ignore_logs=false) {
   } catch (e) {
     console.error(e);
     return Maybe.none();
-  }
+    }
   return Maybe.some(content);
-}
+  }
 
 function configAuxiliar (obj_config) {
-
-  return new Map(
-      Object
-        .keys(obj_config)
-        .map(
-            key => [key, obj_config[key]]
-        )
-    )
-}
+  return new Map(Object.keys(obj_config).map(key => [key, obj_config[key]]))
+  }
     
 function setActivityConfig (config_json) {
-
   ivprogCore.Config.activity_commands = configAuxiliar(config_json.commands);
   ivprogCore.Config.activity_functions = configAuxiliar(config_json.functions);
   ivprogCore.Config.activity_datatypes = configAuxiliar(config_json.datatypes);
   ivprogCore.Config.activity_filter = configAuxiliar(config_json.filter);
   ivprogCore.Config.activity_programming_type = configAuxiliar(config_json.programming);
+  }
 
-}
-
-export function setPreviousAlgorithm (code) {
-  
+// @Calledby: js/iassign-integration-functions.js!prepareActivityToStudent(.)
+export function setPreviousAlgorithm (code) {  
   var code_obj = null;
   try {
-    code_obj = ivprogCore.parseCode(code)
-    parserCodeVisual(code_obj)
-  }
-  catch(e) {
+    code_obj = ivprogCore.parseCode(code);
+    var result = parserCodeVisual(code_obj); // in js/util/codeParser.js
+    if (result == null) { // force exception to "iassign-integration-functions.js" identify error in the current format try
+      console.log("js/util/iassignHelpers.js!setPreviousAlgorithm(code): returned empty");
+      return null;
+      // throw new Error("js/util/iassignHelpers.js!setPreviousAlgorithm(code): returned empty");
+      }
+    console.log("js/util/iassignHelpers.js!setPreviousAlgorithm(code): parserCodeVisual(.) returned: " + result);
+    return result;
+  } catch (e) {
     showInvalidData()
     console.log(e)
     return
+    }
   }
-}
 
 export function prepareActivityToStudentHelperJSON (ilm_cont) {
-  
   setTestCases(ilm_cont.test_cases)
-
   setActivityConfig(ilm_cont.settings)
-
   if (ilm_cont.code)
     setPreviousAlgorithm(ilm_cont.code)
   else 
     if (ilm_cont.algorithm)
       setPreviousAlgorithm(ilm_cont.algorithm)
-
-}
+  }
 
 export function prepareActivityToStudentHelper (ilm_cont, ignore_logs=false) {
   const maybe_content = parseActivityData(ilm_cont, ignore_logs);
@@ -90,7 +85,7 @@ export function prepareActivityToStudentHelper (ilm_cont, ignore_logs=false) {
       prog_type = content.settings_programming_type[0].value;
     } else {
       prog_type = "visual";
-    }
+      }
 
     return {
       settingsProgrammingType: prog_type,
@@ -99,9 +94,9 @@ export function prepareActivityToStudentHelper (ilm_cont, ignore_logs=false) {
       settingsFunctions: content.settings_functions,
       algorithmInIlm: content.algorithm_in_ilm,
       settingsFilter: content.settings_filter,
-    };
-  });
-}
+      };
+    });
+  }
 
 function compareArray (a, b) {
   for (let i = 0; i < a.length; ++i) {
@@ -109,27 +104,27 @@ function compareArray (a, b) {
     const elementB = b[i];
     if (elementA != elementB) {
       return false;
+      }
     }
-  }
   return true;
-}
+  }
 
 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;
+      }
     }
-  }
   return true;
-}
+  }
 
 export function autoEval (originalData, callback) {
   const code = generate();
@@ -138,31 +133,24 @@ export function autoEval (originalData, callback) {
   if (original == null) {
     alert("iAssign did not provide the original activity data!");
     return callback(null);
-  }
+    }
   if (code == null) {
     return callback(-1); // @FeedbackConvention Casos de teste vazios
   } else {
     if (!compareTestcases(original.testcases, getTestCases())) {
       return callback(-2); // @FeedbackConvention Casos de teste alterados pelo aluno
-    }
+      }
     try {
       const ast_code = SemanticAnalyser.analyseFromSource(code);
       const con = new TestConsole([]);
-      const autoAssessment = new IVProgAssessment(
-        ast_code,
-        original.testcases,
-        con
-      );
-      autoAssessment
-        .runTest()
-        .then((grade) => callback(grade))
-        .catch((err) => {
+      const autoAssessment = new IVProgAssessment(ast_code, original.testcases, con);
+      autoAssessment.runTest().then((grade) => callback(grade)).catch((err) => {
           console.log(err);
           callback(-5); // @FeedbackConvention Falha na execução
         });
     } catch (e) {
       console.error(e);
       callback(-5);
+      }
     }
-  }
-}
+  }