瀏覽代碼

New file format: export finished

Igor 2 年之前
父節點
當前提交
215cf25ae8
共有 3 個文件被更改,包括 56 次插入45 次删除
  1. 37 45
      js/iassign-integration-functions.js
  2. 9 0
      js/main.js
  3. 10 0
      js/util/config.ts

+ 37 - 45
js/iassign-integration-functions.js

@@ -61,77 +61,66 @@ function getAnswer () {
     objAnswer.code = generator();
     objAnswer.logs = ivprogCore.getLogs();
     objAnswer.settings = {
-      "functions": [],
-      "datatypes": [],
-      "commands": []
+      "programming": ivprogCore.Config.activity_programming_type,
+      "functions": ivprogCore.Config.activity_functions,
+      "datatypes": ivprogCore.Config.activity_datatypes,
+      "commands": ivprogCore.Config.activity_commands,
+      "filter": ivprogCore.Config.activity_filter
     };
 
-
     return JSON.stringify(objAnswer, null, 4);
 
   } else {
 
-    console.log('professor!!')
-    // Montar o retorno com a criação da atividade do professor
-    var ret = ' { ' + prepareTestCases()
-        + ',\n"settings_programming_type": \n' + JSON.stringify($('form[name="settings_programming_type"]').serializeArray())
-        + ',\n"settings_data_types": \n' + JSON.stringify($('form[name="settings_data_types"]').serializeArray())
-        + ',\n"settings_commands": \n' + JSON.stringify($('form[name="settings_commands"]').serializeArray())
-        + ',\n"settings_functions": \n' + JSON.stringify($('form[name="settings_functions"]').serializeArray())
-        + ',\n"settings_filter": \n' + JSON.stringify($('form[name="settings_filter"]').serializeArray())
-        + ' } ';
+    objAnswer.test_cases = prepareTestCases();
+
+    objAnswer.settings = {
+      "programming": $('form[name="settings_programming_type"]').serializeArray(),
+      "functions": $('form[name="settings_functions"]').serializeArray(),
+      "datatypes": $('form[name="settings_data_types"]').serializeArray(),
+      "commands": $('form[name="settings_commands"]').serializeArray(),
+      "filter": $('form[name="settings_filter"]').serializeArray()
+    };
 
     if ($("input[name='include_algo']").is(':checked')) {
-      ret += '\n::algorithm::';
-      ret += JSON.stringify(window.program_obj, function(key, value) {
-
-          if (key == 'dom_object') {
-              return;
-          }
-          return value;
-      });
+      objAnswer.algorithm = generator();
     }
 
-    return ret;
+    return JSON.stringify(objAnswer, null, 4);
   }
 }
 
 function prepareTestCases () {
-  var ret = ' \n "testcases" : [ '
+
   var test_cases_array = $('form[name="test_cases"]').serializeArray();
-  console.log(test_cases_array);
+
+  var cases = [];
+
   for (var i = 0; i < test_cases_array.length; i = i + 2) {
-    ret += '\n{ ';
-    ret += '\n "input": [';
+
+    var temp = new Object();
+
+    temp.input = [];
+    temp.output = [];
+
     var inps = test_cases_array[i].value.match(/[^\r\n]+/g);
     if (inps) {
       for (var j = 0; j < inps.length; j++) {
-        ret += '"' + inps[j] + '"';
-        if ((j + 1) < inps.length) {
-          ret += ', ';
-        }
+        temp.input.push(inps[j]);
       }
     }
-    ret += '], \n "output": [';
+    
     var outs = test_cases_array[i+1].value.match(/[^\r\n]+/g);
-    console.log(outs);
     if (outs) {
       for (var j = 0; j < outs.length; j++) {
-        console.log("output -> ",outs[j]);
-        ret += '"' + outs[j] + '"';
-        if ((j + 1) < outs.length) {
-          ret += ', ';
-        }
+        temp.output.push(outs[j]);
       }
     }
-    ret += ']';
-    ret += '\n}'
-    if ((i + 2) < test_cases_array.length) {
-      ret += ',';
-    }
+
+    cases.push(temp);
   }
-  ret += '\n] ';
-  return ret;
+  
+  return cases;
 }
 
 // Função chamada pelo iTarefa para receber a nota do aluno na atividade
@@ -504,6 +493,9 @@ function prepareTableTestCases (div_el) {
   $('.button_generate_outputs').on('click', function(e) {
     generateOutputs();
   });
+
+  if (!iLMparameters.iLM_PARAM_Assignment)
+    addTestCase();
 }
 
 function showAlert (msg) {
@@ -519,7 +511,7 @@ function generateOutputs () {
   // código:
   var code_teacher = window.generator();
   // array com as entradas já inseridas:
-  var test_cases = JSON.parse(prepareTestCases().replace('"testcases" :', ''));
+  var test_cases = prepareTestCases();
   ivprogCore.autoGenerateTestCaseOutput(code_teacher, test_cases).catch(function (error) {
     showAlert("Houve um erro durante a execução do seu programa: "+error.message);
   });

+ 9 - 0
js/main.js

@@ -37,6 +37,14 @@ const CodeEditor = {
   disable: CodeEditorAll.disable,
 };
 
+const Settings = {
+  programming: [],
+  functions: [],
+  datatypes: [],
+  commands: [],
+  filter: []
+}
+
 const i18n = i18nHelper.i18n;
 const LocalizedStrings = LocalizedStringsService.getInstance();
 
@@ -67,4 +75,5 @@ export {
   generate as generateCode,
   levenshteinDistance,
   processData,
+  Settings
 };

+ 10 - 0
js/util/config.ts

@@ -10,6 +10,11 @@ class ConfigObject implements ConfigInterface {
   public idle_input_interval: number;
   public suspend_threshold: number;
   public max_instruction_count: number;
+  public activity_programming_type: Map<string, string>;
+  public activity_functions: Map<string, boolean>;
+  public activity_datatypes: Map<string, boolean>;
+  public activity_commands: Map<string, boolean>;
+  public activity_filter: Map<string, boolean>;
   [id: string]: unknown;
 
   constructor () {
@@ -21,6 +26,11 @@ class ConfigObject implements ConfigInterface {
     this.suspend_threshold = 1000;
     // this.max_instruction_count = 350250; - automated evaluation limit
     this.max_instruction_count = Number.MAX_SAFE_INTEGER;
+    this.activity_programming_type = new Map<string, string>();
+    this.activity_functions = new Map<string, boolean>();
+    this.activity_datatypes = new Map<string, boolean>();
+    this.activity_commands = new Map<string, boolean>();
+    this.activity_filter = new Map<string, boolean>();
   }
 
   setConfig (opts: object): void {